summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Hein <hein@kde.org>2017-02-07 08:10:42 (GMT)
committerEike Hein <hein@kde.org>2017-02-16 12:57:27 (GMT)
commit410086d06bf0b6195030fec5e9ac848cc50f50a7 (patch)
tree79abe583a35999d88c598e31bc0c0adf0b68d437
parent49d79637c53ff724cdc1f7c00954042be37e3a41 (diff)
Tweak alphabetic (default) sort behavior.
Summary: Alphabetical sorting currently compares a concatenation of "AppName" (determined by heuristic) and Qt::DisplayRole (usually the window title) using QString::localeAwareSort. This reflects that the motivation behind alphabetical sorting is generally to keep windows belonging to the same app grouped together and then order those groups alphabetically. The current code achieves this, but the particulars turn out to negatively impact users of multi-windowed apps that frequently change window titles in ways that impact sorting, particularly tabbed web browsers. Switching between tabs may change the order of browser windows on the Task Manager. Multiple instances of feedback suggest this is jarring and unexpected, despite technically being alphabetical. This patch changes behavior as follows: 1. Instead of comparing "<App Name><DisplayRole>" it will try to only compare "<App Name>", falling back to "<DisplayRole>" if the app name can't be determined. 2. If two tasks compare to equal in the above, it will fall back to source model row order, i.e. creation/append sorting. This still achieves the primary goal laid out above while keeping the sort order within an app "group" stable when using alphabetical sorting. BUG:373698 An alternative means to achive this behavior would be via existing Task Manager settings. To wit: 1. Enable grouping 2. Disable group popups, so groups are instead maintained inline on the widget I'm actually considering suggesting the above (plus changing sorting to Manual) as new default settings for 5.10 - but in the meantime it still makes sense to tune the alphabetical sorting mode in this way, and put the improved behavior into 5.8 and 5.9 to address user feedback earlier. Reviewers: #plasma, davidedmundson Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D4469
-rw-r--r--libtaskmanager/tasksmodel.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/libtaskmanager/tasksmodel.cpp b/libtaskmanager/tasksmodel.cpp
index 52abce9..7a49936 100644
--- a/libtaskmanager/tasksmodel.cpp
+++ b/libtaskmanager/tasksmodel.cpp
@@ -802,13 +802,26 @@ bool TasksModel::Private::lessThan(const QModelIndex &left, const QModelIndex &r
if (sortMode == SortDisabled) {
return (left.row() < right.row());
} else {
- const QString &leftSortString = left.data(AbstractTasksModel::AppName).toString()
- + left.data(Qt::DisplayRole).toString();
+ QString leftSortString = left.data(AbstractTasksModel::AppName).toString();
- const QString &rightSortString = right.data(AbstractTasksModel::AppName).toString()
- + right.data(Qt::DisplayRole).toString();
+ if (leftSortString.isEmpty()) {
+ leftSortString = left.data(Qt::DisplayRole).toString();
+ }
+
+ QString rightSortString = right.data(AbstractTasksModel::AppName).toString();
+
+ if (rightSortString.isEmpty()) {
+ rightSortString = right.data(Qt::DisplayRole).toString();
+ }
+
+ const int sortResult = leftSortString.localeAwareCompare(rightSortString);
+
+ // If the string are identical fall back to source model (creation/append) order.
+ if (sortResult == 0) {
+ return (left.row() < right.row());
+ }
- return (leftSortString.localeAwareCompare(rightSortString) < 0);
+ return (sortResult < 0);
}
}
}