]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fixed crashing when initial grouping is by size. Fixed size grouping ignoring directo...
authorZakhar Afonin <aza22u419@student.bmstu.ru>
Mon, 17 Jun 2024 21:03:51 +0000 (00:03 +0300)
committerZakhar Afonin <aza22u419@student.bmstu.ru>
Mon, 17 Jun 2024 21:03:51 +0000 (00:03 +0300)
src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kfileitemmodel.h
src/kitemviews/kfileitemmodelrolesupdater.cpp

index 7d5b0f51847f0c25f4f7bf20ebf49f516b4d89ed..63686992f719b702487dec4a4b913819e93756ef 100644 (file)
@@ -1040,6 +1040,7 @@ void KFileItemModel::loadSortingSettings()
     // Workaround for bug https://bugreports.qt.io/browse/QTBUG-69361
     // Force the clean state of QCollator in single thread to avoid thread safety problems in sort
     m_collator.compare(QString(), QString());
+    m_dirSizeMode = ContentDisplaySettings::directorySizeMode();
 }
 
 void KFileItemModel::resortAllItems()
@@ -1105,7 +1106,8 @@ void KFileItemModel::resortAllItems()
         }
 
         Q_EMIT itemsMoved(KItemRange(firstMovedIndex, movedItemsCount), movedToIndexes);
-    } else if (groupedSorting()) {
+    }
+    if (groupedSorting()) {
         // The groups might have changed even if the order of the items has not.
         const QList<QPair<int, QVariant>> oldGroups = m_groups;
         m_groups.clear();
@@ -2129,8 +2131,7 @@ bool KFileItemModel::lessThan(const ItemData *a, const ItemData *b, const QColla
                 return true;
             }
         }
-        if (m_sortDirsFirst
-            || (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount && m_sortRole == SizeRole)) {
+        if (m_sortDirsFirst || (m_dirSizeMode == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount && m_sortRole == SizeRole)) {
             const bool isDirA = a->item.isDir();
             const bool isDirB = b->item.isDir();
             if (isDirA && !isDirB) {
@@ -2184,7 +2185,7 @@ int KFileItemModel::sortRoleCompare(const ItemData *a, const ItemData *b, const
         break;
 
     case SizeRole: {
-        if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount && itemA.isDir()) {
+        if (m_dirSizeMode == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount && itemA.isDir()) {
             // folders first then
             // items A and B are folders thanks to lessThan checks
             auto valueA = a->values.value("count");
@@ -2542,7 +2543,7 @@ KFileItemModel::ItemGroupInfo KFileItemModel::sizeRoleGroup(const ItemData *item
 
     groupInfo.comparable = -1; // None
     if (!item.isNull() && item.isDir()) {
-        if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount || m_sortDirsFirst) {
+        if (m_dirSizeMode == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount) {
             groupInfo.comparable = 0; // Folders
         } else {
             fileSize = itemData->values.value("size").toULongLong();
index f89eae9469976709aab6a79b62fa0e00a9d4e004..fc2f1b6c8c41b03963a50b3185d51b98562eb1fe 100644 (file)
@@ -574,6 +574,7 @@ private:
     bool m_naturalSorting;
     bool m_sortDirsFirst;
     bool m_sortHiddenLast;
+    int m_dirSizeMode;
 
     RoleType m_sortRole;
     RoleType m_groupRole;
index 0ff431ac99a5366120d6fafb568ee52d12209438..0012e99c1c2f1c5bea81426ff65a630e9d3215d7 100644 (file)
@@ -368,7 +368,7 @@ void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList &itemRan
     timer.start();
 
     // Determine the sort role synchronously for as many items as possible.
-    if (m_resolvableRoles.contains(m_model->sortRole())) {
+    if (m_resolvableRoles.contains(m_model->sortRole()) || m_resolvableRoles.contains(m_model->groupRole())) {
         int insertedCount = 0;
         for (const KItemRange &range : itemRanges) {
             const int lastIndex = insertedCount + range.index + range.count - 1;
@@ -1218,13 +1218,14 @@ void KFileItemModelRolesUpdater::applySortRole(int index)
     QHash<QByteArray, QVariant> data;
     const KFileItem item = m_model->fileItem(index);
 
-    if (m_model->sortRole() == "type") {
+    // Despite the name, this handles both sorting and grouping, as they happen at the same time (resorting items).
+    if (m_model->sortRole() == "type" || m_model->groupRole() == "type") {
         if (!item.isMimeTypeKnown()) {
             item.determineMimeType();
         }
 
         data.insert("type", item.mimeComment());
-    } else if (m_model->sortRole() == "size" && item.isLocalFile() && item.isDir()) {
+    } else if ((m_model->sortRole() == "size" || m_model->groupRole() == "size") && item.isLocalFile() && item.isDir()) {
         startDirectorySizeCounting(item, index);
         return;
     } else {