X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/ffb80cb00d8fd886051f970b5155a55b1d066fcd..0464ea82a6850f58805bc4d6fc1df5369d83c3df:/src/tests/kitemlistcontrollertest.cpp diff --git a/src/tests/kitemlistcontrollertest.cpp b/src/tests/kitemlistcontrollertest.cpp index 4149a4d85..e9e1e66c2 100644 --- a/src/tests/kitemlistcontrollertest.cpp +++ b/src/tests/kitemlistcontrollertest.cpp @@ -4,19 +4,19 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ -#include "kitemviews/kitemlistcontainer.h" +#include "kitemviews/kitemlistcontroller.h" #include "kitemviews/kfileitemlistview.h" #include "kitemviews/kfileitemmodel.h" -#include "kitemviews/kitemlistcontroller.h" +#include "kitemviews/kitemlistcontainer.h" #include "kitemviews/kitemlistselectionmanager.h" #include "kitemviews/private/kitemlistviewlayouter.h" #include "testdir.h" -#include #include -#include #include +#include #include +#include /** * \class KItemListControllerTestStyle is a proxy style for testing the @@ -27,9 +27,9 @@ class KItemListControllerTestStyle : public QProxyStyle { Q_OBJECT public: - KItemListControllerTestStyle(QStyle* style) : - QProxyStyle(style), - m_activateItemOnSingleClick((bool)style->styleHint(SH_ItemView_ActivateItemOnSingleClick)) + KItemListControllerTestStyle(QStyle *style) + : QProxyStyle(style) + , m_activateItemOnSingleClick((bool)style->styleHint(SH_ItemView_ActivateItemOnSingleClick)) { } @@ -43,10 +43,7 @@ public: return m_activateItemOnSingleClick; } - int styleHint(StyleHint hint, - const QStyleOption* option = nullptr, - const QWidget* widget = nullptr, - QStyleHintReturn* returnData = nullptr) const override + int styleHint(StyleHint hint, const QStyleOption *option = nullptr, const QWidget *widget = nullptr, QStyleHintReturn *returnData = nullptr) const override { switch (hint) { case QStyle::SH_ItemView_ActivateItemOnSingleClick: @@ -76,8 +73,10 @@ private Q_SLOTS: void init(); void cleanup(); - void testKeyboardNavigation_data(); - void testKeyboardNavigation(); + void testKeyboardNavigationMultiSelection_data(); + void testKeyboardNavigationMultiSelection(); + void testKeyboardNavigationSingleSelectionNoSelection_data(); + void testKeyboardNavigationSingleSelectionNoSelection(); void testMouseClickActivation(); private: @@ -88,13 +87,13 @@ private: void adjustGeometryForColumnCount(int count); private: - KFileItemListView* m_view; - KItemListController* m_controller; - KItemListSelectionManager* m_selectionManager; - KFileItemModel* m_model; - TestDir* m_testDir; - KItemListContainer* m_container; - KItemListControllerTestStyle* m_testStyle; + KFileItemListView *m_view; + KItemListController *m_controller; + KItemListSelectionManager *m_selectionManager; + KFileItemModel *m_model; + TestDir *m_testDir; + KItemListContainer *m_container; + KItemListControllerTestStyle *m_testStyle; }; /** @@ -112,6 +111,9 @@ void KItemListControllerTest::initTestCase() m_view = new KFileItemListView(); m_controller = new KItemListController(m_model, m_view, this); m_container = new KItemListContainer(m_controller); +#ifndef QT_NO_ACCESSIBILITY + m_view->setAccessibleParentsObject(m_container); +#endif m_controller = m_container->controller(); m_controller->setSelectionBehavior(KItemListController::MultiSelection); m_selectionManager = m_controller->selectionManager(); @@ -119,12 +121,26 @@ void KItemListControllerTest::initTestCase() m_view->setStyle(m_testStyle); QStringList files; - files - << "a1" << "a2" << "a3" - << "b1" - << "c1" << "c2" << "c3" << "c4" << "c5" - << "d1" << "d2" << "d3" << "d4" - << "e" << "e 2" << "e 3" << "e 4" << "e 5" << "e 6" << "e 7"; + files << "a1" + << "a2" + << "a3" + << "b1" + << "c1" + << "c2" + << "c3" + << "c4" + << "c5" + << "d1" + << "d2" + << "d3" + << "d4" + << "e" + << "e 2" + << "e 3" + << "e 4" + << "e 5" + << "e 6" + << "e 7"; m_testDir->createFiles(files); m_model->loadDirectory(m_testDir->url()); @@ -156,10 +172,14 @@ void KItemListControllerTest::init() const QSizeF itemSize(50, 50); m_view->setItemSize(itemSize); QCOMPARE(m_view->itemSize(), itemSize); + + m_controller->setSelectionBehavior(KItemListController::MultiSelection); + QCOMPARE(m_controller->selectionBehavior(), KItemListController::MultiSelection); } void KItemListControllerTest::cleanup() { + m_controller->setSelectionModeEnabled(false); } /** @@ -167,11 +187,11 @@ void KItemListControllerTest::cleanup() * including the key and the keyboard modifiers. */ struct KeyPress { - - KeyPress(Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier) : - m_key(key), - m_modifier(modifier) - {} + KeyPress(Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier) + : m_key(key) + , m_modifier(modifier) + { + } Qt::Key m_key; Qt::KeyboardModifiers m_modifier; @@ -185,12 +205,12 @@ struct KeyPress { * key press. */ struct ViewState { - - ViewState(int current, const KItemSet &selection, bool activated = false) : - m_current(current), - m_selection(selection), - m_activated(activated) - {} + ViewState(int current, const KItemSet &selection, bool activated = false) + : m_current(current) + , m_selection(selection) + , m_activated(activated) + { + } int m_current; KItemSet m_selection; @@ -202,21 +222,21 @@ typedef QPair keyPressViewStatePair; Q_DECLARE_METATYPE(QList) /** - * This function provides the data for the actual test function - * KItemListControllerTest::testKeyboardNavigation(). - * It tests all possible combinations of view layouts, selection behaviors, + * This function tests all possible combinations of view layouts, layout direction, * and enabled/disabled groupings for different column counts, and * provides a list of key presses and the states that the view should be in * after the key press event. */ -void KItemListControllerTest::testKeyboardNavigation_data() +void KItemListControllerTest::testKeyboardNavigationMultiSelection_data() { QTest::addColumn("layout"); QTest::addColumn("scrollOrientation"); QTest::addColumn("columnCount"); - QTest::addColumn("selectionBehavior"); QTest::addColumn("groupingEnabled"); - QTest::addColumn > >("testList"); + QTest::addColumn("layoutDirection"); + QTest::addColumn( + "selectionModeEnabled"); // Don't confuse this with "selectionBehaviour". This is about changing controls for users to help multi-selecting. + QTest::addColumn>>("testList"); QList layoutList; QHash layoutNames; @@ -227,15 +247,6 @@ void KItemListControllerTest::testKeyboardNavigation_data() layoutList.append(KFileItemListView::DetailsLayout); layoutNames[KFileItemListView::DetailsLayout] = "Details"; - QList selectionBehaviorList; - QHash selectionBehaviorNames; - selectionBehaviorList.append(KItemListController::NoSelection); - selectionBehaviorNames[KItemListController::NoSelection] = "NoSelection"; - selectionBehaviorList.append(KItemListController::SingleSelection); - selectionBehaviorNames[KItemListController::SingleSelection] = "SingleSelection"; - selectionBehaviorList.append(KItemListController::MultiSelection); - selectionBehaviorNames[KItemListController::MultiSelection] = "MultiSelection"; - QList groupingEnabledList; QHash groupingEnabledNames; groupingEnabledList.append(false); @@ -243,16 +254,26 @@ void KItemListControllerTest::testKeyboardNavigation_data() groupingEnabledList.append(true); groupingEnabledNames[true] = "grouping enabled"; - for (const KFileItemListView::ItemLayout& layout : layoutList) { + QList layoutDirectionList; + QHash layoutDirectionNames; + layoutDirectionList.append(Qt::LeftToRight); + layoutDirectionNames[Qt::LeftToRight] = "Left-to-Right LayoutDirection"; + layoutDirectionList.append(Qt::RightToLeft); + layoutDirectionNames[Qt::RightToLeft] = "Right-to-Left LayoutDirection"; + + bool selectionModeEnabled = false; // For most tests this is kept disabled because it is not really affected by all the other test conditions. + // We only enable it for a few separate tests at the end. + + for (const KFileItemListView::ItemLayout &layout : layoutList) { // The following settings depend on the layout. // Note that 'columns' are actually 'rows' in // Compact layout. Qt::Orientation scrollOrientation; QList columnCountList; - Qt::Key nextItemKey; - Qt::Key previousItemKey; - Qt::Key nextRowKey; - Qt::Key previousRowKey; + Qt::Key nextItemKey = Qt::Key_Right; + Qt::Key previousItemKey = Qt::Key_Right; + Qt::Key nextRowKey = Qt::Key_Right; + Qt::Key previousRowKey = Qt::Key_Right; switch (layout) { case KFileItemListView::IconsLayout: @@ -280,62 +301,72 @@ void KItemListControllerTest::testKeyboardNavigation_data() previousRowKey = Qt::Key_Up; break; } - - for (int columnCount : qAsConst(columnCountList)) { - for (const KItemListController::SelectionBehavior& selectionBehavior : qAsConst(selectionBehaviorList)) { - for (bool groupingEnabled : qAsConst(groupingEnabledList)) { - QList > testList; + for (auto layoutDirection : std::as_const(layoutDirectionList)) { + if (layoutDirection == Qt::RightToLeft) { + switch (layout) { + case KFileItemListView::IconsLayout: + std::swap(nextItemKey, previousItemKey); + break; + case KFileItemListView::CompactLayout: + std::swap(nextRowKey, previousRowKey); + break; + default: + break; + } + } + for (int columnCount : std::as_const(columnCountList)) { + for (bool groupingEnabled : std::as_const(groupingEnabledList)) { + QList> testList; // First, key presses which should have the same effect // for any layout and any number of columns. - testList - << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) - << qMakePair(KeyPress(Qt::Key_Return), ViewState(1, KItemSet() << 1, true)) - << qMakePair(KeyPress(Qt::Key_Enter), ViewState(1, KItemSet() << 1, true)) - << qMakePair(KeyPress(nextItemKey), ViewState(2, KItemSet() << 2)) - << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) - << qMakePair(KeyPress(Qt::Key_Return), ViewState(3, KItemSet() << 2 << 3, true)) - << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(2, KItemSet() << 2)) - << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, KItemSet() << 2 << 3)) - << qMakePair(KeyPress(Qt::Key_Return), ViewState(4, KItemSet() << 2 << 3, true)) - << qMakePair(KeyPress(previousItemKey), ViewState(3, KItemSet() << 3)) - << qMakePair(KeyPress(Qt::Key_Home, Qt::ShiftModifier), ViewState(0, KItemSet() << 0 << 1 << 2 << 3)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 1 << 2 << 3)) - << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 2 << 3)) - << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 1 << 2 << 3)) - << qMakePair(KeyPress(Qt::Key_End), ViewState(19, KItemSet() << 19)) - << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(18, KItemSet() << 18 << 19)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)) - << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet())) - << qMakePair(KeyPress(Qt::Key_Enter), ViewState(0, KItemSet(), true)) - << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet() << 0)) - << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet())) - << qMakePair(KeyPress(Qt::Key_Space), ViewState(0, KItemSet() << 0)) - << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13)) - << qMakePair(KeyPress(Qt::Key_Space), ViewState(14, KItemSet() << 14)) - << qMakePair(KeyPress(Qt::Key_3), ViewState(15, KItemSet() << 15)) - << qMakePair(KeyPress(Qt::Key_Escape), ViewState(15, KItemSet())) - << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13)) - << qMakePair(KeyPress(Qt::Key_E), ViewState(14, KItemSet() << 14)) - << qMakePair(KeyPress(Qt::Key_E), ViewState(15, KItemSet() << 15)) - << qMakePair(KeyPress(Qt::Key_Escape), ViewState(15, KItemSet())) - << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)) - << qMakePair(KeyPress(Qt::Key_Escape), ViewState(0, KItemSet())); + testList << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(Qt::Key_Return), ViewState(1, KItemSet() << 1, true)) + << qMakePair(KeyPress(Qt::Key_Enter), ViewState(1, KItemSet() << 1, true)) + << qMakePair(KeyPress(nextItemKey), ViewState(2, KItemSet() << 2)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_Return), ViewState(3, KItemSet() << 2 << 3, true)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(2, KItemSet() << 2)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, KItemSet() << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_Return), ViewState(4, KItemSet() << 2 << 3, true)) + << qMakePair(KeyPress(previousItemKey), ViewState(3, KItemSet() << 3)) + << qMakePair(KeyPress(Qt::Key_Home, Qt::ShiftModifier), ViewState(0, KItemSet() << 0 << 1 << 2 << 3)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 1 << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 1 << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_End), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(18, KItemSet() << 18 << 19)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet())) + << qMakePair(KeyPress(Qt::Key_Enter), ViewState(0, KItemSet(), true)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet() << 0)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet())) + << qMakePair(KeyPress(Qt::Key_Space), ViewState(0, KItemSet() << 0)) + << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13)) + << qMakePair(KeyPress(Qt::Key_Space), ViewState(14, KItemSet() << 14)) + << qMakePair(KeyPress(Qt::Key_3), ViewState(15, KItemSet() << 15)) + << qMakePair(KeyPress(Qt::Key_Escape), ViewState(15, KItemSet())) + << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13)) + << qMakePair(KeyPress(Qt::Key_E), ViewState(14, KItemSet() << 14)) + << qMakePair(KeyPress(previousItemKey), ViewState(13, KItemSet() << 13)) + << qMakePair(KeyPress(Qt::Key_E), ViewState(14, KItemSet() << 14)) + << qMakePair(KeyPress(Qt::Key_Escape), ViewState(14, KItemSet())) + << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)) + << qMakePair(KeyPress(Qt::Key_Escape), ViewState(0, KItemSet())); // Next, we test combinations of key presses which only work for a // particular number of columns and either enabled or disabled grouping. // One column. if (columnCount == 1) { - testList - << qMakePair(KeyPress(nextRowKey), ViewState(1, KItemSet() << 1)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(2, KItemSet() << 1 << 2)) - << qMakePair(KeyPress(nextRowKey, Qt::ControlModifier), ViewState(3, KItemSet() << 1 << 2)) - << qMakePair(KeyPress(previousRowKey), ViewState(2, KItemSet() << 2)) - << qMakePair(KeyPress(previousItemKey), ViewState(1, KItemSet() << 1)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + testList << qMakePair(KeyPress(nextRowKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(2, KItemSet() << 1 << 2)) + << qMakePair(KeyPress(nextRowKey, Qt::ControlModifier), ViewState(3, KItemSet() << 1 << 2)) + << qMakePair(KeyPress(previousRowKey), ViewState(2, KItemSet() << 2)) + << qMakePair(KeyPress(previousItemKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); } // Multiple columns: we test both 3 and 5 columns with grouping @@ -353,27 +384,26 @@ void KItemListControllerTest::testKeyboardNavigation_data() // d4 e1 e2 | 12 13 14 // e3 e4 e5 | 15 16 17 // e6 e7 | 18 19 - testList - << qMakePair(KeyPress(nextRowKey), ViewState(3, KItemSet() << 3)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, KItemSet() << 3)) - << qMakePair(KeyPress(nextRowKey), ViewState(7, KItemSet() << 7)) - << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(8, KItemSet() << 7 << 8)) - << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(9, KItemSet() << 7 << 8 << 9)) - << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(8, KItemSet() << 7 << 8)) - << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7)) - << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 6 << 7)) - << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(5, KItemSet() << 5 << 6 << 7)) - << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 6 << 7)) - << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7)) - << qMakePair(KeyPress(nextRowKey), ViewState(10, KItemSet() << 10)) - << qMakePair(KeyPress(nextItemKey), ViewState(11, KItemSet() << 11)) - << qMakePair(KeyPress(nextRowKey), ViewState(14, KItemSet() << 14)) - << qMakePair(KeyPress(nextRowKey), ViewState(17, KItemSet() << 17)) - << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) - << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) - << qMakePair(KeyPress(Qt::Key_End), ViewState(19, KItemSet() << 19)) - << qMakePair(KeyPress(previousRowKey), ViewState(16, KItemSet() << 16)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + testList << qMakePair(KeyPress(nextRowKey), ViewState(3, KItemSet() << 3)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, KItemSet() << 3)) + << qMakePair(KeyPress(nextRowKey), ViewState(7, KItemSet() << 7)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(8, KItemSet() << 7 << 8)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(9, KItemSet() << 7 << 8 << 9)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(8, KItemSet() << 7 << 8)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 6 << 7)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(5, KItemSet() << 5 << 6 << 7)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 6 << 7)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7)) + << qMakePair(KeyPress(nextRowKey), ViewState(10, KItemSet() << 10)) + << qMakePair(KeyPress(nextItemKey), ViewState(11, KItemSet() << 11)) + << qMakePair(KeyPress(nextRowKey), ViewState(14, KItemSet() << 14)) + << qMakePair(KeyPress(nextRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(Qt::Key_End), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(16, KItemSet() << 16)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); } if (columnCount == 5 && !groupingEnabled) { @@ -383,18 +413,17 @@ void KItemListControllerTest::testKeyboardNavigation_data() // c2 c3 c4 c5 d1 | 5 6 7 8 9 // d2 d3 d4 e1 e2 | 10 11 12 13 14 // e3 e4 e5 e6 e7 | 15 16 17 18 19 - testList - << qMakePair(KeyPress(nextRowKey), ViewState(5, KItemSet() << 5)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(6, KItemSet() << 5)) - << qMakePair(KeyPress(nextRowKey), ViewState(11, KItemSet() << 11)) - << qMakePair(KeyPress(nextItemKey), ViewState(12, KItemSet() << 12)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(17, KItemSet() << 12 << 13 << 14 << 15 << 16 << 17)) - << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(12, KItemSet() << 12)) - << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7 << 8 << 9 << 10 << 11 << 12)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(12, KItemSet() << 12)) - << qMakePair(KeyPress(Qt::Key_End, Qt::ControlModifier), ViewState(19, KItemSet() << 12)) - << qMakePair(KeyPress(previousRowKey), ViewState(14, KItemSet() << 14)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + testList << qMakePair(KeyPress(nextRowKey), ViewState(5, KItemSet() << 5)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(6, KItemSet() << 5)) + << qMakePair(KeyPress(nextRowKey), ViewState(11, KItemSet() << 11)) + << qMakePair(KeyPress(nextItemKey), ViewState(12, KItemSet() << 12)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(17, KItemSet() << 12 << 13 << 14 << 15 << 16 << 17)) + << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(12, KItemSet() << 12)) + << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7 << 8 << 9 << 10 << 11 << 12)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(12, KItemSet() << 12)) + << qMakePair(KeyPress(Qt::Key_End, Qt::ControlModifier), ViewState(19, KItemSet() << 12)) + << qMakePair(KeyPress(previousRowKey), ViewState(14, KItemSet() << 14)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); } if (columnCount == 3 && groupingEnabled) { @@ -409,20 +438,19 @@ void KItemListControllerTest::testKeyboardNavigation_data() // e1 e2 e3 | 13 14 15 // e4 e5 e6 | 16 17 18 // e7 | 19 - testList - << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) - << qMakePair(KeyPress(nextItemKey), ViewState(2, KItemSet() << 2)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 2 << 3 << 4 << 5 << 6)) - << qMakePair(KeyPress(nextRowKey), ViewState(8, KItemSet() << 8)) - << qMakePair(KeyPress(nextRowKey), ViewState(11, KItemSet() << 11)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(12, KItemSet() << 11)) - << qMakePair(KeyPress(nextRowKey), ViewState(13, KItemSet() << 13)) - << qMakePair(KeyPress(nextRowKey), ViewState(16, KItemSet() << 16)) - << qMakePair(KeyPress(nextItemKey), ViewState(17, KItemSet() << 17)) - << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) - << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + testList << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(nextItemKey), ViewState(2, KItemSet() << 2)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 2 << 3 << 4 << 5 << 6)) + << qMakePair(KeyPress(nextRowKey), ViewState(8, KItemSet() << 8)) + << qMakePair(KeyPress(nextRowKey), ViewState(11, KItemSet() << 11)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(12, KItemSet() << 11)) + << qMakePair(KeyPress(nextRowKey), ViewState(13, KItemSet() << 13)) + << qMakePair(KeyPress(nextRowKey), ViewState(16, KItemSet() << 16)) + << qMakePair(KeyPress(nextItemKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); } if (columnCount == 5 && groupingEnabled) { @@ -434,59 +462,494 @@ void KItemListControllerTest::testKeyboardNavigation_data() // d1 d2 d3 d4 | 9 10 11 12 // e1 e2 e3 e4 e5 | 13 14 15 16 17 // e6 e7 | 18 19 - testList - << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 1 << 2 << 3)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(5, KItemSet() << 1 << 2 << 3 << 4 << 5)) - << qMakePair(KeyPress(nextItemKey), ViewState(6, KItemSet() << 6)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(7, KItemSet() << 6)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(8, KItemSet() << 6)) - << qMakePair(KeyPress(nextRowKey), ViewState(12, KItemSet() << 12)) - << qMakePair(KeyPress(nextRowKey), ViewState(17, KItemSet() << 17)) - << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) - << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) - << qMakePair(KeyPress(Qt::Key_End, Qt::ShiftModifier), ViewState(19, KItemSet() << 17 << 18 << 19)) - << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(14, KItemSet() << 14 << 15 << 16 << 17)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + testList << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 1 << 2 << 3)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(5, KItemSet() << 1 << 2 << 3 << 4 << 5)) + << qMakePair(KeyPress(nextItemKey), ViewState(6, KItemSet() << 6)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(7, KItemSet() << 6)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(8, KItemSet() << 6)) + << qMakePair(KeyPress(nextRowKey), ViewState(12, KItemSet() << 12)) + << qMakePair(KeyPress(nextRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(Qt::Key_End, Qt::ShiftModifier), ViewState(19, KItemSet() << 17 << 18 << 19)) + << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(14, KItemSet() << 14 << 15 << 16 << 17)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); } - const QString testName = - layoutNames[layout] + ", " + - QString("%1 columns, ").arg(columnCount) + - selectionBehaviorNames[selectionBehavior] + ", " + - groupingEnabledNames[groupingEnabled]; + const QString testName = layoutNames[layout] + ", " + QStringLiteral("%1 columns, ").arg(columnCount) + + groupingEnabledNames[groupingEnabled] + ", " + layoutDirectionNames[layoutDirection]; const QByteArray testNameAscii = testName.toLatin1(); QTest::newRow(testNameAscii.data()) - << layout - << scrollOrientation - << columnCount - << selectionBehavior - << groupingEnabled - << testList; + << layout << scrollOrientation << columnCount << groupingEnabled << layoutDirection << selectionModeEnabled << testList; } } } } + + /** + * Selection mode tests + * We only test for the default icon view mode with typical scrollOrientation, selectionBehaviour, no grouping, left-to-right layoutDirection because none + * of this should affect selection mode and special-casing selection mode within the above test would make the above code even more complex than it already + * is. + */ + selectionModeEnabled = true; + const KFileItemListView::ItemLayout layout = KFileItemListView::IconsLayout; + const Qt::Orientation scrollOrientation = Qt::Vertical; + const int columnCount = 3; + const Qt::Key nextItemKey = Qt::Key_Right; + const Qt::Key previousItemKey = Qt::Key_Left; + const Qt::Key nextRowKey = Qt::Key_Down; + const Qt::Key previousRowKey = Qt::Key_Up; + + const Qt::LayoutDirection layoutDirection = Qt::LeftToRight; + const bool groupingEnabled = false; + + QList> testList; + + testList << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet())) // In selection mode nothing is selected simply by moving with arrow keys. + << qMakePair(KeyPress(Qt::Key_Return), ViewState(1, KItemSet() << 1)) // Pressing Return toggles the selection but does not activate. + << qMakePair(KeyPress(Qt::Key_Enter), ViewState(1, KItemSet())) // Pressing Enter toggles the selection but does not activate. + << qMakePair(KeyPress(nextItemKey), ViewState(2, KItemSet())) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) // Shift+Arrow key still selects in selection mode. + << qMakePair(KeyPress(Qt::Key_Return), ViewState(3, KItemSet() << 2)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(2, KItemSet() << 2 << 3)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2)) // Shift+Left and then Shift+Right cancel each other out. + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, KItemSet() << 2)) + << qMakePair(KeyPress(Qt::Key_Return), ViewState(4, KItemSet() << 2 << 4)) + << qMakePair(KeyPress(previousItemKey), ViewState(3, KItemSet() << 2 << 4)) + << qMakePair(KeyPress(Qt::Key_Home, Qt::ShiftModifier), ViewState(0, KItemSet() << 0 << 1 << 2 << 3 << 4)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 1 << 2 << 3 << 4)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 2 << 3 << 4)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 1 << 2 << 3 << 4)) + << qMakePair(KeyPress(Qt::Key_End), ViewState(19, KItemSet() << 0 << 1 << 2 << 3 << 4)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(18, KItemSet() << 0 << 1 << 2 << 3 << 4 << 18 << 19)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0 << 1 << 2 << 3 << 4 << 18 << 19)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet() << 1 << 2 << 3 << 4 << 18 << 19)) + << qMakePair(KeyPress(Qt::Key_Enter), ViewState(0, KItemSet() << 0 << 1 << 2 << 3 << 4 << 18 << 19)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet() << 1 << 2 << 3 << 4 << 18 << 19)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet() << 0 << 1 << 2 << 3 << 4 << 18 << 19)) + << qMakePair(KeyPress(Qt::Key_Space), ViewState(0, KItemSet() << 1 << 2 << 3 << 4 << 18 << 19)) // Space toggles selection in selection mode. + << qMakePair(KeyPress(Qt::Key_D), ViewState(9, KItemSet() << 1 << 2 << 3 << 4 << 18 << 19)) // No selection change by type-ahead. + << qMakePair(KeyPress(Qt::Key_Space), ViewState(9, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) // Space is not added to type-ahead. + << qMakePair(KeyPress(Qt::Key_4), ViewState(12, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) // No selection change by type-ahead. + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + + // The following tests assume a columnCount of three and no grouping enabled. + << qMakePair(KeyPress(nextRowKey), ViewState(3, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + << qMakePair(KeyPress(nextRowKey), ViewState(7, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(8, KItemSet() << 1 << 2 << 3 << 4 << 7 << 8 << 9 << 18 << 19)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(9, KItemSet() << 1 << 2 << 3 << 4 << 7 << 8 << 9 << 18 << 19)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(8, KItemSet() << 1 << 2 << 3 << 4 << 7 << 8 << 9 << 18 << 19)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 1 << 2 << 3 << 4 << 6 << 7 << 9 << 18 << 19)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(5, KItemSet() << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 9 << 18 << 19)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 1 << 2 << 3 << 4 << 6 << 7 << 9 << 18 << 19)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + << qMakePair(KeyPress(nextRowKey), ViewState(10, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + << qMakePair(KeyPress(nextItemKey), ViewState(11, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + << qMakePair(KeyPress(nextRowKey), ViewState(14, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + << qMakePair(KeyPress(nextRowKey), ViewState(17, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + << qMakePair(KeyPress(Qt::Key_End), ViewState(19, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(16, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 1 << 2 << 3 << 4 << 9 << 18 << 19)); + + const QString testName = "Selection Mode: " + layoutNames[layout] + ", " + QStringLiteral("%1 columns, ").arg(columnCount) + + groupingEnabledNames[groupingEnabled] + ", " + layoutDirectionNames[layoutDirection]; + + const QByteArray testNameAscii = testName.toLatin1(); + + QTest::newRow(testNameAscii.data()) << layout << scrollOrientation << columnCount << groupingEnabled << layoutDirection << selectionModeEnabled << testList; } /** - * This function sets the view's properties according to the data provided by - * KItemListControllerTest::testKeyboardNavigation_data(). + * This function sets the view's properties according to the data provided. * * The list \a testList contains pairs of key presses, which are sent to the * container, and expected view states, which are verified then. */ -void KItemListControllerTest::testKeyboardNavigation() +void KItemListControllerTest::testKeyboardNavigationMultiSelection() +{ + QFETCH(KFileItemListView::ItemLayout, layout); + QFETCH(Qt::Orientation, scrollOrientation); + QFETCH(int, columnCount); + QFETCH(bool, groupingEnabled); + QFETCH(Qt::LayoutDirection, layoutDirection); + QFETCH(bool, selectionModeEnabled); + QFETCH(QList, testList); + + QApplication::setLayoutDirection(layoutDirection); + m_view->setLayoutDirection(layoutDirection); + + m_view->setItemLayout(layout); + QCOMPARE(m_view->itemLayout(), layout); + + m_view->setScrollOrientation(scrollOrientation); + QCOMPARE(m_view->scrollOrientation(), scrollOrientation); + + m_controller->setSelectionBehavior(KItemListController::MultiSelection); + QCOMPARE(m_controller->selectionBehavior(), KItemListController::MultiSelection); + + m_model->setGroupedSorting(groupingEnabled); + QCOMPARE(m_model->groupedSorting(), groupingEnabled); + + m_controller->setSelectionModeEnabled(selectionModeEnabled); + QCOMPARE(m_controller->selectionMode(), selectionModeEnabled); + + adjustGeometryForColumnCount(columnCount); + QCOMPARE(m_view->m_layouter->m_columnCount, columnCount); + + QSignalSpy spySingleItemActivated(m_controller, &KItemListController::itemActivated); + QSignalSpy spyMultipleItemsActivated(m_controller, &KItemListController::itemsActivated); + + int rowCount = 0; + while (!testList.isEmpty()) { + ++rowCount; + const QPair test = testList.takeFirst(); + const Qt::Key key = test.first.m_key; + const Qt::KeyboardModifiers modifier = test.first.m_modifier; + const int current = test.second.m_current; + const KItemSet selection = test.second.m_selection; + const bool activated = test.second.m_activated; + + QTest::keyClick(m_container, key, modifier); + + QVERIFY2( + m_selectionManager->currentItem() == current, + qPrintable(QStringLiteral("currentItem() returns index %1 but %2 would be expected. Before this, key \"%3\" was pressed. This test case is defined " + "in row %4 of the testList from KItemListControllerTest::testKeyboardNavigationMultiSelection_data().") + .arg(m_selectionManager->currentItem()) + .arg(current) + .arg(QKeySequence(key).toString()) + .arg(rowCount))); + QCOMPARE(m_selectionManager->selectedItems(), selection); + + if (activated) { + if (!selection.isEmpty()) { + // The selected items should be activated. + if (selection.count() == 1) { + QVERIFY(!spySingleItemActivated.isEmpty()); + QCOMPARE(qvariant_cast(spySingleItemActivated.takeFirst().at(0)), selection.first()); + QVERIFY(spyMultipleItemsActivated.isEmpty()); + } else { + QVERIFY(spySingleItemActivated.isEmpty()); + QVERIFY(!spyMultipleItemsActivated.isEmpty()); + QCOMPARE(qvariant_cast(spyMultipleItemsActivated.takeFirst().at(0)), selection); + } + } else { + QVERIFY(!spySingleItemActivated.isEmpty()); + QCOMPARE(qvariant_cast(spySingleItemActivated.takeFirst().at(0)), current); + QVERIFY(spyMultipleItemsActivated.isEmpty()); + } + } + } +} + +/** + * This function tests all possible combinations of view layouts, layout direction, + * and enabled/disabled groupings for different column counts, and + * provides a list of key presses and the states that the view should be in + * after the key press event. + */ +void KItemListControllerTest::testKeyboardNavigationSingleSelectionNoSelection_data() +{ + QTest::addColumn("layout"); + QTest::addColumn("scrollOrientation"); + QTest::addColumn("columnCount"); + QTest::addColumn("selectionBehavior"); // Defines how many items can be selected at the same time. + QTest::addColumn("groupingEnabled"); + QTest::addColumn("layoutDirection"); + QTest::addColumn( + "selectionModeEnabled"); // Don't confuse this with "selectionBehaviour". This is about changing controls for users to help multi-selecting. + QTest::addColumn>>("testList"); + + QList layoutList; + QHash layoutNames; + layoutList.append(KFileItemListView::IconsLayout); + layoutNames[KFileItemListView::IconsLayout] = "Icons"; + layoutList.append(KFileItemListView::CompactLayout); + layoutNames[KFileItemListView::CompactLayout] = "Compact"; + layoutList.append(KFileItemListView::DetailsLayout); + layoutNames[KFileItemListView::DetailsLayout] = "Details"; + + QList selectionBehaviorList; + QHash selectionBehaviorNames; + selectionBehaviorList.append(KItemListController::NoSelection); + selectionBehaviorNames[KItemListController::NoSelection] = "NoSelection"; + selectionBehaviorList.append(KItemListController::SingleSelection); + selectionBehaviorNames[KItemListController::SingleSelection] = "SingleSelection"; + + QList groupingEnabledList; + QHash groupingEnabledNames; + groupingEnabledList.append(false); + groupingEnabledNames[false] = "ungrouped"; + groupingEnabledList.append(true); + groupingEnabledNames[true] = "grouping enabled"; + + QList layoutDirectionList; + QHash layoutDirectionNames; + layoutDirectionList.append(Qt::LeftToRight); + layoutDirectionNames[Qt::LeftToRight] = "Left-to-Right LayoutDirection"; + layoutDirectionList.append(Qt::RightToLeft); + layoutDirectionNames[Qt::RightToLeft] = "Right-to-Left LayoutDirection"; + + bool selectionModeEnabled = false; // For most tests this is kept disabled because it is not really affected by all the other test conditions. + // We only enable it for a few separate tests at the end. + + for (const KFileItemListView::ItemLayout &layout : layoutList) { + // The following settings depend on the layout. + // Note that 'columns' are actually 'rows' in + // Compact layout. + Qt::Orientation scrollOrientation; + QList columnCountList; + Qt::Key nextItemKey = Qt::Key_Right; + Qt::Key previousItemKey = Qt::Key_Right; + Qt::Key nextRowKey = Qt::Key_Right; + Qt::Key previousRowKey = Qt::Key_Right; + + switch (layout) { + case KFileItemListView::IconsLayout: + scrollOrientation = Qt::Vertical; + columnCountList << 1 << 3 << 5; + nextItemKey = Qt::Key_Right; + previousItemKey = Qt::Key_Left; + nextRowKey = Qt::Key_Down; + previousRowKey = Qt::Key_Up; + break; + case KFileItemListView::CompactLayout: + scrollOrientation = Qt::Horizontal; + columnCountList << 1 << 3 << 5; + nextItemKey = Qt::Key_Down; + previousItemKey = Qt::Key_Up; + nextRowKey = Qt::Key_Right; + previousRowKey = Qt::Key_Left; + break; + case KFileItemListView::DetailsLayout: + scrollOrientation = Qt::Vertical; + columnCountList << 1; + nextItemKey = Qt::Key_Down; + previousItemKey = Qt::Key_Up; + nextRowKey = Qt::Key_Down; + previousRowKey = Qt::Key_Up; + break; + } + for (auto layoutDirection : std::as_const(layoutDirectionList)) { + if (layoutDirection == Qt::RightToLeft) { + switch (layout) { + case KFileItemListView::IconsLayout: + std::swap(nextItemKey, previousItemKey); + break; + case KFileItemListView::CompactLayout: + std::swap(nextRowKey, previousRowKey); + break; + default: + break; + } + } + for (int columnCount : std::as_const(columnCountList)) { + for (const KItemListController::SelectionBehavior &selectionBehavior : std::as_const(selectionBehaviorList)) { + for (bool groupingEnabled : std::as_const(groupingEnabledList)) { + QList> testList; + + // First, key presses which should have the same effect + // for any layout and any number of columns. + testList << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(Qt::Key_Return), ViewState(1, KItemSet() << 1, true)) + << qMakePair(KeyPress(Qt::Key_Enter), ViewState(1, KItemSet() << 1, true)) + << qMakePair(KeyPress(nextItemKey), ViewState(2, KItemSet() << 2)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_Return), ViewState(3, KItemSet() << 2 << 3, true)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(2, KItemSet() << 2)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, KItemSet() << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_Return), ViewState(4, KItemSet() << 2 << 3, true)) + << qMakePair(KeyPress(previousItemKey), ViewState(3, KItemSet() << 3)) + << qMakePair(KeyPress(Qt::Key_Home, Qt::ShiftModifier), ViewState(0, KItemSet() << 0 << 1 << 2 << 3)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 1 << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 1 << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_End), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(18, KItemSet() << 18 << 19)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet())) + << qMakePair(KeyPress(Qt::Key_Enter), ViewState(0, KItemSet(), true)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet() << 0)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet())) + << qMakePair(KeyPress(Qt::Key_Space), ViewState(0, KItemSet() << 0)) + << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13)) + << qMakePair(KeyPress(Qt::Key_Space), ViewState(14, KItemSet() << 14)) + << qMakePair(KeyPress(Qt::Key_3), ViewState(15, KItemSet() << 15)) + << qMakePair(KeyPress(Qt::Key_Escape), ViewState(15, KItemSet())) + << qMakePair(KeyPress(Qt::Key_E), ViewState(16, KItemSet() << 16)) + << qMakePair(KeyPress(Qt::Key_E), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(previousItemKey), ViewState(16, KItemSet() << 16)) + << qMakePair(KeyPress(Qt::Key_E), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(Qt::Key_Escape), ViewState(17, KItemSet())) + << qMakePair(KeyPress(Qt::Key_E), ViewState(18, KItemSet() << 18)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)) + << qMakePair(KeyPress(Qt::Key_Escape), ViewState(0, KItemSet())); + + // Next, we test combinations of key presses which only work for a + // particular number of columns and either enabled or disabled grouping. + + // One column. + if (columnCount == 1) { + testList << qMakePair(KeyPress(nextRowKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(2, KItemSet() << 1 << 2)) + << qMakePair(KeyPress(nextRowKey, Qt::ControlModifier), ViewState(3, KItemSet() << 1 << 2)) + << qMakePair(KeyPress(previousRowKey), ViewState(2, KItemSet() << 2)) + << qMakePair(KeyPress(previousItemKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + } + + // Multiple columns: we test both 3 and 5 columns with grouping + // enabled or disabled. For each case, the layout of the items + // in the view is shown (both using file names and indices) to + // make it easier to understand what the tests do. + + if (columnCount == 3 && !groupingEnabled) { + // 3 columns, no grouping: + // + // a1 a2 a3 | 0 1 2 + // b1 c1 c2 | 3 4 5 + // c3 c4 c5 | 6 7 8 + // d1 d2 d3 | 9 10 11 + // d4 e1 e2 | 12 13 14 + // e3 e4 e5 | 15 16 17 + // e6 e7 | 18 19 + testList << qMakePair(KeyPress(nextRowKey), ViewState(3, KItemSet() << 3)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, KItemSet() << 3)) + << qMakePair(KeyPress(nextRowKey), ViewState(7, KItemSet() << 7)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(8, KItemSet() << 7 << 8)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(9, KItemSet() << 7 << 8 << 9)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(8, KItemSet() << 7 << 8)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 6 << 7)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(5, KItemSet() << 5 << 6 << 7)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 6 << 7)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7)) + << qMakePair(KeyPress(nextRowKey), ViewState(10, KItemSet() << 10)) + << qMakePair(KeyPress(nextItemKey), ViewState(11, KItemSet() << 11)) + << qMakePair(KeyPress(nextRowKey), ViewState(14, KItemSet() << 14)) + << qMakePair(KeyPress(nextRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(Qt::Key_End), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(16, KItemSet() << 16)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + } + + if (columnCount == 5 && !groupingEnabled) { + // 5 columns, no grouping: + // + // a1 a2 a3 b1 c1 | 0 1 2 3 4 + // c2 c3 c4 c5 d1 | 5 6 7 8 9 + // d2 d3 d4 e1 e2 | 10 11 12 13 14 + // e3 e4 e5 e6 e7 | 15 16 17 18 19 + testList << qMakePair(KeyPress(nextRowKey), ViewState(5, KItemSet() << 5)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(6, KItemSet() << 5)) + << qMakePair(KeyPress(nextRowKey), ViewState(11, KItemSet() << 11)) + << qMakePair(KeyPress(nextItemKey), ViewState(12, KItemSet() << 12)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(17, KItemSet() << 12 << 13 << 14 << 15 << 16 << 17)) + << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(12, KItemSet() << 12)) + << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7 << 8 << 9 << 10 << 11 << 12)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(12, KItemSet() << 12)) + << qMakePair(KeyPress(Qt::Key_End, Qt::ControlModifier), ViewState(19, KItemSet() << 12)) + << qMakePair(KeyPress(previousRowKey), ViewState(14, KItemSet() << 14)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + } + + if (columnCount == 3 && groupingEnabled) { + // 3 columns, with grouping: + // + // a1 a2 a3 | 0 1 2 + // b1 | 3 + // c1 c2 c3 | 4 5 6 + // c4 c5 | 7 8 + // d1 d2 d3 | 9 10 11 + // d4 | 12 + // e1 e2 e3 | 13 14 15 + // e4 e5 e6 | 16 17 18 + // e7 | 19 + testList << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(nextItemKey), ViewState(2, KItemSet() << 2)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 2 << 3 << 4 << 5 << 6)) + << qMakePair(KeyPress(nextRowKey), ViewState(8, KItemSet() << 8)) + << qMakePair(KeyPress(nextRowKey), ViewState(11, KItemSet() << 11)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(12, KItemSet() << 11)) + << qMakePair(KeyPress(nextRowKey), ViewState(13, KItemSet() << 13)) + << qMakePair(KeyPress(nextRowKey), ViewState(16, KItemSet() << 16)) + << qMakePair(KeyPress(nextItemKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + } + + if (columnCount == 5 && groupingEnabled) { + // 5 columns, with grouping: + // + // a1 a2 a3 | 0 1 2 + // b1 | 3 + // c1 c2 c3 c4 c5 | 4 5 6 7 8 + // d1 d2 d3 d4 | 9 10 11 12 + // e1 e2 e3 e4 e5 | 13 14 15 16 17 + // e6 e7 | 18 19 + testList << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 1 << 2 << 3)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(5, KItemSet() << 1 << 2 << 3 << 4 << 5)) + << qMakePair(KeyPress(nextItemKey), ViewState(6, KItemSet() << 6)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(7, KItemSet() << 6)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(8, KItemSet() << 6)) + << qMakePair(KeyPress(nextRowKey), ViewState(12, KItemSet() << 12)) + << qMakePair(KeyPress(nextRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(Qt::Key_End, Qt::ShiftModifier), ViewState(19, KItemSet() << 17 << 18 << 19)) + << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(14, KItemSet() << 14 << 15 << 16 << 17)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + } + + const QString testName = layoutNames[layout] + ", " + QStringLiteral("%1 columns, ").arg(columnCount) + + selectionBehaviorNames[selectionBehavior] + ", " + groupingEnabledNames[groupingEnabled] + ", " + + layoutDirectionNames[layoutDirection]; + + const QByteArray testNameAscii = testName.toLatin1(); + + QTest::newRow(testNameAscii.data()) << layout << scrollOrientation << columnCount << selectionBehavior << groupingEnabled + << layoutDirection << selectionModeEnabled << testList; + } + } + } + } + } +} + +/** + * This function sets the view's properties according to the data provided. + * + * The list \a testList contains pairs of key presses, which are sent to the + * container, and expected view states, which are verified then. + */ +void KItemListControllerTest::testKeyboardNavigationSingleSelectionNoSelection() { QFETCH(KFileItemListView::ItemLayout, layout); QFETCH(Qt::Orientation, scrollOrientation); QFETCH(int, columnCount); QFETCH(KItemListController::SelectionBehavior, selectionBehavior); QFETCH(bool, groupingEnabled); + QFETCH(Qt::LayoutDirection, layoutDirection); + QFETCH(bool, selectionModeEnabled); QFETCH(QList, testList); + QApplication::setLayoutDirection(layoutDirection); + m_view->setLayoutDirection(layoutDirection); + m_view->setItemLayout(layout); QCOMPARE(m_view->itemLayout(), layout); @@ -499,13 +962,18 @@ void KItemListControllerTest::testKeyboardNavigation() m_model->setGroupedSorting(groupingEnabled); QCOMPARE(m_model->groupedSorting(), groupingEnabled); + m_controller->setSelectionModeEnabled(selectionModeEnabled); + QCOMPARE(m_controller->selectionMode(), selectionModeEnabled); + adjustGeometryForColumnCount(columnCount); QCOMPARE(m_view->m_layouter->m_columnCount, columnCount); QSignalSpy spySingleItemActivated(m_controller, &KItemListController::itemActivated); QSignalSpy spyMultipleItemsActivated(m_controller, &KItemListController::itemsActivated); + int rowCount = 0; while (!testList.isEmpty()) { + ++rowCount; const QPair test = testList.takeFirst(); const Qt::Key key = test.first.m_key; const Qt::KeyboardModifiers modifier = test.first.m_modifier; @@ -515,32 +983,27 @@ void KItemListControllerTest::testKeyboardNavigation() QTest::keyClick(m_container, key, modifier); - QCOMPARE(m_selectionManager->currentItem(), current); + QVERIFY2( + m_selectionManager->currentItem() == current, + qPrintable(QStringLiteral("currentItem() returns index %1 but %2 would be expected. Before this, key \"%3\" was pressed. This test case is defined " + "in row %4 of the testList from KItemListControllerTest::testKeyboardNavigationSingleSelectionNoSelection_data().") + .arg(m_selectionManager->currentItem()) + .arg(current) + .arg(QKeySequence(key).toString()) + .arg(rowCount))); switch (selectionBehavior) { - case KItemListController::NoSelection: QVERIFY(m_selectionManager->selectedItems().isEmpty()); break; - case KItemListController::SingleSelection: QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << current); break; - case KItemListController::MultiSelection: QCOMPARE(m_selectionManager->selectedItems(), selection); break; + case KItemListController::NoSelection: + QVERIFY(m_selectionManager->selectedItems().isEmpty()); + break; + case KItemListController::SingleSelection: + QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << current); + break; + default: + Q_UNREACHABLE(); } if (activated) { switch (selectionBehavior) { - case KItemListController::MultiSelection: - if (!selection.isEmpty()) { - // The selected items should be activated. - if (selection.count() == 1) { - QVERIFY(!spySingleItemActivated.isEmpty()); - QCOMPARE(qvariant_cast(spySingleItemActivated.takeFirst().at(0)), selection.first()); - QVERIFY(spyMultipleItemsActivated.isEmpty()); - } else { - QVERIFY(spySingleItemActivated.isEmpty()); - QVERIFY(!spyMultipleItemsActivated.isEmpty()); - QCOMPARE(qvariant_cast(spyMultipleItemsActivated.takeFirst().at(0)), selection); - } - break; - } - // No items are selected. Therefore, the current item should be activated. - // This is handled by falling through to the NoSelection/SingleSelection case. - Q_FALLTHROUGH(); case KItemListController::NoSelection: case KItemListController::SingleSelection: // In NoSelection and SingleSelection mode, the current item should be activated. @@ -548,6 +1011,8 @@ void KItemListControllerTest::testKeyboardNavigation() QCOMPARE(qvariant_cast(spySingleItemActivated.takeFirst().at(0)), current); QVERIFY(spyMultipleItemsActivated.isEmpty()); break; + default: + Q_UNREACHABLE(); } } } @@ -580,6 +1045,41 @@ void KItemListControllerTest::testMouseClickActivation() mouseReleaseEvent.setButton(Qt::LeftButton); mouseReleaseEvent.setButtons(Qt::NoButton); + QGraphicsSceneMouseEvent mouseDoubleClickEvent(QEvent::GraphicsSceneMouseDoubleClick); + mouseDoubleClickEvent.setPos(pos); + mouseDoubleClickEvent.setButton(Qt::LeftButton); + mouseDoubleClickEvent.setButtons(Qt::LeftButton); + + QGraphicsSceneMouseEvent mouseRightPressEvent(QEvent::GraphicsSceneMousePress); + mouseRightPressEvent.setPos(pos); + mouseRightPressEvent.setButton(Qt::RightButton); + mouseRightPressEvent.setButtons(Qt::RightButton); + + QGraphicsSceneMouseEvent mouseRightReleaseEvent(QEvent::GraphicsSceneMouseRelease); + mouseRightReleaseEvent.setPos(pos); + mouseRightReleaseEvent.setButton(Qt::RightButton); + mouseRightReleaseEvent.setButtons(Qt::NoButton); + + QGraphicsSceneMouseEvent mouseRightDoubleClickEvent(QEvent::GraphicsSceneMouseDoubleClick); + mouseRightDoubleClickEvent.setPos(pos); + mouseRightDoubleClickEvent.setButton(Qt::RightButton); + mouseRightDoubleClickEvent.setButtons(Qt::RightButton); + + QGraphicsSceneMouseEvent mouseBackPressEvent(QEvent::GraphicsSceneMousePress); + mouseBackPressEvent.setPos(pos); + mouseBackPressEvent.setButton(Qt::BackButton); + mouseBackPressEvent.setButtons(Qt::BackButton); + + QGraphicsSceneMouseEvent mouseBackReleaseEvent(QEvent::GraphicsSceneMouseRelease); + mouseBackReleaseEvent.setPos(pos); + mouseBackReleaseEvent.setButton(Qt::BackButton); + mouseBackReleaseEvent.setButtons(Qt::NoButton); + + QGraphicsSceneMouseEvent mouseBackDoubleClickEvent(QEvent::GraphicsSceneMouseDoubleClick); + mouseBackDoubleClickEvent.setPos(pos); + mouseBackDoubleClickEvent.setButton(Qt::BackButton); + mouseBackDoubleClickEvent.setButtons(Qt::BackButton); + QSignalSpy spyItemActivated(m_controller, &KItemListController::itemActivated); // Default setting: single click activation. @@ -588,6 +1088,7 @@ void KItemListControllerTest::testMouseClickActivation() m_view->event(&mouseReleaseEvent); QCOMPARE(spyItemActivated.count(), 1); spyItemActivated.clear(); + QVERIFY2(!m_view->controller()->selectionManager()->hasSelection(), "An item should not be implicitly selected during activation. @see bug 424723"); // Set the global setting to "double click activation". m_testStyle->setActivateItemOnSingleClick(false); @@ -595,6 +1096,30 @@ void KItemListControllerTest::testMouseClickActivation() m_view->event(&mouseReleaseEvent); QCOMPARE(spyItemActivated.count(), 0); spyItemActivated.clear(); + QVERIFY(m_view->controller()->selectionManager()->hasSelection()); + + // emulation of double click according to https://doc.qt.io/qt-6/qgraphicsscene.html#mouseDoubleClickEvent + m_view->event(&mousePressEvent); + m_view->event(&mouseReleaseEvent); + m_view->event(&mouseDoubleClickEvent); + m_view->event(&mouseReleaseEvent); + QCOMPARE(spyItemActivated.count(), 1); + spyItemActivated.clear(); + QVERIFY2(!m_view->controller()->selectionManager()->hasSelection(), "An item should not be implicitly selected during activation. @see bug 424723"); + + // right mouse button should not trigger activation + m_view->event(&mouseRightPressEvent); + m_view->event(&mouseRightReleaseEvent); + m_view->event(&mouseRightDoubleClickEvent); + m_view->event(&mouseRightReleaseEvent); + QCOMPARE(spyItemActivated.count(), 0); + + // back mouse button should not trigger activation + m_view->event(&mouseBackPressEvent); + m_view->event(&mouseBackReleaseEvent); + m_view->event(&mouseBackDoubleClickEvent); + m_view->event(&mouseBackReleaseEvent); + QCOMPARE(spyItemActivated.count(), 0); // Enforce single click activation in the controller. m_controller->setSingleClickActivationEnforced(true); @@ -602,6 +1127,8 @@ void KItemListControllerTest::testMouseClickActivation() m_view->event(&mouseReleaseEvent); QCOMPARE(spyItemActivated.count(), 1); spyItemActivated.clear(); + constexpr const char *reasonWhySelectionShouldPersist = "An item was selected before this mouse click. The click should not have cleared this selection."; + QVERIFY2(m_view->controller()->selectionManager()->hasSelection(), reasonWhySelectionShouldPersist); // Do not enforce single click activation in the controller. m_controller->setSingleClickActivationEnforced(false); @@ -609,6 +1136,7 @@ void KItemListControllerTest::testMouseClickActivation() m_view->event(&mouseReleaseEvent); QCOMPARE(spyItemActivated.count(), 0); spyItemActivated.clear(); + QVERIFY2(m_view->controller()->selectionManager()->hasSelection(), reasonWhySelectionShouldPersist); // Set the global setting back to "single click activation". m_testStyle->setActivateItemOnSingleClick(true); @@ -616,6 +1144,7 @@ void KItemListControllerTest::testMouseClickActivation() m_view->event(&mouseReleaseEvent); QCOMPARE(spyItemActivated.count(), 1); spyItemActivated.clear(); + QVERIFY2(m_view->controller()->selectionManager()->hasSelection(), reasonWhySelectionShouldPersist); // Enforce single click activation in the controller. m_controller->setSingleClickActivationEnforced(true); @@ -623,6 +1152,7 @@ void KItemListControllerTest::testMouseClickActivation() m_view->event(&mouseReleaseEvent); QCOMPARE(spyItemActivated.count(), 1); spyItemActivated.clear(); + QVERIFY2(m_view->controller()->selectionManager()->hasSelection(), reasonWhySelectionShouldPersist); // Restore previous settings. m_controller->setSingleClickActivationEnforced(true);