aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicklistview
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@theqtcompany.com>2015-11-25 15:20:22 +0100
committerMitch Curtis <mitch.curtis@theqtcompany.com>2015-12-08 09:40:41 +0000
commitd1fbfbbab7f78e0a1050acce3540c02660a0d68f (patch)
tree9326407c3374dddc083fdc3dc58fe6ef43a58039 /tests/auto/quick/qquicklistview
parentd9763f2565445ada2d11bde3c1f46b5217b17dab (diff)
ListView: add keyNavigationEnabled property
It is useful for applications that need to selectively enable or disable mouse and keyboard interaction. [ChangeLog][QtQuick][ListView] added keyNavigationEnabled property to allow mouse and keyboard interaction to be selectively enabled/disabled. Change-Id: I1cdb73e7be105bcc5c131e3cf2ae242dc66e8a65 Task-number: QTBUG-17051 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'tests/auto/quick/qquicklistview')
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
index a5de266636..ad6c6ec12d 100644
--- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
@@ -250,6 +250,8 @@ private slots:
void QTBUG_48044_currentItemNotVisibleAfterTransition();
+ void keyNavigationEnabled();
+
private:
template <class T> void items(const QUrl &source);
template <class T> void changed(const QUrl &source);
@@ -8295,6 +8297,72 @@ void tst_QQuickListView::QTBUG_48044_currentItemNotVisibleAfterTransition()
QVERIFY(!currentPriv->culled);
}
+void tst_QQuickListView::keyNavigationEnabled()
+{
+ QScopedPointer<QQuickView> window(createView());
+ window->setSource(testFileUrl("simplelistview.qml"));
+ window->show();
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
+
+ QQuickListView *listView = qobject_cast<QQuickListView *>(window->rootObject());
+ QVERIFY(listView);
+ QCOMPARE(listView->isKeyNavigationEnabled(), true);
+
+ listView->setFocus(true);
+ QVERIFY(listView->hasActiveFocus());
+
+ listView->setHighlightMoveDuration(0);
+
+ // If keyNavigationEnabled is not explicitly set to true, respect the original behavior
+ // of disabling both mouse and keyboard interaction.
+ QSignalSpy enabledSpy(listView, SIGNAL(keyNavigationEnabledChanged()));
+ listView->setInteractive(false);
+ QCOMPARE(enabledSpy.count(), 1);
+ QCOMPARE(listView->isKeyNavigationEnabled(), false);
+
+ flick(window.data(), QPoint(200, 200), QPoint(200, 50), 100);
+ QVERIFY(!listView->isMoving());
+ QCOMPARE(listView->contentY(), 0.0);
+ QCOMPARE(listView->currentIndex(), 0);
+
+ QTest::keyClick(window.data(), Qt::Key_Down);
+ QCOMPARE(listView->currentIndex(), 0);
+
+ // Check that isKeyNavigationEnabled implicitly follows the value of interactive.
+ listView->setInteractive(true);
+ QCOMPARE(enabledSpy.count(), 2);
+ QCOMPARE(listView->isKeyNavigationEnabled(), true);
+
+ // Change it back again for the next check.
+ listView->setInteractive(false);
+ QCOMPARE(enabledSpy.count(), 3);
+ QCOMPARE(listView->isKeyNavigationEnabled(), false);
+
+ // Setting keyNavigationEnabled to true shouldn't enable mouse interaction.
+ listView->setKeyNavigationEnabled(true);
+ QCOMPARE(enabledSpy.count(), 4);
+ flick(window.data(), QPoint(200, 200), QPoint(200, 50), 100);
+ QVERIFY(!listView->isMoving());
+ QCOMPARE(listView->contentY(), 0.0);
+ QCOMPARE(listView->currentIndex(), 0);
+
+ // Should now work.
+ QTest::keyClick(window.data(), Qt::Key_Down);
+ QCOMPARE(listView->currentIndex(), 1);
+ // contentY won't change for one index change in a view this high.
+
+ // Changing interactive now shouldn't result in keyNavigationEnabled changing,
+ // since we broke the "binding".
+ listView->setInteractive(true);
+ QCOMPARE(enabledSpy.count(), 4);
+
+ // Keyboard interaction shouldn't work now.
+ listView->setKeyNavigationEnabled(false);
+ QTest::keyClick(window.data(), Qt::Key_Down);
+ QCOMPARE(listView->currentIndex(), 1);
+}
+
QTEST_MAIN(tst_QQuickListView)
#include "tst_qquicklistview.moc"