aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-09-06 15:14:44 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-09-07 12:40:33 +0000
commit22023717774ca94b88e2b83756889b98e93aa9e3 (patch)
tree597003f07d722cca227e9dd527dcfc1ba8384758 /tests
parente99c203b77743fe7554663c12a98960d8514fb6b (diff)
QQuickTableView: remove focus for the delegate item itself, not only for the child
"isAncestorOf" will not include itself as an ancestor. So we need to check if the delegate item has focus as well, since we also want to remove focus for that case. This can e.g happen if the delegate is a TextInput directly. Change-Id: I5a5f5a7ec262eacdac64d72b0f41bca991dbab73 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicktableview/data/tableviewfocus.qml6
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp30
2 files changed, 25 insertions, 11 deletions
diff --git a/tests/auto/quick/qquicktableview/data/tableviewfocus.qml b/tests/auto/quick/qquicktableview/data/tableviewfocus.qml
index 35f9c06587..c388e2c8de 100644
--- a/tests/auto/quick/qquicktableview/data/tableviewfocus.qml
+++ b/tests/auto/quick/qquicktableview/data/tableviewfocus.qml
@@ -57,9 +57,13 @@ Item {
Component {
id: tableViewDelegate
Item {
+ id: delegate
implicitWidth: 100
implicitHeight: 50
- property alias textInput: textInput
+ focus: true
+
+ property alias delegateRoot: delegate
+ property alias delegateChild: textInput
TextInput {
id: textInput
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 580500e787..6a6849eeae 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -109,8 +109,9 @@ private slots:
void countDelegateItems();
void checkLayoutOfEqualSizedDelegateItems_data();
void checkLayoutOfEqualSizedDelegateItems();
- void checkTableMargins_data();
+ void checkFocusRemoved_data();
void checkFocusRemoved();
+ void checkTableMargins_data();
void checkTableMargins();
void fillTableViewButNothingMore_data();
void fillTableViewButNothingMore();
@@ -738,27 +739,36 @@ void tst_QQuickTableView::checkLayoutOfEqualSizedDelegateItems()
}
}
+void tst_QQuickTableView::checkFocusRemoved_data()
+{
+ QTest::addColumn<QString>("focusedItemProp");
+
+ QTest::newRow("delegate root") << QStringLiteral("delegateRoot");
+ QTest::newRow("delegate child") << QStringLiteral("delegateChild");
+}
+
void tst_QQuickTableView::checkFocusRemoved()
{
// Check that we clear the focus of a delegate item when
- // it's flicked out of view, and then reused.
+ // a child of the delegate item has focus, and the cell is
+ // flicked out of view.
+ QFETCH(QString, focusedItemProp);
LOAD_TABLEVIEW("tableviewfocus.qml");
- const char *textInputProp = "textInput";
auto model = TestModelAsVariant(100, 100);
tableView->setModel(model);
WAIT_UNTIL_POLISHED;
auto const item = tableViewPrivate->loadedTableItem(QPoint(0, 0))->item;
- auto const textInput = qvariant_cast<QQuickItem *>(item->property(textInputProp));
- QVERIFY(textInput);
+ auto const focusedItem = qvariant_cast<QQuickItem *>(item->property(focusedItemProp.toUtf8().data()));
+ QVERIFY(focusedItem);
QCOMPARE(tableView->hasActiveFocus(), false);
- QCOMPARE(textInput->hasActiveFocus(), false);
+ QCOMPARE(focusedItem->hasActiveFocus(), false);
- textInput->forceActiveFocus();
+ focusedItem->forceActiveFocus();
QCOMPARE(tableView->hasActiveFocus(), true);
- QCOMPARE(textInput->hasActiveFocus(), true);
+ QCOMPARE(focusedItem->hasActiveFocus(), true);
// Flick the focused cell out, and check that none of the
// items in the table has focus (which means that the reused
@@ -767,8 +777,8 @@ void tst_QQuickTableView::checkFocusRemoved()
tableView->setContentX(500);
QCOMPARE(tableView->hasActiveFocus(), true);
for (auto fxItem : tableViewPrivate->loadedItems) {
- auto const textInput2 = qvariant_cast<QQuickItem *>(fxItem->item->property(textInputProp));
- QCOMPARE(textInput2->hasActiveFocus(), false);
+ auto const focusedItem2 = qvariant_cast<QQuickItem *>(fxItem->item->property(focusedItemProp.toUtf8().data()));
+ QCOMPARE(focusedItem2->hasActiveFocus(), false);
}
}