diff options
author | Daniel Pesch <dpesch@blackberry.com> | 2014-01-20 16:40:30 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-20 17:21:02 +0100 |
commit | 4c5cd2f04fdaf946cc67896db7c190a318811d86 (patch) | |
tree | 0a2d12876a57af78bed444c3c366401e554bc845 /tools/qmlplugindump/main.cpp | |
parent | 19025ab3422658ab27415cee99336d88a4ae19fa (diff) |
qmlplugindump: New component properties isCreatable and isSingleton
Qmlplugindump tool does not generate information about singleton status
and creatability from QML for a component. This patch adds two new boolean
properties that contain this information. It is used by Momentics IDE for
providing better code validation and could be used by QtCreator in future
in similar way.
Task-number: QTBUG-36139
Change-Id: If85374a1854aaa0727670b27df735d481cab5337
Signed-off-by: Daniel Pesch <dpesch@blackberry.com>
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
Diffstat (limited to 'tools/qmlplugindump/main.cpp')
-rw-r--r-- | tools/qmlplugindump/main.cpp | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index 6939ce92e2..89af0905d5 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -182,13 +182,20 @@ QByteArray convertToId(const QMetaObject *mo) return className; } -QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, const QList<QQmlType *> &skip = QList<QQmlType *>()) +QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, + QSet<const QMetaObject *> &noncreatables, + QSet<const QMetaObject *> &singletons, + const QList<QQmlType *> &skip = QList<QQmlType *>()) { QSet<const QMetaObject *> metas; metas.insert(FriendlyQObject::qtMeta()); QHash<QByteArray, QSet<QByteArray> > extensions; foreach (const QQmlType *ty, QQmlMetaType::qmlTypes()) { + if (!ty->isCreatable()) + noncreatables.insert(ty->metaObject()); + if (ty->isSingleton()) + singletons.insert(ty->metaObject()); if (!ty->isComposite()) { qmlTypesByCppName[ty->metaObject()->className()].insert(ty); if (ty->isExtendedType()) @@ -406,6 +413,12 @@ public: qml->writeArrayBinding(QLatin1String("exports"), QStringList() << exportString); qml->writeArrayBinding(QLatin1String("exportMetaObjectRevisions"), QStringList() << QString::number(compositeType->minorVersion())); + if (compositeType->isCreatable()) + qml->writeIsCreatable(false); + + if (compositeType->isSingleton()) + qml->writeIsSingleton(true); + for (int index = mainMeta->classInfoCount() - 1 ; index >= 0 ; --index) { QMetaClassInfo classInfo = mainMeta->classInfo(index); if (QLatin1String(classInfo.name()) == QLatin1String("DefaultProperty")) { @@ -437,7 +450,7 @@ public: qml->writeEndObject(); } - void dump(const QMetaObject *meta) + void dump(const QMetaObject *meta, bool isUncreatable, bool isSingleton) { qml->writeStartObject("Component"); @@ -469,6 +482,12 @@ public: std::sort(exportStrings.begin(), exportStrings.end()); qml->writeArrayBinding(QLatin1String("exports"), exportStrings); + if (isUncreatable) + qml->writeIsCreatable(false); + + if (isSingleton) + qml->writeIsSingleton(true); + // write meta object revisions QStringList metaObjectRevisions; foreach (const QString &exportString, exportStrings) { @@ -622,7 +641,6 @@ private: } }; - enum ExitCode { EXIT_INVALIDARGUMENTS = 1, EXIT_SEGV = 2, @@ -642,12 +660,12 @@ void sigSegvHandler(int) { void printUsage(const QString &appName) { - qWarning() << qPrintable(QString( + std::cerr << qPrintable(QString( "Usage: %1 [-v] [-noinstantiate] [-defaultplatform] [-[non]relocatable] module.uri version [module/import/path]\n" " %1 [-v] [-noinstantiate] -path path/to/qmldir/directory [version]\n" " %1 [-v] -builtins\n" "Example: %1 Qt.labs.folderlistmodel 2.0 /home/user/dev/qt-install/imports").arg( - appName)); + appName)) << std::endl; } int main(int argc, char *argv[]) @@ -726,14 +744,14 @@ int main(int argc, char *argv[]) || arg == QLatin1String("-defaultplatform")) { continue; } else { - qWarning() << "Invalid argument: " << arg; + std::cerr << "Invalid argument: " << qPrintable(arg) << std::endl; return EXIT_INVALIDARGUMENTS; } } if (action == Uri) { if (positionalArgs.size() != 3 && positionalArgs.size() != 4) { - qWarning() << "Incorrect number of positional arguments"; + std::cerr << "Incorrect number of positional arguments" << std::endl; return EXIT_INVALIDARGUMENTS; } pluginImportUri = positionalArgs[1]; @@ -742,7 +760,7 @@ int main(int argc, char *argv[]) pluginImportPath = positionalArgs[3]; } else if (action == Path) { if (positionalArgs.size() != 2 && positionalArgs.size() != 3) { - qWarning() << "Incorrect number of positional arguments"; + std::cerr << "Incorrect number of positional arguments" << std::endl; return EXIT_INVALIDARGUMENTS; } pluginImportPath = QDir::fromNativeSeparators(positionalArgs[1]); @@ -750,7 +768,7 @@ int main(int argc, char *argv[]) pluginImportVersion = positionalArgs[2]; } else if (action == Builtins) { if (positionalArgs.size() != 1) { - qWarning() << "Incorrect number of positional arguments"; + std::cerr << "Incorrect number of positional arguments" << std::endl; return EXIT_INVALIDARGUMENTS; } } @@ -760,7 +778,7 @@ int main(int argc, char *argv[]) if (!pluginImportPath.isEmpty()) { QDir cur = QDir::current(); cur.cd(pluginImportPath); - pluginImportPath = cur.absolutePath(); + pluginImportPath = cur.canonicalPath(); QDir::setCurrent(pluginImportPath); engine.addImportPath(pluginImportPath); } @@ -779,7 +797,9 @@ int main(int argc, char *argv[]) } // find all QMetaObjects reachable from the builtin module - QSet<const QMetaObject *> defaultReachable = collectReachableMetaObjects(&engine); + QSet<const QMetaObject *> uncreatableMetas; + QSet<const QMetaObject *> singletonMetas; + QSet<const QMetaObject *> defaultReachable = collectReachableMetaObjects(&engine, uncreatableMetas, singletonMetas); QList<QQmlType *> defaultTypes = QQmlMetaType::qmlTypes(); // add some otherwise unreachable QMetaObjects @@ -831,7 +851,7 @@ int main(int argc, char *argv[]) } } - QSet<const QMetaObject *> candidates = collectReachableMetaObjects(&engine, defaultTypes); + QSet<const QMetaObject *> candidates = collectReachableMetaObjects(&engine, uncreatableMetas, singletonMetas, defaultTypes); candidates.subtract(defaultReachable); // Also eliminate meta objects with the same classname. @@ -873,7 +893,7 @@ int main(int argc, char *argv[]) if (relocatable) dumper.setRelocatableModuleUri(pluginImportUri); foreach (const QMetaObject *meta, nameToMeta) { - dumper.dump(meta); + dumper.dump(meta, uncreatableMetas.contains(meta), singletonMetas.contains(meta)); } foreach (const QQmlType *compositeType, qmlTypesByCompositeName) dumper.dumpComposite(&engine, compositeType, defaultReachableNames); |