summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-11-23 15:32:55 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-12-03 08:51:41 +0000
commit8cd6a0840e9f0fca329a40fdfc72aadb0aeea6ba (patch)
treef481a379b23563adba5a806f63310d6aa69013e9 /tests
parentd2c02eec71ebe0f392c68cae7558412c492a4460 (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 Change-Id: I2fa1b32bf75dc96225b40145b713bf7e2ffc29dd Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit d22bafe3559afef1dcab1c9076f82ac224d012b6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-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)