summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-03-29 06:24:14 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-03-29 06:24:14 (GMT)
commitc3735fe990ca7b18a45d08867e853187fe1d3443 (patch)
tree25feea76946220a2dff89d3018275eef3d898a4f
parentc9500f6aebf276b0d96836698a90f334adf0a797 (diff)
parentf3fe89a22b3339fa683bf656950285d1218b1765 (diff)
downloadQt-c3735fe990ca7b18a45d08867e853187fe1d3443.zip
Qt-c3735fe990ca7b18a45d08867e853187fe1d3443.tar.gz
Qt-c3735fe990ca7b18a45d08867e853187fe1d3443.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
-rw-r--r--doc/src/declarative/scope.qdoc2
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp85
-rw-r--r--tests/auto/declarative/qmlvisual/animation/parentAnimation/data/parentAnimation-visual.qml (renamed from tests/auto/declarative/qmlvisual/animation/parentAnimation/data/parentAnimation.qml)0
-rw-r--r--tests/auto/declarative/qmlvisual/animation/parentAnimation/parentAnimation-visual.qml (renamed from tests/auto/declarative/qmlvisual/animation/parentAnimation/parentAnimation.qml)0
-rw-r--r--tests/auto/declarative/qmlvisual/animation/pauseAnimation/data/pauseAnimation-visual.qml (renamed from tests/auto/declarative/qmlvisual/animation/pauseAnimation/data/pauseAnimation.qml)0
-rw-r--r--tests/auto/declarative/qmlvisual/animation/pauseAnimation/pauseAnimation-visual.qml (renamed from tests/auto/declarative/qmlvisual/animation/pauseAnimation/pauseAnimation.qml)0
-rw-r--r--tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp8
7 files changed, 45 insertions, 50 deletions
diff --git a/doc/src/declarative/scope.qdoc b/doc/src/declarative/scope.qdoc
index c588b45..964f7d5 100644
--- a/doc/src/declarative/scope.qdoc
+++ b/doc/src/declarative/scope.qdoc
@@ -160,7 +160,7 @@ Bindings have access to the scope object's properties without qualification.
In the previous example, the binding accesses the \l Item's \c parent property
directly, without needing any form of object prefix. QML introduces a more
structured, object-oriented approach to JavaScript, and consequently does not
-require (although it does support) use of the implicit \c this property.
+require the use of the JavaScript \c this property.
Care must be used when accessing \l {Attached Properties} from bindings due
to their interaction with the scope object. Conceptually attached properties
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index 2b8cf70..a9224ad 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -71,31 +71,30 @@ QDeclarativeContextPrivate::QDeclarativeContextPrivate()
Contexts allow data to be exposed to the QML components instantiated by the
QML engine.
- Each QDeclarativeContext contains a set of properties, distinct from
- its QObject properties, that allow data to be
- explicitly bound to a context by name. The context properties are defined or
- updated by calling QDeclarativeContext::setContextProperty(). The following example shows
- a Qt model being bound to a context and then accessed from a QML file.
+ Each QDeclarativeContext contains a set of properties, distinct from its QObject
+ properties, that allow data to be explicitly bound to a context by name. The
+ context properties are defined and updated by calling
+ QDeclarativeContext::setContextProperty(). The following example shows a Qt model
+ being bound to a context and then accessed from a QML file.
\code
QDeclarativeEngine engine;
- QDeclarativeContext context(engine.rootContext());
- context.setContextProperty("myModel", modelData);
+ QDeclarativeContext *context = new QDeclarativeContext(engine.rootContext());
+ context->setContextProperty("myModel", modelData);
QDeclarativeComponent component(&engine, "ListView { model=myModel }");
- component.create(&context);
+ component.create(context);
\endcode
- To simplify binding and maintaining larger data sets, QObject's can be
- added to a QDeclarativeContext. These objects are known as the context's default
- objects. In this case all the properties of the QObject are
- made available by name in the context, as though they were all individually
- added by calling QDeclarativeContext::setContextProperty(). Changes to the property's
- values are detected through the property's notify signal. This method is
- also slightly more faster than manually adding property values.
+ To simplify binding and maintaining larger data sets, a context object can be set
+ on a QDeclarativeContext. All the properties of the context object are available
+ by name in the context, as though they were all individually added through calls
+ to QDeclarativeContext::setContextProperty(). Changes to the property's values are
+ detected through the property's notify signal. Setting a context object is both
+ faster and easier than manually adding and maintaing context property values.
- The following example has the same effect as the one above, but it is
- achieved using a default object.
+ The following example has the same effect as the previous one, but it uses a context
+ object.
\code
class MyDataSet : ... {
@@ -104,46 +103,42 @@ QDeclarativeContextPrivate::QDeclarativeContextPrivate()
...
};
- MyDataSet myDataSet;
+ MyDataSet *myDataSet = new MyDataSet;
QDeclarativeEngine engine;
- QDeclarativeContext context(engine.rootContext());
- context.setContextObject(&myDataSet);
+ QDeclarativeContext *context = new QDeclarativeContext(engine.rootContext());
+ context->setContextObject(myDataSet);
QDeclarativeComponent component(&engine, "ListView { model=myModel }");
- component.create(&context);
+ component.create(context);
\endcode
- Default objects added first take precedence over those added later. All properties
- added explicitly by QDeclarativeContext::setContextProperty() take precedence over default
- object properties.
+ All properties added explicitly by QDeclarativeContext::setContextProperty() take
+ precedence over context object's properties.
- Contexts are hierarchal, with the \l {QDeclarativeEngine::rootContext()}{root context}
- being created by the QDeclarativeEngine. A component instantiated in a given context
- has access to that context's data, as well as the data defined by its
- ancestor contexts. Data values (including those added implicitly by the
- default objects) in a context override those in ancestor contexts. Data
- that should be available to all components instantiated by the QDeclarativeEngine
- should be added to the \l {QDeclarativeEngine::rootContext()}{root context}.
+ Contexts form a hierarchy. The root of this heirarchy is the QDeclarativeEngine's
+ \l {QDeclarativeEngine::rootContext()}{root context}. A component instance can
+ access the data in its own context, as well as all its ancestor contexts. Data
+ can be made available to all instances by modifying the
+ \l {QDeclarativeEngine::rootContext()}{root context}.
- In the following example,
+ The following example defines two contexts - \c context1 and \c context2. The
+ second context overrides the "b" context property inherited from the first with a
+ new value.
\code
QDeclarativeEngine engine;
- QDeclarativeContext context1(engine.rootContext());
- QDeclarativeContext context2(&context1);
- QDeclarativeContext context3(&context2);
-
- context1.setContextProperty("a", 12);
- context2.setContextProperty("b", 13);
- context3.setContextProperty("a", 14);
- context3.setContextProperty("c", 14);
+ QDeclarativeContext *context1 = new QDeclarativeContext(engine.rootContext());
+ QDeclarativeContext *context2 = new QDeclarativeContext(context1);
+
+ context1->setContextProperty("a", 12);
+ context1->setContextProperty("b", 12);
+
+ context2->setContextProperty("b", 15);
\endcode
- a QML component instantiated in context1 would have access to the "a" data,
- a QML component instantiated in context2 would have access to the "a" and
- "b" data, and a QML component instantiated in context3 would have access to
- the "a", "b" and "c" data - although its "a" data would return 14, unlike
- that in context1 or context2.
+ While QML objects instantiated in a context are not strictly owned by that
+ context, their bindings are. If a context is destroyed, the property bindings of
+ outstanding QML objects will stop evaluating.
*/
/*! \internal */
diff --git a/tests/auto/declarative/qmlvisual/animation/parentAnimation/data/parentAnimation.qml b/tests/auto/declarative/qmlvisual/animation/parentAnimation/data/parentAnimation-visual.qml
index 5718560..5718560 100644
--- a/tests/auto/declarative/qmlvisual/animation/parentAnimation/data/parentAnimation.qml
+++ b/tests/auto/declarative/qmlvisual/animation/parentAnimation/data/parentAnimation-visual.qml
diff --git a/tests/auto/declarative/qmlvisual/animation/parentAnimation/parentAnimation.qml b/tests/auto/declarative/qmlvisual/animation/parentAnimation/parentAnimation-visual.qml
index 8d0b375..8d0b375 100644
--- a/tests/auto/declarative/qmlvisual/animation/parentAnimation/parentAnimation.qml
+++ b/tests/auto/declarative/qmlvisual/animation/parentAnimation/parentAnimation-visual.qml
diff --git a/tests/auto/declarative/qmlvisual/animation/pauseAnimation/data/pauseAnimation.qml b/tests/auto/declarative/qmlvisual/animation/pauseAnimation/data/pauseAnimation-visual.qml
index 73c6542..73c6542 100644
--- a/tests/auto/declarative/qmlvisual/animation/pauseAnimation/data/pauseAnimation.qml
+++ b/tests/auto/declarative/qmlvisual/animation/pauseAnimation/data/pauseAnimation-visual.qml
diff --git a/tests/auto/declarative/qmlvisual/animation/pauseAnimation/pauseAnimation.qml b/tests/auto/declarative/qmlvisual/animation/pauseAnimation/pauseAnimation-visual.qml
index 8830170..8830170 100644
--- a/tests/auto/declarative/qmlvisual/animation/pauseAnimation/pauseAnimation.qml
+++ b/tests/auto/declarative/qmlvisual/animation/pauseAnimation/pauseAnimation-visual.qml
diff --git a/tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp b/tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp
index f87fd29..8f1a406 100644
--- a/tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp
+++ b/tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp
@@ -97,12 +97,12 @@ void tst_qmlvisual::visual_data()
QTest::addColumn<QString>("testdata");
QStringList files;
- if (qgetenv("RUN_ALL") != "")
+ if (qgetenv("QMLVISUAL_ALL") != "")
files << findQmlFiles(QDir(QT_TEST_SOURCE_DIR));
else {
//these are tests we think are stable and useful enough to be run by the CI system
- files << QT_TEST_SOURCE_DIR "/animation/pauseAnimation/pauseAnimation.qml";
- files << QT_TEST_SOURCE_DIR "/animation/parentAnimation/parentAnimation.qml";
+ files << QT_TEST_SOURCE_DIR "/animation/pauseAnimation/pauseAnimation-visual.qml";
+ files << QT_TEST_SOURCE_DIR "/animation/parentAnimation/parentAnimation-visual.qml";
files << QT_TEST_SOURCE_DIR "/animation/reanchor/reanchor.qml";
}
@@ -124,7 +124,7 @@ void tst_qmlvisual::visual()
QStringList arguments;
arguments << "-script" << testdata
<< "-scriptopts" << "play,testimages,testerror,exitoncomplete,exitonfailure"
- << file;
+ << file << "-graphicssystem" << "raster";
QProcess p;
p.start(qmlruntime, arguments);
QVERIFY(p.waitForFinished());