aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-10-11 18:03:52 +0200
committerUlf Hermann <ulf.hermann@qt.io>2019-10-15 13:20:11 +0200
commite9ae2014976cfc406f74f791ab1313ee369296fc (patch)
treeea31c33df0d8a0f58bb2e2a2c33d066598437354
parentb08809b521591bd17955846fbeee651200983f3b (diff)
qmlplugindump: Fix prototype and name for composite types
Before we would always merge everything up to QObject. That would duplicate entries between types that inherit from the same base class. Also, when the composite type doesn't specify a module (because we just created a component from a plain QML file), use the module URI from our version info. As we're dumping the component we can assume it belongs to the module we're dumping. Change-Id: Icf9a58cfe1165f557ebbf7309251e98a0782dc33 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/Imports/Derived.qml6
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/Imports/imports.pro2
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/Imports/plugins.qmltypes10
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/Imports/qmldir1
-rw-r--r--tools/qmlplugindump/main.cpp46
5 files changed, 44 insertions, 21 deletions
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/Imports/Derived.qml b/tests/auto/qml/qmlplugindump/data/dumper/Imports/Derived.qml
new file mode 100644
index 0000000000..2f0ac401d7
--- /dev/null
+++ b/tests/auto/qml/qmlplugindump/data/dumper/Imports/Derived.qml
@@ -0,0 +1,6 @@
+pragma Singleton
+import dumper.Imports 1.0
+
+Imports {
+ property int something: 2
+}
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/Imports/imports.pro b/tests/auto/qml/qmlplugindump/data/dumper/Imports/imports.pro
index d20ea967ea..b4bd9baf5b 100644
--- a/tests/auto/qml/qmlplugindump/data/dumper/Imports/imports.pro
+++ b/tests/auto/qml/qmlplugindump/data/dumper/Imports/imports.pro
@@ -17,7 +17,7 @@ HEADERS += \
imports.h
!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
- cp.files = qmldir plugins.qmltypes CompositeImports.qml
+ cp.files = qmldir plugins.qmltypes CompositeImports.qml Derived.qml
cp.path = $$OUT_PWD
COPIES += cp
}
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/Imports/plugins.qmltypes b/tests/auto/qml/qmlplugindump/data/dumper/Imports/plugins.qmltypes
index 937dd60a9e..fb13928ba0 100644
--- a/tests/auto/qml/qmlplugindump/data/dumper/Imports/plugins.qmltypes
+++ b/tests/auto/qml/qmlplugindump/data/dumper/Imports/plugins.qmltypes
@@ -14,4 +14,14 @@ Module {
exports: ["dumper.Imports/Imports 1.0"]
exportMetaObjectRevisions: [0]
}
+ Component {
+ prototype: "Imports"
+ name: "dumper.Imports/Derived 1.0"
+ exports: ["dumper.Imports/Derived 1.0"]
+ exportMetaObjectRevisions: [0]
+ isComposite: true
+ isCreatable: false
+ isSingleton: true
+ Property { name: "something"; type: "int" }
+ }
}
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/Imports/qmldir b/tests/auto/qml/qmlplugindump/data/dumper/Imports/qmldir
index c9058a7f95..f84fca1d75 100644
--- a/tests/auto/qml/qmlplugindump/data/dumper/Imports/qmldir
+++ b/tests/auto/qml/qmlplugindump/data/dumper/Imports/qmldir
@@ -1,3 +1,4 @@
module dumper.Imports
plugin Imports
CompositeImports 1.0 CompositeImports.qml
+singleton Derived 1.0 Derived.qml
diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp
index 25447becff..1556718471 100644
--- a/tools/qmlplugindump/main.cpp
+++ b/tools/qmlplugindump/main.cpp
@@ -380,23 +380,21 @@ public:
relocatableModuleUri = uri;
}
- const QString getExportString(QString qmlTyName, int majorVersion, int minorVersion)
+ QString getExportString(const QQmlType &type, const QmlVersionInfo &versionInfo)
{
- if (qmlTyName.startsWith(relocatableModuleUri + QLatin1Char('/'))) {
- qmlTyName.remove(0, relocatableModuleUri.size() + 1);
- }
- if (qmlTyName.startsWith("./")) {
- qmlTyName.remove(0, 2);
- }
- if (qmlTyName.startsWith(QLatin1Char('/'))) {
- qmlTyName.remove(0, 1);
- }
- const QString exportString = enquote(
- QString("%1 %2.%3").arg(
- qmlTyName,
- QString::number(majorVersion),
- QString::number(minorVersion)));
- return exportString;
+ const QString module = type.module().isEmpty() ? versionInfo.pluginImportUri
+ : type.module();
+ const int majorVersion = type.majorVersion() >= 0 ? type.majorVersion()
+ : versionInfo.majorVersion;
+ const int minorVersion = type.minorVersion() >= 0 ? type.minorVersion()
+ : versionInfo.minorVersion;
+
+ const QString versionedElement = type.elementName()
+ + QString::fromLatin1(" %1.%2").arg(majorVersion).arg(minorVersion);
+
+ return enquote((module == relocatableModuleUri)
+ ? versionedElement
+ : module + QLatin1Char('/') + versionedElement);
}
void writeMetaContent(const QMetaObject *meta, KnownAttributes *knownAttributes = nullptr)
@@ -455,11 +453,15 @@ public:
&& !objectsToMerge->contains(metaObject))
objectsToMerge->append(metaObject);
const QMetaObject *superMetaObject = metaObject->superClass();
- if (!superMetaObject)
+ if (!superMetaObject) {
prototypeName = "QObject";
- else
+ } else {
+ QQmlType superType = QQmlMetaType::qmlType(superMetaObject);
+ if (superType.isValid() && !superType.isComposite())
+ return convertToId(superMetaObject->className());
prototypeName = getPrototypeNameForCompositeType(
superMetaObject, objectsToMerge, versionInfo);
+ }
} else {
prototypeName = convertToId(metaObject->className());
}
@@ -498,8 +500,12 @@ public:
qml->writeScriptBinding(QLatin1String("prototype"), enquote(prototypeName));
QString qmlTyName = compositeType.qmlTypeName();
- const QString exportString = getExportString(qmlTyName, compositeType.majorVersion(), compositeType.minorVersion());
+ const QString exportString = getExportString(compositeType, versionInfo);
+
+ // TODO: why don't we simply output the compositeType.elementName() here?
+ // That would make more sense, but it would change the format quite a bit.
qml->writeScriptBinding(QLatin1String("name"), exportString);
+
qml->writeArrayBinding(QLatin1String("exports"), QStringList() << exportString);
qml->writeArrayBinding(QLatin1String("exportMetaObjectRevisions"), QStringList() << QString::number(compositeType.minorVersion()));
qml->writeBooleanBinding(QLatin1String("isComposite"), true);
@@ -566,7 +572,7 @@ public:
if (attachedType != meta)
attachedTypeId = convertToId(attachedType);
}
- const QString exportString = getExportString(type.qmlTypeName(), type.majorVersion(), type.minorVersion());
+ const QString exportString = getExportString(type, { QString(), -1, -1, false });
int metaObjectRevision = type.metaObjectRevision();
if (extendedObject) {
// emulate custom metaobjectrevision out of import