diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2014-11-10 11:39:03 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2014-12-22 21:48:11 +0100 |
commit | fa3cf15e0577fe382ac577456422ad78325a3977 (patch) | |
tree | 3323ab526433f73fb644b1692c10629f01093d62 /tests/auto/qml/qqmlvaluetypeproviders | |
parent | ee771dda2e9e304edea88e6d5f6e6d540a0bab97 (diff) |
Initial work on gadget support
Changed built-in QtQml value types to use gadgets. This is in preparation for
supporting external gadgets.
This replaces the mostly direct inheritance of the concrete value types with
gadgets and "dynamic" inheritance through QQmlValueType being generic. Over
time as some of the value types may become gadgets, we can remove the ones
here. It's important that these "separate" gadgets have the same memory layout
as the actual types (QPointF, etc.).
Also while QQmlValueType remains practically a singleton, it's not required
anymore to be one. Consequently the JS wrappers for value types keep their own
instance of QQmlValueType. This allows eliminating the qobject_cast in various
places that dealt with the singleton nature. This comes at a cost, making the
JS wrappers slightly heavier. However that is meant to be a temporary situation
and finally the value type wrapper should merely store the meta-object in
addition to the data and the type.
Change-Id: I15071ded0a1e54203f29ec1ecf7a9ab646d1168e
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto/qml/qqmlvaluetypeproviders')
-rw-r--r-- | tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp b/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp index fdbcc0dbf2..cdbad96b2f 100644 --- a/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp +++ b/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp @@ -199,6 +199,8 @@ public: bool operator==(const TestValue &other) const { return (m_p1 == other.m_p1) && (m_p2 == other.m_p2); } bool operator!=(const TestValue &other) const { return !operator==(other); } + bool operator<(const TestValue &other) const { if (m_p1 < other.m_p1) return true; return m_p2 < other.m_p2; } + private: int m_p1; double m_p2; @@ -210,16 +212,14 @@ Q_DECLARE_METATYPE(TestValue); namespace { -class TestValueType : public QQmlValueTypeBase<TestValue> +class TestValueType { - Q_OBJECT + TestValue v; + Q_GADGET Q_PROPERTY(int property1 READ property1 WRITE setProperty1) Q_PROPERTY(double property2 READ property2 WRITE setProperty2) public: - TestValueType(QObject *parent = 0) : QQmlValueTypeBase<TestValue>(qMetaTypeId<TestValue>(), parent) {} - - virtual QString toString() const { return QString::number(property1()) + QLatin1Char(',') + QString::number(property2()); } - virtual bool isEqual(const QVariant &other) const { return (other.userType() == qMetaTypeId<TestValue>()) && (v == other.value<TestValue>()); } + Q_INVOKABLE QString toString() const { return QString::number(property1()) + QLatin1Char(',') + QString::number(property2()); } int property1() const { return v.property1(); } void setProperty1(int p1) { v.setProperty1(p1); } @@ -231,14 +231,12 @@ public: class TestValueTypeProvider : public QQmlValueTypeProvider { public: - bool create(int type, QQmlValueType *&v) + const QMetaObject *getMetaObjectForMetaType(int type) { - if (type == qMetaTypeId<TestValue>()) { - v = new TestValueType; - return true; - } + if (type == qMetaTypeId<TestValue>()) + return &TestValueType::staticMetaObject; - return false; + return 0; } }; @@ -279,6 +277,7 @@ void tst_qqmlvaluetypeproviders::userType() Q_ASSERT(qMetaTypeId<TestValue>() >= QMetaType::User); qRegisterMetaType<TestValue>(); + QMetaType::registerComparators<TestValue>(); qmlRegisterType<TestValueExporter>("Test", 1, 0, "TestValueExporter"); TestValueExporter exporter; |