summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/itemmodels
diff options
context:
space:
mode:
authorNils Jeisecke <jeisecke@saltation.de>2013-12-06 19:00:59 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-03 22:12:20 +0100
commit6894bc0f3f8a579529dc0a7ab869ce565abd06ad (patch)
tree06d0fa7c96ed785883f34bc23f65d4236d254d28 /tests/auto/corelib/itemmodels
parent72259baa76a0f1faa1983c720621676e9c15e15f (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 'tests/auto/corelib/itemmodels')
-rw-r--r--tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
index 923b9a3a07..c6c81ad75d 100644
--- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -92,6 +92,7 @@ private slots:
void filterTable();
void filterCurrent();
+ void filter_qtbug30662();
void changeSourceLayout();
void removeSourceRows_data();
@@ -1480,6 +1481,33 @@ void tst_QSortFilterProxyModel::filterCurrent()
QCOMPARE(spy.count(), 2);
}
+void tst_QSortFilterProxyModel::filter_qtbug30662()
+{
+ QStringListModel model;
+ QSortFilterProxyModel proxy;
+ proxy.setSourceModel(&model);
+
+ // make sure the filter does not match any entry
+ proxy.setFilterRegExp(QRegExp("[0-9]+"));
+
+ QStringList slSource;
+ slSource << "z" << "x" << "a" << "b";
+
+ proxy.setDynamicSortFilter(true);
+ proxy.sort(0);
+ model.setStringList(slSource);
+
+ // without fix for QTBUG-30662 this will make all entries visible - but unsorted
+ proxy.setFilterRegExp(QRegExp("[a-z]+"));
+
+ QStringList slResult;
+ for (int i = 0; i < proxy.rowCount(); ++i)
+ slResult.append(proxy.index(i, 0).data().toString());
+
+ slSource.sort();
+ QCOMPARE(slResult, slSource);
+}
+
void tst_QSortFilterProxyModel::changeSourceLayout()
{
QStandardItemModel model(2, 1);