From 5443871a89e01c8d8a8440f7786a24ea87922106 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 5 May 2009 17:03:09 +0200 Subject: Accept the event when doing keyboard search on a itemview. This is required for KHTML Patch by David Faure (the test is not really related) Reviewed-by: Thierry Task-number: 252912 --- src/gui/itemviews/qabstractitemview.cpp | 9 +++++---- tests/auto/qlistview/tst_qlistview.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 4e4392f..4c1f7fc 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -2165,11 +2165,12 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event) } #endif bool modified = (event->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)); - if (!event->text().isEmpty() && !modified) { - if (!edit(currentIndex(), AnyKeyPressed, event)) - keyboardSearch(event->text()); + if (!event->text().isEmpty() && !modified && !edit(currentIndex(), AnyKeyPressed, event)) { + keyboardSearch(event->text()); + event->accept(); + } else { + event->ignore(); } - event->ignore(); break; } } } diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp index c372475..791a472 100644 --- a/tests/auto/qlistview/tst_qlistview.cpp +++ b/tests/auto/qlistview/tst_qlistview.cpp @@ -106,6 +106,7 @@ private slots: void task228566_infiniteRelayout(); void task248430_crashWith0SizedItem(); void task250446_scrollChanged(); + void keyboardSearch(); }; // Testing get/set functions @@ -1555,6 +1556,30 @@ void tst_QListView::task250446_scrollChanged() QCOMPARE(view.currentIndex(), index); } +void tst_QListView::keyboardSearch() +{ + QStringList items; + items << "AB" << "AC" << "BA" << "BB" << "BD" << "KAFEINE" << "KONQUEROR" << "KOPETE" << "KOOKA" << "OKULAR"; + QStringListModel model(items); + + QListView view; + view.setModel(&model); + view.show(); + QTest::qWait(30); +// QCOMPARE(view.currentIndex() , model.index(0,0)); + + QTest::keyClick(&view, Qt::Key_K); + QTest::qWait(10); + QCOMPARE(view.currentIndex() , model.index(5,0)); //KAFEINE + + QTest::keyClick(&view, Qt::Key_O); + QTest::qWait(10); + QCOMPARE(view.currentIndex() , model.index(6,0)); //KONQUEROR + + QTest::keyClick(&view, Qt::Key_N); + QTest::qWait(10); + QCOMPARE(view.currentIndex() , model.index(6,0)); //KONQUEROR +} QTEST_MAIN(tst_QListView) #include "tst_qlistview.moc" -- cgit v0.12