diff options
-rw-r--r-- | src/qml/qml/qqmlglobal.cpp | 52 | ||||
-rw-r--r-- | src/qml/qml/qqmlglobal_p.h | 4 | ||||
-rw-r--r-- | src/quick/util/qquickglobal.cpp | 136 |
3 files changed, 18 insertions, 174 deletions
diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp index 1c0bb41804..cd08a5270c 100644 --- a/src/qml/qml/qqmlglobal.cpp +++ b/src/qml/qml/qqmlglobal.cpp @@ -70,13 +70,11 @@ const QMetaObject *QQmlValueTypeProvider::metaObjectForMetaType(int type) bool QQmlValueTypeProvider::initValueType(int type, QVariant& dst) { - QQmlValueTypeProvider *p = this; - do { - if (p->init(type, dst)) - return true; - } while ((p = p->next)); - - return false; + const QMetaType metaType(type); + if (!metaType.isValid()) + return false; + dst = QVariant(QMetaType(type)); + return true; } QVariant QQmlValueTypeProvider::createValueType(int type, int argc, const void *argv[]) @@ -141,14 +139,7 @@ QVariant QQmlValueTypeProvider::createVariantFromJsObject(int type, const QV4::V bool QQmlValueTypeProvider::equalValueType(int type, const void *lhs, const QVariant& rhs) { Q_ASSERT(lhs); - - QQmlValueTypeProvider *p = this; - do { - if (p->equal(type, lhs, rhs)) - return true; - } while ((p = p->next)); - - return false; + return QMetaType(type).equals(lhs, rhs.constData()); } bool QQmlValueTypeProvider::storeValueType(int type, const void *src, void *dst, size_t dstSize) @@ -165,42 +156,35 @@ bool QQmlValueTypeProvider::storeValueType(int type, const void *src, void *dst, return false; } -bool QQmlValueTypeProvider::readValueType(const QVariant& src, void *dst, int dstType) +bool QQmlValueTypeProvider::readValueType(const QVariant& src, void *dst, int type) { Q_ASSERT(dst); + const QMetaType dstType(type); + if (!dstType.isValid() || (src.metaType() == dstType && dstType.equals(src.constData(), dst))) + return false; - QQmlValueTypeProvider *p = this; - do { - if (p->read(src, dst, dstType)) - return true; - } while ((p = p->next)); - - return false; + dstType.destruct(dst); + dstType.construct(dst, src.metaType() == dstType ? src.constData() : nullptr); + return true; } bool QQmlValueTypeProvider::writeValueType(int type, const void *src, QVariant& dst) { Q_ASSERT(src); + const QMetaType srcType(type); + if (!srcType.isValid() || (dst.metaType() == srcType && srcType.equals(src, dst.constData()))) + return false; - QQmlValueTypeProvider *p = this; - do { - if (p->write(type, src, dst)) - return true; - } while ((p = p->next)); - - return false; + dst = QVariant(srcType, src); + return true; } const QMetaObject *QQmlValueTypeProvider::getMetaObjectForMetaType(int) { return nullptr; } -bool QQmlValueTypeProvider::init(int, QVariant&) { return false; } bool QQmlValueTypeProvider::create(int, int, const void *[], QVariant *) { return false; } bool QQmlValueTypeProvider::createFromString(int, const QString &, void *, size_t) { return false; } bool QQmlValueTypeProvider::variantFromString(int, const QString &, QVariant *) { return false; } bool QQmlValueTypeProvider::variantFromJsObject(int, const QV4::Value &, QV4::ExecutionEngine *, QVariant *) { return false; } -bool QQmlValueTypeProvider::equal(int, const void *, const QVariant&) { return false; } bool QQmlValueTypeProvider::store(int, const void *, void *, size_t) { return false; } -bool QQmlValueTypeProvider::read(const QVariant&, void *, int) { return false; } -bool QQmlValueTypeProvider::write(int, const void *, QVariant&) { return false; } struct ValueTypeProviderList { QQmlValueTypeProvider nullProvider; diff --git a/src/qml/qml/qqmlglobal_p.h b/src/qml/qml/qqmlglobal_p.h index f2a11e5456..3c03753d08 100644 --- a/src/qml/qml/qqmlglobal_p.h +++ b/src/qml/qml/qqmlglobal_p.h @@ -239,7 +239,6 @@ public: private: virtual const QMetaObject *getMetaObjectForMetaType(int); - virtual bool init(int, QVariant&); virtual bool create(int, int, const void *[], QVariant *); virtual bool createFromString(int, const QString &, void *, size_t); @@ -247,10 +246,7 @@ private: virtual bool variantFromString(int, const QString &, QVariant *); virtual bool variantFromJsObject(int, const QV4::Value &, QV4::ExecutionEngine *, QVariant *); - virtual bool equal(int, const void *, const QVariant&); virtual bool store(int, const void *, void *, size_t); - virtual bool read(const QVariant&, void *, int); - virtual bool write(int, const void *, QVariant&); friend Q_QML_PRIVATE_EXPORT void QQml_addValueTypeProvider(QQmlValueTypeProvider *); friend Q_QML_PRIVATE_EXPORT void QQml_removeValueTypeProvider(QQmlValueTypeProvider *); diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index e6000e352a..bf636407ed 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -607,39 +607,6 @@ public: return nullptr; } - bool init(int type, QVariant& dst) override - { - switch (type) { - case QMetaType::QColor: - dst.setValue<QColor>(QColor()); - return true; - case QMetaType::QColorSpace: - dst.setValue<QColorSpace>(QColorSpace()); - return true; - case QMetaType::QFont: - dst.setValue<QFont>(QFont()); - return true; - case QMetaType::QVector2D: - dst.setValue<QVector2D>(QVector2D()); - return true; - case QMetaType::QVector3D: - dst.setValue<QVector3D>(QVector3D()); - return true; - case QMetaType::QVector4D: - dst.setValue<QVector4D>(QVector4D()); - return true; - case QMetaType::QQuaternion: - dst.setValue<QQuaternion>(QQuaternion()); - return true; - case QMetaType::QMatrix4x4: - dst.setValue<QMatrix4x4>(QMatrix4x4()); - return true; - default: break; - } - - return false; - } - bool create(int type, int argc, const void *argv[], QVariant *v) override { switch (type) { @@ -797,37 +764,6 @@ public: } template<typename T> - bool typedEqual(const void *lhs, const QVariant& rhs) - { - return (*(reinterpret_cast<const T *>(lhs)) == rhs.value<T>()); - } - - bool equal(int type, const void *lhs, const QVariant &rhs) override - { - switch (type) { - case QMetaType::QColor: - return typedEqual<QColor>(lhs, rhs); - case QMetaType::QColorSpace: - return typedEqual<QColorSpace>(lhs, rhs); - case QMetaType::QFont: - return typedEqual<QFont>(lhs, rhs); - case QMetaType::QVector2D: - return typedEqual<QVector2D>(lhs, rhs); - case QMetaType::QVector3D: - return typedEqual<QVector3D>(lhs, rhs); - case QMetaType::QVector4D: - return typedEqual<QVector4D>(lhs, rhs); - case QMetaType::QQuaternion: - return typedEqual<QQuaternion>(lhs, rhs); - case QMetaType::QMatrix4x4: - return typedEqual<QMatrix4x4>(lhs, rhs); - default: break; - } - - return false; - } - - template<typename T> bool typedStore(const void *src, void *dst, size_t dstSize) { ASSERT_VALID_SIZE(dstSize, sizeof(T)); @@ -855,78 +791,6 @@ public: return false; } - template<typename T> - bool typedRead(const QVariant& src, int dstType, void *dst) - { - T *dstT = reinterpret_cast<T *>(dst); - if (src.userType() == dstType) { - *dstT = src.value<T>(); - } else { - *dstT = T(); - } - return true; - } - - bool read(const QVariant &src, void *dst, int dstType) override - { - switch (dstType) { - case QMetaType::QColor: - return typedRead<QColor>(src, dstType, dst); - case QMetaType::QColorSpace: - return typedRead<QColorSpace>(src, dstType, dst); - case QMetaType::QFont: - return typedRead<QFont>(src, dstType, dst); - case QMetaType::QVector2D: - return typedRead<QVector2D>(src, dstType, dst); - case QMetaType::QVector3D: - return typedRead<QVector3D>(src, dstType, dst); - case QMetaType::QVector4D: - return typedRead<QVector4D>(src, dstType, dst); - case QMetaType::QQuaternion: - return typedRead<QQuaternion>(src, dstType, dst); - case QMetaType::QMatrix4x4: - return typedRead<QMatrix4x4>(src, dstType, dst); - default: break; - } - - return false; - } - - template<typename T> - bool typedWrite(const void *src, QVariant& dst) - { - const T *srcT = reinterpret_cast<const T *>(src); - if (dst.value<T>() != *srcT) { - dst = *srcT; - return true; - } - return false; - } - - bool write(int type, const void *src, QVariant& dst) override - { - switch (type) { - case QMetaType::QColor: - return typedWrite<QColor>(src, dst); - case QMetaType::QColorSpace: - return typedWrite<QColorSpace>(src, dst); - case QMetaType::QFont: - return typedWrite<QFont>(src, dst); - case QMetaType::QVector2D: - return typedWrite<QVector2D>(src, dst); - case QMetaType::QVector3D: - return typedWrite<QVector3D>(src, dst); - case QMetaType::QVector4D: - return typedWrite<QVector4D>(src, dst); - case QMetaType::QQuaternion: - return typedWrite<QQuaternion>(src, dst); - case QMetaType::QMatrix4x4: - return typedWrite<QMatrix4x4>(src, dst); - default: break; - } - - return false; - } #undef ASSERT_VALID_SIZE }; |