diff options
Diffstat (limited to 'tests/auto/quick/qquickgridview/tst_qquickgridview.cpp')
-rw-r--r-- | tests/auto/quick/qquickgridview/tst_qquickgridview.cpp | 96 |
1 files changed, 79 insertions, 17 deletions
diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index 4edfb0ed3b..07c03a57d7 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.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$ ** @@ -213,6 +208,8 @@ private slots: void QTBUG_45640(); void QTBUG_48870_fastModelUpdates(); + void keyNavigationEnabled(); + private: QList<int> toIntList(const QVariantList &list); void matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes); @@ -6568,6 +6565,71 @@ void tst_QQuickGridView::QTBUG_45640() delete window; } +void tst_QQuickGridView::keyNavigationEnabled() +{ + QScopedPointer<QQuickView> window(createView()); + window->setSource(testFileUrl("gridview4.qml")); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + + QQuickGridView *gridView = qobject_cast<QQuickGridView *>(window->rootObject()); + QVERIFY(gridView); + QCOMPARE(gridView->isKeyNavigationEnabled(), true); + + gridView->setFocus(true); + QVERIFY(gridView->hasActiveFocus()); + + gridView->setHighlightMoveDuration(0); + + // If keyNavigationEnabled is not explicitly set to true, respect the original behavior + // of disabling both mouse and keyboard interaction. + QSignalSpy enabledSpy(gridView, SIGNAL(keyNavigationEnabledChanged())); + gridView->setInteractive(false); + QCOMPARE(enabledSpy.count(), 1); + QCOMPARE(gridView->isKeyNavigationEnabled(), false); + + flick(window.data(), QPoint(200, 175), QPoint(200, 50), 100); + QVERIFY(!gridView->isMoving()); + QCOMPARE(gridView->contentY(), 0.0); + QCOMPARE(gridView->currentIndex(), 0); + + QTest::keyClick(window.data(), Qt::Key_Right); + QCOMPARE(gridView->currentIndex(), 0); + + // Check that isKeyNavigationEnabled implicitly follows the value of interactive. + gridView->setInteractive(true); + QCOMPARE(enabledSpy.count(), 2); + QCOMPARE(gridView->isKeyNavigationEnabled(), true); + + // Change it back again for the next check. + gridView->setInteractive(false); + QCOMPARE(enabledSpy.count(), 3); + QCOMPARE(gridView->isKeyNavigationEnabled(), false); + + // Setting keyNavigationEnabled to true shouldn't enable mouse interaction. + gridView->setKeyNavigationEnabled(true); + QCOMPARE(enabledSpy.count(), 4); + flick(window.data(), QPoint(200, 175), QPoint(200, 50), 100); + QVERIFY(!gridView->isMoving()); + QCOMPARE(gridView->contentY(), 0.0); + QCOMPARE(gridView->currentIndex(), 0); + + // Should now work. + QTest::keyClick(window.data(), Qt::Key_Right); + QCOMPARE(gridView->currentIndex(), 1); + + // Changing interactive now shouldn't result in keyNavigationEnabled changing, + // since we broke the "binding". + gridView->setInteractive(true); + QCOMPARE(enabledSpy.count(), 4); + + // Keyboard interaction shouldn't work now. + gridView->setKeyNavigationEnabled(false); + QTest::keyClick(window.data(), Qt::Key_Right); + QCOMPARE(gridView->currentIndex(), 1); +} + void tst_QQuickGridView::QTBUG_48870_fastModelUpdates() { StressTestModel model; |