diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-07-13 10:02:40 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-08-24 00:17:12 +0200 |
commit | f44d2ea1cc14587ab8f0ba3a36f10ab3bee34504 (patch) | |
tree | a425baced649b220a2372456df3c138fefe3dd12 /src/corelib/kernel | |
parent | 560a419281651b3a66d726d736c170f9eeae4bd6 (diff) |
Always try to conversions through QMetaType
Always ask QMetaType to convert first before trying the builtin
code in QVariant. That way we can migrate conversions piece by
piece to QMetaType.
Change-Id: I4fd1bad3ef045d37f84f68e748a6357e0ee0c16c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 80aefa0c4d..137c2bb783 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -2462,11 +2462,9 @@ inline T qVariantToHelper(const QVariant::Private &d) return d.get<T>(); T ret; - if (d.typeId() >= QMetaType::LastCoreType || targetType.id() >= QMetaType::LastCoreType) { - const void * const from = d.storage(); - if (QMetaType::convert(from, d.typeId(), &ret, targetType.id())) - return ret; - } + const void * const from = d.storage(); + if (QMetaType::convert(from, d.typeId(), &ret, targetType.id())) + return ret; convert(&d, targetType.id(), &ret); return ret; @@ -2896,8 +2894,7 @@ inline T qNumVariantToHelper(const QVariant::Private &d, bool *ok, const T& val) return val; T ret = 0; - if ((d.typeId() >= QMetaType::LastCoreType || t >= QMetaType::LastCoreType) - && QMetaType::convert(d.storage(), d.typeId(), &ret, t)) + if (QMetaType::convert(d.storage(), d.typeId(), &ret, t)) return ret; bool success = convert(&d, t, &ret); @@ -3003,11 +3000,8 @@ bool QVariant::toBool() const bool res = false; - if (d.typeId() >= QMetaType::LastCoreType) { - const void * const from = constData(); - if (QMetaType::convert(from, d.typeId(), &res, QMetaType::Bool)) - return res; - } + if (QMetaType::convert(constData(), d.typeId(), &res, QMetaType::Bool)) + return res; ::convert(&d, Bool, &res); @@ -3547,10 +3541,7 @@ bool QVariant::convert(int targetTypeId) } bool isOk = false; - if (oldValue.d.typeId() >= QMetaType::LastCoreType || targetTypeId >= QMetaType::LastCoreType) { - const void * const from = oldValue.constData(); - isOk = QMetaType::convert(from, oldValue.d.typeId(), data(), targetTypeId); - } + isOk = QMetaType::convert(oldValue.constData(), oldValue.d.typeId(), data(), targetTypeId); if (!isOk) isOk = ::convert(&oldValue.d, targetTypeId, data()); @@ -3565,11 +3556,8 @@ bool QVariant::convert(int targetTypeId) */ bool QVariant::convert(const int type, void *ptr) const { - if (d.typeId() >= QMetaType::LastCoreType || type >= QMetaType::LastCoreType) { - const void * const from = constData(); - if (QMetaType::convert(from, d.typeId(), ptr, type)) - return true; - } + if (QMetaType::convert(constData(), d.typeId(), ptr, type)) + return true; return ::convert(&d, type, ptr); } |