aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2012-08-14 11:44:49 +1000
committerQt by Nokia <qt-info@nokia.com>2012-08-28 04:32:48 +0200
commit70a2c0491d66aa05f9e9e67f8a845f4df84da857 (patch)
tree08d7828cfb6950926e1176ee420d5e15dedd9817 /tools
parent3912bbaceab166eb116447311eb16453e4f26edf (diff)
Refactor singleton type registration code
Previously each singleton type was registered as an implicit separate import. This commit changes the code so that these types are treated just like any other type in the registration sense. It also ensures that singleton types are instantiated per-engine. Change-Id: I5c81c4ca5bf65210f7125d74a62a282a21838068 Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmlplugindump/main.cpp74
1 files changed, 16 insertions, 58 deletions
diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp
index 23cac659b6..f753dcfa65 100644
--- a/tools/qmlplugindump/main.cpp
+++ b/tools/qmlplugindump/main.cpp
@@ -177,17 +177,6 @@ QByteArray convertToId(const QMetaObject *mo)
return className;
}
-/* All exported singleton Types are collected into this list */
-class SingletonType {
-public:
- QString uri;
- int majorVersion;
- int minorVersion;
- QByteArray objectId;
- QString typeName;
-};
-QList<SingletonType> singletonTypes;
-
QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, const QList<QQmlType *> &skip = QList<QQmlType *>())
{
QSet<const QMetaObject *> metas;
@@ -252,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)
@@ -261,34 +265,6 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, const
qWarning() << "Could not create" << tyName;
}
- // extract exported singleton type
- QHashIterator<QString, QList<QQmlMetaType::SingletonType> > singletonTypeIt(QQmlMetaType::singletonTypes());
- while (singletonTypeIt.hasNext()) {
- singletonTypeIt.next();
- foreach (const QQmlMetaType::SingletonType &api, singletonTypeIt.value()) {
- SingletonType singletonType;
- singletonType.uri = singletonTypeIt.key();
- singletonType.majorVersion = api.major;
- singletonType.minorVersion = api.minor;
- singletonType.typeName = api.typeName;
-
- if (api.qobject) {
- if (QObject *object = (*api.qobject)(engine, engine)) {
- collectReachableMetaObjects(object, &metas);
- singletonType.objectId = convertToId(object->metaObject()->className());
- delete object;
- }
- } else if (api.script) {
- qWarning() << "Can't dump the singleton type in " << singletonType.uri << ". QJSValue based singleton Type is not supported.";
-// QJSValue value = (*api.script)(engine, engine);
-// IdToObjectHash jsObjects;
-// collectReachableJSObjects(value, &jsObjects, &metas);
- }
-
- singletonTypes += singletonType;
- }
- }
-
return metas;
}
@@ -418,19 +394,6 @@ public:
qml->writeEndObject();
}
- void dump(const SingletonType &api)
- {
- qml->writeStartObject(QLatin1String("SingletonType"));
- 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->writeScriptBinding(QLatin1String("typeName"), enquote(api.typeName));
- qml->writeEndObject();
- }
-
void writeEasingCurve()
{
qml->writeStartObject(QLatin1String("Component"));
@@ -792,11 +755,6 @@ int main(int argc, char *argv[])
if (pluginImportUri.isEmpty())
dumper.writeEasingCurve();
- // write out singleton type elements
- foreach (const SingletonType &api, singletonTypes) {
- dumper.dump(api);
- }
-
qml.writeEndObject();
qml.writeEndDocument();