diff options
| author | mread <qt-info@nokia.com> | 2009-08-07 13:34:12 (GMT) |
|---|---|---|
| committer | mread <qt-info@nokia.com> | 2009-08-07 13:34:12 (GMT) |
| commit | 5a72890b7ce12815f9567316da867006cff73f39 (patch) | |
| tree | 46c8c793f19274f9ed19678d1732d2123adbdf34 /doc/src/snippets/stringlistmodel/model.cpp | |
| parent | 0f6f1f841cea61cbb6905de92c2ca63bd369d55d (diff) | |
| parent | cc0a411e5e874aa224c26298a109973cb15ea291 (diff) | |
| download | Qt-5a72890b7ce12815f9567316da867006cff73f39.zip Qt-5a72890b7ce12815f9567316da867006cff73f39.tar.gz Qt-5a72890b7ce12815f9567316da867006cff73f39.tar.bz2 | |
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt-s60-public
Conflicts fixed:
src/corelib/io/qdiriterator.cpp
Diffstat (limited to 'doc/src/snippets/stringlistmodel/model.cpp')
| -rw-r--r-- | doc/src/snippets/stringlistmodel/model.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/doc/src/snippets/stringlistmodel/model.cpp b/doc/src/snippets/stringlistmodel/model.cpp index 76329dd..49e0fc7 100644 --- a/doc/src/snippets/stringlistmodel/model.cpp +++ b/doc/src/snippets/stringlistmodel/model.cpp @@ -59,6 +59,11 @@ int StringListModel::rowCount(const QModelIndex &parent) const } //! [0] + +#ifdef 0 +// This represents a read-only version of data(), an early stage in the +// development of the example leading to an editable StringListModel. + /*! Returns an appropriate value for the requested data. If the view requests an invalid index, an invalid variant is returned. @@ -66,7 +71,7 @@ int StringListModel::rowCount(const QModelIndex &parent) const string to be returned. */ -//! [1] +//! [1-data-read-only] QVariant StringListModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) @@ -80,6 +85,31 @@ QVariant StringListModel::data(const QModelIndex &index, int role) const else return QVariant(); } +//! [1-data-read-only] +#endif + + +/*! + Returns an appropriate value for the requested data. + If the view requests an invalid index, an invalid variant is returned. + Any valid index that corresponds to a string in the list causes that + string to be returned. +*/ + +//! [1] +QVariant StringListModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() >= stringList.size()) + return QVariant(); + + if (role == Qt::DisplayRole || role == Qt::EditRole) + return stringList.at(index.row()); + else + return QVariant(); +} //! [1] /*! |
