┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
authorMéven Car <[email protected]>2021-03-11 08:09:18 +0100
committerMéven Car <[email protected]>2021-04-05 14:27:47 +0200
commit0429e5330e09f7a379f0a70372c262faeda2c5a6 (patch)
tree3b7cbd7ead4792f57c8ad6af695eba7cc93256cc /src/kitemviews
parentc0e3a5afb2acc701fea8a58b7250de07da2d207d (diff)
KFileItemModel: DetailsModeSettings::directorySizeCount forces m_sortDirsFirst
Before this patch when !m_sortDirsFirst and DetailsModeSettings::directorySizeCount() == true, the ordering of folders before files would be affected by the sortOrder. I.e descending order would put the folders after the files.
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/kfileitemmodel.cpp37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index b000d649c..da15ccbdd 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -1719,7 +1719,7 @@ bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b, const QColla
}
}
- if (m_sortDirsFirst) {
+ if (m_sortDirsFirst || (DetailsModeSettings::directorySizeCount() && m_sortRole == SizeRole)) {
const bool isDirA = a->item.isDir();
const bool isDirB = b->item.isDir();
if (isDirA && !isDirB) {
@@ -1768,30 +1768,25 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const
break;
case SizeRole: {
- if (DetailsModeSettings::directorySizeCount() && (itemA.isDir() || itemB.isDir())) {
+ if (DetailsModeSettings::directorySizeCount() && itemA.isDir()) {
// folders first then
- if (itemA.isDir() && itemB.isDir()) {
- auto valueA = a->values.value("count");
- auto valueB = b->values.value("count");
- if (valueA.isNull()) {
- if (valueB.isNull()) {
- return 0;
- } else {
- return -1;
- }
- } else if (valueB.isNull()) {
- return +1;
+ // items A and B are folders thanks to lessThan checks
+ auto valueA = a->values.value("count");
+ auto valueB = b->values.value("count");
+ if (valueA.isNull()) {
+ if (valueB.isNull()) {
+ return 0;
} else {
- if (valueA.toLongLong() < valueB.toLongLong()) {
- return -1;
- } else {
- return +1;
- }
+ return -1;
}
- } else if (itemA.isDir()) {
- return 1;
+ } else if (valueB.isNull()) {
+ return +1;
} else {
- return -1;
+ if (valueA.toLongLong() < valueB.toLongLong()) {
+ return -1;
+ } else {
+ return +1;
+ }
}
}
KIO::filesize_t sizeA = 0;