tests/auto/qheaderview/tst_qheaderview.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/tests/auto/qheaderview/tst_qheaderview.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/tests/auto/qheaderview/tst_qheaderview.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -43,6 +43,7 @@
 #include <QtTest/QtTest>
 #include <QStandardItemModel>
 #include <QStringListModel>
+#include <QSortFilterProxyModel>
 
 #include <qabstractitemmodel.h>
 #include <qapplication.h>
@@ -188,6 +189,7 @@
     void task236450_hidden_data();
     void task236450_hidden();
     void task248050_hideRow();
+    void QTBUG6058_reset();
 
 protected:
     QHeaderView *view;
@@ -1947,5 +1949,49 @@
 }
 
 
+//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"