summaryrefslogtreecommitdiffstats
path: root/doc/src/declarative
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-02-01 23:03:34 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-02-01 23:03:34 (GMT)
commit35a211cd95e0d09ef0b547b57f01f0a9ff41da2f (patch)
treea74bdf9eedee7ae0eba4ddb2fe13064cd79db81e /doc/src/declarative
parente93f76cc533751944e66c02d868f3c527814efa0 (diff)
downloadQt-35a211cd95e0d09ef0b547b57f01f0a9ff41da2f.zip
Qt-35a211cd95e0d09ef0b547b57f01f0a9ff41da2f.tar.gz
Qt-35a211cd95e0d09ef0b547b57f01f0a9ff41da2f.tar.bz2
Fix QList<QObject*> as a model. Add docs and example.
Diffstat (limited to 'doc/src/declarative')
-rw-r--r--doc/src/declarative/qmlmodels.qdoc57
1 files changed, 52 insertions, 5 deletions
diff --git a/doc/src/declarative/qmlmodels.qdoc b/doc/src/declarative/qmlmodels.qdoc
index 322f225..4115e8d 100644
--- a/doc/src/declarative/qmlmodels.qdoc
+++ b/doc/src/declarative/qmlmodels.qdoc
@@ -169,11 +169,58 @@ will be positioned by the view.
\section1 C++ Data Models
-\list
-\o QAbstractItemModel provides the roles set via the QAbstractItemModel::setRoleNames() method.
-\o QStringList provides the contents of the list via the \e modelData role.
-\o QList<QObject*> provides the properties of the objects in the list as roles.
-\endlist
+\section2 QAbstractItemModel
+
+QAbstractItemModel provides the roles set via the QAbstractItemModel::setRoleNames() method.
+
+
+\section2 QStringList
+
+QStringList provides the contents of the list via the \e modelData role.
+
+
+\section2 QList<QObject*>
+
+QList<QObject*> provides the properties of the objects in the list as roles.
+
+\code
+class DataObject : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QString name READ name WRITE setName)
+ Q_PROPERTY(QString color READ color WRITE setColor)
+...
+};
+
+QList<QObject*> dataList;
+dataList.append(new DataObject("Item 1", "red"));
+dataList.append(new DataObject("Item 2", "green"));
+dataList.append(new DataObject("Item 3", "blue"));
+dataList.append(new DataObject("Item 4", "yellow"));
+
+QmlContext *ctxt = view.rootContext();
+ctxt->setContextProperty("myModel", QVariant::fromValue(&dataList));
+\endcode
+
+The properties of the object may then be accessed in the delegate:
+
+\code
+ListView {
+ width: 100
+ height: 100
+ anchors.fill: parent
+ model: myModel
+ delegate: Component {
+ Rectangle {
+ height: 25
+ width: 100
+ color: model.color
+ Text { text: name }
+ }
+ }
+}
+\endcode
\section1 Other Data Models