Merge remote-tracking branch 'origin/master' into refactor
[profile/ivi/qtdeclarative.git] / tools / qmlplugindump / main.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the tools applications of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <QtDeclarative/QtDeclarative>
43 #include <QtDeclarative/private/qdeclarativemetatype_p.h>
44 #include <QtDeclarative/private/qdeclarativeopenmetaobject_p.h>
45
46 #include <QtWidgets/QApplication>
47
48 #include <QtCore/QSet>
49 #include <QtCore/QMetaObject>
50 #include <QtCore/QMetaProperty>
51 #include <QtCore/QDebug>
52 #include <QtCore/private/qobject_p.h>
53 #include <QtCore/private/qmetaobject_p.h>
54
55 #include <iostream>
56
57 #include "qmlstreamwriter.h"
58
59 #ifdef QT_SIMULATOR
60 #include <QtGui/private/qsimulatorconnection_p.h>
61 #endif
62
63 #ifdef Q_OS_UNIX
64 #include <signal.h>
65 #endif
66
67 QString pluginImportPath;
68 bool verbose = false;
69
70 QString currentProperty;
71 QString inObjectInstantiation;
72
73 void collectReachableMetaObjects(const QMetaObject *meta, QSet<const QMetaObject *> *metas)
74 {
75     if (! meta || metas->contains(meta))
76         return;
77
78     // dynamic meta objects break things badly, so just ignore them
79     const QMetaObjectPrivate *mop = reinterpret_cast<const QMetaObjectPrivate *>(meta->d.data);
80     if (!(mop->flags & DynamicMetaObject))
81         metas->insert(meta);
82
83     collectReachableMetaObjects(meta->superClass(), metas);
84 }
85
86 void collectReachableMetaObjects(QObject *object, QSet<const QMetaObject *> *metas)
87 {
88     if (! object)
89         return;
90
91     const QMetaObject *meta = object->metaObject();
92     if (verbose)
93         qDebug() << "Processing object" << meta->className();
94     collectReachableMetaObjects(meta, metas);
95
96     for (int index = 0; index < meta->propertyCount(); ++index) {
97         QMetaProperty prop = meta->property(index);
98         if (QDeclarativeMetaType::isQObject(prop.userType())) {
99             if (verbose)
100                 qDebug() << "  Processing property" << prop.name();
101             currentProperty = QString("%1::%2").arg(meta->className(), prop.name());
102
103             // if the property was not initialized during construction,
104             // accessing a member of oo is going to cause a segmentation fault
105             QObject *oo = QDeclarativeMetaType::toQObject(prop.read(object));
106             if (oo && !metas->contains(oo->metaObject()))
107                 collectReachableMetaObjects(oo, metas);
108             currentProperty.clear();
109         }
110     }
111 }
112
113 void collectReachableMetaObjects(const QDeclarativeType *ty, QSet<const QMetaObject *> *metas)
114 {
115     collectReachableMetaObjects(ty->metaObject(), metas);
116     if (ty->attachedPropertiesType())
117         collectReachableMetaObjects(ty->attachedPropertiesType(), metas);
118 }
119
120 /* We want to add the MetaObject for 'Qt' to the list, this is a
121    simple way to access it.
122 */
123 class FriendlyQObject: public QObject
124 {
125 public:
126     static const QMetaObject *qtMeta() { return &staticQtMetaObject; }
127 };
128
129 /* When we dump a QMetaObject, we want to list all the types it is exported as.
130    To do this, we need to find the QDeclarativeTypes associated with this
131    QMetaObject.
132 */
133 static QHash<QByteArray, QSet<const QDeclarativeType *> > qmlTypesByCppName;
134
135 static QHash<QByteArray, QByteArray> cppToId;
136
137 /* Takes a C++ type name, such as Qt::LayoutDirection or QString and
138    maps it to how it should appear in the description file.
139
140    These names need to be unique globally, so we don't change the C++ symbol's
141    name much. It is mostly used to for explicit translations such as
142    QString->string and translations for extended QML objects.
143 */
144 QByteArray convertToId(const QByteArray &cppName)
145 {
146     return cppToId.value(cppName, cppName);
147 }
148
149 QSet<const QMetaObject *> collectReachableMetaObjects(const QList<QDeclarativeType *> &skip = QList<QDeclarativeType *>())
150 {
151     QSet<const QMetaObject *> metas;
152     metas.insert(FriendlyQObject::qtMeta());
153
154     QHash<QByteArray, QSet<QByteArray> > extensions;
155     foreach (const QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) {
156         qmlTypesByCppName[ty->metaObject()->className()].insert(ty);
157         if (ty->isExtendedType()) {
158             extensions[ty->typeName()].insert(ty->metaObject()->className());
159         }
160         collectReachableMetaObjects(ty, &metas);
161     }
162
163     // Adjust exports of the base object if there are extensions.
164     // For each export of a base object there can be a single extension object overriding it.
165     // Example: QDeclarativeGraphicsWidget overrides the QtQuick/QGraphicsWidget export
166     //          of QGraphicsWidget.
167     foreach (const QByteArray &baseCpp, extensions.keys()) {
168         QSet<const QDeclarativeType *> baseExports = qmlTypesByCppName.value(baseCpp);
169
170         const QSet<QByteArray> extensionCppNames = extensions.value(baseCpp);
171         foreach (const QByteArray &extensionCppName, extensionCppNames) {
172             const QSet<const QDeclarativeType *> extensionExports = qmlTypesByCppName.value(extensionCppName);
173
174             // remove extension exports from base imports
175             // unfortunately the QDeclarativeType pointers don't match, so can't use QSet::substract
176             QSet<const QDeclarativeType *> newBaseExports;
177             foreach (const QDeclarativeType *baseExport, baseExports) {
178                 bool match = false;
179                 foreach (const QDeclarativeType *extensionExport, extensionExports) {
180                     if (baseExport->qmlTypeName() == extensionExport->qmlTypeName()
181                             && baseExport->majorVersion() == extensionExport->majorVersion()
182                             && baseExport->minorVersion() == extensionExport->minorVersion()) {
183                         match = true;
184                         break;
185                     }
186                 }
187                 if (!match)
188                     newBaseExports.insert(baseExport);
189             }
190             baseExports = newBaseExports;
191         }
192         qmlTypesByCppName[baseCpp] = baseExports;
193     }
194
195     // find even more QMetaObjects by instantiating QML types and running
196     // over the instances
197     foreach (QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) {
198         if (skip.contains(ty))
199             continue;
200         if (ty->isExtendedType())
201             continue;
202         if (!ty->isCreatable())
203             continue;
204         if (ty->typeName() == "QDeclarativeComponent")
205             continue;
206
207         QByteArray tyName = ty->qmlTypeName();
208         tyName = tyName.mid(tyName.lastIndexOf('/') + 1);
209         if (tyName.isEmpty())
210             continue;
211
212         inObjectInstantiation = tyName;
213         QObject *object = ty->create();
214         inObjectInstantiation.clear();
215
216         if (object)
217             collectReachableMetaObjects(object, &metas);
218         else
219             qWarning() << "Could not create" << tyName;
220     }
221
222     return metas;
223 }
224
225
226 class Dumper
227 {
228     QmlStreamWriter *qml;
229     QString relocatableModuleUri;
230
231 public:
232     Dumper(QmlStreamWriter *qml) : qml(qml) {}
233
234     void setRelocatableModuleUri(const QString &uri)
235     {
236         relocatableModuleUri = uri;
237     }
238
239     void dump(const QMetaObject *meta)
240     {
241         qml->writeStartObject("Component");
242
243         QByteArray id = convertToId(meta->className());
244         qml->writeScriptBinding(QLatin1String("name"), enquote(id));
245
246         for (int index = meta->classInfoCount() - 1 ; index >= 0 ; --index) {
247             QMetaClassInfo classInfo = meta->classInfo(index);
248             if (QLatin1String(classInfo.name()) == QLatin1String("DefaultProperty")) {
249                 qml->writeScriptBinding(QLatin1String("defaultProperty"), enquote(QLatin1String(classInfo.value())));
250                 break;
251             }
252         }
253
254         if (meta->superClass())
255             qml->writeScriptBinding(QLatin1String("prototype"), enquote(convertToId(meta->superClass()->className())));
256
257         QSet<const QDeclarativeType *> qmlTypes = qmlTypesByCppName.value(meta->className());
258         if (!qmlTypes.isEmpty()) {
259             QStringList exports;
260
261             foreach (const QDeclarativeType *qmlTy, qmlTypes) {
262                 QString qmlTyName = qmlTy->qmlTypeName();
263                 // some qmltype names are missing the actual names, ignore that import
264                 if (qmlTyName.endsWith('/'))
265                     continue;
266                 if (qmlTyName.startsWith(relocatableModuleUri + QLatin1Char('/'))) {
267                     qmlTyName.remove(0, relocatableModuleUri.size() + 1);
268                 }
269                 if (qmlTyName.startsWith("./")) {
270                     qmlTyName.remove(0, 2);
271                 }
272                 exports += enquote(QString("%1 %2.%3").arg(
273                                        qmlTyName,
274                                        QString::number(qmlTy->majorVersion()),
275                                        QString::number(qmlTy->minorVersion())));
276             }
277
278             // ensure exports are sorted and don't change order when the plugin is dumped again
279             exports.removeDuplicates();
280             qSort(exports);
281
282             qml->writeArrayBinding(QLatin1String("exports"), exports);
283
284             if (const QMetaObject *attachedType = (*qmlTypes.begin())->attachedPropertiesType()) {
285                 qml->writeScriptBinding(QLatin1String("attachedType"), enquote(
286                                             convertToId(attachedType->className())));
287             }
288         }
289
290         for (int index = meta->enumeratorOffset(); index < meta->enumeratorCount(); ++index)
291             dump(meta->enumerator(index));
292
293         for (int index = meta->propertyOffset(); index < meta->propertyCount(); ++index)
294             dump(meta->property(index));
295
296         for (int index = meta->methodOffset(); index < meta->methodCount(); ++index)
297             dump(meta->method(index));
298
299         qml->writeEndObject();
300     }
301
302     void writeEasingCurve()
303     {
304         qml->writeStartObject("Component");
305         qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("QEasingCurve")));
306         qml->writeScriptBinding(QLatin1String("prototype"), enquote(QLatin1String("QDeclarativeEasingValueType")));
307         qml->writeEndObject();
308     }
309
310 private:
311     static QString enquote(const QString &string)
312     {
313         return QString("\"%1\"").arg(string);
314     }
315
316     /* Removes pointer and list annotations from a type name, returning
317        what was removed in isList and isPointer
318     */
319     static void removePointerAndList(QByteArray *typeName, bool *isList, bool *isPointer)
320     {
321         static QByteArray declListPrefix = "QDeclarativeListProperty<";
322
323         if (typeName->endsWith('*')) {
324             *isPointer = true;
325             typeName->truncate(typeName->length() - 1);
326             removePointerAndList(typeName, isList, isPointer);
327         } else if (typeName->startsWith(declListPrefix)) {
328             *isList = true;
329             typeName->truncate(typeName->length() - 1); // get rid of the suffix '>'
330             *typeName = typeName->mid(declListPrefix.size());
331             removePointerAndList(typeName, isList, isPointer);
332         }
333
334         *typeName = convertToId(*typeName);
335     }
336
337     void writeTypeProperties(QByteArray typeName, bool isWritable)
338     {
339         bool isList = false, isPointer = false;
340         removePointerAndList(&typeName, &isList, &isPointer);
341
342         qml->writeScriptBinding(QLatin1String("type"), enquote(typeName));
343         if (isList)
344             qml->writeScriptBinding(QLatin1String("isList"), QLatin1String("true"));
345         if (!isWritable)
346             qml->writeScriptBinding(QLatin1String("isReadonly"), QLatin1String("true"));
347         if (isPointer)
348             qml->writeScriptBinding(QLatin1String("isPointer"), QLatin1String("true"));
349     }
350
351     void dump(const QMetaProperty &prop)
352     {
353         qml->writeStartObject("Property");
354
355         qml->writeScriptBinding(QLatin1String("name"), enquote(QString::fromUtf8(prop.name())));
356 #if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 4))
357         if (int revision = prop.revision())
358             qml->writeScriptBinding(QLatin1String("revision"), QString::number(revision));
359 #endif
360         writeTypeProperties(prop.typeName(), prop.isWritable());
361
362         qml->writeEndObject();
363     }
364
365     void dump(const QMetaMethod &meth)
366     {
367         if (meth.methodType() == QMetaMethod::Signal) {
368             if (meth.access() != QMetaMethod::Protected)
369                 return; // nothing to do.
370         } else if (meth.access() != QMetaMethod::Public) {
371             return; // nothing to do.
372         }
373
374         QByteArray name = meth.signature();
375         int lparenIndex = name.indexOf('(');
376         if (lparenIndex == -1) {
377             return; // invalid signature
378         }
379         name = name.left(lparenIndex);
380
381         if (meth.methodType() == QMetaMethod::Signal)
382             qml->writeStartObject(QLatin1String("Signal"));
383         else
384             qml->writeStartObject(QLatin1String("Method"));
385
386         qml->writeScriptBinding(QLatin1String("name"), enquote(name));
387
388 #if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 4))
389         if (int revision = meth.revision())
390             qml->writeScriptBinding(QLatin1String("revision"), QString::number(revision));
391 #endif
392
393         const QString typeName = convertToId(meth.typeName());
394         if (! typeName.isEmpty())
395             qml->writeScriptBinding(QLatin1String("type"), enquote(typeName));
396
397         for (int i = 0; i < meth.parameterTypes().size(); ++i) {
398             QByteArray argName = meth.parameterNames().at(i);
399
400             qml->writeStartObject(QLatin1String("Parameter"));
401             if (! argName.isEmpty())
402                 qml->writeScriptBinding(QLatin1String("name"), enquote(argName));
403             writeTypeProperties(meth.parameterTypes().at(i), true);
404             qml->writeEndObject();
405         }
406
407         qml->writeEndObject();
408     }
409
410     void dump(const QMetaEnum &e)
411     {
412         qml->writeStartObject(QLatin1String("Enum"));
413         qml->writeScriptBinding(QLatin1String("name"), enquote(QString::fromUtf8(e.name())));
414
415         QList<QPair<QString, QString> > namesValues;
416         for (int index = 0; index < e.keyCount(); ++index) {
417             namesValues.append(qMakePair(enquote(QString::fromUtf8(e.key(index))), QString::number(e.value(index))));
418         }
419
420         qml->writeScriptObjectLiteralBinding(QLatin1String("values"), namesValues);
421         qml->writeEndObject();
422     }
423 };
424
425
426 enum ExitCode {
427     EXIT_INVALIDARGUMENTS = 1,
428     EXIT_SEGV = 2,
429     EXIT_IMPORTERROR = 3
430 };
431
432 #ifdef Q_OS_UNIX
433 void sigSegvHandler(int) {
434     fprintf(stderr, "Error: SEGV\n");
435     if (!currentProperty.isEmpty())
436         fprintf(stderr, "While processing the property '%s', which probably has uninitialized data.\n", currentProperty.toLatin1().constData());
437     if (!inObjectInstantiation.isEmpty())
438         fprintf(stderr, "While instantiating the object '%s'.\n", inObjectInstantiation.toLatin1().constData());
439     exit(EXIT_SEGV);
440 }
441 #endif
442
443 void printUsage(const QString &appName)
444 {
445     qWarning() << qPrintable(QString(
446                                  "Usage: %1 [-v] [-notrelocatable] module.uri version [module/import/path]\n"
447                                  "       %1 [-v] -path path/to/qmldir/directory [version]\n"
448                                  "       %1 [-v] -builtins\n"
449                                  "Example: %1 Qt.labs.particles 4.7 /home/user/dev/qt-install/imports").arg(
450                                  appName));
451 }
452
453 int main(int argc, char *argv[])
454 {
455 #ifdef Q_OS_UNIX
456     // qmldump may crash, but we don't want any crash handlers to pop up
457     // therefore we intercept the segfault and just exit() ourselves
458     struct sigaction sigAction;
459
460     sigemptyset(&sigAction.sa_mask);
461     sigAction.sa_handler = &sigSegvHandler;
462     sigAction.sa_flags   = 0;
463
464     sigaction(SIGSEGV, &sigAction, 0);
465 #endif
466
467 #ifdef QT_SIMULATOR
468     // Running this application would bring up the Qt Simulator (since it links QtGui), avoid that!
469     QtSimulatorPrivate::SimulatorConnection::createStubInstance();
470 #endif
471     QApplication app(argc, argv);
472     const QStringList args = app.arguments();
473     const QString appName = QFileInfo(app.applicationFilePath()).baseName();
474     if (args.size() < 2) {
475         printUsage(appName);
476         return EXIT_INVALIDARGUMENTS;
477     }
478
479     QString pluginImportUri;
480     QString pluginImportVersion;
481     bool relocatable = true;
482     enum Action { Uri, Path, Builtins };
483     Action action = Uri;
484     {
485         QStringList positionalArgs;
486         foreach (const QString &arg, args) {
487             if (!arg.startsWith(QLatin1Char('-'))) {
488                 positionalArgs.append(arg);
489                 continue;
490             }
491
492             if (arg == QLatin1String("--notrelocatable")
493                     || arg == QLatin1String("-notrelocatable")) {
494                 relocatable = false;
495             } else if (arg == QLatin1String("--path")
496                        || arg == QLatin1String("-path")) {
497                 action = Path;
498             } else if (arg == QLatin1String("--builtins")
499                        || arg == QLatin1String("-builtins")) {
500                 action = Builtins;
501             } else if (arg == QLatin1String("-v")) {
502                 verbose = true;
503             } else {
504                 qWarning() << "Invalid argument: " << arg;
505                 return EXIT_INVALIDARGUMENTS;
506             }
507         }
508
509         if (action == Uri) {
510             if (positionalArgs.size() != 3 && positionalArgs.size() != 4) {
511                 qWarning() << "Incorrect number of positional arguments";
512                 return EXIT_INVALIDARGUMENTS;
513             }
514             pluginImportUri = positionalArgs[1];
515             pluginImportVersion = positionalArgs[2];
516             if (positionalArgs.size() >= 4)
517                 pluginImportPath = positionalArgs[3];
518         } else if (action == Path) {
519             if (positionalArgs.size() != 2 && positionalArgs.size() != 3) {
520                 qWarning() << "Incorrect number of positional arguments";
521                 return EXIT_INVALIDARGUMENTS;
522             }
523             pluginImportPath = QDir::fromNativeSeparators(positionalArgs[1]);
524             if (positionalArgs.size() == 3)
525                 pluginImportVersion = positionalArgs[2];
526         } else if (action == Builtins) {
527             if (positionalArgs.size() != 1) {
528                 qWarning() << "Incorrect number of positional arguments";
529                 return EXIT_INVALIDARGUMENTS;
530             }
531         }
532     }
533
534     QDeclarativeEngine engine;
535     if (!pluginImportPath.isEmpty()) {
536         QDir cur = QDir::current();
537         cur.cd(pluginImportPath);
538         pluginImportPath = cur.absolutePath();
539         QDir::setCurrent(pluginImportPath);
540         engine.addImportPath(pluginImportPath);
541     }
542
543     // load the QtQuick 1 plugin
544     {
545         QByteArray code("import QtQuick 1.0\nQtObject {}");
546         QDeclarativeComponent c(&engine);
547         c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/loadqtquick1.qml"));
548         c.create();
549         if (!c.errors().isEmpty()) {
550             foreach (const QDeclarativeError &error, c.errors())
551                 qWarning() << error.toString();
552             return EXIT_IMPORTERROR;
553         }
554     }
555
556     // find all QMetaObjects reachable from the builtin module
557     QSet<const QMetaObject *> defaultReachable = collectReachableMetaObjects();
558     QList<QDeclarativeType *> defaultTypes = QDeclarativeMetaType::qmlTypes();
559
560     // this will hold the meta objects we want to dump information of
561     QSet<const QMetaObject *> metas;
562
563     if (action == Builtins) {
564         metas = defaultReachable;
565     } else {
566         // find a valid QtQuick import
567         QByteArray importCode;
568         QDeclarativeType *qtObjectType = QDeclarativeMetaType::qmlType(&QObject::staticMetaObject);
569         if (!qtObjectType) {
570             qWarning() << "Could not find QtObject type";
571             importCode = QByteArray("import QtQuick 2.0\n");
572         } else {
573             QByteArray module = qtObjectType->qmlTypeName();
574             module = module.mid(0, module.lastIndexOf('/'));
575             importCode = QString("import %1 %2.%3\n").arg(module,
576                                                           QString::number(qtObjectType->majorVersion()),
577                                                           QString::number(qtObjectType->minorVersion())).toUtf8();
578         }
579
580         // find all QMetaObjects reachable when the specified module is imported
581         if (action != Path) {
582             importCode += QString("import %0 %1\n").arg(pluginImportUri, pluginImportVersion).toAscii();
583         } else {
584             // pluginImportVersion can be empty
585             importCode += QString("import \".\" %2\n").arg(pluginImportVersion).toAscii();
586         }
587
588         // create a component with these imports to make sure the imports are valid
589         // and to populate the declarative meta type system
590         {
591             QByteArray code = importCode;
592             code += "QtObject {}";
593             QDeclarativeComponent c(&engine);
594
595             c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/typelist.qml"));
596             c.create();
597             if (!c.errors().isEmpty()) {
598                 foreach (const QDeclarativeError &error, c.errors())
599                     qWarning() << error.toString();
600                 return EXIT_IMPORTERROR;
601             }
602         }
603
604         QSet<const QMetaObject *> candidates = collectReachableMetaObjects(defaultTypes);
605         candidates.subtract(defaultReachable);
606
607         // Also eliminate meta objects with the same classname.
608         // This is required because extended objects seem not to share
609         // a single meta object instance.
610         QSet<QByteArray> defaultReachableNames;
611         foreach (const QMetaObject *mo, defaultReachable)
612             defaultReachableNames.insert(QByteArray(mo->className()));
613         foreach (const QMetaObject *mo, candidates) {
614             if (!defaultReachableNames.contains(mo->className()))
615                 metas.insert(mo);
616         }
617     }
618
619     // setup static rewrites of type names
620     cppToId.insert("QString", "string");
621     cppToId.insert("QDeclarativeEasingValueType::Type", "Type");
622
623     // start dumping data
624     QByteArray bytes;
625     QmlStreamWriter qml(&bytes);
626
627     qml.writeStartDocument();
628     qml.writeLibraryImport(QLatin1String("QtQuick.tooling"), 1, 1);
629     qml.write("\n"
630               "// This file describes the plugin-supplied types contained in the library.\n"
631               "// It is used for QML tooling purposes only.\n"
632               "\n");
633     qml.writeStartObject("Module");
634
635     // put the metaobjects into a map so they are always dumped in the same order
636     QMap<QString, const QMetaObject *> nameToMeta;
637     foreach (const QMetaObject *meta, metas)
638         nameToMeta.insert(convertToId(meta->className()), meta);
639
640     Dumper dumper(&qml);
641     if (relocatable)
642         dumper.setRelocatableModuleUri(pluginImportUri);
643     foreach (const QMetaObject *meta, nameToMeta) {
644         dumper.dump(meta);
645     }
646
647     // define QEasingCurve as an extension of QDeclarativeEasingValueType, this way
648     // properties using the QEasingCurve type get useful type information.
649     if (pluginImportUri.isEmpty())
650         dumper.writeEasingCurve();
651
652     qml.writeEndObject();
653     qml.writeEndDocument();
654
655     std::cout << bytes.constData();
656
657     // workaround to avoid crashes on exit
658     QTimer timer;
659     timer.setSingleShot(true);
660     timer.setInterval(0);
661     QObject::connect(&timer, SIGNAL(timeout()), &app, SLOT(quit()));
662     timer.start();
663
664     return app.exec();
665 }