diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2022-05-16 12:45:44 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2022-05-23 12:50:02 +0200 |
commit | cfbc5ecf2af04e4c0ae6053081b2fa47e8ac5ca8 (patch) | |
tree | 4d73675c7a379b3704f4b5a38bbcfd6c703ecd7c /tests | |
parent | 560a47590fc0c22c18ca91fee56176e2501561f6 (diff) |
QML: Correctly detect extended types
Introduce a compile-time procedure to distinguish types without
extensions but with base type extensions from types with direct
extensions. Previously, we would have treated both cases the
same due to the C++ mechanism employed to mark a type as
extension-containing
As a drive by, make QQmlMetaType::clone() use class name of the
extension when we clone the extension
[ChangeLog][Important Behavior Changes] A derived type is no longer
considered to be extended itself when only its base type is extended.
Instead, the extension only exists on the base type.
Change-Id: I74092a5f88cad09c1e07626ae90bb986db0da73d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmllanguage/testtypes.h | 8 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 37 |
2 files changed, 39 insertions, 6 deletions
diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h index ca42ae02bc..54022b268f 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.h +++ b/tests/auto/qml/qqmllanguage/testtypes.h @@ -1629,6 +1629,14 @@ public: int own() const { return 93; } }; +class ExtendedByNamespaceInParent : public ExtendedByNamespace +{ + Q_OBJECT + QML_ELEMENT +public: + ExtendedByNamespaceInParent(QObject *parent = nullptr) : ExtendedByNamespace(parent) { } +}; + class ExtendedNamespaceByObject : public QObject { Q_OBJECT diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index bfcd146b10..81d6e6f6a0 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -367,6 +367,7 @@ private slots: void multiExtension(); void multiExtensionExtra(); void multiExtensionIndirect(); + void multiExtensionQmlTypes(); void extensionSpecial(); void invalidInlineComponent(); void warnOnInjectedParameters(); @@ -6441,15 +6442,11 @@ void tst_qqmllanguage::multiExtensionExtra() QCOMPARE(QQmlPrivate::qmlExtendedObject(o.get(), 0), extension); - QObject *pseudoExtension = QQmlPrivate::qmlExtendedObject(o.get(), 1); - QVERIFY(pseudoExtension); - QVERIFY(qobject_cast<ExtensionB *>(pseudoExtension) != nullptr); - - QObject *baseBaseTypeExtension = QQmlPrivate::qmlExtendedObject(o.get(), 2); + QObject *baseBaseTypeExtension = QQmlPrivate::qmlExtendedObject(o.get(), 1); QVERIFY(baseBaseTypeExtension); QVERIFY(qobject_cast<ExtensionB *>(baseBaseTypeExtension) != nullptr); - QObject *baseBaseBaseTypeExtension = QQmlPrivate::qmlExtendedObject(o.get(), 3); + QObject *baseBaseBaseTypeExtension = QQmlPrivate::qmlExtendedObject(o.get(), 2); QVERIFY(baseBaseBaseTypeExtension); QVERIFY(qobject_cast<ExtensionA *>(baseBaseBaseTypeExtension) != nullptr); } @@ -6473,6 +6470,34 @@ void tst_qqmllanguage::multiExtensionIndirect() QCOMPARE(o->property("g").toInt(), 44); // NB: taken from the type, not from the extension! } +void tst_qqmllanguage::multiExtensionQmlTypes() +{ + QQmlType extendedType = QQmlMetaType::qmlType(&MultiExtensionParent::staticMetaObject, + QStringLiteral("StaticTest"), QTypeRevision()); + QVERIFY(extendedType.isValid()); + QVERIFY(extendedType.extensionFunction()); + QVERIFY(extendedType.extensionMetaObject() != nullptr); + + QQmlType nonExtendedType = QQmlMetaType::qmlType(&ExtendedInParent::staticMetaObject, + QStringLiteral("StaticTest"), QTypeRevision()); + QVERIFY(nonExtendedType.isValid()); + QVERIFY(!nonExtendedType.extensionFunction()); + QCOMPARE(nonExtendedType.extensionMetaObject(), nullptr); + + QQmlType namespaceExtendedType = QQmlMetaType::qmlType( + &ExtendedByNamespace::staticMetaObject, QStringLiteral("StaticTest"), QTypeRevision()); + QVERIFY(namespaceExtendedType.isValid()); + QVERIFY(!namespaceExtendedType.extensionFunction()); // namespaces are non-creatable + QVERIFY(namespaceExtendedType.extensionMetaObject() != nullptr); + + QQmlType namespaceNonExtendedType = + QQmlMetaType::qmlType(&ExtendedByNamespaceInParent::staticMetaObject, + QStringLiteral("StaticTest"), QTypeRevision()); + QVERIFY(namespaceNonExtendedType.isValid()); + QVERIFY(!namespaceNonExtendedType.extensionFunction()); + QCOMPARE(namespaceNonExtendedType.extensionMetaObject(), nullptr); +} + void tst_qqmllanguage::extensionSpecial() { QQmlEngine engine; |