From 6ebf215fdaf2d757ab90ae4d46c4b938e978e2dc Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Tue, 24 Jul 2012 11:41:50 +1000 Subject: Add type name to singleton (module api) implementations. This change renames the previous module api implementation to singleton types. When a singleton type is registered, a type name must be provided that is used when accessing the API from QML. This makes the implementation more consistent with the rest of QML. Task-number: QTBUG-26549 Change-Id: Iab0bb1ccf516bd3ae20aee562a64d22976e0aecd Reviewed-by: Chris Adams --- src/qml/qml/v4/qv4bindings.cpp | 16 ++++++++-------- src/qml/qml/v4/qv4compiler.cpp | 2 +- src/qml/qml/v4/qv4irbuilder.cpp | 14 +++++++------- 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src/qml/qml/v4') diff --git a/src/qml/qml/v4/qv4bindings.cpp b/src/qml/qml/v4/qv4bindings.cpp index c0e0f22fad..9b74c2aa72 100644 --- a/src/qml/qml/v4/qv4bindings.cpp +++ b/src/qml/qml/v4/qv4bindings.cpp @@ -949,15 +949,15 @@ void QV4Bindings::run(int instrIndex, quint32 &executedBlocks, reg.cleanupString(); if (r.isValid() && r.importNamespace) { - QQmlMetaType::ModuleApiInstance *moduleApi = context->imports->moduleApi(r.importNamespace); - if (moduleApi) { - if (moduleApi->qobjectCallback) { - moduleApi->qobjectApi = moduleApi->qobjectCallback(context->engine, context->engine); - moduleApi->qobjectCallback = 0; - moduleApi->scriptCallback = 0; + QQmlMetaType::SingletonInstance *singletonType = context->imports->singletonType(r.importNamespace); + if (singletonType) { + if (singletonType->qobjectCallback) { + singletonType->qobjectApi = singletonType->qobjectCallback(context->engine, context->engine); + singletonType->qobjectCallback = 0; + singletonType->scriptCallback = 0; } - if (moduleApi->qobjectApi) - reg.setQObject(moduleApi->qobjectApi); + if (singletonType->qobjectApi) + reg.setQObject(singletonType->qobjectApi); } } } diff --git a/src/qml/qml/v4/qv4compiler.cpp b/src/qml/qml/v4/qv4compiler.cpp index 8f87583a94..b697204839 100644 --- a/src/qml/qml/v4/qv4compiler.cpp +++ b/src/qml/qml/v4/qv4compiler.cpp @@ -334,7 +334,7 @@ void QV4CompilerPrivate::visitName(IR::Name *e) /* Existing module object lookup methods include: 1. string -> module object (search via importCache->query(name)) - 2. QQmlMetaType::ModuleApi -> module object (via QQmlEnginePrivate::moduleApiInstance() cache) + 2. QQmlMetaType::SingletonType -> module object (via QQmlEnginePrivate::singletonTypeInstance() cache) We currently use 1, which is not ideal for performance */ _subscribeName << *e->id; diff --git a/src/qml/qml/v4/qv4irbuilder.cpp b/src/qml/qml/v4/qv4irbuilder.cpp index 79090b4269..93c552173f 100644 --- a/src/qml/qml/v4/qv4irbuilder.cpp +++ b/src/qml/qml/v4/qv4irbuilder.cpp @@ -446,15 +446,15 @@ bool QV4IRBuilder::visit(AST::IdentifierExpression *ast) if (r.type) { _expr.code = _block->ATTACH_TYPE(name, r.type, IR::Name::ScopeStorage, line, column); } else if (r.importNamespace) { - QQmlMetaType::ModuleApiInstance *moduleApi = m_expression->importCache->moduleApi(r.importNamespace); - if (moduleApi && moduleApi->instanceMetaObject) { - // Note: we don't need to check moduleApi->qobjectCallback here, since - // we did that check in registerModuleApi() in qqmlmetatype.cpp. - // We cannot create the QObject Module Api Instance here, + QQmlMetaType::SingletonInstance *singletonType = m_expression->importCache->singletonType(r.importNamespace); + if (singletonType && singletonType->instanceMetaObject) { + // Note: we don't need to check singletonType->qobjectCallback here, since + // we did that check in registerSingletonType() in qqmlmetatype.cpp. + // We cannot create the QObject Singleton Type Instance here, // as we might be running in a loader thread. - // Thus, V4 can only handle bindings which use Module APIs which + // Thus, V4 can only handle bindings which use Singleton Types which // were registered with the templated registration function. - _expr.code = _block->MODULE_OBJECT(name, moduleApi->instanceMetaObject, IR::Name::MemberStorage, line, column); + _expr.code = _block->MODULE_OBJECT(name, singletonType->instanceMetaObject, IR::Name::MemberStorage, line, column); } } // We don't support anything else -- cgit v1.2.3