summaryrefslogtreecommitdiffstats
path: root/doc/src/declarative/qdeclarativemodels.qdoc
diff options
context:
space:
mode:
authorDavid Boddie <dboddie@trolltech.com>2010-05-19 09:33:21 (GMT)
committerDavid Boddie <dboddie@trolltech.com>2010-05-19 09:33:21 (GMT)
commitebe28bdd77ca615c47ebf6b41e34aee0c154fcf9 (patch)
treea1aa1578f798bae0cc23c32656134628bf5af788 /doc/src/declarative/qdeclarativemodels.qdoc
parent109024630cbf577d6f6bcb10ea3ac6272113b79e (diff)
parent28b894f65c5aba01d5ee80c20f617478faaee7e7 (diff)
downloadQt-ebe28bdd77ca615c47ebf6b41e34aee0c154fcf9.zip
Qt-ebe28bdd77ca615c47ebf6b41e34aee0c154fcf9.tar.gz
Qt-ebe28bdd77ca615c47ebf6b41e34aee0c154fcf9.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.7
Diffstat (limited to 'doc/src/declarative/qdeclarativemodels.qdoc')
-rw-r--r--doc/src/declarative/qdeclarativemodels.qdoc33
1 files changed, 31 insertions, 2 deletions
diff --git a/doc/src/declarative/qdeclarativemodels.qdoc b/doc/src/declarative/qdeclarativemodels.qdoc
index 91acb3c..788d417 100644
--- a/doc/src/declarative/qdeclarativemodels.qdoc
+++ b/doc/src/declarative/qdeclarativemodels.qdoc
@@ -143,6 +143,28 @@ ListView {
}
\endcode
+It is also possible to manipulate the ListModel directly via JavaScript.
+In this case, the first item inserted will determine the roles available
+to any views using the model. For example, if an empty ListModel is
+created and populated via JavaScript the roles provided by the first
+insertion are the only roles that will be shown in the view:
+
+\code
+Item {
+ ListModel {
+ id: fruitModel
+ }
+ MouseArea {
+ anchors.fill: parent
+ onClicked: fruitModel.append({"cost": 5.95, "name":"Pizza"})
+ }
+}
+\endcode
+
+When the MouseArea is clicked fruitModel will have two roles, "cost" and "name".
+Even if subsequent roles are added, only the first two will be handled by views
+using the model.
+
\section2 XmlListModel
@@ -283,7 +305,9 @@ QDeclarativeContext *ctxt = view.rootContext();
ctxt->setContextProperty("myModel", QVariant::fromValue(dataList));
\endcode
-The properties of the object may then be accessed in the delegate:
+The QObject* is available as the \c modelData property. As a convenience,
+the properties of the object are also made available directly in the
+delegate's context:
\code
ListView {
@@ -295,13 +319,18 @@ ListView {
Rectangle {
height: 25
width: 100
- color: model.color
+ color: model.modelData.color
Text { text: name }
}
}
}
\endcode
+Note the use of the fully qualified access to the \c color property.
+The properties of the object are not replicated in the \c model
+object, since they are easily available via the modelData
+object.
+
Note: There is no way for the view to know that the contents of a QList
have changed. If the QList is changed, it will be necessary to reset
the model by calling QDeclarativeContext::setContextProperty() again.