From 722798a359761a1eb635d18547b076615f192508 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 2 Apr 2013 17:52:54 +0200 Subject: Don't call virtual methods after the source model is destroyed. Calling clear_mapping causes the persistent indexes to be queried, and mapped using map_to_source, so that they can be restored later. That is not the appropriate response to the source model being deleted because there won't be anything to restore. Simply clear the stored mapping information instead so that the source model actually exists when mapToSource is called by the framework. Change-Id: I99692ee7aa9c6714aec45c68fe4a2d62be189d60 Reviewed-by: Olivier Goffart --- src/corelib/itemmodels/qabstractproxymodel.cpp | 1 + src/corelib/itemmodels/qsortfilterproxymodel.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src/corelib/itemmodels') diff --git a/src/corelib/itemmodels/qabstractproxymodel.cpp b/src/corelib/itemmodels/qabstractproxymodel.cpp index d5887a52d5..0e1764ba7c 100644 --- a/src/corelib/itemmodels/qabstractproxymodel.cpp +++ b/src/corelib/itemmodels/qabstractproxymodel.cpp @@ -91,6 +91,7 @@ QT_BEGIN_NAMESPACE //detects the deletion of the source model void QAbstractProxyModelPrivate::_q_sourceModelDestroyed() { + invalidatePersistentIndexes(); model = QAbstractItemModelPrivate::staticEmptyModel(); } diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index e5bdd83dc3..67b0d98402 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -295,7 +295,8 @@ typedef QHash IndexMap; void QSortFilterProxyModelPrivate::_q_sourceModelDestroyed() { QAbstractProxyModelPrivate::_q_sourceModelDestroyed(); - _q_clearMapping(); + qDeleteAll(source_index_mapping); + source_index_mapping.clear(); } void QSortFilterProxyModelPrivate::remove_from_mapping(const QModelIndex &source_parent) -- cgit v1.2.3 From 96e3c2bcbfedc8b5cb8fc099229a02a1fa335c21 Mon Sep 17 00:00:00 2001 From: Volker Krause Date: Mon, 8 Apr 2013 14:14:32 +0200 Subject: Don't bypass overwritten [set]data() methods in the proxy. By calling itemData() of the source model directly, the result cannot contain data provided by the proxy model itself. The base class implementation however will call data() on the proxy instead. Change-Id: Ib0ef5f5621457adbfa4bd896a756dfcb98d0ae54 Reviewed-by: Stephen Kelly --- src/corelib/itemmodels/qabstractproxymodel.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/corelib/itemmodels') diff --git a/src/corelib/itemmodels/qabstractproxymodel.cpp b/src/corelib/itemmodels/qabstractproxymodel.cpp index 0e1764ba7c..d435c4bcf5 100644 --- a/src/corelib/itemmodels/qabstractproxymodel.cpp +++ b/src/corelib/itemmodels/qabstractproxymodel.cpp @@ -272,8 +272,7 @@ QVariant QAbstractProxyModel::headerData(int section, Qt::Orientation orientatio */ QMap QAbstractProxyModel::itemData(const QModelIndex &proxyIndex) const { - Q_D(const QAbstractProxyModel); - return d->model->itemData(mapToSource(proxyIndex)); + return QAbstractItemModel::itemData(proxyIndex); } /*! @@ -299,8 +298,7 @@ bool QAbstractProxyModel::setData(const QModelIndex &index, const QVariant &valu */ bool QAbstractProxyModel::setItemData(const QModelIndex &index, const QMap< int, QVariant >& roles) { - Q_D(QAbstractProxyModel); - return d->model->setItemData(mapToSource(index), roles); + return QAbstractItemModel::setItemData(index, roles); } /*! -- cgit v1.2.3