diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-09-16 16:41:27 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-09-23 14:54:46 +0200 |
commit | 8e222a70d19d5eef616e1d6306415da64fbab4cb (patch) | |
tree | 535e4cd02c2dbca0289bc6ec39f2699856554737 /tests/auto/qml/qqmlvaluetypeproviders | |
parent | 90b5d7fa03f9818fa5edc897ee6a109fcc182b9e (diff) |
Allow proper registration of value types
You can now have an extension object on a value type that offers
additional properties. This is how we model the QtQuick value types. It
allows us to retrieve the extension's metaobject without using the
virtual functions in the value type provider.
As before, this mechanism is still rather dangerous and not fit for
public consumption. It relies on the extension object having exactly the
same layout as the original value type, and it hides any properties the
original value type might expose.
Furthermore we enforce now that gadgets should have lowercase names.
The ones that didn't before are split up into an anonymous value type
and a namespace that contains all the addressable bits.
Task-number: QTBUG-82443
Change-Id: Ic93d6764538d6ccc0774b3c5648eee08ba0939c0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlvaluetypeproviders')
-rw-r--r-- | tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp | 33 |
1 files changed, 2 insertions, 31 deletions
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp b/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp index 6af32c4011..d95d378adb 100644 --- a/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp +++ b/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp @@ -225,33 +225,6 @@ public: void setProperty2(double p2) { v.setProperty2(p2); } }; -class TestValueTypeProvider : public QQmlValueTypeProvider -{ -public: - const QMetaObject *getMetaObjectForMetaType(int type) - { - if (type == qMetaTypeId<TestValue>()) - return &TestValueType::staticMetaObject; - - return nullptr; - } - -}; - -TestValueTypeProvider *getValueTypeProvider() -{ - static TestValueTypeProvider valueTypeProvider; - return &valueTypeProvider; -} - -bool initializeProviders() -{ - QQml_addValueTypeProvider(getValueTypeProvider()); - return true; -} - -const bool initialized = initializeProviders(); - class TestValueExporter : public QObject { Q_OBJECT @@ -271,11 +244,9 @@ private: void tst_qqmlvaluetypeproviders::userType() { - Q_ASSERT(initialized); - Q_ASSERT(qMetaTypeId<TestValue>() >= QMetaType::User); - - qRegisterMetaType<TestValue>(); + qmlRegisterExtendedType<TestValue, TestValueType>("Test", 1, 0, "test_value"); qmlRegisterTypesAndRevisions<TestValueExporter>("Test", 1); + Q_ASSERT(qMetaTypeId<TestValue>() >= QMetaType::User); TestValueExporter exporter; |