diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2013-01-28 19:17:21 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-30 10:44:32 +0100 |
commit | 8eae3a923a540f3dbfe9445a1d58c59f20294684 (patch) | |
tree | a93dad0a54077d5f35a040f5c580a0987d05d837 /src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp | |
parent | b28d56588a93852a8c7034a3b8b3c9146d1d8b28 (diff) |
Provide the resetInternalData slot to cleanly reset data in proxy subclasses.
This was part of Qt 4.8, but Qt 5.0 was branched before that, so
the commit was lost.
Change-Id: I2a2ab3c75a0943ac734d588ebd74bc158dd6aaaf
Reviewed-by: Nils Jeisecke <jeisecke@saltation.de>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp')
-rw-r--r-- | src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp index 2f81b15752..c448c75206 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp @@ -97,3 +97,37 @@ beginResetModel(); myData.clear(); endResetModel(); //! [11] + +//! [12] +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; +}; +//! [12] + |