[plasma/plasma-workspace] libtaskmanager: Avoid the updateCounts function

Nate Graham <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 6304aec289f061e537e35c962730a89e9b30b105 by Nate Graham, on behalf of Marco Martin.
Committed on 05/08/2026 at 13:45.
Pushed by mart into branch 'master'.

Avoid the updateCounts function

emit countChanged in launcherCountChanged, as if it changes the launcher
count, changes also the total count

connect countChanged to updateActiveTask, as new tasks that appear might
be immediately active

M  +7    -10   libtaskmanager/tasksmodel.cpp
M  +0    -1    libtaskmanager/tasksmodel.h

https://invent.kde.org/plasma/plasma-workspace/-/commit/6304aec289f061e537e35c962730a89e9b30b105

diff --git a/libtaskmanager/tasksmodel.cpp b/libtaskmanager/tasksmodel.cpp
index 3ffae78a47..8ec42c2b15 100644
--- a/libtaskmanager/tasksmodel.cpp
+++ b/libtaskmanager/tasksmodel.cpp
@@ -674,9 +674,9 @@ void TasksModel::Private::updateGroupInline()
     // Minor optimization: We only make these connections after we populate for
     // the first time to avoid some churn.
     if (!hadSourceModel) {
-        QObject::connect(q, &QAbstractItemModel::rowsInserted, q, &TasksModel::updateCounts, Qt::UniqueConnection);
-        QObject::connect(q, &QAbstractItemModel::rowsRemoved, q, &TasksModel::updateCounts, Qt::UniqueConnection);
-        QObject::connect(q, &QAbstractItemModel::modelReset, q, &TasksModel::updateCounts, Qt::UniqueConnection);
+        QObject::connect(q, &QAbstractItemModel::rowsInserted, q, &TasksModel::updateLauncherCount, Qt::UniqueConnection);
+        QObject::connect(q, &QAbstractItemModel::rowsRemoved, q, &TasksModel::updateLauncherCount, Qt::UniqueConnection);
+        QObject::connect(q, &QAbstractItemModel::modelReset, q, &TasksModel::updateLauncherCount, Qt::UniqueConnection);
 
         activeTaskWinIds = q->activeTask().data(AbstractTasksModel::WinIdList).toList();
     }
@@ -1021,6 +1021,9 @@ TasksModel::TasksModel(QObject *parent)
             d->updateActiveTask();
         }
     });
+    connect(this, &TasksModel::countChanged, this, [this]() {
+        d->updateActiveTask();
+    });
 }
 
 TasksModel::~TasksModel() = default;
@@ -1088,16 +1091,10 @@ void TasksModel::updateLauncherCount()
     if (d->launcherCount != count) {
         d->launcherCount = count;
         Q_EMIT launcherCountChanged();
+        Q_EMIT countChanged();
     }
 }
 
-void TasksModel::updateCounts()
-{
-    updateLauncherCount();
-    Q_EMIT countChanged();
-    d->updateActiveTask();
-}
-
 int TasksModel::launcherCount() const
 {
     return d->launcherCount;
diff --git a/libtaskmanager/tasksmodel.h b/libtaskmanager/tasksmodel.h
index 0ae3d5b023..6d97fd774c 100644
--- a/libtaskmanager/tasksmodel.h
+++ b/libtaskmanager/tasksmodel.h
@@ -1053,7 +1053,6 @@ protected:
 
 private:
     Q_INVOKABLE void updateLauncherCount();
-    void updateCounts();
 
     class Private;
     class TasksModelLessThan;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.