diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-10-11 18:03:52 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-10-15 13:20:11 +0200 |
commit | e9ae2014976cfc406f74f791ab1313ee369296fc (patch) | |
tree | ea31c33df0d8a0f58bb2e2a2c33d066598437354 /tools | |
parent | b08809b521591bd17955846fbeee651200983f3b (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>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qmlplugindump/main.cpp | 46 |
1 files changed, 26 insertions, 20 deletions
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 |