diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-08-10 14:13:52 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-08-11 22:45:54 +0000 |
commit | 8ca41ef6e23ce9a3f8ef04069a4d0f6e34b3114b (patch) | |
tree | a27225f535919fe701149aa2cc6b4a00edd1f4fe /tests | |
parent | 7c5570ca8c010b2f8fecd2073dd039e665b83804 (diff) |
QQuickTableView: clear selection on tap directly in TableView
Before 6.4, it was only possible to make a selection in
TableView by using a SelectionRectangle. But in 6.4, you
can also make a selection directly in TableView by using
the shift+arrow keys. To make sure that a selection is
cleared either way on tap, move the implementation that
clears the selection from SelectionRectangle to TableView.
Change-Id: Ic718763bf9b643cb3e3c04cc3b90c6ffcf9ca4b2
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
(cherry picked from commit b51ad14bc6a055de22b9c5f0083a3ca42795779b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index 856a8d7794..eeaf95068f 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -199,6 +199,7 @@ private slots: void testSelectableStartPosEndPosOutsideView(); void testSelectableScrollTowardsPos(); void setCurrentIndexFromSelectionModel(); + void clearSelectionOnTap(); void moveCurrentIndexUsingArrowKeys(); void moveCurrentIndexUsingHomeAndEndKeys(); void moveCurrentIndexUsingPageUpDownKeys(); @@ -4443,6 +4444,29 @@ void tst_QQuickTableView::setCurrentIndexFromSelectionModel() QVERIFY(tableView->itemAtCell(cellAtEnd)->property(kCurrent).toBool()); } +void tst_QQuickTableView::clearSelectionOnTap() +{ + LOAD_TABLEVIEW("tableviewwithselected2.qml"); + + TestModel model(40, 40); + tableView->setModel(QVariant::fromValue(&model)); + + WAIT_UNTIL_POLISHED; + + // Select root item + const auto index = tableView->selectionModel()->model()->index(0, 0); + tableView->selectionModel()->select(index, QItemSelectionModel::Select); + QCOMPARE(tableView->selectionModel()->selectedIndexes().count(), 1); + + // Click on a cell. This should remove the selection + const auto item = tableView->itemAtCell(0, 0); + QVERIFY(item); + QPoint localPos = QPoint(item->width() / 2, item->height() / 2); + QPoint pos = item->window()->contentItem()->mapFromItem(item, localPos).toPoint(); + QTest::mouseClick(item->window(), Qt::LeftButton, Qt::NoModifier, pos); + QCOMPARE(tableView->selectionModel()->selectedIndexes().count(), 0); +} + void tst_QQuickTableView::moveCurrentIndexUsingArrowKeys() { LOAD_TABLEVIEW("tableviewwithselected1.qml"); |