/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
** This file is part of the tools applications of the Qt Toolkit.
**
**
**
**
+**
** $QT_END_LICENSE$
**
****************************************************************************/
-#include <QtDeclarative/QtDeclarative>
-#include <QtDeclarative/private/qdeclarativemetatype_p.h>
-#include <QtDeclarative/private/qdeclarativeopenmetaobject_p.h>
-#include <QtDeclarative/private/qsgevents_p_p.h>
-#include <QtDeclarative/private/qsgpincharea_p.h>
-
-#include <QtWidgets/QApplication>
+#include <QtQml/qqmlengine.h>
+#include <QtQml/private/qqmlmetatype_p.h>
+#include <QtQml/private/qqmlopenmetaobject_p.h>
+#include <QtQuick/private/qquickevents_p_p.h>
+#include <QtQuick/private/qquickpincharea_p.h>
+#include <QtGui/QGuiApplication>
+#include <QtCore/QDir>
+#include <QtCore/QFileInfo>
#include <QtCore/QSet>
+#include <QtCore/QStringList>
+#include <QtCore/QTimer>
#include <QtCore/QMetaObject>
#include <QtCore/QMetaProperty>
#include <QtCore/QDebug>
QString currentProperty;
QString inObjectInstantiation;
-void collectReachableMetaObjects(const QMetaObject *meta, QSet<const QMetaObject *> *metas)
+void collectReachableMetaObjects(const QMetaObject *meta, QSet<const QMetaObject *> *metas, bool extended = false)
{
if (! meta || metas->contains(meta))
return;
- // dynamic meta objects break things badly, so just ignore them
+ // dynamic meta objects can break things badly
+ // but extended types are usually fine
const QMetaObjectPrivate *mop = reinterpret_cast<const QMetaObjectPrivate *>(meta->d.data);
- if (!(mop->flags & DynamicMetaObject))
+ if (extended || !(mop->flags & DynamicMetaObject))
metas->insert(meta);
collectReachableMetaObjects(meta->superClass(), metas);
for (int index = 0; index < meta->propertyCount(); ++index) {
QMetaProperty prop = meta->property(index);
- if (QDeclarativeMetaType::isQObject(prop.userType())) {
+ if (QQmlMetaType::isQObject(prop.userType())) {
if (verbose)
qDebug() << " Processing property" << prop.name();
currentProperty = QString("%1::%2").arg(meta->className(), prop.name());
// if the property was not initialized during construction,
// accessing a member of oo is going to cause a segmentation fault
- QObject *oo = QDeclarativeMetaType::toQObject(prop.read(object));
+ QObject *oo = QQmlMetaType::toQObject(prop.read(object));
if (oo && !metas->contains(oo->metaObject()))
collectReachableMetaObjects(oo, metas);
currentProperty.clear();
}
}
-void collectReachableMetaObjects(const QDeclarativeType *ty, QSet<const QMetaObject *> *metas)
+void collectReachableMetaObjects(const QQmlType *ty, QSet<const QMetaObject *> *metas)
{
- collectReachableMetaObjects(ty->metaObject(), metas);
+ collectReachableMetaObjects(ty->metaObject(), metas, ty->isExtendedType());
if (ty->attachedPropertiesType())
collectReachableMetaObjects(ty->attachedPropertiesType(), metas);
}
};
/* When we dump a QMetaObject, we want to list all the types it is exported as.
- To do this, we need to find the QDeclarativeTypes associated with this
+ To do this, we need to find the QQmlTypes associated with this
QMetaObject.
*/
-static QHash<QByteArray, QSet<const QDeclarativeType *> > qmlTypesByCppName;
+static QHash<QByteArray, QSet<const QQmlType *> > qmlTypesByCppName;
static QHash<QByteArray, QByteArray> cppToId;
return cppToId.value(cppName, cppName);
}
-QSet<const QMetaObject *> collectReachableMetaObjects(const QList<QDeclarativeType *> &skip = QList<QDeclarativeType *>())
+QByteArray convertToId(const QMetaObject *mo)
+{
+ QByteArray className(mo->className());
+ if (!className.isEmpty())
+ return convertToId(className);
+
+ // likely a metaobject generated for an extended qml object
+ if (mo->superClass()) {
+ className = convertToId(mo->superClass());
+ className.append("_extended");
+ return className;
+ }
+
+ static QHash<const QMetaObject *, QByteArray> generatedNames;
+ className = generatedNames.value(mo);
+ if (!className.isEmpty())
+ return className;
+
+ qWarning() << "Found a QMetaObject without a className, generating a random name";
+ className = QByteArray("error-unknown-name-");
+ className.append(QByteArray::number(generatedNames.size()));
+ generatedNames.insert(mo, className);
+ 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;
metas.insert(FriendlyQObject::qtMeta());
QHash<QByteArray, QSet<QByteArray> > extensions;
- foreach (const QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) {
+ foreach (const QQmlType *ty, QQmlMetaType::qmlTypes()) {
qmlTypesByCppName[ty->metaObject()->className()].insert(ty);
if (ty->isExtendedType()) {
extensions[ty->typeName()].insert(ty->metaObject()->className());
// Example: QDeclarativeGraphicsWidget overrides the QtQuick/QGraphicsWidget export
// of QGraphicsWidget.
foreach (const QByteArray &baseCpp, extensions.keys()) {
- QSet<const QDeclarativeType *> baseExports = qmlTypesByCppName.value(baseCpp);
+ QSet<const QQmlType *> baseExports = qmlTypesByCppName.value(baseCpp);
const QSet<QByteArray> extensionCppNames = extensions.value(baseCpp);
foreach (const QByteArray &extensionCppName, extensionCppNames) {
- const QSet<const QDeclarativeType *> extensionExports = qmlTypesByCppName.value(extensionCppName);
+ const QSet<const QQmlType *> extensionExports = qmlTypesByCppName.value(extensionCppName);
// remove extension exports from base imports
- // unfortunately the QDeclarativeType pointers don't match, so can't use QSet::substract
- QSet<const QDeclarativeType *> newBaseExports;
- foreach (const QDeclarativeType *baseExport, baseExports) {
+ // unfortunately the QQmlType pointers don't match, so can't use QSet::substract
+ QSet<const QQmlType *> newBaseExports;
+ foreach (const QQmlType *baseExport, baseExports) {
bool match = false;
- foreach (const QDeclarativeType *extensionExport, extensionExports) {
+ foreach (const QQmlType *extensionExport, extensionExports) {
if (baseExport->qmlTypeName() == extensionExport->qmlTypeName()
&& baseExport->majorVersion() == extensionExport->majorVersion()
&& baseExport->minorVersion() == extensionExport->minorVersion()) {
// find even more QMetaObjects by instantiating QML types and running
// over the instances
- foreach (QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) {
+ foreach (QQmlType *ty, QQmlMetaType::qmlTypes()) {
if (skip.contains(ty))
continue;
if (ty->isExtendedType())
continue;
if (!ty->isCreatable())
continue;
- if (ty->typeName() == "QDeclarativeComponent")
+ if (ty->typeName() == "QQmlComponent")
continue;
QString tyName = ty->qmlTypeName();
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;
}
{
qml->writeStartObject("Component");
- QByteArray id = convertToId(meta->className());
+ QByteArray id = convertToId(meta);
qml->writeScriptBinding(QLatin1String("name"), enquote(id));
for (int index = meta->classInfoCount() - 1 ; index >= 0 ; --index) {
}
if (meta->superClass())
- qml->writeScriptBinding(QLatin1String("prototype"), enquote(convertToId(meta->superClass()->className())));
+ qml->writeScriptBinding(QLatin1String("prototype"), enquote(convertToId(meta->superClass())));
- QSet<const QDeclarativeType *> qmlTypes = qmlTypesByCppName.value(meta->className());
+ QSet<const QQmlType *> qmlTypes = qmlTypesByCppName.value(meta->className());
if (!qmlTypes.isEmpty()) {
- QHash<QString, const QDeclarativeType *> exports;
+ QHash<QString, const QQmlType *> exports;
- foreach (const QDeclarativeType *qmlTy, qmlTypes) {
+ foreach (const QQmlType *qmlTy, qmlTypes) {
QString qmlTyName = qmlTy->qmlTypeName();
if (qmlTyName.startsWith(relocatableModuleUri + QLatin1Char('/'))) {
qmlTyName.remove(0, relocatableModuleUri.size() + 1);
qml->writeArrayBinding(QLatin1String("exportMetaObjectRevisions"), metaObjectRevisions);
if (const QMetaObject *attachedType = (*qmlTypes.begin())->attachedPropertiesType()) {
- qml->writeScriptBinding(QLatin1String("attachedType"), enquote(
- convertToId(attachedType->className())));
+ // Can happen when a type is registered that returns itself as attachedPropertiesType()
+ // because there is no creatable type to attach to.
+ if (attachedType != meta) {
+ qml->writeScriptBinding(QLatin1String("attachedType"), enquote(
+ convertToId(attachedType)));
+ }
}
}
implicitSignals.insert(QString("%1Changed").arg(QString::fromUtf8(property.name())));
}
- for (int index = meta->methodOffset(); index < meta->methodCount(); ++index)
- dump(meta->method(index), implicitSignals);
+ if (meta == &QObject::staticMetaObject) {
+ // for QObject, hide deleteLater() and onDestroyed
+ for (int index = meta->methodOffset(); index < meta->methodCount(); ++index) {
+ QMetaMethod method = meta->method(index);
+ QByteArray signature = method.methodSignature();
+ if (signature == QByteArrayLiteral("destroyed(QObject*)")
+ || signature == QByteArrayLiteral("destroyed()")
+ || signature == QByteArrayLiteral("deleteLater()"))
+ continue;
+ dump(method, implicitSignals);
+ }
+
+ // and add toString(), destroy() and destroy(int)
+ qml->writeStartObject(QLatin1String("Method"));
+ qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("toString")));
+ qml->writeEndObject();
+ qml->writeStartObject(QLatin1String("Method"));
+ qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("destroy")));
+ qml->writeEndObject();
+ qml->writeStartObject(QLatin1String("Method"));
+ qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("destroy")));
+ qml->writeStartObject(QLatin1String("Parameter"));
+ qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("delay")));
+ qml->writeScriptBinding(QLatin1String("type"), enquote(QLatin1String("int")));
+ qml->writeEndObject();
+ qml->writeEndObject();
+ } else {
+ for (int index = meta->methodOffset(); index < meta->methodCount(); ++index)
+ dump(meta->method(index), implicitSignals);
+ }
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->writeScriptBinding(QLatin1String("prototype"), enquote(QLatin1String("QQmlEasingValueType")));
qml->writeEndObject();
}
*/
static void removePointerAndList(QByteArray *typeName, bool *isList, bool *isPointer)
{
- static QByteArray declListPrefix = "QDeclarativeListProperty<";
+ static QByteArray declListPrefix = "QQmlListProperty<";
if (typeName->endsWith('*')) {
*isPointer = true;
return; // nothing to do.
}
- QByteArray name = meth.signature();
- int lparenIndex = name.indexOf('(');
- if (lparenIndex == -1) {
- return; // invalid signature
- }
- name = name.left(lparenIndex);
+ QByteArray name = meth.name();
const QString typeName = convertToId(meth.typeName());
if (implicitSignals.contains(name)
// Running this application would bring up the Qt Simulator (since it links QtGui), avoid that!
QtSimulatorPrivate::SimulatorConnection::createStubInstance();
#endif
- QApplication app(argc, argv);
+
+ QGuiApplication app(argc, argv);
const QStringList args = app.arguments();
const QString appName = QFileInfo(app.applicationFilePath()).baseName();
if (args.size() < 2) {
}
}
- QDeclarativeEngine engine;
+ QQmlEngine engine;
if (!pluginImportPath.isEmpty()) {
QDir cur = QDir::current();
cur.cd(pluginImportPath);
engine.addImportPath(pluginImportPath);
}
- // load the QtQuick 1 plugin
+ // load the QtQuick 2 plugin
{
- QByteArray code("import QtQuick 1.0\nQtObject {}");
- QDeclarativeComponent c(&engine);
- c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/loadqtquick1.qml"));
+ QByteArray code("import QtQuick 2.0\nQtObject {}");
+ QQmlComponent c(&engine);
+ c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/loadqtquick2.qml"));
c.create();
if (!c.errors().isEmpty()) {
- foreach (const QDeclarativeError &error, c.errors())
+ foreach (const QQmlError &error, c.errors())
qWarning() << error.toString();
return EXIT_IMPORTERROR;
}
}
// find all QMetaObjects reachable from the builtin module
- QSet<const QMetaObject *> defaultReachable = collectReachableMetaObjects();
- QList<QDeclarativeType *> defaultTypes = QDeclarativeMetaType::qmlTypes();
+ QSet<const QMetaObject *> defaultReachable = collectReachableMetaObjects(&engine);
+ QList<QQmlType *> defaultTypes = QQmlMetaType::qmlTypes();
// add some otherwise unreachable QMetaObjects
- defaultReachable.insert(&QSGMouseEvent::staticMetaObject);
- // QSGKeyEvent, QSGPinchEvent, QSGDropEvent are not exported
+ defaultReachable.insert(&QQuickMouseEvent::staticMetaObject);
+ // QQuickKeyEvent, QQuickPinchEvent, QQuickDropEvent are not exported
// this will hold the meta objects we want to dump information of
QSet<const QMetaObject *> metas;
} else {
// find a valid QtQuick import
QByteArray importCode;
- QDeclarativeType *qtObjectType = QDeclarativeMetaType::qmlType(&QObject::staticMetaObject);
+ QQmlType *qtObjectType = QQmlMetaType::qmlType(&QObject::staticMetaObject);
if (!qtObjectType) {
qWarning() << "Could not find QtObject type";
importCode = QByteArray("import QtQuick 2.0\n");
{
QByteArray code = importCode;
code += "QtObject {}";
- QDeclarativeComponent c(&engine);
+ QQmlComponent c(&engine);
c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/typelist.qml"));
c.create();
if (!c.errors().isEmpty()) {
- foreach (const QDeclarativeError &error, c.errors())
+ foreach (const QQmlError &error, c.errors())
qWarning() << error.toString();
return EXIT_IMPORTERROR;
}
}
- QSet<const QMetaObject *> candidates = collectReachableMetaObjects(defaultTypes);
+ QSet<const QMetaObject *> candidates = collectReachableMetaObjects(&engine, defaultTypes);
candidates.subtract(defaultReachable);
// Also eliminate meta objects with the same classname.
// setup static rewrites of type names
cppToId.insert("QString", "string");
- cppToId.insert("QDeclarativeEasingValueType::Type", "Type");
+ cppToId.insert("QQmlEasingValueType::Type", "Type");
// start dumping data
QByteArray bytes;
// put the metaobjects into a map so they are always dumped in the same order
QMap<QString, const QMetaObject *> nameToMeta;
foreach (const QMetaObject *meta, metas)
- nameToMeta.insert(convertToId(meta->className()), meta);
+ nameToMeta.insert(convertToId(meta), meta);
Dumper dumper(&qml);
if (relocatable)
dumper.dump(meta);
}
- // define QEasingCurve as an extension of QDeclarativeEasingValueType, this way
+ // define QEasingCurve as an extension of QQmlEasingValueType, this way
// properties using the QEasingCurve type get useful type information.
if (pluginImportUri.isEmpty())
dumper.writeEasingCurve();
+ // write out module api elements
+ foreach (const ModuleApi &api, moduleApis) {
+ dumper.dump(api);
+ }
+
qml.writeEndObject();
qml.writeEndDocument();
- std::cout << bytes.constData();
+ std::cout << bytes.constData() << std::flush;
// workaround to avoid crashes on exit
QTimer timer;