]> cloud.milkyroute.net Git - dolphin.git/commitdiff
KFileItemModel: Allow to group files and folder together
authorMéven Car <meven29@gmail.com>
Mon, 8 Mar 2021 06:25:31 +0000 (07:25 +0100)
committerMéven Car <meven29@gmail.com>
Sun, 27 Jun 2021 09:19:43 +0000 (09:19 +0000)
When folders size is available and unless sort dir first is set, folders
and files can be grouped together in the regular size groups.

Without this you can end up with multiple groups being added each time a
folder size alternates with a file size.

Relates to d520b417c97bdbdfece2a497dac8b5384a80b597

src/kitemviews/kfileitemmodel.cpp

index a6c5e48ec7b1e44cbaa61b78f4a9d07e47388333..9441bc8714c4ad6cd020b90b782dec060c2a9f41 100644 (file)
@@ -2026,16 +2026,24 @@ QList<QPair<int, QVariant> > KFileItemModel::sizeRoleGroups() const
         }
 
         const KFileItem& item = m_itemData.at(i)->item;
-        const KIO::filesize_t fileSize = !item.isNull() ? item.size() : ~0U;
+        KIO::filesize_t fileSize = !item.isNull() ? item.size() : ~0U;
         QString newGroupValue;
         if (!item.isNull() && item.isDir()) {
-            newGroupValue = i18nc("@title:group Size", "Folders");
-        } else if (fileSize < 5 * 1024 * 1024) {
-            newGroupValue = i18nc("@title:group Size", "Small");
-        } else if (fileSize < 10 * 1024 * 1024) {
-            newGroupValue = i18nc("@title:group Size", "Medium");
-        } else {
-            newGroupValue = i18nc("@title:group Size", "Big");
+            if (DetailsModeSettings::directorySizeCount() || m_sortDirsFirst) {
+                newGroupValue = i18nc("@title:group Size", "Folders");
+            } else {
+                fileSize = m_itemData.at(i)->values.value("size").toULongLong();
+            }
+        }
+
+        if (newGroupValue.isEmpty()) {
+            if (fileSize < 5 * 1024 * 1024) { // < 5 MB
+                newGroupValue = i18nc("@title:group Size", "Small");
+            } else if (fileSize < 10 * 1024 * 1024) { // < 10 MB
+                newGroupValue = i18nc("@title:group Size", "Medium");
+            } else {
+                newGroupValue = i18nc("@title:group Size", "Big");
+            }
         }
 
         if (newGroupValue != groupValue) {