diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-11-02 03:53:11 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-11-02 03:53:11 (GMT) |
commit | c0a7cfc6d205caf93bc46693ef4aca15fbcc36f8 (patch) | |
tree | 4d5e20eda722535e8f1c51935c9b2c7a7db39e84 /src/declarative/qml/qmlcontext.cpp | |
parent | d01db18696a7729b0d54af76f5224aed6750f3bb (diff) | |
download | Qt-c0a7cfc6d205caf93bc46693ef4aca15fbcc36f8.zip Qt-c0a7cfc6d205caf93bc46693ef4aca15fbcc36f8.tar.gz Qt-c0a7cfc6d205caf93bc46693ef4aca15fbcc36f8.tar.bz2 |
QmlContext tests
Diffstat (limited to 'src/declarative/qml/qmlcontext.cpp')
-rw-r--r-- | src/declarative/qml/qmlcontext.cpp | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index fe0d9cb..d37d959 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -180,9 +180,9 @@ void QmlContextPrivate::init() component.create(&context); \endcode - Each context may have up to 32 default objects, and objects added first take - precedence over those added later. All properties added explicitly by - QmlContext::setContextProperty() take precedence over default object properties. + Default objects added first take precedence over those added later. All properties + added explicitly by QmlContext::setContextProperty() take precedence over default + object properties. Contexts are hierarchal, with the \l {QmlEngine::rootContext()}{root context} being created by the QmlEngine. A component instantiated in a given context @@ -323,6 +323,26 @@ void QmlContextPrivate::invalidateEngines() } } +/* +Refreshes all expressions that could possibly depend on this context. +Refreshing flushes all context-tree dependent caches in the expressions, and should occur every +time the context tree *structure* (not values) changes. +*/ +void QmlContextPrivate::refreshExpressions() +{ + for (QSet<QmlContext *>::ConstIterator iter = childContexts.begin(); + iter != childContexts.end(); + ++iter) { + (*iter)->d_func()->refreshExpressions(); + } + + QmlAbstractExpression *expression = expressions; + while (expression) { + expression->refresh(); + expression = expression->m_nextExpression; + } +} + /*! Return the context's QmlEngine, or 0 if the context has no QmlEngine or the QmlEngine was destroyed. @@ -373,6 +393,8 @@ void QmlContext::setContextProperty(const QString &name, const QVariant &value) if (idx == -1) { d->propertyNames->add(name, d->idValueCount + d->propertyValues.count()); d->propertyValues.append(value); + + d->refreshExpressions(); } else { d->propertyValues[idx] = value; QMetaObject::activate(this, idx + d->notifyIndex, 0); @@ -404,7 +426,7 @@ void QmlContextPrivate::setIdPropertyData(QmlIntegerCache *data) /*! Set a the \a value of the \a name property on this context. - QmlContext does \b not take ownership of \a value. + QmlContext does \bold not take ownership of \a value. */ void QmlContext::setContextProperty(const QString &name, QObject *value) { @@ -418,6 +440,8 @@ void QmlContext::setContextProperty(const QString &name, QObject *value) if (idx == -1) { d->propertyNames->add(name, d->idValueCount + d->propertyValues.count()); d->propertyValues.append(QVariant::fromValue(value)); + + d->refreshExpressions(); } else { d->propertyValues[idx] = QVariant::fromValue(value); QMetaObject::activate(this, idx + d->notifyIndex, 0); @@ -432,6 +456,7 @@ void QmlContext::setContextProperty(const QString &name, QObject *value) */ QUrl QmlContext::resolvedUrl(const QUrl &src) { + Q_D(QmlContext); QmlContext *ctxt = this; if (src.isRelative() && !src.isEmpty()) { if (ctxt) { @@ -444,6 +469,8 @@ QUrl QmlContext::resolvedUrl(const QUrl &src) if (ctxt) return ctxt->d_func()->url.resolved(src); + else if (d->engine) + return d->engine->baseUrl().resolved(src); } return QUrl(); } else { |