summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2010-02-22 16:23:23 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2010-02-22 16:23:23 (GMT)
commit895b9bedc3746723f6c77754df3c428dbc0661d3 (patch)
treeac557328bee8d96c08eb7b19e4b02f593916dfbe /tests
parentc42343ab8bedda2700b16b10ee7a7409130cb500 (diff)
downloadQt-895b9bedc3746723f6c77754df3c428dbc0661d3.zip
Qt-895b9bedc3746723f6c77754df3c428dbc0661d3.tar.gz
Qt-895b9bedc3746723f6c77754df3c428dbc0661d3.tar.bz2
QSortFilterProxyModel: Sorting occured unnecessarily when the dynamicSortFilter is turned off
We should not sort when inserting items if the dinamicSortFilter flag is set to false. Note that some of the test used to rely on the fact that it was sorted. Those test have been fixed. The patch has been contributed to us in the task. Task-number: QTBUG-7716 Reviewed-by: Thierry
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
index 5b2b0cf..56eaf25 100644
--- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -137,6 +137,7 @@ private slots:
void task255652_removeRowsRecursive();
void taskQTBUG_6205_doubleProxySelectionSetSourceModel();
void taskQTBUG_7537_appearsAndSort();
+ void taskQTBUG_7716_unnecessaryDynamicSorting();
protected:
void buildHierarchy(const QStringList &data, QAbstractItemModel *model);
@@ -918,15 +919,16 @@ void tst_QSortFilterProxyModel::removeRows()
QStandardItemModel model;
QSortFilterProxyModel proxy;
proxy.setSourceModel(&model);
- if (sortOrder != -1)
- proxy.sort(0, static_cast<Qt::SortOrder>(sortOrder));
- if (!filter.isEmpty())
- proxy.setFilterRegExp(QRegExp(filter));
// prepare model
foreach (QString s, initial)
model.appendRow(new QStandardItem(s));
+ if (sortOrder != -1)
+ proxy.sort(0, static_cast<Qt::SortOrder>(sortOrder));
+ if (!filter.isEmpty())
+ proxy.setFilterRegExp(QRegExp(filter));
+
// remove the rows
QCOMPARE(proxy.removeRows(position, count, QModelIndex()), success);
QCOMPARE(model.rowCount(QModelIndex()), expectedSource.count());
@@ -2419,6 +2421,7 @@ void tst_QSortFilterProxyModel::sortColumnTracking2()
{
QStandardItemModel model;
QSortFilterProxyModel proxyModel;
+ proxyModel.setDynamicSortFilter(true);
proxyModel.setSourceModel(&model);
proxyModel.sort(0);
@@ -2921,5 +2924,32 @@ void tst_QSortFilterProxyModel::taskQTBUG_7537_appearsAndSort()
QCOMPARE(spyChanged2.count(), 1);
}
+void tst_QSortFilterProxyModel::taskQTBUG_7716_unnecessaryDynamicSorting()
+{
+ QStringListModel model;
+ const QStringList initial = QString("bravo charlie delta echo").split(" ");
+ model.setStringList(initial);
+ QSortFilterProxyModel proxy;
+ proxy.setDynamicSortFilter(false);
+ proxy.setSourceModel(&model);
+ proxy.sort(Qt::AscendingOrder);
+
+ //append two rows
+ int maxrows = proxy.rowCount(QModelIndex());
+ model.insertRows(maxrows, 2);
+ model.setData(model.index(maxrows, 0), QString("alpha"));
+ model.setData(model.index(maxrows + 1, 0), QString("fondue"));
+
+ //append new items to the initial string list and compare with model
+ QStringList expected = initial;
+ expected << QString("alpha") << QString("fondue");
+
+ //if bug 7716 is present, new rows were prepended, when they should have been appended
+ for (int row = 0; row < proxy.rowCount(QModelIndex()); ++row) {
+ QModelIndex index = proxy.index(row, 0, QModelIndex());
+ QCOMPARE(proxy.data(index, Qt::DisplayRole).toString(), expected.at(row));
+ }
+}
+
QTEST_MAIN(tst_QSortFilterProxyModel)
#include "tst_qsortfilterproxymodel.moc"