summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews/qtableview
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-11-23 15:32:55 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-12-02 14:16:49 +0000
commitd22bafe3559afef1dcab1c9076f82ac224d012b6 (patch)
tree32b8130d16e2297f23dff4a9b8f61ce5bb8c6cda /tests/auto/widgets/itemviews/qtableview
parent97cfd4940157817dd761fd02f2e6da4afc5b4a30 (diff)
QTableView: correctly toggle column selection when scrolled
We need to check whether the horizontal header's selection includes the index for the row at the top, rather than for row 0, as the index we check is based on the scrolled position of the header, so would never be included in the top row when the view is scrolled. This is correctly done in selectRow already. Add a test case that simulates selection of rows and columns by clicking on the header. Fixes: QTBUG-98444 Pick-to: 6.2 Change-Id: I2fa1b32bf75dc96225b40145b713bf7e2ffc29dd Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/auto/widgets/itemviews/qtableview')
-rw-r--r--tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
index 662226de52..6ed3b4ecdd 100644
--- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
+++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
@@ -439,6 +439,8 @@ private slots:
void deselectRow();
void selectRowsAndCells();
void selectColumnsAndCells();
+ void selectWithHeader_data();
+ void selectWithHeader();
#if QT_CONFIG(wheelevent)
void mouseWheel_data();
@@ -4855,6 +4857,60 @@ void tst_QTableView::selectColumnsAndCells()
checkColumns(tw.selectionModel()->selectedColumns());
}
+void tst_QTableView::selectWithHeader_data()
+{
+ QTest::addColumn<Qt::Orientation>("orientation");
+
+ QTest::addRow("horizontal") << Qt::Horizontal;
+ QTest::addRow("vertical") << Qt::Vertical;
+}
+
+void tst_QTableView::selectWithHeader()
+{
+ QFETCH(Qt::Orientation, orientation);
+
+ QTableWidget view(10, 10);
+ view.resize(200, 100);
+ view.show();
+
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
+ QHeaderView *header;
+ QPoint clickPos;
+ QModelIndex lastIndex;
+
+ switch (orientation) {
+ case Qt::Horizontal:
+ header = view.horizontalHeader();
+ clickPos.rx() = header->sectionPosition(0) + header->sectionSize(0) / 2;
+ clickPos.ry() = header->height() / 2;
+ lastIndex = view.model()->index(9, 0);
+ break;
+ case Qt::Vertical:
+ header = view.verticalHeader();
+ clickPos.rx() = header->width() / 2;
+ clickPos.ry() = header->sectionPosition(0) + header->sectionSize(0) / 2;
+ lastIndex = view.model()->index(0, 9);
+ break;
+ }
+
+ const auto isSelected = [&]{
+ return orientation == Qt::Horizontal
+ ? view.selectionModel()->isColumnSelected(0)
+ : view.selectionModel()->isRowSelected(0);
+ };
+
+ QTest::mouseClick(header->viewport(), Qt::LeftButton, {}, clickPos);
+ QVERIFY(isSelected());
+ QTest::mouseClick(header->viewport(), Qt::LeftButton, Qt::ControlModifier, clickPos);
+ QVERIFY(!isSelected());
+ QTest::mouseClick(header->viewport(), Qt::LeftButton, {}, clickPos);
+ QVERIFY(isSelected());
+ view.scrollTo(lastIndex);
+ QTest::mouseClick(header->viewport(), Qt::LeftButton, Qt::ControlModifier, clickPos);
+ QVERIFY(!isSelected());
+}
+
// This has nothing to do with QTableView, but it's convenient to reuse the QtTestTableModel
#if QT_CONFIG(textmarkdownwriter)