Commit eed79b83 authored by Frank Reininghaus's avatar Frank Reininghaus

Keep current item and selection when resorting, part 2

This commit adds the missing pieces to KItemListView and makes
KFileItemModel::resortAllItems() only emit the itemsMoved() signal.
parent d7b09852
......@@ -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()
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment