Verified Commit 71f33e17 authored by Fushan Wen's avatar Fushan Wen
Browse files

libtaskmanager: Add a new sort mode "LastActivated"



Tasks are ordered following SortLastActivated sort mode: tasks are
sorted by opening history.

Grouped tasks are sorted by the last activated task in the group.

Co-Authored-By: Yari Polla's avatarYari Polla <skilvingr@gmail.com>
parent 1d917aa3
Pipeline #167890 passed with stage
in 6 minutes and 40 seconds
......@@ -723,6 +723,20 @@ QVariant TaskGroupingProxyModel::data(const QModelIndex &proxyIndex, int role) c
return d->any(proxyIndex, AbstractTasksModel::IsDemandingAttention);
} else if (role == AbstractTasksModel::SkipTaskbar) {
return d->all(proxyIndex, AbstractTasksModel::SkipTaskbar);
} else if (role == AbstractTasksModel::LastActivated) {
// Find the last activated task in the single group
const int groupSize = d->rowMap.at(proxyIndex.row())->size();
QTime lastActivated = mapToSource(index(0, 0, proxyIndex)).data(AbstractTasksModel::LastActivated).toTime();
for (int i = 1; i < groupSize; i++) {
const QTime activated = mapToSource(index(i, 0, proxyIndex)).data(AbstractTasksModel::LastActivated).toTime();
if (lastActivated < activated) {
lastActivated = activated;
}
}
return lastActivated;
}
}
......
......@@ -827,6 +827,38 @@ bool TasksModel::Private::lessThan(const QModelIndex &left, const QModelIndex &r
// Sort other cases by sort mode.
switch (sortMode) {
case SortLastActivated: {
QTime leftSortTime, rightSortTime;
// Check if the task is in a group
if (left.parent().isValid()) {
leftSortTime = left.parent().data(AbstractTasksModel::LastActivated).toTime();
} else {
leftSortTime = left.data(AbstractTasksModel::LastActivated).toTime();
}
if (!leftSortTime.isValid()) {
leftSortTime = left.data(Qt::DisplayRole).toTime();
}
if (right.parent().isValid()) {
rightSortTime = right.parent().data(AbstractTasksModel::LastActivated).toTime();
} else {
rightSortTime = right.data(AbstractTasksModel::LastActivated).toTime();
}
if (!rightSortTime.isValid()) {
rightSortTime = right.data(Qt::DisplayRole).toTime();
}
if (leftSortTime != rightSortTime) {
// Move latest to leftmost
return leftSortTime > rightSortTime;
}
Q_FALLTHROUGH();
}
case SortVirtualDesktop: {
const bool leftAll = left.data(AbstractTasksModel::IsOnAllVirtualDesktops).toBool();
const bool rightAll = right.data(AbstractTasksModel::IsOnAllVirtualDesktops).toBool();
......@@ -1201,6 +1233,10 @@ void TasksModel::setSortMode(SortMode mode)
setSortRole(Qt::DisplayRole);
}
if (mode == SortLastActivated) {
setSortRole(AbstractTasksModel::LastActivated);
}
d->sortMode = mode;
d->forceResort();
......
......@@ -81,6 +81,7 @@ public:
SortAlpha, /**< Tasks are sorted alphabetically, by AbstractTasksModel::AppName and Qt::DisplayRole. */
SortVirtualDesktop, /**< Tasks are sorted by the virtual desktop they are on. */
SortActivity, /**< Tasks are sorted by the number of tasks on the activities they're on. */
SortLastActivated, /**< Tasks are sorted by the last time they were active. */
};
Q_ENUM(SortMode)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment