aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2022-11-18 22:39:31 +0100
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2022-11-25 00:04:03 +0100
commit2becb1c2073b3bcc0a108c4d7d9ce5b60f29306b (patch)
tree0270aaf559aa560675ba7182a43b3da9aa480bf4 /tests/auto/quick
parentac4fea75379467dde9065825d3f15da3b86e9ad8 (diff)
QQuickTableView: respect activeFocusOnTab
QQuickItem has a activeFocusOnTab property which should also be respected by TableView. When disabled, TableView should not transfer focus between the cells when the user hits the tab key. Change-Id: I234286926b58753fa50923321302d4fa108a4515 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index f04816b167..08cd1b81fb 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -210,6 +210,7 @@ private slots:
void moveCurrentIndexUsingPageUpDownKeys();
void moveCurrentIndexUsingTabKey_data();
void moveCurrentIndexUsingTabKey();
+ void respectActiveFocusOnTabDisabled();
void setCurrentIndexOnFirstKeyPress_data();
void setCurrentIndexOnFirstKeyPress();
void setCurrentIndexFromMouse();
@@ -4957,6 +4958,8 @@ void tst_QQuickTableView::moveCurrentIndexUsingTabKey()
WAIT_UNTIL_POLISHED;
+ QVERIFY(tableView->activeFocusOnTab());
+
QCOMPARE(tableView->currentColumn(), -1);
QCOMPARE(tableView->currentRow(), -1);
@@ -5017,6 +5020,49 @@ void tst_QQuickTableView::moveCurrentIndexUsingTabKey()
QVERIFY(!selectionModel.hasSelection());
}
+void tst_QQuickTableView::respectActiveFocusOnTabDisabled()
+{
+ // Ensure that we don't move focus for tab or backtab
+ // when TableView.setActiveFocusOnTab is false.
+ LOAD_TABLEVIEW("tableviewwithselected1.qml");
+
+ TestModel model(3, 3);
+ QItemSelectionModel selectionModel(&model);
+
+ tableView->setModel(QVariant::fromValue(&model));
+ tableView->setSelectionModel(&selectionModel);
+ tableView->setActiveFocusOnTab(false);
+ tableView->setFocus(true);
+
+ QQuickWindow *window = tableView->window();
+ const char kCurrent[] = "current";
+
+ WAIT_UNTIL_POLISHED;
+
+ QCOMPARE(tableView->currentColumn(), -1);
+ QCOMPARE(tableView->currentRow(), -1);
+ QVERIFY(!tableView->activeFocusOnTab());
+
+ // Start by making cell 0, 0 current
+ const QPoint cell0_0(0, 0);
+ selectionModel.setCurrentIndex(tableView->modelIndex(cell0_0), QItemSelectionModel::NoUpdate);
+ QVERIFY(tableView->itemAtCell(cell0_0)->property(kCurrent).toBool());
+ QCOMPARE(tableView->currentColumn(), cell0_0.x());
+ QCOMPARE(tableView->currentRow(), cell0_0.y());
+
+ // Press Tab
+ const QPoint cell1_0(1, 0);
+ QTest::keyPress(window, Qt::Key_Tab);
+ QCOMPARE(selectionModel.currentIndex(), tableView->modelIndex(cell0_0));
+ QVERIFY(tableView->itemAtCell(cell0_0)->property(kCurrent).toBool());
+ QVERIFY(!tableView->itemAtCell(cell1_0)->property(kCurrent).toBool());
+
+ // Press Backtab
+ QTest::keyPress(window, Qt::Key_Backtab);
+ QCOMPARE(selectionModel.currentIndex(), tableView->modelIndex(cell0_0));
+ QVERIFY(tableView->itemAtCell(cell0_0)->property(kCurrent).toBool());
+}
+
void tst_QQuickTableView::setCurrentIndexOnFirstKeyPress_data()
{
QTest::addColumn<Qt::Key>("arrowKey");