From 635c012b3c6ed31a53d0fd40ddac6300b677bf60 Mon Sep 17 00:00:00 2001 From: Wang Zichong Date: Tue, 4 Nov 2025 20:58:46 +0800 Subject: [PATCH] fix: incorrect window state for JLCPCB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 简单而言,对于程序A,打开a1,打开a2,关闭a1后会观察到任务栏指示此图标无 窗口.原因是 DockGroupModel 的 rowsRemoved 发了 dataChanged,会触发 all(), 然后因为其是继承的 RoleGroupModel,它的rowsRemoved 会被它本 体和 DockGroupModel 都接到,但 DockGroupModel 比 RoleGroupModel先收 到了信号,导致了时序问题,使后续 all() 调用时其中获取的数据已经不再正 确. 此处通过使相关信号排队处理的方式,使 DockGroupModel 的事件响应晚于 RoleGroupModel 的移除事件响应. PMS: BUG-338573 Log: --- panels/dock/taskmanager/dockgroupmodel.cpp | 95 +++++++++++++--------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/panels/dock/taskmanager/dockgroupmodel.cpp b/panels/dock/taskmanager/dockgroupmodel.cpp index 0546c7784..0d4513edf 100644 --- a/panels/dock/taskmanager/dockgroupmodel.cpp +++ b/panels/dock/taskmanager/dockgroupmodel.cpp @@ -18,48 +18,63 @@ DockGroupModel::DockGroupModel(QAbstractItemModel *sourceModel, int role, QObjec , AbstractTaskManagerInterface(this) , m_roleForDeduplication(role) { - connect(this, &QAbstractItemModel::rowsInserted, this, [this](const QModelIndex &parent, int first, int last) { - Q_UNUSED(first) - Q_UNUSED(last) - if (!parent.isValid()) - return; - Q_EMIT dataChanged(index(parent.row(), 0), index(parent.row(), 0), {TaskManager::WindowsRole}); - }); - connect(this, &QAbstractItemModel::rowsRemoved, this, [this](const QModelIndex &parent, int first, int last) { - if (!parent.isValid()) - return; - - // Update m_currentActiveWindow when windows are removed - int parentRow = parent.row(); - if (m_currentActiveWindow.contains(parentRow)) { - int currentActive = m_currentActiveWindow.value(parentRow); - int windowCount = RoleGroupModel::rowCount(parent); - - // Check if the current active window was removed - if (currentActive >= first && currentActive <= last) { - // Current active window was removed, reset to first window - resetActiveWindow(parentRow); - } else if (currentActive > last) { - // Current active window is after the removed range, shift it back - int removedCount = last - first + 1; - m_currentActiveWindow[parentRow] = currentActive - removedCount; + connect( + this, + &QAbstractItemModel::rowsInserted, + this, + [this](const QModelIndex &parent, int first, int last) { + Q_UNUSED(first) + Q_UNUSED(last) + if (!parent.isValid()) + return; + Q_EMIT dataChanged(index(parent.row(), 0), index(parent.row(), 0), {TaskManager::WindowsRole}); + }, + Qt::QueuedConnection); + connect( + this, + &QAbstractItemModel::rowsRemoved, + this, + [this](const QModelIndex &parent, int first, int last) { + if (!parent.isValid()) + return; + + // Update m_currentActiveWindow when windows are removed + int parentRow = parent.row(); + if (m_currentActiveWindow.contains(parentRow)) { + int currentActive = m_currentActiveWindow.value(parentRow); + int windowCount = RoleGroupModel::rowCount(parent); + + // Check if the current active window was removed + if (currentActive >= first && currentActive <= last) { + // Current active window was removed, reset to first window + resetActiveWindow(parentRow); + } else if (currentActive > last) { + // Current active window is after the removed range, shift it back + int removedCount = last - first + 1; + m_currentActiveWindow[parentRow] = currentActive - removedCount; + } + // If currentActive < first, no change needed } - // If currentActive < first, no change needed - } - - Q_EMIT dataChanged(index(parent.row(), 0), index(parent.row(), 0), {TaskManager::WindowsRole}); - }); - - connect(this, &QAbstractItemModel::dataChanged, this, [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList &roles) { - Q_UNUSED(bottomRight) - if (!topLeft.parent().isValid()) - return; - auto parentRow = topLeft.parent().row(); - Q_EMIT dataChanged(index(parentRow, 0), index(parentRow, 0), roles); - if (roles.contains(TaskManager::ActiveRole)) - m_currentActiveWindow.insert(parentRow, topLeft.row()); - }); + Q_EMIT dataChanged(index(parent.row(), 0), index(parent.row(), 0), {TaskManager::WindowsRole}); + }, + Qt::QueuedConnection); + + connect( + this, + &QAbstractItemModel::dataChanged, + this, + [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList &roles) { + Q_UNUSED(bottomRight) + if (!topLeft.parent().isValid()) + return; + auto parentRow = topLeft.parent().row(); + Q_EMIT dataChanged(index(parentRow, 0), index(parentRow, 0), roles); + + if (roles.contains(TaskManager::ActiveRole)) + m_currentActiveWindow.insert(parentRow, topLeft.row()); + }, + Qt::QueuedConnection); } QVariant DockGroupModel::data(const QModelIndex &index, int role) const