From 17d3e13e0f327d02448bdc07b2680a0af13848c9 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 28 Jun 2016 13:31:50 +0200 Subject: [PATCH] make activeTask a property it can now be binded, besides being used in imperative code as it was REVIEWED-BY:Eike Hein --- libtaskmanager/tasksmodel.cpp | 4 ++++ libtaskmanager/tasksmodel.h | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/libtaskmanager/tasksmodel.cpp b/libtaskmanager/tasksmodel.cpp index 90bddd90d..333438b2f 100644 --- a/libtaskmanager/tasksmodel.cpp +++ b/libtaskmanager/tasksmodel.cpp @@ -197,6 +197,10 @@ void TasksModel::Private::initModels() if (sortMode == SortActivity && roles.contains(AbstractTasksModel::Activities)) { updateActivityTaskCounts(); } + + if (roles.contains(AbstractTasksModel::IsActive)) { + emit q->activeTaskChanged(); + } } ); diff --git a/libtaskmanager/tasksmodel.h b/libtaskmanager/tasksmodel.h index 5462e4f16..954e21000 100644 --- a/libtaskmanager/tasksmodel.h +++ b/libtaskmanager/tasksmodel.h @@ -88,6 +88,7 @@ class TASKMANAGER_EXPORT TasksModel : public QSortFilterProxyModel, public Abstr WRITE setGroupingAppIdBlacklist NOTIFY groupingAppIdBlacklistChanged) Q_PROPERTY(QStringList groupingLauncherUrlBlacklist READ groupingLauncherUrlBlacklist WRITE setGroupingLauncherUrlBlacklist NOTIFY groupingLauncherUrlBlacklistChanged) + Q_PROPERTY(QModelIndex activeTask READ activeTask NOTIFY activeTaskChanged) public: enum SortMode { @@ -509,6 +510,15 @@ public: **/ void setGroupingLauncherUrlBlacklist(const QStringList &list); + /** + * Finds the first active (AbstractTasksModel::IsActive) task in the model + * and returns its QModelIndex, or a null QModelIndex if no active task is + * found. + * + * @returns the model index for the first active task, if any. + */ + QModelIndex activeTask() const; + /** * Request adding a launcher with the given URL. * @@ -737,15 +747,6 @@ public: */ Q_INVOKABLE void syncLaunchers(); - /** - * Finds the first active (AbstractTasksModel::IsActive) task in the model - * and returns its QModelIndex, or a null QModelIndex if no active task is - * found. - * - * @returns the model index for the first active task, if any. - */ - Q_INVOKABLE QModelIndex activeTask() const; - /** * Given a row in the model, returns a QModelIndex for it. To get an index * for a child in a task group, an optional child row may be passed as well. @@ -779,6 +780,7 @@ Q_SIGNALS: void groupingWindowTasksThresholdChanged() const; void groupingAppIdBlacklistChanged() const; void groupingLauncherUrlBlacklistChanged() const; + void activeTaskChanged() const; protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;