diff options
Diffstat (limited to 'tests/auto/quick/qquicklistview/tst_qquicklistview.cpp')
-rw-r--r-- | tests/auto/quick/qquicklistview/tst_qquicklistview.cpp | 96 |
1 files changed, 79 insertions, 17 deletions
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 12405e32c0..1e3d1d95b3 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -253,6 +248,7 @@ private slots: void QTBUG_48870_fastModelUpdates(); void QTBUG_50105(); + void keyNavigationEnabled(); void QTBUG_50097_stickyHeader_positionViewAtIndex(); private: @@ -8310,6 +8306,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); +} + static bool testVisibleItems(const QQuickItemViewPrivate *priv, bool *nonUnique, FxViewItem **failItem, int *expectedIdx) { QHash<QQuickItem*, int> uniqueItems; |