]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Iterate over a const copy list of containers
authorIsmael Asensio <isma.af@gmail.com>
Fri, 6 Nov 2020 20:22:14 +0000 (21:22 +0100)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Sun, 8 Nov 2020 21:59:34 +0000 (21:59 +0000)
This effectively reverts the mutable iterations approach on
2448f88c5f42d7a2040fcf3bcd3c5f2a2f62cd03, and fix crashes
and ghost items when using the filter bar

BUG: 428374

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

index c06202fd82fb84cc8aa2ca2d568901ca2d63972e..dbbd63a6a19d38feee20d1987c00ffe71f21cbbc 100644 (file)
@@ -919,9 +919,9 @@ void KFileItemModel::slotCompleted()
         // Note that the parent folder must be expanded before any of its subfolders become visible.
         // Therefore, some URLs in m_restoredExpandedUrls might not be visible yet
         // -> we expand the first visible URL we find in m_restoredExpandedUrls.
-        QMutableSetIterator<QUrl> it(m_urlsToExpand);
-        while (it.hasNext()) {
-            const QUrl url = it.next();
+        // Iterate over a const copy because items are deleted and inserted within the loop
+        const auto urlsToExpand = m_urlsToExpand;
+        for(const QUrl &url : urlsToExpand) {
             const int indexForUrl = index(url);
             if (indexForUrl >= 0) {
                 m_urlsToExpand.remove(url);
index 25e1a368531cd128f4c0094d18f51d69d06051da..f6f2815dff739cf9b4ee0a04b62b0d643067cd2c 100644 (file)
@@ -957,9 +957,9 @@ void KFileItemModelRolesUpdater::updateChangedItems()
     QList<int> visibleChangedIndexes;
     QList<int> invisibleChangedIndexes;
 
-    QMutableSetIterator<KFileItem> it(m_changedItems);
-    while (it.hasNext()) {
-        const KFileItem item = it.next();
+    // Iterate over a const copy because items are deleted within the loop
+    const auto changedItems = m_changedItems;
+    for (const KFileItem item : changedItems) {
         const int index = m_model->index(item);
 
         if (index < 0) {
index 281edc3e906397075309dcaa10995f02981d0ec9..f6e5e666bb8e2e00ecdf710d3c7aa492a4ff9bb6 100644 (file)
@@ -1155,10 +1155,10 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
         QVector<int> itemsToMove;
 
         // Remove all KItemListWidget instances that got deleted
-        QMutableHashIterator<int, KItemListWidget*> it(m_visibleItems);
-        while (it.hasNext()) {
-            it.next();
-            KItemListWidget* widget = it.value();
+        // Iterate over a const copy because the container is mutated within the loop
+        // directly and in `recycleWidget()` (https://bugs.kde.org/show_bug.cgi?id=428374)
+        const auto visibleItems = m_visibleItems;
+        for (KItemListWidget* widget : visibleItems) {
             const int i = widget->index();
             if (i < firstRemovedIndex) {
                 continue;