summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2011-10-05 11:42:33 +0200
committerQt by Nokia <qt-info@nokia.com>2011-10-28 07:27:03 +0200
commitf4130410d36edd80adbcb576d0ac137f8e167190 (patch)
treea74b496d46f2ead6e3e992fbd22866eab100575f
parentc5ad9fda817f61ae9b460dd9b2a5f44c9a6f90b4 (diff)
qmlplugindump: Dump QObject based module api.
Change-Id: Icc18392f63cd505e0264567e6c7d2d4cf7dac021 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
-rw-r--r--tools/qmlplugindump/main.cpp62
1 files changed, 58 insertions, 4 deletions
diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp
index b4cf2da3ff..19e94c2652 100644
--- a/tools/qmlplugindump/main.cpp
+++ b/tools/qmlplugindump/main.cpp
@@ -148,7 +148,17 @@ QByteArray convertToId(const QByteArray &cppName)
return cppToId.value(cppName, cppName);
}
-QSet<const QMetaObject *> collectReachableMetaObjects(const QList<QDeclarativeType *> &skip = QList<QDeclarativeType *>())
+/* All exported module APIs are collected into this list */
+class ModuleApi {
+public:
+ QString uri;
+ int majorVersion;
+ int minorVersion;
+ QByteArray objectId;
+};
+QList<ModuleApi> moduleApis;
+
+QSet<const QMetaObject *> collectReachableMetaObjects(QDeclarativeEngine *engine, const QList<QDeclarativeType *> &skip = QList<QDeclarativeType *>())
{
QSet<const QMetaObject *> metas;
metas.insert(FriendlyQObject::qtMeta());
@@ -221,6 +231,33 @@ QSet<const QMetaObject *> collectReachableMetaObjects(const QList<QDeclarativeTy
qWarning() << "Could not create" << tyName;
}
+ // extract exported module api
+ QHashIterator<QString, QList<QDeclarativeMetaType::ModuleApi> > moduleApiIt(QDeclarativeMetaType::moduleApis());
+ while (moduleApiIt.hasNext()) {
+ moduleApiIt.next();
+ foreach (const QDeclarativeMetaType::ModuleApi &api, moduleApiIt.value()) {
+ ModuleApi moduleApi;
+ moduleApi.uri = moduleApiIt.key();
+ moduleApi.majorVersion = api.major;
+ moduleApi.minorVersion = api.minor;
+
+ if (api.qobject) {
+ if (QObject *object = (*api.qobject)(engine, engine)) {
+ collectReachableMetaObjects(object, &metas);
+ moduleApi.objectId = convertToId(object->metaObject()->className());
+ delete object;
+ }
+ } else if (api.script) {
+ qWarning() << "Can't dump the module api in " << moduleApi.uri << ". QJSValue based module API is not supported.";
+// QJSValue value = (*api.script)(engine, engine);
+// IdToObjectHash jsObjects;
+// collectReachableJSObjects(value, &jsObjects, &metas);
+ }
+
+ moduleApis += moduleApi;
+ }
+ }
+
return metas;
}
@@ -318,9 +355,21 @@ public:
qml->writeEndObject();
}
+ void dump(const ModuleApi &api)
+ {
+ qml->writeStartObject(QLatin1String("ModuleApi"));
+ if (api.uri != relocatableModuleUri)
+ qml->writeScriptBinding(QLatin1String("uri"), enquote(api.uri));
+ qml->writeScriptBinding(QLatin1String("version"), QString("%1.%2").arg(
+ QString::number(api.majorVersion),
+ QString::number(api.minorVersion)));
+ qml->writeScriptBinding(QLatin1String("name"), enquote(api.objectId));
+ qml->writeEndObject();
+ }
+
void writeEasingCurve()
{
- qml->writeStartObject("Component");
+ qml->writeStartObject(QLatin1String("Component"));
qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("QEasingCurve")));
qml->writeScriptBinding(QLatin1String("prototype"), enquote(QLatin1String("QDeclarativeEasingValueType")));
qml->writeEndObject();
@@ -582,7 +631,7 @@ int main(int argc, char *argv[])
}
// find all QMetaObjects reachable from the builtin module
- QSet<const QMetaObject *> defaultReachable = collectReachableMetaObjects();
+ QSet<const QMetaObject *> defaultReachable = collectReachableMetaObjects(&engine);
QList<QDeclarativeType *> defaultTypes = QDeclarativeMetaType::qmlTypes();
// add some otherwise unreachable QMetaObjects
@@ -633,7 +682,7 @@ int main(int argc, char *argv[])
}
}
- QSet<const QMetaObject *> candidates = collectReachableMetaObjects(defaultTypes);
+ QSet<const QMetaObject *> candidates = collectReachableMetaObjects(&engine, defaultTypes);
candidates.subtract(defaultReachable);
// Also eliminate meta objects with the same classname.
@@ -681,6 +730,11 @@ int main(int argc, char *argv[])
if (pluginImportUri.isEmpty())
dumper.writeEasingCurve();
+ // write out module api elements
+ foreach (const ModuleApi &api, moduleApis) {
+ dumper.dump(api);
+ }
+
qml.writeEndObject();
qml.writeEndDocument();