From a3559a19db218e2a320fd81634d14e7cf891662e Mon Sep 17 00:00:00 2001 From: =?utf8?q?M=C3=A9ven=20Car?= Date: Mon, 8 Mar 2021 07:25:31 +0100 Subject: [PATCH] KFileItemModel: Allow to group files and folder together 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 | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index a6c5e48ec..9441bc871 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -2026,16 +2026,24 @@ QList > 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) { -- 2.47.3