mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
Two small selection improvements in DolphinView
1. Implement DolphinView::clearSelection(). 2. Simplify DolphinView::invertSelection(). I found, fixed, and unit-tested a bug in the selection manager which was uncovered by this change.
This commit is contained in:
parent
98e859b0c3
commit
7b911df33e
3 changed files with 18 additions and 14 deletions
|
@ -104,6 +104,7 @@ void KItemListSelectionManager::setSelected(int index, int count, SelectionMode
|
|||
return;
|
||||
}
|
||||
|
||||
endAnchoredSelection();
|
||||
const QSet<int> previous = selectedItems();
|
||||
|
||||
count = qMin(count, m_model->count() - index);
|
||||
|
|
|
@ -315,7 +315,8 @@ namespace {
|
|||
NoChange,
|
||||
InsertItems,
|
||||
RemoveItems,
|
||||
EndAnchoredSelection
|
||||
EndAnchoredSelection,
|
||||
ToggleSelected
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -360,6 +361,13 @@ void KItemListSelectionManagerTest::testChangeSelection_data()
|
|||
<< QSet<int>()
|
||||
<< EndAnchoredSelection << KItemRangeList()
|
||||
<< QSet<int>();
|
||||
|
||||
QTest::newRow("Toggle selection")
|
||||
<< (QSet<int>() << 1 << 3 << 4)
|
||||
<< 6 << 8
|
||||
<< (QSet<int>() << 1 << 3 << 4 << 6 << 7 << 8)
|
||||
<< ToggleSelected << (KItemRangeList() << KItemRange(0, 10))
|
||||
<< (QSet<int>() << 0 << 2 << 5 << 9);
|
||||
}
|
||||
|
||||
void KItemListSelectionManagerTest::testChangeSelection()
|
||||
|
@ -423,6 +431,11 @@ void KItemListSelectionManagerTest::testChangeSelection()
|
|||
m_selectionManager->endAnchoredSelection();
|
||||
QVERIFY(!m_selectionManager->isAnchoredSelectionActive());
|
||||
break;
|
||||
case ToggleSelected:
|
||||
foreach(const KItemRange& range, changedItems) {
|
||||
m_selectionManager->setSelected(range.index, range.count, KItemListSelectionManager::Toggle);
|
||||
}
|
||||
break;
|
||||
case NoChange:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -530,22 +530,12 @@ void DolphinView::selectAll()
|
|||
void DolphinView::invertSelection()
|
||||
{
|
||||
KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
|
||||
const QSet<int> selectedItems = selectionManager->selectedItems();
|
||||
QSet<int> invertedSelectedItems;
|
||||
|
||||
const int maxIndex = fileItemModel()->count() - 1;
|
||||
for (int i = 0; i <= maxIndex; ++i) {
|
||||
if (!selectedItems.contains(i)) {
|
||||
invertedSelectedItems.insert(i);
|
||||
}
|
||||
}
|
||||
|
||||
selectionManager->setSelectedItems(invertedSelectedItems);
|
||||
selectionManager->setSelected(0, fileItemModel()->count(), KItemListSelectionManager::Toggle);
|
||||
}
|
||||
|
||||
void DolphinView::clearSelection()
|
||||
{
|
||||
//m_viewAccessor.itemView()->clearSelection();
|
||||
m_container->controller()->selectionManager()->clearSelection();
|
||||
}
|
||||
|
||||
void DolphinView::renameSelectedItems()
|
||||
|
|
Loading…
Reference in a new issue