diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-10-12 08:33:06 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-10-12 08:33:06 (GMT) |
commit | 1ed2d93f4aeceb024934af00a8b075813cbd8dc1 (patch) | |
tree | ad132383d45323b7e5ae40b596240c22d6de9778 /doc | |
parent | 8d22b82d3883518b83bfb49dcc6e3506d0a8731e (diff) | |
parent | 3a83d69ee744216bc72c1b67ad752a9640bb3605 (diff) | |
download | Qt-1ed2d93f4aeceb024934af00a8b075813cbd8dc1.zip Qt-1ed2d93f4aeceb024934af00a8b075813cbd8dc1.tar.gz Qt-1ed2d93f4aeceb024934af00a8b075813cbd8dc1.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'doc')
-rw-r--r-- | doc/src/declarative/qmlmodels.qdoc | 108 |
1 files changed, 99 insertions, 9 deletions
diff --git a/doc/src/declarative/qmlmodels.qdoc b/doc/src/declarative/qmlmodels.qdoc index d0a5464..6ebb734 100644 --- a/doc/src/declarative/qmlmodels.qdoc +++ b/doc/src/declarative/qmlmodels.qdoc @@ -71,14 +71,87 @@ or C++ (via QmlContext::setContextProperty(), for example). \section1 QML Data Models -\list -\o ListModel is a simple hierarchy of elements specified in QML. The +\section2 ListModel + +ListModel is a simple hierarchy of elements specified in QML. The available roles are specified by the \l ListElement properties. -\o XmlListModel allows construction of a model from an XML data source. The roles + +\code +ListModel { + id: fruitModel + ListElement { + name: "Apple" + cost: 2.45 + } + ListElement { + name: "Orange" + cost: 3.25 + } + ListElement { + name: "Banana" + cost: 1.95 + } +} +\endcode + +The above model has two roles, \e name and \e cost. These can be bound +bound to by a ListView delegate, for example: + +\code +Component { + id: fruitDelegate + Row { + Text { text: "Fruit: " + name } + Text { text: "Cost: $" + cost } + } +} +ListView { + model: fruitModel + delegate: fruitDelegate +} +\endcode + + +\section2 XmlListModel + +XmlListModel allows construction of a model from an XML data source. The roles are specified via the \l XmlRole element. -\o VisualItemModel allows QML items to be provided as a model. This model contains + +The following model has three roles, \e title, \e link and \e description: +\code +XmlListModel { + id: feedModel + source: "http://rss.news.yahoo.com/rss/oceania" + query: "/rss/channel/item" + XmlRole { name: "title"; query: "title/string()" } + XmlRole { name: "link"; query: "link/string()" } + XmlRole { name: "description"; query: "description/string()" } +} +\endcode + + +\section2 VisualItemModel + +VisualItemModel allows QML items to be provided as a model. This model contains both the data and delegate (its child items). This model does not provide any roles. -\endlist + +\code + VisualItemModel { + id: itemModel + Rectangle { height: 30; width: 80; color: "red" } + Rectangle { height: 30; width: 80; color: "green" } + Rectangle { height: 30; width: 80; color: "blue" } + } + + ListView { + anchors.fill: parent + model: itemModel + } +\endcode + +Note that in the above example there is no delegate required. +The items of the model itself provide the visual elements that +will be positioned by the view. \section1 C++ Data Models @@ -92,11 +165,28 @@ both the data and delegate (its child items). This model does not provide any r \section1 Other Data Models -\list -\o An Integer specifies a model containing the integer number of elements. + +\section2 An Integer + +An Integer specifies a model containing the integer number of elements. There are no data roles. -\o An Object Instance specifies a model with a single Object element. The + +The following example creates a ListView with five elements: +\code +Component { + id: itemDelegate + Text { text: "I am item number: " + index } +} +ListView { + model: 5 + delegate: itemDelegate +} +\endcode + + +\section2 An Object Instance + +An Object Instance specifies a model with a single Object element. The properties of the object are provided as roles. -\endlist */ |