From bb80d1877a8474ed60d4d0d41c587347fb521c95 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Wed, 10 Aug 2011 10:38:24 +0200 Subject: Update the anchor item when items are added or removed If items are added or removed in the model, not only the current item, but also the anchor item, which is the starting point for any selections via Shift+Click or Shift+Key, needs to be updated. BUG: 262638 FIXED-IN: 4.8.0 --- src/kitemviews/kitemlistselectionmanager.cpp | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/kitemviews/kitemlistselectionmanager.cpp') diff --git a/src/kitemviews/kitemlistselectionmanager.cpp b/src/kitemviews/kitemlistselectionmanager.cpp index ee8ba929e..cdc6dbc7d 100644 --- a/src/kitemviews/kitemlistselectionmanager.cpp +++ b/src/kitemviews/kitemlistselectionmanager.cpp @@ -187,6 +187,20 @@ void KItemListSelectionManager::itemsInserted(const KItemRangeList& itemRanges) setCurrentItem(m_currentItem + inc); } + // Update the anchor item + if (m_anchorItem < 0) { + setAnchorItem(0); + } else { + int inc = 0; + foreach (const KItemRange& itemRange, itemRanges) { + if (m_anchorItem < itemRange.index) { + break; + } + inc += itemRange.count; + } + setAnchorItem(m_anchorItem + inc); + } + // Update the selections if (!m_selectedItems.isEmpty()) { const QSet previous = m_selectedItems; @@ -231,6 +245,22 @@ void KItemListSelectionManager::itemsRemoved(const KItemRangeList& itemRanges) setCurrentItem(currentItem); } + // Update the anchor item + if (m_anchorItem >= 0) { + int anchorItem = m_anchorItem; + foreach (const KItemRange& itemRange, itemRanges) { + if (anchorItem < itemRange.index) { + break; + } + if (anchorItem >= itemRange.index + itemRange.count) { + anchorItem -= itemRange.count; + } else if (anchorItem >= m_model->count()) { + anchorItem = m_model->count() - 1; + } + } + setAnchorItem(anchorItem); + } + // Update the selections if (!m_selectedItems.isEmpty()) { const QSet previous = m_selectedItems; -- cgit v1.3