diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2010-02-22 17:23:23 +0100 |
---|---|---|
committer | Samuli Piippo <samuli.piippo@digia.com> | 2011-06-09 13:04:55 +0300 |
commit | d9ec38f8dc238bf1b624458318e7492579ce9033 (patch) | |
tree | e781522d9d3c39aff9a96b20d43ad4769dea13c2 /tests | |
parent | 18ac6c1bcb80b85a4e9e2f280ed5d454ad82f20f (diff) | |
download | qt4-tools-d9ec38f8dc238bf1b624458318e7492579ce9033.tar.gz |
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
(cherry picked from commit 895b9bedc3746723f6c77754df3c428dbc0661d3)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 7c5160f377..0b60026c0d 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" |