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:
Frank Reininghaus 2011-08-14 11:05:19 +02:00
parent 98e859b0c3
commit 7b911df33e
3 changed files with 18 additions and 14 deletions

View file

@ -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);

View file

@ -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;
}

View file

@ -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()