15#include <QJsonDocument>
27 if ( nType == qMetaTypeId<QFileInfo>() )
28 return QVariant::fromValue< QFileInfo >( *((QFileInfo *)pValue) );
30 if (nType > QMetaType::User)
32 QObject *pObj = *((QObject **)pValue);
34 return QVariant::fromValue<QObject*>( pObj );
37#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
38 return { nType, pValue };
40 return QVariant( QMetaType(nType), pValue );
50 const QString &sParamType,
52 const QString &sValue )
59 case QMetaType::Bool : *((
bool *)pParam) =
ToBool( sValue );
break;
61 case QMetaType::Char : *((
char *)pParam) = ( sValue.length() > 0) ? sValue.at( 0 ).toLatin1() : 0;
break;
62 case QMetaType::UChar : *((
unsigned char *)pParam) = ( sValue.length() > 0) ? sValue.at( 0 ).toLatin1() : 0;
break;
63 case QMetaType::QChar : *(( QChar *)pParam) = ( sValue.length() > 0) ? sValue.at( 0 ) : QChar(0);
break;
65 case QMetaType::Short : *((
short *)pParam) = sValue.toShort ();
break;
66 case QMetaType::UShort : *(( ushort *)pParam) = sValue.toUShort ();
break;
68 case QMetaType::Int : *((
int *)pParam) = sValue.toInt ();
break;
69 case QMetaType::UInt : *((
uint *)pParam) = sValue.toUInt ();
break;
71 case QMetaType::Long : *((
long *)pParam) = sValue.toLong ();
break;
72 case QMetaType::ULong : *(( ulong *)pParam) = sValue.toULong ();
break;
74 case QMetaType::LongLong : *(( qlonglong *)pParam) = sValue.toLongLong ();
break;
75 case QMetaType::ULongLong : *(( qulonglong *)pParam) = sValue.toULongLong ();
break;
77 case QMetaType::Double : *((
double *)pParam) = sValue.toDouble ();
break;
78 case QMetaType::Float : *((
float *)pParam) = sValue.toFloat ();
break;
80 case QMetaType::QString : *(( QString *)pParam) = sValue;
break;
81 case QMetaType::QByteArray : *(( QByteArray *)pParam) = sValue.toUtf8 ();
break;
83 case QMetaType::QDateTime :
86#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
87 dt.setTimeSpec( Qt::UTC );
89 dt.setTimeZone( QTimeZone(QTimeZone::UTC) );
91 *(( QDateTime *)pParam) = dt;
96 case QMetaType::QJsonObject :
98 QJsonDocument doc = QJsonDocument::fromJson(sValue.toUtf8());
104 *(( QJsonObject *)pParam) = doc.object();
108 throw QString(
"Invalid JSON: %1").arg(sValue);
119 int nLastIdx = sParamType.lastIndexOf(
"::" );
124 QString sParentFQN = sParamType.mid( 0, nLastIdx );
125 QString sEnumName = sParamType.mid( nLastIdx+2 );
131#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
134 auto *pParentClass = (QObject *)QMetaType::create( nParentId );
135 if (pParentClass ==
nullptr)
138 const QMetaObject *pMetaObject = pParentClass->metaObject();
140 QMetaType::destroy( nParentId, pParentClass );
142 const QMetaObject *pMetaObject =
143 QMetaType::fromName( sParentFQN.toUtf8() ).metaObject();
150 int nEnumIdx = pMetaObject->indexOfEnumerator( sEnumName.toUtf8());
155 QMetaEnum metaEnum = pMetaObject->enumerator( nEnumIdx );
157 *((
int *)pParam) = metaEnum.keyToValue( sValue.toUtf8() );
171 if (sVal.compare(
"1", Qt::CaseInsensitive ) == 0)
174 if (sVal.compare(
"y", Qt::CaseInsensitive ) == 0)
177 if (sVal.compare(
"true", Qt::CaseInsensitive ) == 0)
virtual void * ConvertToParameterPtr(int nTypeId, const QString &sParamType, void *pParam, const QString &sValue)
static bool ToBool(const QString &sVal)
virtual QVariant ConvertToVariant(int nType, void *pValue)
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.