]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.cpp
Merge remote-tracking branch 'origin/master' into frameworks
[dolphin.git] / src / kitemviews / kfileitemmodel.cpp
index 066af20f7fe397715c2b614e3156ca54259ad8b7..51bf546f9a2c133b16d262fe10f70e4794bbf3d2 100644 (file)
@@ -218,7 +218,7 @@ void KFileItemModel::setShowHiddenFiles(bool show)
     m_dirLister->setShowingDotFiles(show);
     m_dirLister->emitChanges();
     if (show) {
-        slotCompleted();
+        dispatchPendingItemsToInsert();
     }
 }
 
@@ -488,6 +488,18 @@ bool KFileItemModel::setExpanded(int index, bool expanded)
             m_urlsToExpand.insert(url);
         }
     } else {
+        // Note that there might be (indirect) children of the folder which is to be collapsed in
+        // m_pendingItemsToInsert. To prevent that they will be inserted into the model later,
+        // possibly without a parent, which might result in a crash, we insert all pending items
+        // right now. All new items which would be without a parent will then be removed.
+        dispatchPendingItemsToInsert();
+
+        // Check if the index of the collapsed folder has changed. If that is the case, then items
+        // were inserted before the collapsed folder, and its index needs to be updated.
+        if (m_itemData.at(index)->item != item) {
+            index = this->index(item);
+        }
+
         m_expandedDirs.remove(targetUrl);
         m_dirLister->stop(url);
 
@@ -502,7 +514,9 @@ bool KFileItemModel::setExpanded(int index, bool expanded)
             ItemData* itemData = m_itemData.at(childIndex);
             if (itemData->values.value("isExpanded").toBool()) {
                 const KUrl targetUrl = itemData->item.targetUrl();
+                const KUrl url = itemData->item.url();
                 m_expandedDirs.remove(targetUrl);
+                m_dirLister->stop(url);     // TODO: try to unit-test this, see https://bugs.kde.org/show_bug.cgi?id=332102#c11
                 expandedChildren.append(targetUrl);
             }
             ++childIndex;