diff options
author | Peter Yard <peter.yard@nokia.com> | 2009-07-24 00:46:21 (GMT) |
---|---|---|
committer | Peter Yard <peter.yard@nokia.com> | 2009-07-24 00:46:21 (GMT) |
commit | e37d314eb3e5b26b271aa5ec17dac1f2e8e16a45 (patch) | |
tree | 149291e690bb6662599594635082b5e8ec193731 /doc/src/snippets/stringlistmodel | |
parent | 6ca14dce65634e202b36499c76c268c87f78ceb6 (diff) | |
download | Qt-e37d314eb3e5b26b271aa5ec17dac1f2e8e16a45.zip Qt-e37d314eb3e5b26b271aa5ec17dac1f2e8e16a45.tar.gz Qt-e37d314eb3e5b26b271aa5ec17dac1f2e8e16a45.tar.bz2 |
#250741 Doc for Making task editable
Diffstat (limited to 'doc/src/snippets/stringlistmodel')
-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] /*! |