summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2011-07-14 09:04:17 +0200
committerQt by Nokia <qt-info@nokia.com>2011-07-20 03:25:59 +0200
commit5d1eddc6cffe5f7e737b530ca8665a6181358c86 (patch)
tree759b0b562cde520a0d2c792ff722d475a5f264a1 /tools
parent6ef9beba08a78f490fb9451f1a04bb9f153ec4fb (diff)
qmldump: Fix creation of objects from QDeclarativeTypes.
Previously, the import statement was not necessarily set up correctly for the type we wanted to instantiate. We simply use QDeclarativeType::create now and thus can skip finding the right import. Mirrors qtcreator/f326bd067d455e979b5d83195e19581a9e2fd494 Mirrors qt4.8/bdbc3ff0a32bb37a32dc4825413e60f9d75e5007 Change-Id: Ic9e652b341854941c0e6a51f49f23dfaae4f87d7 Reviewed-on: http://codereview.qt.nokia.com/1648 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com> Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmlplugindump/main.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp
index ea82bc1b2e..46d31739ee 100644
--- a/tools/qmlplugindump/main.cpp
+++ b/tools/qmlplugindump/main.cpp
@@ -146,7 +146,7 @@ QByteArray convertToId(const QByteArray &cppName)
return cppToId.value(cppName, cppName);
}
-QSet<const QMetaObject *> collectReachableMetaObjects(const QString &importCode, QDeclarativeEngine *engine)
+QSet<const QMetaObject *> collectReachableMetaObjects(const QList<QDeclarativeType *> &skip = QList<QDeclarativeType *>())
{
QSet<const QMetaObject *> metas;
metas.insert(FriendlyQObject::qtMeta());
@@ -194,7 +194,9 @@ QSet<const QMetaObject *> collectReachableMetaObjects(const QString &importCode,
// find even more QMetaObjects by instantiating QML types and running
// over the instances
- foreach (const QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) {
+ foreach (QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) {
+ if (skip.contains(ty))
+ continue;
if (ty->isExtendedType())
continue;
if (!ty->isCreatable())
@@ -207,21 +209,14 @@ QSet<const QMetaObject *> collectReachableMetaObjects(const QString &importCode,
if (tyName.isEmpty())
continue;
- QByteArray code = importCode.toUtf8();
- code += tyName;
- code += " {}\n";
-
- QDeclarativeComponent c(engine);
- c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/typeinstance.qml"));
-
inObjectInstantiation = tyName;
- QObject *object = c.create();
+ QObject *object = ty->create();
inObjectInstantiation.clear();
if (object)
collectReachableMetaObjects(object, &metas);
else
- qWarning() << "Could not create" << tyName << ":" << c.errorString();
+ qWarning() << "Could not create" << tyName;
}
return metas;
@@ -546,8 +541,8 @@ int main(int argc, char *argv[])
}
// find all QMetaObjects reachable from the builtin module
- QByteArray importCode("import QtQuick 2.0\n");
- QSet<const QMetaObject *> defaultReachable = collectReachableMetaObjects(importCode, &engine);
+ QSet<const QMetaObject *> defaultReachable = collectReachableMetaObjects();
+ QList<QDeclarativeType *> defaultTypes = QDeclarativeMetaType::qmlTypes();
// this will hold the meta objects we want to dump information of
QSet<const QMetaObject *> metas;
@@ -555,6 +550,20 @@ int main(int argc, char *argv[])
if (action == Builtins) {
metas = defaultReachable;
} else {
+ // find a valid QtQuick import
+ QByteArray importCode;
+ QDeclarativeType *qtObjectType = QDeclarativeMetaType::qmlType(&QObject::staticMetaObject);
+ if (!qtObjectType) {
+ qWarning() << "Could not find QtObject type";
+ importCode = QByteArray("import QtQuick 2.0\n");
+ } else {
+ QByteArray module = qtObjectType->qmlTypeName();
+ module = module.mid(0, module.lastIndexOf('/'));
+ importCode = QString("import %1 %2.%3\n").arg(module,
+ QString::number(qtObjectType->majorVersion()),
+ QString::number(qtObjectType->minorVersion())).toUtf8();
+ }
+
// find all QMetaObjects reachable when the specified module is imported
if (action != Path) {
importCode += QString("import %0 %1\n").arg(pluginImportUri, pluginImportVersion).toAscii();
@@ -579,7 +588,7 @@ int main(int argc, char *argv[])
}
}
- QSet<const QMetaObject *> candidates = collectReachableMetaObjects(importCode, &engine);
+ QSet<const QMetaObject *> candidates = collectReachableMetaObjects(defaultTypes);
candidates.subtract(defaultReachable);
// Also eliminate meta objects with the same classname.