URL To paste - | raw - Sat Nov 07 2020 12:01:08 GMT+0000 (Coordinated Universal Time)
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp
index 281edc3e9..a4442e5a9 100644
--- a/src/kitemviews/kitemlistview.cpp
+++ b/src/kitemviews/kitemlistview.cpp
@@ -1153,6 +1153,7 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
// Remember which items have to be moved because they are behind the removed range.
QVector itemsToMove;
+ QVector widgetsToRecycle;
// Remove all KItemListWidget instances that got deleted
QMutableHashIterator it(m_visibleItems);
@@ -1177,19 +1178,21 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
if (m_model->count() == 0 || hasMultipleRanges || !animateChangedItemCount(count)) {
// Remove the widget without animation
- recycleWidget(widget);
+ widgetsToRecycle.push_back(widget);
} else {
// Animate the removing of the items. Special case: When removing an item there
// is no valid model index available anymore. For the
// remove-animation the item gets removed from m_visibleItems but the widget
// will stay alive until the animation has been finished and will
// be recycled (deleted) in KItemListView::slotAnimationFinished().
- m_visibleItems.remove(i);
+ it.remove();
widget->setIndex(-1);
m_animation->start(widget, KItemListViewAnimation::DeleteAnimation);
}
}
+ recycleWidgets(widgetsToRecycle);
+
// Update the indexes of all KItemListWidget instances that are located
// after the deleted items. It is important to update them in ascending
// order to prevent overlaps when setting the new index.
@@ -1977,6 +1980,13 @@ void KItemListView::recycleWidget(KItemListWidget* widget)
widgetCreator()->recycle(widget);
}
+void KItemListView::recycleWidgets(const QVector &widgets)
+{
+ for (KItemListWidget *widget : qAsConst(widgets)) {
+ recycleWidget(widget);
+ }
+}
+
void KItemListView::setWidgetIndex(KItemListWidget* widget, int index)
{
const int oldIndex = widget->index();
diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h
index df582aad0..c71eca95c 100644
--- a/src/kitemviews/kitemlistview.h
+++ b/src/kitemviews/kitemlistview.h
@@ -478,6 +478,7 @@ private:
KItemListWidget* createWidget(int index);
void recycleWidget(KItemListWidget* widget);
+ void recycleWidgets(const QVector &widgets);
/**
* Changes the index of the widget to \a index and assures a consistent