diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2010-09-23 14:14:18 +0200 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2011-06-27 18:13:45 +0200 |
commit | 0f6853e9c775dd8fbb64f66119c2c9b2ea23da29 (patch) | |
tree | 880ec281b07648a14b0a4b95473001b5fb8b5eb5 /doc | |
parent | 031958c130904c16a4bafa5617aaa197469efa9e (diff) | |
download | qt4-tools-0f6853e9c775dd8fbb64f66119c2c9b2ea23da29.tar.gz |
Provide the resetInternalData slot to cleanly reset data in proxy subclasses.
Direct subclasses of QAbstractItemModel are unnaffected as they can update
internal data in a slot connected to the sourceModel's modelReset signal or
layoutChanged signal.
Rehabilitated for 4.8. Should be reverted again in Qt 5.
Reviewed-by: gabi
Merge-request: 694
Diffstat (limited to 'doc')
-rw-r--r-- | doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp b/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp index 5919c01085..cf40f9a05a 100644 --- a/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp +++ b/doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp @@ -86,3 +86,38 @@ beginMoveRows(parent, 2, 2, parent, 0); //! [9] beginMoveRows(parent, 2, 2, parent, 4); //! [9] + + +//! [10] +class CustomDataProxy : public QSortFilterProxyModel +{ + Q_OBJECT +public: + CustomDataProxy(QObject *parent) + : QSortFilterProxyModel(parent) + { + } + + ... + + QVariant data(const QModelIndex &index, int role) + { + if (role != Qt::BackgroundRole) + return QSortFilterProxyModel::data(index, role); + + if (m_customData.contains(index.row())) + return m_customData.value(index.row()); + return QSortFilterProxyModel::data(index, role); + } + +private slots: + void resetInternalData() + { + m_customData.clear(); + } + +private: + QHash<int, QVariant> m_customData; +}; +//! [10] + |