From 7424fcc3314a63d0716cb428a8b8de24b23e0279 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Thu, 29 Sep 2011 20:50:00 +0200 Subject: Keep current item and selection when resorting, part 1 KFileItemModel now emits the itemsMoved signal when the model is resorted, and KItemListSelectionManager has a new function itemsMoved() which will be called indirectly when this signal is emitted. Unit tests for the new functionality are included. The following things are still needed to make the feature work: 1. KFileItemMdel::resortAllItems() should not emit itemsAdded/itemsRemoved any more. 2. KItemListView::itemsMoved() must update the view according to the changes in the model, and it must call KItemListSelectionManager::itemsMoved(). --- src/kitemviews/kfileitemmodel.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/kitemviews/kfileitemmodel.cpp') diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 7874d3025..0d6f60336 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -732,6 +732,8 @@ void KFileItemModel::resortAllItems() return; } + const KFileItemList oldSortedItems = m_sortedItems; + KFileItemList sortedItems = m_sortedItems; m_sortedItems.clear(); m_items.clear(); @@ -748,12 +750,28 @@ void KFileItemModel::resortAllItems() ++index; } + bool emitItemsMoved = false; + QList movedToIndexes; + movedToIndexes.reserve(sortedItems.count()); + for (int i = 0; i < itemCount; i++) { + const int newIndex = m_items.value(oldSortedItems.at(i).url()); + movedToIndexes.append(newIndex); + if (!emitItemsMoved && newIndex != i) { + emitItemsMoved = true; + } + } + + if (emitItemsMoved) { + // TODO: + // * Implement KItemListView::slotItemsMoved() (which should call KItemListSelectionManager::itemsMoved()) + // * Do not emit itemsRemoved()/itemsInserted() here. + emit itemsMoved(KItemRange(0, itemCount), movedToIndexes); + } emit itemsInserted(KItemRangeList() << KItemRange(0, itemCount)); } void KFileItemModel::removeExpandedItems() { - KFileItemList expandedItems; const int maxIndex = m_data.count() - 1; -- cgit v1.3