┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2012-02-01 21:52:50 +0100
committerFrank Reininghaus <[email protected]>2012-02-01 21:58:23 +0100
commit7f4e9d9ed908eaa10659cbd04f53a82e28e8a59b (patch)
tree109395e80e67886a26128853a3b7c7f6095fc069 /src/kitemviews
parent43373b3a1650a5834f3d030b61d80b0a4e858588 (diff)
First version of a unit test for KItemListController
At the moment, only key press events are tested, and the current item and selection after the event are verified. Moreover, this commit makes sure that KItemListController::keyPressEvent() really does not select anything if the selection mode is NoSelection.
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/kitemlistcontroller.cpp51
-rw-r--r--src/kitemviews/kitemlistview.h1
-rw-r--r--src/kitemviews/kitemlistviewlayouter_p.h2
3 files changed, 37 insertions, 17 deletions
diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp
index e3210dd22..69320247a 100644
--- a/src/kitemviews/kitemlistcontroller.cpp
+++ b/src/kitemviews/kitemlistcontroller.cpp
@@ -203,7 +203,8 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
}
}
- const bool selectSingleItem = itemCount == 1 &&
+ const bool selectSingleItem = m_selectionBehavior != NoSelection &&
+ itemCount == 1 &&
(key == Qt::Key_Home || key == Qt::Key_End ||
key == Qt::Key_Up || key == Qt::Key_Down ||
key == Qt::Key_Left || key == Qt::Key_Right);
@@ -322,13 +323,15 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
}
case Qt::Key_Space:
- if (controlPressed) {
- m_selectionManager->endAnchoredSelection();
- m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle);
- m_selectionManager->beginAnchoredSelection(index);
- } else {
- const int current = m_selectionManager->currentItem();
- m_selectionManager->setSelected(current);
+ if (m_selectionBehavior == MultiSelection) {
+ if (controlPressed) {
+ m_selectionManager->endAnchoredSelection();
+ m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle);
+ m_selectionManager->beginAnchoredSelection(index);
+ } else {
+ const int current = m_selectionManager->currentItem();
+ m_selectionManager->setSelected(current);
+ }
}
break;
@@ -361,19 +364,33 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
}
if (m_selectionManager->currentItem() != index) {
- if (controlPressed) {
- m_selectionManager->endAnchoredSelection();
- }
-
- m_selectionManager->setCurrentItem(index);
+ switch (m_selectionBehavior) {
+ case NoSelection:
+ m_selectionManager->setCurrentItem(index);
+ break;
- if (!shiftOrControlPressed || m_selectionBehavior == SingleSelection) {
+ case SingleSelection:
+ m_selectionManager->setCurrentItem(index);
m_selectionManager->clearSelection();
m_selectionManager->setSelected(index, 1);
- }
+ break;
+
+ case MultiSelection:
+ if (controlPressed) {
+ m_selectionManager->endAnchoredSelection();
+ }
+
+ m_selectionManager->setCurrentItem(index);
+
+ if (!shiftOrControlPressed) {
+ m_selectionManager->clearSelection();
+ m_selectionManager->setSelected(index, 1);
+ }
- if (!shiftPressed) {
- m_selectionManager->beginAnchoredSelection(index);
+ if (!shiftPressed) {
+ m_selectionManager->beginAnchoredSelection(index);
+ }
+ break;
}
m_view->scrollToItem(index);
diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h
index 95215fffd..9c34daba3 100644
--- a/src/kitemviews/kitemlistview.h
+++ b/src/kitemviews/kitemlistview.h
@@ -513,6 +513,7 @@ private:
bool m_useHeaderWidths;
friend class KItemListController;
+ friend class KItemListControllerTest;
};
/**
diff --git a/src/kitemviews/kitemlistviewlayouter_p.h b/src/kitemviews/kitemlistviewlayouter_p.h
index dec99d054..25f8eb6cd 100644
--- a/src/kitemviews/kitemlistviewlayouter_p.h
+++ b/src/kitemviews/kitemlistviewlayouter_p.h
@@ -161,6 +161,8 @@ private:
qreal m_groupHeaderHeight;
QList<QRectF> m_itemRects;
+
+ friend class KItemListControllerTest;
};
#endif