summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2010-09-23 12:14:18 (GMT)
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-10-19 08:33:27 (GMT)
commit6f1384fcbeea993d5be47590c696de60215b7608 (patch)
treeedb2b7de78ee57b5b785a4dab6d636b3e8b2cc6d /doc/src/snippets
parentfbf11a9584c011e5fb10bf008cc3c8ad99c3103f (diff)
downloadQt-6f1384fcbeea993d5be47590c696de60215b7608.zip
Qt-6f1384fcbeea993d5be47590c696de60215b7608.tar.gz
Qt-6f1384fcbeea993d5be47590c696de60215b7608.tar.bz2
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. Reviewed-by: gabi Merge-request: 694
Diffstat (limited to 'doc/src/snippets')
-rw-r--r--doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp35
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 59e6ae0..07ff2a0 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]
+