diff options
author | Nils Jeisecke <jeisecke@saltation.de> | 2013-12-06 19:00:59 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-03 22:12:20 +0100 |
commit | 6894bc0f3f8a579529dc0a7ab869ce565abd06ad (patch) | |
tree | 06d0fa7c96ed785883f34bc23f65d4236d254d28 /src/corelib/itemmodels/qsortfilterproxymodel.cpp | |
parent | 72259baa76a0f1faa1983c720621676e9c15e15f (diff) |
Fix sorted QSortFilterProxyModel filter update
When changing a filter so that a previously empty proxy model becomes
populated sorting was not applied correctly.
This was caused by using mapToSource for getting source_sort_column
from proxy_sort_column. For an empty proxy model this won't work because
no valid proxy index can be created in this case.
We now directly use the root index column mapping instead by doing
essentially the same as QSortFilterProxyModelPrivate::proxy_to_source
but without the sanity checks needed for external use.
The sorting feature of QSortFilterProxyModel has always assumed that
the number of columns is specified by columnCount(QModelIndex()) so
the behavior doesn't change.
[ChangeLog][QtCore][QSortFilterProxyModel] Fixed sorting when a
previously empty proxy model becomes populated because of a change in
the filter.
Task-number: QTBUG-30662
Change-Id: I21322122e127889dfadc02f838f0119ed322dcab
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src/corelib/itemmodels/qsortfilterproxymodel.cpp')
-rw-r--r-- | src/corelib/itemmodels/qsortfilterproxymodel.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index 63e0374740..930c2871d3 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -458,10 +458,21 @@ void QSortFilterProxyModelPrivate::sort() */ bool QSortFilterProxyModelPrivate::update_source_sort_column() { - Q_Q(QSortFilterProxyModel); - QModelIndex proxy_index = q->index(0, proxy_sort_column, QModelIndex()); int old_source_sort_column = source_sort_column; - source_sort_column = q->mapToSource(proxy_index).column(); + + if (proxy_sort_column == -1) { + source_sort_column = -1; + } else { + // We cannot use index mapping here because in case of a still-empty + // proxy model there's no valid proxy index we could map to source. + // So always use the root mapping directly instead. + Mapping *m = create_mapping(QModelIndex()).value(); + if (proxy_sort_column < m->source_columns.size()) + source_sort_column = m->source_columns.at(proxy_sort_column); + else + source_sort_column = -1; + } + return old_source_sort_column != source_sort_column; } |