]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Slightly refactor count resorting
authorFelix Ernst <felixernst@zohomail.eu>
Mon, 22 Jan 2024 17:33:09 +0000 (18:33 +0100)
committerFelix Ernst <felixernst@kde.org>
Tue, 23 Jan 2024 11:13:00 +0000 (11:13 +0000)
The bug fix 8f043b2958477d3fe2ef094b7e42f792f4cf0b02 introduced a
secondary code path to trigger a resort of items. However, the previous
way to trigger it only required a small bug fix to work and gives us a
couple of optimisations for free. This commit removes the secondary code
path and fixes the primary one.

CCBUG: 473999

src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kfileitemmodel.h
src/kitemviews/kfileitemmodelrolesupdater.cpp

index 81c3be64050a7f89d402a7e8f1b0102990de04e6..f9bab74cd63fa9502dbd6577a8226f029255316e 100644 (file)
@@ -1726,7 +1726,8 @@ void KFileItemModel::emitItemsChangedAndTriggerResorting(const KItemRangeList &i
 
     // Trigger a resorting if necessary. Note that this can happen even if the sort
     // role has not changed at all because the file name can be used as a fallback.
-    if (changedRoles.contains(sortRole()) || changedRoles.contains(roleForType(NameRole))) {
+    if (changedRoles.contains(sortRole()) || changedRoles.contains(roleForType(NameRole))
+        || (changedRoles.contains("count") && sortRole() == "size")) { // "count" is used in the "size" sort role, so this might require a resorting.
         for (const KItemRange &range : itemRanges) {
             bool needsResorting = false;
 
@@ -1751,7 +1752,7 @@ void KFileItemModel::emitItemsChangedAndTriggerResorting(const KItemRangeList &i
             }
 
             if (needsResorting) {
-                m_resortAllItemsTimer->start();
+                scheduleResortAllItems();
                 return;
             }
         }
index f87d2d5437af262e7823f8acb38e51fbd1eb1fb8..ad1b0a1384481029423d638fffcb30067763fba1 100644 (file)
@@ -205,8 +205,6 @@ public:
     /** set to true to hide application/x-trash files */
     void setShowTrashMime(bool show);
 
-    void scheduleResortAllItems();
-
 Q_SIGNALS:
     /**
      * Is emitted if the loading of a directory has been started. It is
@@ -464,6 +462,8 @@ private:
      */
     bool isChildItem(int index) const;
 
+    void scheduleResortAllItems();
+
     /**
      * Is invoked by KFileItemModelRolesUpdater and results in emitting the
      * sortProgress signal with a percent-value of the progress.
index 9dfa674bc524bbdf61935e91c82699b286507eae..2a3a8eeb35c48f58ca501238a7604702b8948fa6 100644 (file)
@@ -1354,10 +1354,6 @@ void KFileItemModelRolesUpdater::startDirectorySizeCounting(const KFileItem &ite
                 disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged);
                 m_model->setData(index, newData);
                 connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged);
-
-                if (newData.contains("count") && m_model->sortRole() == "size") {
-                    m_model->scheduleResortAllItems();
-                }
             }
         });
         return;