]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Keep current item and selection when resorting, part 2
authorFrank Reininghaus <frank78ac@googlemail.com>
Mon, 3 Oct 2011 14:12:18 +0000 (16:12 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Mon, 3 Oct 2011 14:15:31 +0000 (16:15 +0200)
This commit adds the missing pieces to KItemListView and makes
KFileItemModel::resortAllItems() only emit the itemsMoved() signal.

src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kitemlistview.cpp

index 0d6f60336376741936a51d73c6662aaf82a182af..ddb89533c3b7cd6aa21aebb5895b4a57d900ce30 100644 (file)
@@ -733,26 +733,26 @@ void KFileItemModel::resortAllItems()
     }
 
     const KFileItemList oldSortedItems = m_sortedItems;
+    const QHash<KUrl, int> oldItems = m_items;
+    const QList<QHash<QByteArray, QVariant> > oldData = m_data;
 
-    KFileItemList sortedItems = m_sortedItems;
-    m_sortedItems.clear();
     m_items.clear();
     m_data.clear();
-    emit itemsRemoved(KItemRangeList() << KItemRange(0, itemCount));
 
-    sort(sortedItems.begin(), sortedItems.end());
+    sort(m_sortedItems.begin(), m_sortedItems.end());
     int index = 0;
-    foreach (const KFileItem& item, sortedItems) {
-        m_sortedItems.append(item);
+    foreach (const KFileItem& item, m_sortedItems) {
         m_items.insert(item.url(), index);
-        m_data.append(retrieveData(item));
+
+        const int oldItemIndex = oldItems.value(item.url());
+        m_data.append(oldData.at(oldItemIndex));
 
         ++index;
     }
 
     bool emitItemsMoved = false;
     QList<int> movedToIndexes;
-    movedToIndexes.reserve(sortedItems.count());
+    movedToIndexes.reserve(m_sortedItems.count());
     for (int i = 0; i < itemCount; i++) {
         const int newIndex = m_items.value(oldSortedItems.at(i).url());
         movedToIndexes.append(newIndex);
@@ -762,12 +762,8 @@ void KFileItemModel::resortAllItems()
     }
 
     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()
index 612b6fd6536677e9dd61011382019a1039c69cd7..4818527baf318c647637bca4145013fb3ad92d89 100644 (file)
@@ -771,8 +771,19 @@ void KItemListView::slotItemsMoved(const KItemRange& itemRange, const QList<int>
     // TODO:
     // * Implement KItemListView::slotItemsMoved() (which should call KItemListSelectionManager::itemsMoved())
     // * Do not emit itemsRemoved()/itemsInserted() in KFileItemModel::resortAllItems()
-    Q_UNUSED(itemRange);
-    Q_UNUSED(movedToIndexes);
+    const int firstVisibleMovedIndex = qMax(firstVisibleIndex(), itemRange.index);
+    const int lastVisibleMovedIndex = qMin(lastVisibleIndex(), itemRange.index + itemRange.count - 1);
+
+    for (int index = firstVisibleMovedIndex; index <= lastVisibleMovedIndex; ++index) {
+        KItemListWidget* widget = m_visibleItems.value(index);
+        if (widget) {
+            updateWidgetProperties(widget, index);
+        }
+    }
+
+    if (m_controller) {
+        m_controller->selectionManager()->itemsMoved(itemRange, movedToIndexes);
+    }
 }
 
 void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges,