qmlplugindump: Take care of 'void' types
[profile/ivi/qtdeclarative.git] / tools / qmlplugindump / main.cpp
index b3cc721..b2e503c 100644 (file)
@@ -177,16 +177,6 @@ QByteArray convertToId(const QMetaObject *mo)
     return className;
 }
 
-/* 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(QQmlEngine *engine, const QList<QQmlType *> &skip = QList<QQmlType *>())
 {
     QSet<const QMetaObject *> metas;
@@ -251,7 +241,22 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, const
             continue;
 
         inObjectInstantiation = tyName;
-        QObject *object = ty->create();
+        QObject *object = 0;
+
+        if (ty->isSingleton()) {
+            QQmlType::SingletonInstanceInfo *siinfo = ty->singletonInstanceInfo();
+            if (siinfo->qobjectCallback) {
+                siinfo->init(engine);
+                collectReachableMetaObjects(object, &metas);
+                object = siinfo->qobjectApi(engine);
+            } else {
+                inObjectInstantiation.clear();
+                continue; // we don't handle QJSValue singleton types.
+            }
+        } else {
+            ty->create();
+        }
+
         inObjectInstantiation.clear();
 
         if (object)
@@ -260,33 +265,6 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, const
             qWarning() << "Could not create" << tyName;
     }
 
-    // extract exported module api
-    QHashIterator<QString, QList<QQmlMetaType::ModuleApi> > moduleApiIt(QQmlMetaType::moduleApis());
-    while (moduleApiIt.hasNext()) {
-        moduleApiIt.next();
-        foreach (const QQmlMetaType::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;
 }
 
@@ -416,18 +394,6 @@ 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(QLatin1String("Component"));
@@ -507,7 +473,7 @@ private:
                 && !meth.revision()
                 && meth.methodType() == QMetaMethod::Signal
                 && meth.parameterNames().isEmpty()
-                && typeName.isEmpty()) {
+                && typeName != QLatin1String("void")) {
             // don't mention implicit signals
             return;
         }
@@ -524,7 +490,7 @@ private:
             qml->writeScriptBinding(QLatin1String("revision"), QString::number(revision));
 #endif
 
-        if (! typeName.isEmpty())
+        if (typeName != QLatin1String("void"))
             qml->writeScriptBinding(QLatin1String("type"), enquote(typeName));
 
         for (int i = 0; i < meth.parameterTypes().size(); ++i) {
@@ -717,10 +683,10 @@ int main(int argc, char *argv[])
 
         // find all QMetaObjects reachable when the specified module is imported
         if (action != Path) {
-            importCode += QString("import %0 %1\n").arg(pluginImportUri, pluginImportVersion).toAscii();
+            importCode += QString("import %0 %1\n").arg(pluginImportUri, pluginImportVersion).toLatin1();
         } else {
             // pluginImportVersion can be empty
-            importCode += QString("import \".\" %2\n").arg(pluginImportVersion).toAscii();
+            importCode += QString("import \".\" %2\n").arg(pluginImportVersion).toLatin1();
         }
 
         // create a component with these imports to make sure the imports are valid
@@ -764,10 +730,12 @@ int main(int argc, char *argv[])
 
     qml.writeStartDocument();
     qml.writeLibraryImport(QLatin1String("QtQuick.tooling"), 1, 1);
-    qml.write("\n"
+    qml.write(QString("\n"
               "// This file describes the plugin-supplied types contained in the library.\n"
               "// It is used for QML tooling purposes only.\n"
-              "\n");
+              "//\n"
+              "// This file was auto-generated with the command '%1'.\n"
+              "\n").arg(args.join(QLatin1String(" "))));
     qml.writeStartObject("Module");
 
     // put the metaobjects into a map so they are always dumped in the same order
@@ -787,11 +755,6 @@ 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();