From 6f968781c4c8a278a7743b0904fb2bdf4c6ddf1a Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 28 Oct 2020 16:48:53 +0100 Subject: QML: Allow namespaces as extensions to types This way we can access the enums of namespaces as properties of the primary type. This is achieved by: 1. Making enums of extended types available in the base type 2. Allowing the extension to be specified as plain metaObject rather than as type name. 3. Refraining from creating the extension if the create function does not exist. The goal of this is to declare the Qt namespace in a civilized way, but will also help with cleaning up the QtQuick value types and their enums. Change-Id: I13399741d30ce38d1bff753cfa1b11e72ccfbf6a Reviewed-by: Fabian Kosmale --- tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp') diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 4e8e668c18..74b7c0e64e 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -340,6 +340,7 @@ private slots: void checkURLtoURLObject(); void registerValueTypes(); + void extendedNamespace(); private: QQmlEngine engine; @@ -6027,6 +6028,26 @@ void tst_qqmllanguage::accessNullPointerPropertyCache() QVERIFY(!obj.isNull()); } +void tst_qqmllanguage::extendedNamespace() +{ + QQmlEngine engine; + QQmlComponent c(&engine); + c.setData("import StaticTest\n" + "import QtQml\n" + "ExtendedByNamespace {\n" + " property int mine: own\n" + " property int myEnum: ExtendedByNamespace.Moo\n" + " property int fromExtension: ExtendedByNamespace.Bar\n" + "}", QUrl()); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer obj(c.create()); + QVERIFY(!obj.isNull()); + + QCOMPARE(obj->property("mine").toInt(), 93); + QCOMPARE(obj->property("myEnum").toInt(), 16); + QCOMPARE(obj->property("fromExtension").toInt(), 9); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" -- cgit v1.2.3