diff --git a/panels/dock/taskmanager/dockitemmodel.cpp b/panels/dock/taskmanager/dockitemmodel.cpp index 0a63d3160..b31682fa9 100644 --- a/panels/dock/taskmanager/dockitemmodel.cpp +++ b/panels/dock/taskmanager/dockitemmodel.cpp @@ -52,6 +52,15 @@ void DockItemModel::setSourceModel(QAbstractItemModel *model) QAbstractProxyModel::setSourceModel(model); endResetModel(); + connect(sourceModel(), &QAbstractItemModel::modelAboutToBeReset, this, [this]() { + m_isUpdating = true; + beginResetModel(); + }); + connect(sourceModel(), &QAbstractItemModel::modelReset, this, [this]() { + endResetModel(); + m_isUpdating = false; + }); + connect(sourceModel(), &QAbstractItemModel::rowsInserted, this, [this](const QModelIndex &parent, int first, int last) { if (parent.isValid() || m_isUpdating) return; diff --git a/panels/dock/taskmanager/rolegroupmodel.cpp b/panels/dock/taskmanager/rolegroupmodel.cpp index 6ae68d032..40d3a6e52 100644 --- a/panels/dock/taskmanager/rolegroupmodel.cpp +++ b/panels/dock/taskmanager/rolegroupmodel.cpp @@ -5,6 +5,7 @@ #include "rolegroupmodel.h" #include +#include RoleGroupModel::RoleGroupModel(QAbstractItemModel *sourceModel, int role, QObject *parent) : QAbstractProxyModel(parent) @@ -94,10 +95,22 @@ void RoleGroupModel::setSourceModel(QAbstractItemModel *model) }); connect(sourceModel(), &QAbstractItemModel::dataChanged, this, [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList &roles) { - // TODO: if roles contains m_roleForDeduplication, need update from topLeft 2 bottomRight or just send dataChanged - if (roles.contains(m_roleForDeduplication)) { - rebuildTreeSource(); - return; + // An advertised grouping role need not have changed. Keep delegates + // intact for ordinary application updates, including all-role updates. + if (roles.isEmpty() || roles.contains(m_roleForDeduplication)) { + for (int i = topLeft.row(); i <= bottomRight.row(); ++i) { + const auto group = sourceModel()->index(i, 0).data(m_roleForDeduplication).toString(); + const auto rows = m_map.value(group, nullptr); + // Empty ids are not grouped, but a row that just lost its id + // must be removed from its previous group. + const bool changed = group.isEmpty() + ? std::any_of(m_rowMap.cbegin(), m_rowMap.cend(), [i](const QList *rows) { return rows->contains(i); }) + : !rows || !rows->contains(i); + if (changed) { + rebuildTreeSource(); + return; + } + } } for (int i = topLeft.row(); i <= bottomRight.row(); ++i) {