summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/qmlbinding.cpp8
-rw-r--r--src/declarative/qml/qmlbinding_p.h1
-rw-r--r--src/declarative/qml/qmlcontext.cpp35
-rw-r--r--src/declarative/qml/qmlcontext_p.h1
-rw-r--r--src/declarative/qml/qmlexpression.cpp4
-rw-r--r--src/declarative/qml/qmlexpression_p.h6
6 files changed, 51 insertions, 4 deletions
diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp
index eb08b61..5f7330f 100644
--- a/src/declarative/qml/qmlbinding.cpp
+++ b/src/declarative/qml/qmlbinding.cpp
@@ -67,6 +67,14 @@ QmlBindingData::~QmlBindingData()
removeError();
}
+void QmlBindingData::refresh()
+{
+ if (enabled && !updating && q) {
+ QmlBinding *b = static_cast<QmlBinding *>(QmlExpressionPrivate::get(q));
+ b->update();
+ }
+}
+
void QmlBindingData::removeError()
{
if (!prevError) return;
diff --git a/src/declarative/qml/qmlbinding_p.h b/src/declarative/qml/qmlbinding_p.h
index 6977e5b..e4de239 100644
--- a/src/declarative/qml/qmlbinding_p.h
+++ b/src/declarative/qml/qmlbinding_p.h
@@ -70,6 +70,7 @@ public:
QmlMetaProperty property;
+ virtual void refresh();
void removeError();
bool addError();
QmlBindingData *nextError;
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 {
diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h
index 286b882..cc8fcc6 100644
--- a/src/declarative/qml/qmlcontext_p.h
+++ b/src/declarative/qml/qmlcontext_p.h
@@ -105,6 +105,7 @@ public:
void dump(int depth);
void invalidateEngines();
+ void refreshExpressions();
QSet<QmlContext *> childContexts;
QmlAbstractExpression *expressions;
diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp
index 2470c1d..faf9f5a 100644
--- a/src/declarative/qml/qmlexpression.cpp
+++ b/src/declarative/qml/qmlexpression.cpp
@@ -728,6 +728,10 @@ void QmlAbstractExpression::setContext(QmlContext *context)
}
}
+void QmlAbstractExpression::refresh()
+{
+}
+
bool QmlAbstractExpression::isValid() const
{
return m_context != 0;
diff --git a/src/declarative/qml/qmlexpression_p.h b/src/declarative/qml/qmlexpression_p.h
index ea572c3..c6ba54d 100644
--- a/src/declarative/qml/qmlexpression_p.h
+++ b/src/declarative/qml/qmlexpression_p.h
@@ -72,8 +72,11 @@ public:
QmlContext *context() const;
void setContext(QmlContext *);
+ virtual void refresh();
+
private:
friend class QmlContext;
+ friend class QmlContextPrivate;
QmlContext *m_context;
QmlAbstractExpression **m_prevExpression;
QmlAbstractExpression *m_nextExpression;
@@ -152,6 +155,9 @@ public:
static QmlExpressionPrivate *get(QmlExpression *expr) {
return static_cast<QmlExpressionPrivate *>(QObjectPrivate::get(expr));
}
+ static QmlExpression *get(QmlExpressionPrivate *expr) {
+ return expr->q_func();
+ }
static void exceptionToError(QScriptEngine *, QmlError &);
};