diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2009-08-06 11:37:15 (GMT) |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2009-08-06 11:37:15 (GMT) |
commit | f577abca43ec341ac4b96d5a9fb6fcfdc7411965 (patch) | |
tree | 0df451f4de071f2e055cd3850a1513ef9ecab2e0 /doc/src/snippets/stringlistmodel/model.cpp | |
parent | 31f4e677256487e7d167517ffd5dd4bef6bb4dd4 (diff) | |
parent | 1b7d4d29d970405d5559c5641260ea1f09375b27 (diff) | |
download | Qt-f577abca43ec341ac4b96d5a9fb6fcfdc7411965.zip Qt-f577abca43ec341ac4b96d5a9fb6fcfdc7411965.tar.gz Qt-f577abca43ec341ac4b96d5a9fb6fcfdc7411965.tar.bz2 |
Merge branch 'master' of git@scm.dev.troll.no:qt/qt-s60-public
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] /*! |