From f5cb65b35e076facbce45e896902a34da7036135 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 26 Jun 2012 18:02:35 +1000 Subject: Fix broken value-type support by allowing property definition In QtQuick 1.x the "variant" property type was supported, which could be used to allow value type properties to be defined in QML. In QtQuick 2.0, we have deprecated the "variant" property, but its replacement ("var") is not suited for defining lightweight C++ type values (such as QColor, QFont, QRectF, QVector3D etc). This commit allows those QML basic types to be used in QML once more, by supporting them in the property definition syntax. Note that since some value types are provided by QtQuick and others are provided by QtQml, if a client imports only QtQml they can define but not use properties of certain types (eg, font). Task-number: QTBUG-21034 Task-number: QTBUG-18217 Change-Id: Ia951a8522f223408d27293bb96c276281a710277 Reviewed-by: Matthew Vogt --- src/qml/qml/qqmlglobal.cpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/qml/qml/qqmlglobal.cpp') diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp index 6f4942963f..0ebc802dec 100644 --- a/src/qml/qml/qqmlglobal.cpp +++ b/src/qml/qml/qqmlglobal.cpp @@ -175,42 +175,58 @@ QVariant QQmlValueTypeProvider::createVariantFromString(int type, const QString return QVariant(); } -bool QQmlValueTypeProvider::equalValueType(int type, const void *lhs, const void *rhs) +QVariant QQmlValueTypeProvider::createVariantFromJsObject(int type, QQmlV8Handle obj, QV8Engine *e, bool *ok) +{ + QVariant v; + + QQmlValueTypeProvider *p = this; + do { + if (p->variantFromJsObject(type, obj, e, &v)) { + if (ok) *ok = true; + return v; + } + } while ((p = p->next)); + + if (ok) *ok = false; + return QVariant(); +} + +bool QQmlValueTypeProvider::equalValueType(int type, const void *lhs, const void *rhs, size_t rhsSize) { Q_ASSERT(lhs); Q_ASSERT(rhs); QQmlValueTypeProvider *p = this; do { - if (p->equal(type, lhs, rhs)) + if (p->equal(type, lhs, rhs, rhsSize)) return true; } while ((p = p->next)); return false; } -bool QQmlValueTypeProvider::storeValueType(int type, const void *src, void *dst, size_t n) +bool QQmlValueTypeProvider::storeValueType(int type, const void *src, void *dst, size_t dstSize) { Q_ASSERT(src); Q_ASSERT(dst); QQmlValueTypeProvider *p = this; do { - if (p->store(type, src, dst, n)) + if (p->store(type, src, dst, dstSize)) return true; } while ((p = p->next)); return false; } -bool QQmlValueTypeProvider::readValueType(int srcType, const void *src, int dstType, void *dst) +bool QQmlValueTypeProvider::readValueType(int srcType, const void *src, size_t srcSize, int dstType, void *dst) { Q_ASSERT(src); Q_ASSERT(dst); QQmlValueTypeProvider *p = this; do { - if (p->read(srcType, src, dstType, dst)) + if (p->read(srcType, src, srcSize, dstType, dst)) return true; } while ((p = p->next)); @@ -240,9 +256,10 @@ bool QQmlValueTypeProvider::createFromString(int, const QString &, void *, size_ bool QQmlValueTypeProvider::createStringFrom(int, const void *, QString *) { return false; } bool QQmlValueTypeProvider::variantFromString(const QString &, QVariant *) { return false; } bool QQmlValueTypeProvider::variantFromString(int, const QString &, QVariant *) { return false; } -bool QQmlValueTypeProvider::equal(int, const void *, const void *) { return false; } +bool QQmlValueTypeProvider::variantFromJsObject(int, QQmlV8Handle, QV8Engine *, QVariant *) { return false; } +bool QQmlValueTypeProvider::equal(int, const void *, const void *, size_t) { return false; } bool QQmlValueTypeProvider::store(int, const void *, void *, size_t) { return false; } -bool QQmlValueTypeProvider::read(int, const void *, int, void *) { return false; } +bool QQmlValueTypeProvider::read(int, const void *, size_t, int, void *) { return false; } bool QQmlValueTypeProvider::write(int, const void *, void *, size_t) { return false; } static QQmlValueTypeProvider *valueTypeProvider = 0; @@ -266,10 +283,6 @@ Q_QML_PRIVATE_EXPORT void QQml_addValueTypeProvider(QQmlValueTypeProvider *newPr Q_AUTOTEST_EXPORT QQmlValueTypeProvider *QQml_valueTypeProvider(void) { - if (valueTypeProvider == 0) { - qWarning() << "Warning: QQml_valueTypeProvider: no value type provider has been set!"; - } - static QQmlValueTypeProvider **providerPtr = getValueTypeProvider(); return *providerPtr; } -- cgit v1.2.3