summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qvariant.cpp
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@digia.com>2013-05-06 10:26:38 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-06-14 15:50:49 +0200
commitd57d184b6d18deab172ac400b9db973e6aacab21 (patch)
treeb2f1df0d7472ec836722f5597953636c81f4779e /src/corelib/kernel/qvariant.cpp
parentaf2deb85caa5e179ce1bd6b7031af757eadc3ba9 (diff)
Add basic conversion functions from QVariant(QJsonValue).
There is a mismatch how QML and C++ converts QJsonValue. This patch unifies conversions by adding QJsonValue support in QVariant::convert(). Change-Id: I8a1db3d77c517945ef48064b4b66ba03aa4f2fd0 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Diffstat (limited to 'src/corelib/kernel/qvariant.cpp')
-rw-r--r--src/corelib/kernel/qvariant.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index bae4a837a0..276257ddcf 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -162,6 +162,10 @@ static qlonglong qMetaTypeNumber(const QVariant::Private *d)
return qRound64(d->data.f);
case QVariant::Double:
return qRound64(d->data.d);
+#ifndef QT_BOOTSTRAPPED
+ case QMetaType::QJsonValue:
+ return v_cast<QJsonValue>(d)->toDouble();
+#endif
}
Q_ASSERT(false);
return 0;
@@ -206,12 +210,14 @@ static qlonglong qConvertToNumber(const QVariant::Private *d, bool *ok)
case QMetaType::Long:
case QMetaType::Float:
case QMetaType::LongLong:
+ case QMetaType::QJsonValue:
return qMetaTypeNumber(d);
case QVariant::ULongLong:
case QVariant::UInt:
case QMetaType::UChar:
case QMetaType::UShort:
case QMetaType::ULong:
+
return qlonglong(qMetaTypeUNumber(d));
}
@@ -240,6 +246,7 @@ static qulonglong qConvertToUnsignedNumber(const QVariant::Private *d, bool *ok)
case QMetaType::Long:
case QMetaType::Float:
case QMetaType::LongLong:
+ case QMetaType::QJsonValue:
return qulonglong(qMetaTypeNumber(d));
case QVariant::ULongLong:
case QVariant::UInt:
@@ -340,6 +347,9 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
case QVariant::Url:
*str = v_cast<QUrl>(d)->toString();
break;
+ case QMetaType::QJsonValue:
+ *str = v_cast<QJsonValue>(d)->toString();
+ break;
#endif
case QVariant::Uuid:
*str = v_cast<QUuid>(d)->toString();
@@ -580,6 +590,11 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
case QMetaType::ULong:
*b = qMetaTypeUNumber(d) != Q_UINT64_C(0);
break;
+#ifndef QT_BOOTSTRAPPED
+ case QMetaType::QJsonValue:
+ *b = v_cast<QJsonValue>(d)->toBool();
+ break;
+#endif
default:
*b = false;
return false;
@@ -616,6 +631,11 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
case QMetaType::ULong:
*f = double(qMetaTypeUNumber(d));
break;
+#ifndef QT_BOOTSTRAPPED
+ case QMetaType::QJsonValue:
+ *f = v_cast<QJsonValue>(d)->toDouble();
+ break;
+#endif
default:
*f = 0.0;
return false;
@@ -652,6 +672,11 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
case QMetaType::ULong:
*f = float(qMetaTypeUNumber(d));
break;
+#ifndef QT_BOOTSTRAPPED
+ case QMetaType::QJsonValue:
+ *f = v_cast<QJsonValue>(d)->toDouble();
+ break;
+#endif
default:
*f = 0.0f;
return false;
@@ -2731,6 +2756,29 @@ bool QVariant::canConvert(int targetTypeId) const
if (targetTypeId >= QMetaType::User)
return canConvertMetaObject(currentType, targetTypeId, d.data.o);
+ if (currentType == QMetaType::QJsonValue) {
+ switch (targetTypeId) {
+ case QMetaType::QString:
+ case QMetaType::Bool:
+ case QMetaType::Int:
+ case QMetaType::UInt:
+ case QMetaType::Double:
+ case QMetaType::Float:
+ case QMetaType::ULong:
+ case QMetaType::Long:
+ case QMetaType::LongLong:
+ case QMetaType::ULongLong:
+ case QMetaType::UShort:
+ case QMetaType::UChar:
+ case QMetaType::Char:
+ case QMetaType::SChar:
+ case QMetaType::Short:
+ return true;
+ default:
+ return false;
+ }
+ }
+
// FIXME It should be LastCoreType intead of Uuid
if (currentType > int(QMetaType::QUuid) || targetTypeId > int(QMetaType::QUuid)) {
switch (uint(targetTypeId)) {