diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-11-23 11:59:05 +0100 |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-11-23 12:14:11 +0100 |
commit | b4dbbd30c8092a81984cca30248db087353fe66e (patch) | |
tree | 7d338a46623118bf262fe58ac5731ddf040a5ced /tests/auto/qheaderview/tst_qheaderview.cpp | |
parent | 76b66d6da548ce4a247727f14e09b1d301330db5 (diff) | |
download | qt4-tools-b4dbbd30c8092a81984cca30248db087353fe66e.tar.gz |
Fix QHeaderView when the model is reset and section have moved.
The logicalIndices and visualIndices array where not clean of the
old sections, resulting in corrupted header.
Task-number: QTBUG-6058
Reviewed-by: Thierry
Diffstat (limited to 'tests/auto/qheaderview/tst_qheaderview.cpp')
-rw-r--r-- | tests/auto/qheaderview/tst_qheaderview.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/qheaderview/tst_qheaderview.cpp b/tests/auto/qheaderview/tst_qheaderview.cpp index c13e829832..a8e7461cf0 100644 --- a/tests/auto/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/qheaderview/tst_qheaderview.cpp @@ -43,6 +43,7 @@ #include <QtTest/QtTest> #include <QStandardItemModel> #include <QStringListModel> +#include <QSortFilterProxyModel> #include <qabstractitemmodel.h> #include <qapplication.h> @@ -188,6 +189,7 @@ private slots: void task236450_hidden_data(); void task236450_hidden(); void task248050_hideRow(); + void QTBUG6058_reset(); protected: QHeaderView *view; @@ -1947,5 +1949,49 @@ void tst_QHeaderView::task248050_hideRow() } +//returns 0 if everything is fine. +static int checkHeaderViewOrder(QHeaderView *view, const QVector<int> &expected) +{ + if (view->count() != expected.count()) + return 1; + + for (int i = 0; i < expected.count(); i++) { + if (view->logicalIndex(i) != expected.at(i)) + return i + 10; + if (view->visualIndex(expected.at(i)) != i) + return i + 100; + } + return 0; +} + + +void tst_QHeaderView::QTBUG6058_reset() +{ + QStringListModel model1( QStringList() << "0" << "1" << "2" << "3" << "4" << "5" ); + QStringListModel model2( QStringList() << "a" << "b" << "c" ); + QSortFilterProxyModel proxy; + + QHeaderView view(Qt::Vertical); + view.setModel(&proxy); + view.show(); + QTest::qWait(20); + + proxy.setSourceModel(&model1); + QApplication::processEvents(); + view.swapSections(0,2); + view.swapSections(1,4); + QApplication::processEvents(); + QCOMPARE(checkHeaderViewOrder(&view, QVector<int>() << 2 << 4 << 0 << 3 << 1 << 5) , 0); + + proxy.setSourceModel(&model2); + QApplication::processEvents(); + QCOMPARE(checkHeaderViewOrder(&view, QVector<int>() << 2 << 0 << 1 ) , 0); + + proxy.setSourceModel(&model1); + QApplication::processEvents(); + QCOMPARE(checkHeaderViewOrder(&view, QVector<int>() << 2 << 0 << 1 << 3 << 4 << 5 ) , 0); +} + + QTEST_MAIN(tst_QHeaderView) #include "tst_qheaderview.moc" |