]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.h
Make the code that removes items from KFileItemModel more robust
[dolphin.git] / src / kitemviews / kfileitemmodel.h
index 1d837cb2a5c38938201d9cb914e233e869ac9254..d005705492e1a0feb4092808eca2f488ac0143ae 100644 (file)
@@ -309,7 +309,7 @@ private:
     };
 
     void insertItems(QList<ItemData*>& items);
     };
 
     void insertItems(QList<ItemData*>& items);
-    void removeItems(const KFileItemList& items, RemoveItemsBehavior behavior);
+    void removeItems(const KItemRangeList& itemRanges, RemoveItemsBehavior behavior);
 
     /**
      * Helper method for insertItems() and removeItems(): Creates
 
     /**
      * Helper method for insertItems() and removeItems(): Creates
@@ -319,8 +319,17 @@ private:
      */
     QList<ItemData*> createItemDataList(const KUrl& parentUrl, const KFileItemList& items) const;
 
      */
     QList<ItemData*> createItemDataList(const KUrl& parentUrl, const KFileItemList& items) const;
 
+    static int expandedParentsCount(const ItemData* data);
+
     void removeExpandedItems();
 
     void removeExpandedItems();
 
+    /**
+     * This function is called by setData() and slotRefreshItems(). It emits
+     * the itemsChanged() signal, checks if the sort order is still correct,
+     * and starts m_resortAllItemsTimer if that is not the case.
+     */
+    void emitItemsChangedAndTriggerResorting(const KItemRangeList& itemRanges, const QSet<QByteArray>& changedRoles);
+
     /**
      * Resets all values from m_requestRole to false.
      */
     /**
      * Resets all values from m_requestRole to false.
      */
@@ -380,11 +389,6 @@ private:
      */
     bool isChildItem(int index) const;
 
      */
     bool isChildItem(int index) const;
 
-    /**
-     * @return Recursive list of child items that have \a item as upper most parent.
-     */
-    KFileItemList childItems(const KFileItem& item) const;
-
     /**
      * Is invoked by KFileItemModelRolesUpdater and results in emitting the
      * sortProgress signal with a percent-value of the progress.
     /**
      * Is invoked by KFileItemModelRolesUpdater and results in emitting the
      * sortProgress signal with a percent-value of the progress.
@@ -400,7 +404,7 @@ private:
      * Removes filtered items whose expanded parents have been deleted
      * or collapsed via setExpanded(parentIndex, false).
      */
      * Removes filtered items whose expanded parents have been deleted
      * or collapsed via setExpanded(parentIndex, false).
      */
-    void removeFilteredChildren(const KFileItemList& parentsList);
+    void removeFilteredChildren(const KItemRangeList& parents);
 
     /**
      * Maps the QByteArray-roles to RoleTypes and provides translation- and
 
     /**
      * Maps the QByteArray-roles to RoleTypes and provides translation- and
@@ -429,6 +433,12 @@ private:
      */
     static void determineMimeTypes(const KFileItemList& items, int timeout);
 
      */
     static void determineMimeTypes(const KFileItemList& items, int timeout);
 
+    /**
+     * @return Returns a copy of \a value that is implicitly shared
+     * with other users to save memory.
+     */
+    static QByteArray sharedValue(const QByteArray& value);
+
     /**
      * Checks if the model's internal data structures are consistent.
      */
     /**
      * Checks if the model's internal data structures are consistent.
      */
@@ -460,8 +470,8 @@ private:
     // Cache for KFileItemModel::groups()
     mutable QList<QPair<int, QVariant> > m_groups;
 
     // Cache for KFileItemModel::groups()
     mutable QList<QPair<int, QVariant> > m_groups;
 
-    // Stores the URLs of the expanded directories.
-    QSet<KUrl> m_expandedDirs;
+    // Stores the URLs (key: target url, value: url) of the expanded directories.
+    QHash<KUrl, KUrl> m_expandedDirs;
 
     // URLs that must be expanded. The expanding is initially triggered in setExpanded()
     // and done step after step in slotCompleted().
 
     // URLs that must be expanded. The expanding is initially triggered in setExpanded()
     // and done step after step in slotCompleted().
@@ -477,7 +487,11 @@ private:
 
 inline bool KFileItemModel::isChildItem(int index) const
 {
 
 inline bool KFileItemModel::isChildItem(int index) const
 {
-    return m_requestRole[ExpandedParentsCountRole] && m_itemData.at(index)->values.value("expandedParentsCount").toInt() > 0;
+    if (m_itemData.at(index)->parent) {
+        return true;
+    } else {
+        return false;
+    }
 }
 
 #endif
 }
 
 #endif