[plasma/plasma-workspace] libtaskmanager: TasksModel: fix activeTaskChanged signals
Nate Graham <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 6cf762033114e647671650514ab33375ef8a4477 by Nate Graham, on behalf of Marco Martin.
Committed on 05/08/2026 at 13:45.
Pushed by mart into branch 'master'.
TasksModel: fix activeTaskChanged signals
We were unconditionally signaling activeTaskChanged in rowsRemoved and dataChanged
of the source windowtaskmodel, but this has a couple of incorrect things:
* the signal can be emitted also for windows we aren't interested in, if
the windows are filtered out (ie show only on current desktop)
* we emit the signals everytime something "might" have changed, causing useless signal emits
* the check if the signal should be emitted should be done when the taskmodel is done propagating
its own rowsInserted, removed, and dataChanged, not the source model.
otherwise could be "too soon" and activeTask() still be invalid
BUG:523409
M +36 -7 libtaskmanager/tasksmodel.cpp
https://invent.kde.org/plasma/plasma-workspace/-/commit/6cf762033114e647671650514ab33375ef8a4477
diff --git a/libtaskmanager/tasksmodel.cpp b/libtaskmanager/tasksmodel.cpp
index 7ea063dfb0..1fb0084115 100644
--- a/libtaskmanager/tasksmodel.cpp
+++ b/libtaskmanager/tasksmodel.cpp
@@ -68,6 +68,8 @@ public:
bool groupInline = false;
int groupingWindowTasksThreshold = -1;
+ // A "stable" way to remember the active tasks without having to instantiate complex QPersistentModelIndex
+ QVariantList activeTaskWinIds;
bool usedByQml = false;
bool componentComplete = false;
@@ -78,6 +80,7 @@ public:
void updateManualSortMap();
void consolidateManualSortMapForGroup(const QModelIndex &groupingProxyIndex);
void updateGroupInline();
+ void updateActiveTask();
QModelIndex preFilterIndex(const QModelIndex &sourceIndex) const;
void updateActivityTaskCounts();
void forceResort();
@@ -160,9 +163,6 @@ void TasksModel::Private::initModels()
updateActivityTaskCounts();
forceResort();
}
- // the active task may have potentially changed, so signal that so that users
- // will recompute it
- Q_EMIT q->activeTaskChanged();
});
QObject::connect(windowTasksModel,
@@ -176,10 +176,6 @@ void TasksModel::Private::initModels()
updateActivityTaskCounts();
}
- if (roles.contains(AbstractTasksModel::IsActive)) {
- Q_EMIT q->activeTaskChanged();
- }
-
// In manual sort mode, updateManualSortMap() may consult the sortRowInsertQueue
// for new tasks to sort in. Hidden tasks remain in the queue to potentially sort
// them later, when they are are actually revealed to the user.
@@ -685,7 +681,40 @@ void TasksModel::Private::updateGroupInline()
QObject::connect(q, &QAbstractItemModel::rowsInserted, q, &TasksModel::countChanged, Qt::UniqueConnection);
QObject::connect(q, &QAbstractItemModel::rowsRemoved, q, &TasksModel::countChanged, Qt::UniqueConnection);
QObject::connect(q, &QAbstractItemModel::modelReset, q, &TasksModel::countChanged, Qt::UniqueConnection);
+
+ QObject::connect(q, &QAbstractItemModel::rowsInserted, q, [this]() {
+ updateActiveTask();
+ });
+ QObject::connect(q, &QAbstractItemModel::rowsRemoved, q, [this]() {
+ updateActiveTask();
+ });
+ QObject::connect(q, &QAbstractItemModel::modelReset, q, [this]() {
+ updateActiveTask();
+ });
+
+ QObject::connect(q, &QAbstractItemModel::dataChanged, q, [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles) {
+ Q_UNUSED(topLeft)
+ Q_UNUSED(bottomRight)
+
+ if (roles.contains(AbstractTasksModel::IsActive)) {
+ updateActiveTask();
+ }
+ });
+
+ activeTaskWinIds = q->activeTask().data(AbstractTasksModel::WinIdList).toList();
+ }
+}
+
+void TasksModel::Private::updateActiveTask()
+{
+ const QVariantList currentActiveTaskWinIds = q->activeTask().data(AbstractTasksModel::WinIdList).toList();
+
+ if (activeTaskWinIds == currentActiveTaskWinIds) {
+ return;
}
+
+ activeTaskWinIds = currentActiveTaskWinIds;
+ Q_EMIT q->activeTaskChanged();
}
QModelIndex TasksModel::Private::preFilterIndex(const QModelIndex &sourceIndex) const