diff options
Diffstat (limited to 'tools/qmlplugindump/main.cpp')
-rw-r--r-- | tools/qmlplugindump/main.cpp | 59 |
1 files changed, 35 insertions, 24 deletions
diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index 6248d3dc64..36a5c5ab76 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -32,6 +32,7 @@ ****************************************************************************/ #include <QtQml/qqmlengine.h> +#include <QtQml/private/qqmlengine_p.h> #include <QtQml/private/qqmlmetatype_p.h> #include <QtQml/private/qqmlopenmetaobject_p.h> #include <QtQuick/private/qquickevents_p_p.h> @@ -129,11 +130,11 @@ void collectReachableMetaObjects(QObject *object, QSet<const QMetaObject *> *met } } -void collectReachableMetaObjects(const QQmlType *ty, QSet<const QMetaObject *> *metas) +void collectReachableMetaObjects(QQmlEnginePrivate *engine, const QQmlType *ty, QSet<const QMetaObject *> *metas) { collectReachableMetaObjects(ty->metaObject(), metas, ty->isExtendedType()); - if (ty->attachedPropertiesType()) - collectReachableMetaObjects(ty->attachedPropertiesType(), metas); + if (ty->attachedPropertiesType(engine)) + collectReachableMetaObjects(ty->attachedPropertiesType(engine), metas); } /* We want to add the MetaObject for 'Qt' to the list, this is a @@ -151,8 +152,9 @@ public: */ static QHash<QByteArray, QSet<const QQmlType *> > qmlTypesByCppName; -// No different versioning possible for a composite type. -static QMap<QString, const QQmlType * > qmlTypesByCompositeName; +/* A composite type is completely specified by name, major version and minor version. +*/ +static QMap<QString, QSet<const QQmlType *> > qmlTypesByCompositeName; static QHash<QByteArray, QByteArray> cppToId; @@ -195,13 +197,13 @@ QByteArray convertToId(const QMetaObject *mo) // Collect all metaobjects for types registered with qmlRegisterType() without parameters -void collectReachableMetaObjectsWithoutQmlName( QSet<const QMetaObject *>& metas ) { +void collectReachableMetaObjectsWithoutQmlName(QQmlEnginePrivate *engine, QSet<const QMetaObject *>& metas ) { foreach (const QQmlType *ty, QQmlMetaType::qmlAllTypes()) { if ( ! metas.contains(ty->metaObject()) ) { if (!ty->isComposite()) { - collectReachableMetaObjects(ty, &metas); + collectReachableMetaObjects(engine, ty, &metas); } else { - qmlTypesByCompositeName[ty->elementName()] = ty; + qmlTypesByCompositeName[ty->elementName()].insert(ty); } } } @@ -225,9 +227,9 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, qmlTypesByCppName[ty->metaObject()->className()].insert(ty); if (ty->isExtendedType()) extensions[ty->typeName()].insert(ty->metaObject()->className()); - collectReachableMetaObjects(ty, &metas); + collectReachableMetaObjects(QQmlEnginePrivate::get(engine), ty, &metas); } else { - qmlTypesByCompositeName[ty->elementName()] = ty; + qmlTypesByCompositeName[ty->elementName()].insert(ty); } } @@ -324,7 +326,7 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, } } - collectReachableMetaObjectsWithoutQmlName(metas); + collectReachableMetaObjectsWithoutQmlName(QQmlEnginePrivate::get(engine), metas); return metas; } @@ -374,7 +376,7 @@ public: if (qmlTyName.startsWith("./")) { qmlTyName.remove(0, 2); } - if (qmlTyName.startsWith("/")) { + if (qmlTyName.startsWith(QLatin1Char('/'))) { qmlTyName.remove(0, 1); } const QString exportString = enquote( @@ -458,7 +460,13 @@ public: return prototypeName; } - void dumpComposite(QQmlEngine *engine, const QQmlType *compositeType, QSet<QByteArray> &defaultReachableNames) + void dumpComposite(QQmlEngine *engine, const QSet<const QQmlType *> &compositeType, QSet<QByteArray> &defaultReachableNames) + { + foreach (const QQmlType *type, compositeType) + dumpCompositeItem(engine, type, defaultReachableNames); + } + + void dumpCompositeItem(QQmlEngine *engine, const QQmlType *compositeType, QSet<QByteArray> &defaultReachableNames) { QQmlComponent e(engine, compositeType->sourceUrl()); if (!e.isReady()) { @@ -484,9 +492,8 @@ public: qml->writeScriptBinding(QLatin1String("prototype"), enquote(prototypeName)); QString qmlTyName = compositeType->qmlTypeName(); - // name should be unique - qml->writeScriptBinding(QLatin1String("name"), enquote(qmlTyName)); const QString exportString = getExportString(qmlTyName, compositeType->majorVersion(), compositeType->minorVersion()); + 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); @@ -510,7 +517,7 @@ public: qml->writeEndObject(); } - void dump(const QMetaObject *meta, bool isUncreatable, bool isSingleton) + void dump(QQmlEnginePrivate *engine, const QMetaObject *meta, bool isUncreatable, bool isSingleton) { qml->writeStartObject("Component"); @@ -556,7 +563,7 @@ public: } qml->writeArrayBinding(QLatin1String("exportMetaObjectRevisions"), metaObjectRevisions); - if (const QMetaObject *attachedType = (*qmlTypes.begin())->attachedPropertiesType()) { + if (const QMetaObject *attachedType = (*qmlTypes.begin())->attachedPropertiesType(engine)) { // Can happen when a type is registered that returns itself as attachedPropertiesType() // because there is no creatable type to attach to. if (attachedType != meta) { @@ -691,7 +698,9 @@ private: qml->writeScriptBinding(QLatin1String("name"), enquote(QString::fromUtf8(e.name()))); QList<QPair<QString, QString> > namesValues; - for (int index = 0; index < e.keyCount(); ++index) { + const int keyCount = e.keyCount(); + namesValues.reserve(keyCount); + for (int index = 0; index < keyCount; ++index) { namesValues.append(qMakePair(enquote(QString::fromUtf8(e.key(index))), QString::number(e.value(index)))); } @@ -733,7 +742,7 @@ static bool readDependenciesData(QString dependenciesFile, const QByteArray &fil std::cerr << "parsing " << qPrintable( dependenciesFile ) << " skipping"; foreach (const QString &uriToSkip, urisToSkip) - std::cerr << " " << qPrintable(uriToSkip); + std::cerr << ' ' << qPrintable(uriToSkip); std::cerr << std::endl; } QJsonParseError parseError; @@ -826,7 +835,7 @@ static bool getDependencies(const QQmlEngine &engine, const QString &pluginImpor if (!importScanner.waitForFinished()) { std::cerr << "failure to start " << qPrintable(command); foreach (const QString &arg, commandArgs) - std::cerr << " " << qPrintable(arg); + std::cerr << ' ' << qPrintable(arg); std::cerr << std::endl; return false; } @@ -1155,7 +1164,7 @@ int main(int argc, char *argv[]) "//\n" "// This file was auto-generated by:\n" "// '%1 %2'\n" - "\n").arg(QFileInfo(args.at(0)).fileName()).arg(QStringList(args.mid(1)).join(QLatin1String(" ")))); + "\n").arg(QFileInfo(args.at(0)).baseName(), args.mid(1).join(QLatin1Char(' ')))); qml.writeStartObject("Module"); QStringList quotedDependencies; foreach (const QString &dep, dependencies) @@ -1171,10 +1180,12 @@ int main(int argc, char *argv[]) if (relocatable) dumper.setRelocatableModuleUri(pluginImportUri); foreach (const QMetaObject *meta, nameToMeta) { - dumper.dump(meta, uncreatableMetas.contains(meta), singletonMetas.contains(meta)); + dumper.dump(QQmlEnginePrivate::get(&engine), meta, uncreatableMetas.contains(meta), singletonMetas.contains(meta)); } - foreach (const QQmlType *compositeType, qmlTypesByCompositeName) - dumper.dumpComposite(&engine, compositeType, defaultReachableNames); + + QMap<QString, QSet<const QQmlType *> >::const_iterator iter = qmlTypesByCompositeName.constBegin(); + for (; iter != qmlTypesByCompositeName.constEnd(); ++iter) + dumper.dumpComposite(&engine, iter.value(), defaultReachableNames); // define QEasingCurve as an extension of QQmlEasingValueType, this way // properties using the QEasingCurve type get useful type information. |