[plasma/plasma-workspace] libtaskmanager: TasksModel: simplify by introducing updateCounts
Nate Graham <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 936a5bc70ab791e4886b543bf36a5d17b5ae58e7 by Nate Graham, on behalf of Marco Martin.
Committed on 05/08/2026 at 13:45.
Pushed by mart into branch 'master'.
TasksModel: simplify by introducing updateCounts
factor the things we do on insert/remove/reset into an updateCounts()
slot, which we need to make it a private of the global class because
we need to mke it am UniqueConnection
M +19 -26 libtaskmanager/tasksmodel.cpp
M +1 -0 libtaskmanager/tasksmodel.h
https://invent.kde.org/plasma/plasma-workspace/-/commit/936a5bc70ab791e4886b543bf36a5d17b5ae58e7
diff --git a/libtaskmanager/tasksmodel.cpp b/libtaskmanager/tasksmodel.cpp
index 1fb0084115..3ffae78a47 100644
--- a/libtaskmanager/tasksmodel.cpp
+++ b/libtaskmanager/tasksmodel.cpp
@@ -674,32 +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::updateLauncherCount, Qt::UniqueConnection);
- QObject::connect(q, &QAbstractItemModel::rowsRemoved, q, &TasksModel::updateLauncherCount, Qt::UniqueConnection);
- QObject::connect(q, &QAbstractItemModel::modelReset, q, &TasksModel::updateLauncherCount, Qt::UniqueConnection);
-
- 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();
- }
- });
+ 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);
activeTaskWinIds = q->activeTask().data(AbstractTasksModel::WinIdList).toList();
}
@@ -1035,6 +1012,15 @@ TasksModel::TasksModel(QObject *parent)
QTimer::singleShot(0, this, [this]() {
d->updateGroupInline();
});
+
+ QObject::connect(this, &QAbstractItemModel::dataChanged, this, [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles) {
+ Q_UNUSED(topLeft)
+ Q_UNUSED(bottomRight)
+
+ if (roles.contains(AbstractTasksModel::IsActive)) {
+ d->updateActiveTask();
+ }
+ });
}
TasksModel::~TasksModel() = default;
@@ -1105,6 +1091,13 @@ void TasksModel::updateLauncherCount()
}
}
+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 6d97fd774c..0ae3d5b023 100644
--- a/libtaskmanager/tasksmodel.h
+++ b/libtaskmanager/tasksmodel.h
@@ -1053,6 +1053,7 @@ protected:
private:
Q_INVOKABLE void updateLauncherCount();
+ void updateCounts();
class Private;
class TasksModelLessThan;