From 18eba786347c42e0c1c9a2a5f8331624f1779920 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Tue, 29 May 2012 09:50:13 +1000 Subject: [PATCH] Fix nested GridView key navigation with a single row or column. Don't ignore key events when the currentIndex is unchanged due to wrapping. . Task-number: QTBUG-21999 Change-Id: Idc82d472ca7ec495669207761bfe7de58b8781f9 Reviewed-by: Bea Lam --- src/quick/items/qquickgridview.cpp | 2 +- tests/auto/quick/qquickgridview/data/gridview1.qml | 3 +++ .../quick/qquickgridview/tst_qquickgridview.cpp | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletions(-) diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp index 61bd202..48d04bf 100644 --- a/src/quick/items/qquickgridview.cpp +++ b/src/quick/items/qquickgridview.cpp @@ -2091,7 +2091,7 @@ void QQuickGridView::keyPressEvent(QKeyEvent *event) default: break; } - if (oldCurrent != currentIndex()) { + if (oldCurrent != currentIndex() || d->wrap) { event->accept(); return; } diff --git a/tests/auto/quick/qquickgridview/data/gridview1.qml b/tests/auto/quick/qquickgridview/data/gridview1.qml index 1424955..c381101 100644 --- a/tests/auto/quick/qquickgridview/data/gridview1.qml +++ b/tests/auto/quick/qquickgridview/data/gridview1.qml @@ -8,6 +8,7 @@ Rectangle { property real cacheBuffer: 0 property int added: -1 property variant removed + property int lastKey: 0 width: 240 height: 320 @@ -66,4 +67,6 @@ Rectangle { cacheBuffer: root.cacheBuffer focus: true } + + Keys.onPressed: lastKey = event.key } diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index 04cc79d..235c29f 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -2027,6 +2027,25 @@ void tst_QQuickGridView::keyNavigation() QTRY_COMPARE(gridview->contentX(), contentPosAtFirstItem.x()); QTRY_COMPARE(gridview->contentY(), contentPosAtFirstItem.y()); + // Test key press still accepted when position wraps to same index. + canvas->rootObject()->setProperty("lastKey", 0); + model.removeItems(1, model.count() - 1); + + QTest::keyClick(canvas, backwardsKey); + QCOMPARE(canvas->rootObject()->property("lastKey").toInt(), 0); + + QTest::keyClick(canvas, forwardsKey); + QCOMPARE(canvas->rootObject()->property("lastKey").toInt(), 0); + + // Test key press not accepted at limits when wrap is disabled. + gridview->setWrapEnabled(false); + + QTest::keyClick(canvas, backwardsKey); + QCOMPARE(canvas->rootObject()->property("lastKey").toInt(), int(backwardsKey)); + + QTest::keyClick(canvas, forwardsKey); + QCOMPARE(canvas->rootObject()->property("lastKey").toInt(), int(forwardsKey)); + releaseView(canvas); } -- 1.7.2.5