From 7b96944a02991e404cdab61e24182b90f5849120 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 2 Feb 2010 13:46:09 +0100 Subject: QSortFilterProxyModel: Fix dynamic sorting when severals rows are added. We need to update the sorting column in clear_mapping. But the problem is that updating the source column create a mapping (because it uses mapToSource). So we need to clear that wrong mapping again In _q_sourceLayoutChanged there was an uneeded special case. The case where the source_sort_column might change was never triggered because of that. So now that the special case has been removed, we need to do as in clear_mapping. The test cover the change in clear_mapping and in _q_sourceLayoutChanged The problem was shown in the Kopete: https://bugs.kde.org/show_bug.cgi?id=199850 Reviewed-by: Thierry Task-number: QTBUG-7537 --- src/gui/itemviews/qsortfilterproxymodel.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/gui/itemviews/qsortfilterproxymodel.cpp') diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp index 472af7d804..e73013cc9f 100644 --- a/src/gui/itemviews/qsortfilterproxymodel.cpp +++ b/src/gui/itemviews/qsortfilterproxymodel.cpp @@ -270,6 +270,11 @@ void QSortFilterProxyModelPrivate::clear_mapping() qDeleteAll(source_index_mapping); source_index_mapping.clear(); + if (dynamic_sortfilter && update_source_sort_column()) { + //update_source_sort_column might have created wrong mapping so we have to clear it again + qDeleteAll(source_index_mapping); + source_index_mapping.clear(); + } // update the persistent indexes update_persistent_indexes(source_indexes); @@ -1208,11 +1213,6 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutAboutToBeChanged() void QSortFilterProxyModelPrivate::_q_sourceLayoutChanged() { Q_Q(QSortFilterProxyModel); - if (saved_persistent_indexes.isEmpty()) { - clear_mapping(); - emit q->layoutChanged(); - return; - } qDeleteAll(source_index_mapping); source_index_mapping.clear(); @@ -1220,7 +1220,11 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutChanged() update_persistent_indexes(saved_persistent_indexes); saved_persistent_indexes.clear(); - update_source_sort_column(); + if (dynamic_sortfilter && update_source_sort_column()) { + //update_source_sort_column might have created wrong mapping so we have to clear it again + qDeleteAll(source_index_mapping); + source_index_mapping.clear(); + } emit q->layoutChanged(); } -- cgit v1.2.3