diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-07-16 05:28:48 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-07-16 05:28:48 (GMT) |
commit | a5e11573712fcf1c95696bed4ce4bfd04bc17e01 (patch) | |
tree | 9cb882a1404fb5bf44264e350c78285a959d9113 /src/declarative/qml | |
parent | d03ef52960576837f4454da0b3bf196d92ee558c (diff) | |
download | Qt-a5e11573712fcf1c95696bed4ce4bfd04bc17e01.zip Qt-a5e11573712fcf1c95696bed4ce4bfd04bc17e01.tar.gz Qt-a5e11573712fcf1c95696bed4ce4bfd04bc17e01.tar.bz2 |
Remove unnecessary global context management stuff
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/qmlcomponent.cpp | 10 | ||||
-rw-r--r-- | src/declarative/qml/qmlcontext.cpp | 50 | ||||
-rw-r--r-- | src/declarative/qml/qmlcontext.h | 5 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 130 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.h | 3 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine_p.h | 3 | ||||
-rw-r--r-- | src/declarative/qml/qmlmetaproperty.cpp | 3 | ||||
-rw-r--r-- | src/declarative/qml/qmlvme.cpp | 22 |
8 files changed, 16 insertions, 210 deletions
diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 0e68f8a..c7d45fd 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -405,9 +405,10 @@ QString QmlComponent::errorsString() const QString ret; if(!isError()) return ret; - foreach(const QmlError &e, d->errors){ - ret += e.url().toString() + ":" + QString::number(e.line()) + " " - + e.description() + "\n"; + foreach(const QmlError &e, d->errors) { + ret += e.url().toString() + QLatin1String(":") + + QString::number(e.line()) + QLatin1String(" ") + + e.description() + QLatin1String("\n"); } return ret; } @@ -532,7 +533,6 @@ QObject *QmlComponent::beginCreate(QmlContext *context) static_cast<QmlContextPrivate*>(ctxt->d_ptr)->startLine = d->cc->bytecode.at(d->start - 1).line; static_cast<QmlContextPrivate*>(ctxt->d_ptr)->endLine = d->cc->bytecode.at(d->start - 1).createComponent.endLine; } - ctxt->activate(); QmlVME vme; QObject *rv = vme.run(ctxt, d->cc, d->start, d->count); @@ -540,8 +540,6 @@ QObject *QmlComponent::beginCreate(QmlContext *context) if (vme.isError()) d->errors = vme.errors(); - ctxt->deactivate(); - QmlEnginePrivate *ep = d->engine->d_func(); if (ep->rootComponent == this) { ep->rootComponent = 0; diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index 440f4b8..5bc70bc 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -405,56 +405,6 @@ void QmlContext::setContextProperty(const QString &name, QObject *value) } /*! - Activate this bind context. - - \sa QmlEngine::activeContext() QmlContext::activeContext() -*/ -void QmlContext::activate() -{ - QmlEnginePrivate *ep = engine()->d_func(); - ep->activeContexts.push(this); - ep->setCurrentBindContext(this); - ep->contextActivated(this); -} - -/*! - Deactivate this bind context. The previously active bind context will - become active, or, if there was no previously active bind context, no - context will be active. - - \sa QmlEngine::activeContext() QmlContext::activeContext() -*/ -void QmlContext::deactivate() -{ - QmlEnginePrivate *ep = engine()->d_func(); - Q_ASSERT(ep->activeContexts.top() == this); - ep->activeContexts.pop(); - if (ep->activeContexts.isEmpty()) - ep->setCurrentBindContext(0); - else - ep->setCurrentBindContext(ep->activeContexts.top()); - ep->contextDeactivated(this); -} - -/*! - Returns the currently active context, or 0 if no context is active. - - This method is thread-safe. The active context is maintained individually - for each thread. This method is equivalent to - \code - QmlEngine::activeEngine()->activeContext() - \endcode -*/ -QmlContext *QmlContext::activeContext() -{ - QmlEngine *engine = QmlEngine::activeEngine(); - if (engine) - return engine->activeContext(); - else - return 0; -} - -/*! Resolves the URL \a src relative to the URL of the containing component. If \a src is absolute, it is simply returned. If there is no containing component, diff --git a/src/declarative/qml/qmlcontext.h b/src/declarative/qml/qmlcontext.h index 77f6634..877ff0f 100644 --- a/src/declarative/qml/qmlcontext.h +++ b/src/declarative/qml/qmlcontext.h @@ -73,11 +73,6 @@ public: void setContextProperty(const QString &, QObject *); void setContextProperty(const QString &, const QVariant &); - void activate(); - void deactivate(); - - static QmlContext *activeContext(); - QUrl resolvedUrl(const QUrl &); void setBaseUrl(const QUrl &); diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 44b857c..d724c49 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -90,49 +90,6 @@ struct StaticQtMetaObject : public QObject { return &static_cast<StaticQtMetaObject*> (0)->staticQtMetaObject; } }; - -struct QmlEngineStack { - QmlEngineStack(); - - QStack<QmlEngine *> mainThreadEngines; - QThread *mainThread; - - QThreadStorage<QStack<QmlEngine *> *> storage; - - QStack<QmlEngine *> *engines(); -}; - -Q_GLOBAL_STATIC(QmlEngineStack, engineStack); - -QmlEngineStack::QmlEngineStack() -: mainThread(0) -{ -} - -QStack<QmlEngine *> *QmlEngineStack::engines() -{ - if (mainThread== 0) { - if (!QCoreApplication::instance()) - return 0; - mainThread = QCoreApplication::instance()->thread(); - } - - // Note: This is very slightly faster than just using the thread storage - // for everything. - QStack<QmlEngine *> *engines = 0; - if (QThread::currentThread() == mainThread) { - engines = &mainThreadEngines; - } else { - engines = storage.localData(); - if (!engines) { - engines = new QStack<QmlEngine *>; - storage.setLocalData(engines); - } - } - return engines; -} - - QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) : rootContext(0), currentBindContext(0), currentExpression(0), q(e), isDebugging(false), rootComponent(0), networkAccessManager(0), typeManager(e), @@ -295,30 +252,6 @@ QScriptValue QmlEnginePrivate::propertyObject(const QScriptString &propName, return QScriptValue(); } -void QmlEnginePrivate::contextActivated(QmlContext *) -{ - Q_Q(QmlEngine); - QmlEngineStack *stack = engineStack(); - if (!stack) - return; - QStack<QmlEngine *> *engines = stack->engines(); - if (engines) - engines->push(q); -} - -void QmlEnginePrivate::contextDeactivated(QmlContext *) -{ - QmlEngineStack *stack = engineStack(); - if (!stack) - return; - QStack<QmlEngine *> *engines = stack->engines(); - if (engines) { - Q_ASSERT(engines->top() == q_func()); - engines->pop(); - } -} - - //////////////////////////////////////////////////////////////////// bool QmlEnginePrivate::fetchCache(QmlBasicScriptNodeCache &cache, const QString &propName, QObject *obj) @@ -469,40 +402,12 @@ QmlContext *QmlEngine::rootContext() } /*! - Returns this engine's active context, or 0 if no context is active on this - engine. - - Contexts are activated and deactivated by calling QmlContext::activate() and - QmlContext::deactivate() respectively. - - Context activation holds no special semantic, other than it allows types - instantiated by QML to access "their" context without having it passed as - a parameter in their constructor, as shown below. - \code - class MyClass : ... { - ... - MyClass() { - qWarning() << "I was instantiated in this context:" - << QmlContext::activeContext(); - } - }; - \endcode -*/ -QmlContext *QmlEngine::activeContext() -{ - Q_D(QmlEngine); - if (d->currentBindContext) - return d->currentBindContext; - else - return 0; -} - -/*! - Sets the common QNetworkAccessManager, \a network, used by all QML elements instantiated - by this engine. + Sets the common QNetworkAccessManager, \a network, used by all QML elements + instantiated by this engine. - Any previously set manager is deleted and \a network is owned by the QmlEngine. This - method should only be called before any QmlComponents are instantiated. + Any previously set manager is deleted and \a network is owned by the + QmlEngine. This method should only be called before any QmlComponents are + instantiated. */ void QmlEngine::setNetworkAccessManager(QNetworkAccessManager *network) { @@ -669,30 +574,6 @@ QScriptEngine *QmlEngine::scriptEngine() } /*! - Returns the currently active QmlEngine. - - The active engine is the engine associated with the last activated - QmlContext. This method is thread-safe - the "active" engine is maintained - independently for each thread. -*/ -QmlEngine *QmlEngine::activeEngine() -{ - QmlEngineStack *stack = engineStack(); - if (!stack) return 0; - - QStack<QmlEngine *> *engines = stack->engines(); - if (!engines) { - qWarning("QmlEngine::activeEngine() cannot be called before the construction of QCoreApplication"); - return 0; - } - - if (engines->isEmpty()) - return 0; - else - return engines->top(); -} - -/*! Creates a QScriptValue allowing you to use \a object in QML script. \a engine is the QmlEngine it is to be created in. @@ -777,7 +658,6 @@ QScriptValue QmlEngine::createComponent(QScriptContext *ctxt, QScriptEngine *eng QUrl url = QUrl(activeEngine->d_func()->currentExpression->context() ->resolvedUrl(ctxt->argument(0).toString())); if(!url.isValid()){ - qDebug() << "Error A:" << url << activeEngine->activeContext() << QmlEngine::activeEngine() << activeEngine; url = QUrl(ctxt->argument(0).toString()); } c = new QmlComponent(activeEngine, url, activeEngine); diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h index 6a418b5..38bf423 100644 --- a/src/declarative/qml/qmlengine.h +++ b/src/declarative/qml/qmlengine.h @@ -70,10 +70,7 @@ public: QmlEngine(QObject *p = 0); virtual ~QmlEngine(); - static QmlEngine *activeEngine(); - QmlContext *rootContext(); - QmlContext *activeContext(); void clearComponentCache(); diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index e0824cc..f459dc5 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -93,9 +93,6 @@ public: void init(); - void contextActivated(QmlContext *); - void contextDeactivated(QmlContext *); - bool fetchCache(QmlBasicScriptNodeCache &cache, const QString &propName, QObject *); bool loadCache(QmlBasicScriptNodeCache &cache, const QString &propName, QmlContextPrivate *context); diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 6602021..dea3467 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -643,8 +643,7 @@ void QmlMetaPropertyPrivate::writeSignalProperty(const QVariant &value) if (!expr.isEmpty()) { // XXX scope - (void *)new QmlBoundSignal(QmlContext::activeContext(), expr, object, - coreIdx, object); + (void *)new QmlBoundSignal(qmlContext(object), expr, object, coreIdx, object); } } diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index 3b33686..f468cd0 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -116,7 +116,6 @@ void QmlVME::runDeferred(QObject *object) return; QmlContext *ctxt = data->context; - ctxt->activate(); QmlCompiledData *comp = data->deferredComponent; int start = data->deferredIdx + 1; int count = data->deferredComponent->bytecode.at(data->deferredIdx).defer.deferCount; @@ -124,17 +123,10 @@ void QmlVME::runDeferred(QObject *object) stack.push(object); run(stack, ctxt, comp, start, count); - ctxt->deactivate(); } QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledData *comp, int start, int count) { - // XXX - All instances of QmlContext::activeContext() here should be - // replaced with the use of ctxt. However, this cannot be done until - // behaviours stop modifying the active context and expecting the - // instantiation to notice. Instead, QmlParserStatus::beginClass() should - // be able to return a QmlContext that is used for expressions and - // sub-instances on that type. Q_ASSERT(comp); Q_ASSERT(ctxt); const QList<QmlCompiledData::TypeReference> &types = comp->types; @@ -169,7 +161,7 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledData case QmlInstruction::CreateObject: { - QObject *o = types.at(instr.create.type).createInstance(QmlContext::activeContext()); + QObject *o = types.at(instr.create.type).createInstance(ctxt); if (!o) { if(types.at(instr.create.type).component) vmeErrors << types.at(instr.create.type).component->errors(); @@ -203,8 +195,6 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledData case QmlInstruction::SetId: { QObject *target = stack.top(); - QmlContext *ctxt = - QmlContext::activeContext(); ctxt->setContextProperty(primitives.at(instr.setId.value), target); } break; @@ -213,7 +203,7 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledData case QmlInstruction::SetDefault: { QObject *target = stack.top(); - QmlContext::activeContext()->addDefaultObject(target); + ctxt->addDefaultObject(target); } break; @@ -515,9 +505,9 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledData target->metaObject()->method(instr.storeSignal.signalIndex); if (signal.parameterTypes().isEmpty()) { - (void *)new QmlBoundSignal(QmlContext::activeContext(), primitives.at(instr.storeSignal.value), target, instr.storeSignal.signalIndex, target); + (void *)new QmlBoundSignal(ctxt, primitives.at(instr.storeSignal.value), target, instr.storeSignal.signalIndex, target); } else { - (void *)new QmlBoundSignalProxy(new QmlContext(QmlContext::activeContext(), target, true), primitives.at(instr.storeSignal.value), target, instr.storeSignal.signalIndex, target); + (void *)new QmlBoundSignalProxy(new QmlContext(ctxt, target, true), primitives.at(instr.storeSignal.value), target, instr.storeSignal.signalIndex, target); } } break; @@ -550,7 +540,7 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledData QmlMetaProperty mp(target, instr.assignBinding.property, (QmlMetaProperty::PropertyCategory)instr.assignBinding.category); - QmlBindableValue *bind = new QmlBindableValue((void *)datas.at(instr.assignBinding.value).constData(), comp, context, QmlContext::activeContext(), 0); + QmlBindableValue *bind = new QmlBindableValue((void *)datas.at(instr.assignBinding.value).constData(), comp, context, ctxt, 0); bindValues.append(bind); QmlBindableValuePrivate *p = static_cast<QmlBindableValuePrivate *>(QObjectPrivate::get(bind)); @@ -570,7 +560,7 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledData QmlMetaProperty mp(target, instr.assignBinding.property, (QmlMetaProperty::PropertyCategory)instr.assignBinding.category); - QmlBindableValue *bind = new QmlBindableValue(primitives.at(instr.assignBinding.value), context, QmlContext::activeContext()); + QmlBindableValue *bind = new QmlBindableValue(primitives.at(instr.assignBinding.value), context, ctxt); bindValues.append(bind); QmlBindableValuePrivate *p = static_cast<QmlBindableValuePrivate *>(QObjectPrivate::get(bind)); |