summaryrefslogtreecommitdiffstats
path: root/tests/auto/qheaderview
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2010-02-03 17:00:24 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2010-02-04 09:21:32 (GMT)
commit188c2ef11e92d04dcf334309c85a7f1b14945aaa (patch)
treef25391e9b903c82dd426eb299cb7e66b3a9b8de7 /tests/auto/qheaderview
parent5cff63b217118e087a6cbd1f27c2a28be83374bb (diff)
downloadQt-188c2ef11e92d04dcf334309c85a7f1b14945aaa.zip
Qt-188c2ef11e92d04dcf334309c85a7f1b14945aaa.tar.gz
Qt-188c2ef11e92d04dcf334309c85a7f1b14945aaa.tar.bz2
QHeaderView: fixes sectionClicked() emitted with wrong section index
The obvious fix is to use the previsously computed 'section' as paramatter. (It is even faster) But one might wonder why logicalIndexAt() does not return the same result before and after flipSortIndicator(). The reason is that while being sorted, in _q_layoutChanged, all the hidden section where unhidden and hidden again. Leaving some pending computation. Task-number: QTBUG-7833 Reviewed-by: Gabriel
Diffstat (limited to 'tests/auto/qheaderview')
-rw-r--r--tests/auto/qheaderview/tst_qheaderview.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/qheaderview/tst_qheaderview.cpp b/tests/auto/qheaderview/tst_qheaderview.cpp
index 857e7e3..4642830 100644
--- a/tests/auto/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/qheaderview/tst_qheaderview.cpp
@@ -44,6 +44,7 @@
#include <QStandardItemModel>
#include <QStringListModel>
#include <QSortFilterProxyModel>
+#include <QTableView>
#include <qabstractitemmodel.h>
#include <qapplication.h>
@@ -190,6 +191,7 @@ private slots:
void task236450_hidden();
void task248050_hideRow();
void QTBUG6058_reset();
+ void QTBUG7833_sectionClicked();
protected:
QHeaderView *view;
@@ -1992,6 +1994,68 @@ void tst_QHeaderView::QTBUG6058_reset()
QCOMPARE(checkHeaderViewOrder(&view, QVector<int>() << 2 << 0 << 1 << 3 << 4 << 5 ) , 0);
}
+void tst_QHeaderView::QTBUG7833_sectionClicked()
+{
+
+
+
+
+ QTableView tv;
+ QStandardItemModel *sim = new QStandardItemModel(&tv);
+ QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(&tv);
+ proxyModel->setSourceModel(sim);
+ proxyModel->setDynamicSortFilter(true);
+ proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
+
+ QList<QStandardItem *> row;
+ for (int i = 0; i < 12; i++)
+ row.append(new QStandardItem(QString(QLatin1Char('A' + i))));
+ sim->appendRow(row);
+ row.clear();
+ for (int i = 12; i > 0; i--)
+ row.append(new QStandardItem(QString(QLatin1Char('A' + i))));
+ sim->appendRow(row);
+
+ tv.setSortingEnabled(true);
+ tv.horizontalHeader()->setSortIndicatorShown(true);
+ tv.horizontalHeader()->setClickable(true);
+ tv.horizontalHeader()->setStretchLastSection(true);
+ tv.horizontalHeader()->setResizeMode(QHeaderView::Interactive);
+
+ tv.setModel(proxyModel);
+ tv.setColumnHidden(5, true);
+ tv.setColumnHidden(6, true);
+ tv.horizontalHeader()->swapSections(8, 10);
+ tv.sortByColumn(1, Qt::AscendingOrder);
+
+ QSignalSpy clickedSpy(tv.horizontalHeader(), SIGNAL(sectionClicked(int)));
+ QSignalSpy pressedSpy(tv.horizontalHeader(), SIGNAL(sectionPressed(int)));
+
+
+ QTest::mouseClick(tv.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier,
+ QPoint(tv.horizontalHeader()->sectionViewportPosition(11) + 5, 5));
+ QCOMPARE(clickedSpy.count(), 1);
+ QCOMPARE(pressedSpy.count(), 1);
+ QCOMPARE(clickedSpy.at(0).at(0).toInt(), 11);
+ QCOMPARE(pressedSpy.at(0).at(0).toInt(), 11);
+
+ QTest::mouseClick(tv.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier,
+ QPoint(tv.horizontalHeader()->sectionViewportPosition(8) + 5, 5));
+
+ QCOMPARE(clickedSpy.count(), 2);
+ QCOMPARE(pressedSpy.count(), 2);
+ QCOMPARE(clickedSpy.at(1).at(0).toInt(), 8);
+ QCOMPARE(pressedSpy.at(1).at(0).toInt(), 8);
+
+ QTest::mouseClick(tv.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier,
+ QPoint(tv.horizontalHeader()->sectionViewportPosition(0) + 5, 5));
+
+ QCOMPARE(clickedSpy.count(), 3);
+ QCOMPARE(pressedSpy.count(), 3);
+ QCOMPARE(clickedSpy.at(2).at(0).toInt(), 0);
+ QCOMPARE(pressedSpy.at(2).at(0).toInt(), 0);
+}
+
QTEST_MAIN(tst_QHeaderView)
#include "tst_qheaderview.moc"