diff options
Diffstat (limited to 'src/declarative/qml/qdeclarativecontext.cpp')
-rw-r--r-- | src/declarative/qml/qdeclarativecontext.cpp | 93 |
1 files changed, 56 insertions, 37 deletions
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index f70e143..237cb7e 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -59,12 +59,14 @@ QT_BEGIN_NAMESPACE QDeclarativeContextPrivate::QDeclarativeContextPrivate() : parent(0), engine(0), isInternal(false), propertyNames(0), - notifyIndex(-1), highPriorityCount(0), imports(0), expressions(0), contextObjects(0), + notifyIndex(-1), contextObject(0), imports(0), childContexts(0), + nextChild(0), prevChild(0), expressions(0), contextObjects(0), idValues(0), idValueCount(0), optimizedBindings(0) { } -void QDeclarativeContextPrivate::addScript(const QDeclarativeParser::Object::ScriptBlock &script, QObject *scopeObject) +void QDeclarativeContextPrivate::addScript(const QDeclarativeParser::Object::ScriptBlock &script, + QObject *scopeObject) { Q_Q(QDeclarativeContext); @@ -109,12 +111,7 @@ void QDeclarativeContextPrivate::destroyed(ContextGuard *guard) if (parent && QObjectPrivate::get(parent)->wasDeleted) return; - while(guard->bindings) { - QObject *o = guard->bindings->target; - int mi = guard->bindings->methodIndex; - guard->bindings->clear(); - if (o) o->qt_metacall(QMetaObject::InvokeMetaMethod, mi, 0); - } + guard->bindings.notify(); for (int ii = 0; ii < idValueCount; ++ii) { if (&idValues[ii] == guard) { @@ -128,8 +125,13 @@ void QDeclarativeContextPrivate::init() { Q_Q(QDeclarativeContext); - if (parent) - parent->d_func()->childContexts.insert(q); + if (parent) { + QDeclarativeContextPrivate *ppriv = parent->d_func(); + nextChild = ppriv->childContexts; + if (nextChild) nextChild->d_func()->prevChild = &nextChild; + prevChild = &ppriv->childContexts; + ppriv->childContexts = q; + } } /*! @@ -177,7 +179,7 @@ void QDeclarativeContextPrivate::init() MyDataSet myDataSet; QDeclarativeEngine engine; QDeclarativeContext context(engine.rootContext()); - context.addDefaultObject(&myDataSet); + context.setContextObject(&myDataSet); QDeclarativeComponent component(&engine, "ListView { model=myModel }"); component.create(&context); @@ -275,15 +277,24 @@ QDeclarativeContext::QDeclarativeContext(QDeclarativeContext *parentContext, QOb QDeclarativeContext::~QDeclarativeContext() { Q_D(QDeclarativeContext); - if (d->parent) - d->parent->d_func()->childContexts.remove(this); - - for (QSet<QDeclarativeContext *>::ConstIterator iter = d->childContexts.begin(); - iter != d->childContexts.end(); - ++iter) { - (*iter)->d_func()->invalidateEngines(); - (*iter)->d_func()->parent = 0; + + if (d->prevChild) { + *d->prevChild = d->nextChild; + if (d->nextChild) d->nextChild->d_func()->prevChild = d->prevChild; + d->nextChild = 0; + d->prevChild = 0; } + + QDeclarativeContext *child = d->childContexts; + while (child) { + QDeclarativeContextPrivate *childpriv = child->d_func(); + childpriv->invalidateEngines(); + childpriv->parent = 0; + child = childpriv->nextChild; + childpriv->nextChild = 0; + childpriv->prevChild = 0; + } + d->childContexts = 0; QDeclarativeAbstractExpression *expression = d->expressions; while (expression) { @@ -322,10 +333,12 @@ void QDeclarativeContextPrivate::invalidateEngines() if (!engine) return; engine = 0; - for (QSet<QDeclarativeContext *>::ConstIterator iter = childContexts.begin(); - iter != childContexts.end(); - ++iter) { - (*iter)->d_func()->invalidateEngines(); + + QDeclarativeContext *child = childContexts; + while (child) { + QDeclarativeContextPrivate *childpriv = child->d_func(); + childpriv->invalidateEngines(); + child = childpriv->nextChild; } } @@ -336,10 +349,11 @@ time the context tree *structure* (not values) changes. */ void QDeclarativeContextPrivate::refreshExpressions() { - for (QSet<QDeclarativeContext *>::ConstIterator iter = childContexts.begin(); - iter != childContexts.end(); - ++iter) { - (*iter)->d_func()->refreshExpressions(); + QDeclarativeContext *child = childContexts; + while (child) { + QDeclarativeContextPrivate *childpriv = child->d_func(); + childpriv->refreshExpressions(); + child = childpriv->nextChild; } QDeclarativeAbstractExpression *expression = expressions; @@ -370,13 +384,21 @@ QDeclarativeContext *QDeclarativeContext::parentContext() const } /*! - Add \a defaultObject to this context. The object will be added after - any existing default objects. + Return the context object, or 0 if there is no context object. */ -void QDeclarativeContext::addDefaultObject(QObject *defaultObject) +QObject *QDeclarativeContext::contextObject() const +{ + Q_D(const QDeclarativeContext); + return d->contextObject; +} + +/*! + Set the context \a object. +*/ +void QDeclarativeContext::setContextObject(QObject *object) { Q_D(QDeclarativeContext); - d->defaultObjects.prepend(defaultObject); + d->contextObject = object; } /*! @@ -471,15 +493,12 @@ QVariant QDeclarativeContext::contextProperty(const QString &name) const if (idx == -1) { QByteArray utf8Name = name.toUtf8(); - for (int ii = d->defaultObjects.count() - 1; ii >= 0; --ii) { - QObject *obj = d->defaultObjects.at(ii); + if (d->contextObject) { + QObject *obj = d->contextObject; QDeclarativePropertyCache::Data local; QDeclarativePropertyCache::Data *property = QDeclarativePropertyCache::property(d->engine, obj, name, local); - if (property) { - value = obj->metaObject()->property(property->coreIndex).read(obj); - break; - } + if (property) value = obj->metaObject()->property(property->coreIndex).read(obj); } if (!value.isValid() && parentContext()) value = parentContext()->contextProperty(name); |