From 7f6d49377b3b66da9811d94aa0166872e4f44836 Mon Sep 17 00:00:00 2001 From: Nazar Kalinowski Date: Sun, 1 Sep 2019 17:48:32 +0200 Subject: [PATCH] Make non-empty textual columns come first in sorting Summary: Current behavior of dolphin in sorting of files with textual columns (e.g. tags) is to show files without this particular textual column (e.g. without tags) first. This patch changes this behavior so that dolphin shows the files with some value before the files without any value for chosen sorting method. BUG: 410538 Test Plan: Sorting by name (isn't affected by the patch): https://i.imgur.com/eqbYwyZ.png Sorting by textual column ("tags" in this particular example), old version (non-tagged files and folders come first): https://i.imgur.com/5KLLujU.png patched version (tagged files and folders come first): https://i.imgur.com/oUAeZ2z.png Reviewers: #dolphin, #vdg, ngraham Reviewed By: #dolphin, #vdg, ngraham Subscribers: elvisangelaccio, ngraham, kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D23482 --- src/kitemviews/kfileitemmodel.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 49c96ec37f..091044c06c 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -1829,8 +1829,15 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const default: { const QByteArray role = roleForType(m_sortRole); - result = QString::compare(a->values.value(role).toString(), - b->values.value(role).toString()); + const QString roleValueA = a->values.value(role).toString(); + const QString roleValueB = b->values.value(role).toString(); + if (!roleValueA.isEmpty() && roleValueB.isEmpty()) { + result = -1; + } else if (roleValueA.isEmpty() && !roleValueB.isEmpty()) { + result = +1; + } else { + result = QString::compare(roleValueA, roleValueB); + } break; }