diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-05-25 16:32:46 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-05-26 08:37:07 (GMT) |
commit | 2a390bb481a2433a239a9198e463c9337a26db59 (patch) | |
tree | 8c8661482ab497a97fb557fad63fc748c10d4d5d /tests/auto | |
parent | 5839b16a73c36ff7636c13f841d26e6a5e0c5435 (diff) | |
download | Qt-2a390bb481a2433a239a9198e463c9337a26db59.zip Qt-2a390bb481a2433a239a9198e463c9337a26db59.tar.gz Qt-2a390bb481a2433a239a9198e463c9337a26db59.tar.bz2 |
Fixed: QSortFilterProxyModel setDynamicSortFilter doesn't works when setting the model initially
This was caused by two different bug:
- In the QSortFilterProxyModel, we need to re-sort when setting the
source model change the sorting column (happen when setting a model
initially)
- In the treeview, we need to activate the sorting even if there is no
column yet (because the initial model is empty
Task-number: 254234
Reviewed-by: Thierry
BT:
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp | 10 | ||||
-rw-r--r-- | tests/auto/qtreeview/tst_qtreeview.cpp | 29 |
2 files changed, 38 insertions, 1 deletions
diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index bd66fdf..80d90a6 100644 --- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -2585,6 +2585,16 @@ void tst_QSortFilterProxyModel::task248868_dynamicSorting() QModelIndex index = proxy1.index(row, 0, QModelIndex()); QCOMPARE(proxy1.data(index, Qt::DisplayRole).toString(), expected.at(row)); } + + //set up the sorting before seting the model up + QSortFilterProxyModel proxy2; + proxy2.setDynamicSortFilter(true); + proxy2.sort(0); + proxy2.setSourceModel(&model2); + for (int row = 0; row < proxy2.rowCount(QModelIndex()); ++row) { + QModelIndex index = proxy2.index(row, 0, QModelIndex()); + QCOMPARE(proxy2.data(index, Qt::DisplayRole).toString(), expected.at(row)); + } } class QtTestModel: public QAbstractItemModel diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index 655ea4e..54d6619 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -225,6 +225,7 @@ private slots: void task238873_avoidAutoReopening(); void task244304_clickOnDecoration(); void task246536_scrollbarsNotWorking(); + void task254234_proxySort(); }; class QtTestModel: public QAbstractItemModel @@ -2493,7 +2494,6 @@ void tst_QTreeView::sortByColumn() QCOMPARE(view.header()->sortIndicatorSection(), 0); QCOMPARE(view.model()->data(view.model()->index(0,0)).toString(), QString::fromLatin1("a")); QCOMPARE(view.model()->data(view.model()->index(1,0)).toString(), QString::fromLatin1("b")); - } /* @@ -3272,5 +3272,32 @@ void tst_QTreeView::task246536_scrollbarsNotWorking() QVERIFY(o.count > 0); } +void tst_QTreeView::task254234_proxySort() +{ + //based on tst_QTreeView::sortByColumn + // it used not to work when setting the source of a proxy after enabling sorting + QTreeView view; + QStandardItemModel model(4,2); + model.setItem(0,0,new QStandardItem("b")); + model.setItem(1,0,new QStandardItem("d")); + model.setItem(2,0,new QStandardItem("c")); + model.setItem(3,0,new QStandardItem("a")); + model.setItem(0,1,new QStandardItem("e")); + model.setItem(1,1,new QStandardItem("g")); + model.setItem(2,1,new QStandardItem("h")); + model.setItem(3,1,new QStandardItem("f")); + + view.sortByColumn(1); + view.setSortingEnabled(true); + + QSortFilterProxyModel proxy; + proxy.setDynamicSortFilter(true); + view.setModel(&proxy); + proxy.setSourceModel(&model); + QCOMPARE(view.header()->sortIndicatorSection(), 1); + QCOMPARE(view.model()->data(view.model()->index(0,1)).toString(), QString::fromLatin1("h")); + QCOMPARE(view.model()->data(view.model()->index(1,1)).toString(), QString::fromLatin1("g")); +} + QTEST_MAIN(tst_QTreeView) #include "tst_qtreeview.moc" |