aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@qt.io>2018-09-18 12:03:09 +0200
committerKai Koehne <kai.koehne@qt.io>2018-10-09 07:50:37 +0000
commitb7f5d34602e72eeda6620ea3e4326c6ff26b52d5 (patch)
tree5525654e04a9cad638eb925802e9b0f54e8e4bf5 /tests/auto/qml
parent9aa954e20e9fd02581d7334bda32deeb09752e66 (diff)
qmlplugindump: Properly handle extension types
Extension classes do augment the primary C++ class with additional properties that should be part of the QML type. Anyhow, they should not be visible in the API. The old logic tried to emulate this by making the extension class the actual C++ type, and 'inheriting' from the normal class by setting it in the prototype. Anyhow, this failed for e.g. Qt3D, where there are numerous types sharing the same extension class. Instead, this patch fixes the issue a) hiding the extension class metainformation itself, and b) printing properties of the extension class as part of the main type. In the QMetaObject collection phase, we now traverse the class hierarchy using QQmlType::baseMetaObject instead of QQmlType::metaObject. In the generation phase, we explicitly resolve the extended type, and dump additional properties and "DefaultProperty" information into the main type description. Note that the ExtendedType sets the DefaultProperty independent of the version. Changing this would require either revisioning the defaultProperty, or (again) splitting up the types, which however brings other problems. Task-number: QTBUG-70294 Change-Id: I324469152398a605fae9e5a35b619845444ac4e8 Reviewed-by: Marco Benelli <marco.benelli@qt.io>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/extendedtype.pro22
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/plugin.cpp40
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/plugin.h43
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/plugins.qmltypes35
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/qmldir3
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/types.h86
-rw-r--r--tests/auto/qml/qmlplugindump/qmlplugindump.pro3
-rw-r--r--tests/auto/qml/qmlplugindump/tst_qmlplugindump.cpp2
8 files changed, 233 insertions, 1 deletions
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/extendedtype.pro b/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/extendedtype.pro
new file mode 100644
index 0000000000..24243aa622
--- /dev/null
+++ b/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/extendedtype.pro
@@ -0,0 +1,22 @@
+TEMPLATE = lib
+TARGET = ExtendedType
+QT += qml
+CONFIG += qt plugin
+
+CONFIG -= debug_and_release_target
+!build_pass:qtConfig(debug_and_release): CONFIG += release
+
+TARGET = $$qtLibraryTarget($$TARGET)
+
+SOURCES += \
+ plugin.cpp
+
+HEADERS += \
+ plugin.h \
+ types.h
+
+!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
+ cp.files = qmldir plugins.qmltypes
+ cp.path = $$OUT_PWD
+ COPIES += cp
+}
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/plugin.cpp b/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/plugin.cpp
new file mode 100644
index 0000000000..423fbc1f4c
--- /dev/null
+++ b/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/plugin.cpp
@@ -0,0 +1,40 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "plugin.h"
+#include "types.h"
+
+#include <qqml.h>
+
+void Plugin::registerTypes(const char *uri)
+{
+ // @uri dumper.ExtendedType
+ qmlRegisterType<Type>(uri, 1, 0, "Type");
+ qmlRegisterExtendedType<Type, ExtendedType>(uri, 1, 1, "Type");
+ qmlRegisterType<DerivedType2>(uri, 1, 1, "DerivedType");
+}
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/plugin.h b/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/plugin.h
new file mode 100644
index 0000000000..b677fe2940
--- /dev/null
+++ b/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/plugin.h
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PLUGIN_H
+#define PLUGIN_H
+
+#include <QQmlExtensionPlugin>
+
+class Plugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
+
+public:
+ void registerTypes(const char *uri);
+};
+
+#endif // PLUGIN_H
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/plugins.qmltypes b/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/plugins.qmltypes
new file mode 100644
index 0000000000..d84eb0011a
--- /dev/null
+++ b/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/plugins.qmltypes
@@ -0,0 +1,35 @@
+import QtQuick.tooling 1.2
+
+// This file describes the plugin-supplied types contained in the library.
+// It is used for QML tooling purposes only.
+//
+// This file was auto-generated by:
+// 'qmlplugindump -nonrelocatable -noforceqtquick dumper.ExtendedType 1.1 .'
+
+Module {
+ dependencies: []
+ Component {
+ name: "DerivedType1"
+ prototype: "Type"
+ Property { name: "m_exendedProperty2"; type: "int" }
+ }
+ Component {
+ name: "DerivedType2"
+ prototype: "DerivedType1"
+ exports: ["dumper.ExtendedType/DerivedType 1.1"]
+ exportMetaObjectRevisions: [0]
+ }
+ Component {
+ name: "Type"
+ defaultProperty: "data"
+ prototype: "QObject"
+ exports: [
+ "dumper.ExtendedType/Type 1.0",
+ "dumper.ExtendedType/Type 1.1"
+ ]
+ exportMetaObjectRevisions: [0, 101]
+ Property { name: "baseProperty"; type: "int" }
+ Property { name: "extendedProperty"; revision: 101; type: "int" }
+ Property { name: "data"; revision: 101; type: "QObject"; isList: true; isReadonly: true }
+ }
+}
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/qmldir b/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/qmldir
new file mode 100644
index 0000000000..6693f403d9
--- /dev/null
+++ b/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/qmldir
@@ -0,0 +1,3 @@
+module dumper.ExtendedType
+plugin ExtendedType
+
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/types.h b/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/types.h
new file mode 100644
index 0000000000..dfba55a094
--- /dev/null
+++ b/tests/auto/qml/qmlplugindump/data/dumper/ExtendedType/types.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TYPES_H
+#define TYPES_H
+
+#include <QObject>
+#include <QQmlListProperty>
+
+class Type : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int baseProperty MEMBER m_baseProperty)
+
+public:
+ Type(QObject *parent = nullptr)
+ : QObject(parent) {}
+
+private:
+ int m_baseProperty;
+};
+
+class ExtendedType : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int extendedProperty MEMBER m_extendedProperty)
+ Q_PROPERTY(QQmlListProperty<QObject> data READ data)
+ Q_CLASSINFO("DefaultProperty", "data")
+
+public:
+ ExtendedType(QObject *parent = nullptr)
+ : QObject(parent) {}
+ QQmlListProperty<QObject> data() { return QQmlListProperty<QObject>(this, m_data); }
+
+private:
+ QList<QObject *> m_data;
+ int m_extendedProperty;
+};
+
+class DerivedType1 : public Type
+{
+ Q_OBJECT
+ Q_PROPERTY(int m_exendedProperty2 MEMBER m_extendedProperty2)
+
+public:
+ DerivedType1(QObject *parent = nullptr)
+ : Type(parent) {}
+
+private:
+ int m_extendedProperty2;
+};
+
+class DerivedType2 : public DerivedType1
+{
+ Q_OBJECT
+public:
+ DerivedType2(QObject *parent = nullptr)
+ : DerivedType1(parent) {}
+};
+
+#endif // TYPES_H
diff --git a/tests/auto/qml/qmlplugindump/qmlplugindump.pro b/tests/auto/qml/qmlplugindump/qmlplugindump.pro
index cd33e5606e..34eb58c981 100644
--- a/tests/auto/qml/qmlplugindump/qmlplugindump.pro
+++ b/tests/auto/qml/qmlplugindump/qmlplugindump.pro
@@ -4,4 +4,5 @@ SUBDIRS += \
tst_qmlplugindump.pro \
data/dumper/Dummy/dummy.pro \
data/dumper/Imports/imports.pro \
- data/dumper/Versions/versions.pro
+ data/dumper/Versions/versions.pro \
+ data/dumper/ExtendedType/extendedtype.pro
diff --git a/tests/auto/qml/qmlplugindump/tst_qmlplugindump.cpp b/tests/auto/qml/qmlplugindump/tst_qmlplugindump.cpp
index a326ff9702..f673fca1d7 100644
--- a/tests/auto/qml/qmlplugindump/tst_qmlplugindump.cpp
+++ b/tests/auto/qml/qmlplugindump/tst_qmlplugindump.cpp
@@ -127,6 +127,8 @@ void tst_qmlplugindump::plugin_data()
QTest::newRow("dumper.Dummy") << "dumper.Dummy" << "1.0" << testFile("dumper/Dummy/plugins.qmltypes");
QTest::newRow("dumper.Imports") << "dumper.Imports" << "1.0" << testFile("dumper/Imports/plugins.qmltypes");
QTest::newRow("dumper.Versions") << "dumper.Versions" << "1.1" << testFile("dumper/Versions/plugins.qmltypes");
+ QTest::newRow("dumper.ExtendedType") << "dumper.ExtendedType"
+ << "1.1" << testFile("dumper/ExtendedType/plugins.qmltypes");
}
void tst_qmlplugindump::plugin()