Commit aceff05c authored by Yari Polla's avatar Yari Polla Committed by Devin Lin
Browse files

libtaskmanager: Add a new sort mode and relative handler in TasksModel

parent 540027b6
Pipeline #149373 failed with stage
in 12 minutes and 29 seconds
......@@ -21,6 +21,7 @@ public:
QVariant virtualDesktop;
QRect screenGeometry;
QString activity;
bool switchingFromActiveTask = false;
bool filterByVirtualDesktop = false;
bool filterByScreen = false;
......@@ -109,6 +110,18 @@ void TaskFilterProxyModel::setActivity(const QString &activity)
}
}
bool TaskFilterProxyModel::switchingFromActiveTask() const
{
return d->switchingFromActiveTask;
}
void TaskFilterProxyModel::setSwitchingFromActiveTask(const bool switchingFromActiveTask)
{
d->switchingFromActiveTask = switchingFromActiveTask;
Q_EMIT switchingFromActiveTaskChanged();
}
bool TaskFilterProxyModel::filterByVirtualDesktop() const
{
return d->filterByVirtualDesktop;
......
......@@ -32,6 +32,7 @@ class TASKMANAGER_EXPORT TaskFilterProxyModel : public QSortFilterProxyModel, pu
Q_PROPERTY(QVariant virtualDesktop READ virtualDesktop WRITE setVirtualDesktop NOTIFY virtualDesktopChanged)
Q_PROPERTY(QRect screenGeometry READ screenGeometry WRITE setScreenGeometry NOTIFY screenGeometryChanged)
Q_PROPERTY(QString activity READ activity WRITE setActivity NOTIFY activityChanged)
Q_PROPERTY(bool switchingFromActiveTask READ switchingFromActiveTask WRITE setSwitchingFromActiveTask NOTIFY switchingFromActiveTaskChanged)
Q_PROPERTY(bool filterByVirtualDesktop READ filterByVirtualDesktop WRITE setFilterByVirtualDesktop NOTIFY filterByVirtualDesktopChanged)
Q_PROPERTY(bool filterByScreen READ filterByScreen WRITE setFilterByScreen NOTIFY filterByScreenChanged)
......@@ -108,6 +109,26 @@ public:
**/
void setActivity(const QString &activity);
/**
* Whether the activation of the task was triggered while
* on an active task.
* Needed to activate delayed reordering in SortLastActivated sort mode.
*
* @see setSwitchingFromActiveTask
* @returns @c true if the activation of a task was triggered while on an active task
**/
bool switchingFromActiveTask() const;
/**
* Set whether the activation of the task is triggered while on
* an active task.
*
* @see switchingFromActiveTask
* @param switchingFromActiveTask whether the activation
* of the task is triggered while on an active task.
**/
void setSwitchingFromActiveTask(const bool switchingFromActiveTask);
/**
* Whether tasks should be filtered by virtual desktop. Defaults to
* @c false.
......@@ -302,6 +323,7 @@ Q_SIGNALS:
void virtualDesktopChanged() const;
void screenGeometryChanged() const;
void activityChanged() const;
void switchingFromActiveTaskChanged() const;
void filterByVirtualDesktopChanged() const;
void filterByScreenChanged() const;
void filterByActivityChanged() const;
......
......@@ -284,6 +284,7 @@ void TasksModel::Private::initModels()
QObject::connect(filterProxyModel, &TaskFilterProxyModel::virtualDesktopChanged, q, &TasksModel::virtualDesktopChanged);
QObject::connect(filterProxyModel, &TaskFilterProxyModel::screenGeometryChanged, q, &TasksModel::screenGeometryChanged);
QObject::connect(filterProxyModel, &TaskFilterProxyModel::activityChanged, q, &TasksModel::activityChanged);
QObject::connect(filterProxyModel, &TaskFilterProxyModel::switchingFromActiveTaskChanged, q, &TasksModel::switchingFromActiveTaskChanged);
QObject::connect(filterProxyModel, &TaskFilterProxyModel::filterByVirtualDesktopChanged, q, &TasksModel::filterByVirtualDesktopChanged);
QObject::connect(filterProxyModel, &TaskFilterProxyModel::filterByScreenChanged, q, &TasksModel::filterByScreenChanged);
QObject::connect(filterProxyModel, &TaskFilterProxyModel::filterByActivityChanged, q, &TasksModel::filterByActivityChanged);
......@@ -918,6 +919,25 @@ bool TasksModel::Private::lessThan(const QModelIndex &left, const QModelIndex &r
return (leftScore > rightScore);
}
}
// fall through
case SortLastActivated: {
QTime leftSortTime = left.data(AbstractTasksModel::LastActivated).toTime();
if (!leftSortTime.isValid()) {
leftSortTime = left.data(Qt::DisplayRole).toTime();
}
QTime rightSortTime = right.data(AbstractTasksModel::LastActivated).toTime();
if (!rightSortTime.isValid()) {
rightSortTime = right.data(Qt::DisplayRole).toTime();
}
if (leftSortTime == rightSortTime)
return (left.row() < right.row());
return (leftSortTime < rightSortTime);
}
// Fall through to source order if sorting is disabled or manual, or alphabetical by app name otherwise.
// This marker comment makes gcc/clang happy:
// fall through
......@@ -970,6 +990,8 @@ TasksModel::TasksModel(QObject *parent)
: QSortFilterProxyModel(parent)
, d(new Private(this))
{
reorderTimer = new QTimer();
d->initModels();
// Start sorting.
......@@ -1213,6 +1235,34 @@ void TasksModel::setSortMode(SortMode mode)
d->activityTaskCounts.clear();
setSortRole(Qt::DisplayRole);
}
if (mode == SortLastActivated) {
setDynamicSortFilter(false);
QObject::connect(this, &TasksModel::activeTaskChanged, reorderTimer, [this] {
if (!d->filterProxyModel->switchingFromActiveTask()) {
reorderTimer->stop();
setDynamicSortFilter(true);
setDynamicSortFilter(false);
} else {
reorderTimer->start(5000);
}
});
QObject::connect(reorderTimer, &QTimer::timeout, reorderTimer, [this]() {
reorderTimer->stop();
if (d->filterProxyModel->switchingFromActiveTask()) {
d->filterProxyModel->setSwitchingFromActiveTask(false);
setDynamicSortFilter(true);
setDynamicSortFilter(false);
}
});
QObject::connect(this, &TasksModel::switchingFromActiveTaskChanged, this, [this]() {
if (d->filterProxyModel->switchingFromActiveTask())
reorderTimer->start(5000);
});
}
d->sortMode = mode;
......@@ -1553,6 +1603,11 @@ void TasksModel::requestActivities(const QModelIndex &index, const QStringList &
}
}
void TasksModel::requestLastActivatedReorderDelay(const bool enableReorderDelay)
{
d->filterProxyModel->setSwitchingFromActiveTask(enableReorderDelay);
}
void TasksModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate)
{
if (index.isValid() && index.model() == this) {
......
......@@ -12,6 +12,7 @@
#include "abstracttasksmodeliface.h"
#include "taskmanager_export.h"
#include <QTimer>
namespace TaskManager
{
......@@ -81,6 +82,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)
......@@ -99,6 +101,8 @@ public:
QVariant data(const QModelIndex &proxyIndex, int role) const override;
QTimer *reorderTimer;
/**
* The number of launcher tasks in the tast list.
*
......@@ -770,6 +774,15 @@ public:
**/
Q_INVOKABLE void requestActivities(const QModelIndex &index, const QStringList &activities) override;
/**
* Request whether to enable delay in the reorder phase of tasks model when the sort mode is SortLastActivated.
*
* This base implementation does nothing.
*
* @param enableReorderDelay @c true to enable the delay
**/
Q_INVOKABLE void requestLastActivatedReorderDelay(const bool enableReorderDelay);
/**
* Request informing the window manager of new geometry for a visual
* delegate for the task at the given index. The geometry should be in
......@@ -865,6 +878,7 @@ Q_SIGNALS:
void virtualDesktopChanged() const;
void screenGeometryChanged() const;
void activityChanged() const;
void switchingFromActiveTaskChanged() const;
void filterByVirtualDesktopChanged() const;
void filterByScreenChanged() const;
void filterByActivityChanged() const;
......
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