fix(dock): fix wrong docked app icons after login - #1696
Conversation
1. Track rowsInserted of the apps model in DockGlobalElementModel to keep the cached sourceRow of docked items in sync while the apps model is rebuilt at startup; only rowsRemoved was handled before, so inserted rows made docked items resolve to the wrong app and show the wrong icon/name 2. Handle apps-model modelReset by re-resolving every cached sourceRow by desktopId 3. Guard DockGlobalElementModel::data() against an out-of-range cached sourceRow and re-resolve it on demand 4. Include IconNameRole/NameRole in dataChanged when a dock row switches its source between the apps model and the active-app model, so QML delegates refresh the icon/name 5. Drop invalid dataChanged (row -1) in DockItemModel before forwarding to QML Log: fix docked app icon/name showing another app's data after login Influence: 1. Verify docked app icons are correct right after login/restart 2. Verify icons stay correct while apps are installed/uninstalled/launched 3. Verify dock item name/tooltip matches the hovered app 4. Verify window split and group modes still work fix(dock): 修复登录后驻留应用图标显示错误 1. 在 DockGlobalElementModel 中跟踪应用模型的行插入(rowsInserted),使 驻留项缓存的 sourceRow 在启动期应用模型重建时保持同步;此前仅处理行删除, 插入的行会使驻留项解析到错误的应用,显示错误的图标/名称 2. 应用模型整体重建(modelReset)时按 desktopId 重新解析所有缓存的 sourceRow 3. DockGlobalElementModel::data() 对越界的缓存 sourceRow 增加保护,并按需 重新解析 4. 驻留行在应用模型与运行应用模型之间切换时,dataChanged 补充 IconNameRole/NameRole,确保 QML 委托刷新图标/名称 5. DockItemModel 转发 dataChanged 前过滤无效索引(row 为 -1) Log: 修复登录后驻留应用图标/名称显示为其他应用数据的问题 Influence: 1. 验证重启登录后驻留应用图标正确 2. 验证应用安装/卸载、启动过程中图标仍正确 3. 验证驻留项名称/悬浮提示与所悬停应用一致 4. 验证窗口拆分/分组模式正常 PMS: BUG-372179
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ivy233 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideKeeps docked items’ cached mappings in sync with the apps model, hardens bounds checking when resolving roles, ensures icon/name roles are emitted when sources change, and filters invalid dataChanged signals before forwarding to QML so docked icons/names stay correct after login and during model rebuilds. Sequence diagram for dock model updates keeping docked icons in syncsequenceDiagram
actor User
participant AppsModel
participant ActiveAppModel
participant DockGlobalElementModel
participant DockItemModel
participant QMLDelegate
rect rgb(235,235,255)
AppsModel->>DockGlobalElementModel: rowsInserted(parent, first, last)
DockGlobalElementModel->>DockGlobalElementModel: update m_data cached sourceRow
end
rect rgb(235,255,235)
AppsModel->>DockGlobalElementModel: modelReset
DockGlobalElementModel->>AppsModel: match(DesktopIdRole, id)
AppsModel-->>DockGlobalElementModel: matching index
DockGlobalElementModel->>DockGlobalElementModel: update cached sourceRow
end
rect rgb(255,235,235)
ActiveAppModel->>DockGlobalElementModel: rowsInserted(parent, first, last)
DockGlobalElementModel->>DockGlobalElementModel: switch dock row source
DockGlobalElementModel-->>DockItemModel: dataChanged(pIndex, pIndex, IconNameRole, NameRole,...)
DockItemModel->>DockItemModel: [!m_isUpdating && indices valid]
DockItemModel-->>QMLDelegate: dataChanged(pIndex, pIndex, IconNameRole, NameRole,...)
end
rect rgb(235,245,245)
QMLDelegate->>DockItemModel: data(index, NameRole)
DockItemModel->>DockGlobalElementModel: data(index, NameRole)
DockGlobalElementModel->>DockGlobalElementModel: [model == m_appsModel]
DockGlobalElementModel->>DockGlobalElementModel: [row < 0 || row >= rowCount]
DockGlobalElementModel->>AppsModel: match(DesktopIdRole, id)
AppsModel-->>DockGlobalElementModel: matching index
DockGlobalElementModel-->>DockItemModel: data(NameRole)
DockItemModel-->>QMLDelegate: data(NameRole)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In DockGlobalElementModel::data(), when you re-resolve the apps-model row via match() for out-of-range cached rows, you only update the local
rowvariable; consider writing the resolved row back intom_dataso subsequent accesses don’t repeatedly perform a match and so the cache is actually corrected. - The repeated
row < 0 || row >= model->rowCount()checks andmodel->index(row, 0)calls in DockGlobalElementModel::data() could be refactored into a small helper to centralize bounds checking and index retrieval, reducing duplication and the risk of future inconsistencies.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In DockGlobalElementModel::data(), when you re-resolve the apps-model row via match() for out-of-range cached rows, you only update the local `row` variable; consider writing the resolved row back into `m_data` so subsequent accesses don’t repeatedly perform a match and so the cache is actually corrected.
- The repeated `row < 0 || row >= model->rowCount()` checks and `model->index(row, 0)` calls in DockGlobalElementModel::data() could be refactored into a small helper to centralize bounds checking and index retrieval, reducing duplication and the risk of future inconsistencies.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
deepin pr auto review★ 总体评分:85分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 diff --git a/panels/dock/taskmanager/dockglobalelementmodel.cpp b/panels/dock/taskmanager/dockglobalelementmodel.cpp
index 23de5c700..8f9a12b41 100644
--- a/panels/dock/taskmanager/dockglobalelementmodel.cpp
+++ b/panels/dock/taskmanager/dockglobalelementmodel.cpp
@@ -58,7 +58,7 @@ DockGlobalElementModel::DockGlobalElementModel(QAbstractItemModel *appsModel, Do
+ // Keep the cached apps-model sourceRow in sync when apps are inserted.
+ // Use DirectConnection to prevent race conditions with modelReset signals in the event loop.
+ connect(
+ m_appsModel,
+ &QAbstractItemModel::rowsInserted,
+ this,
+ [this](const QModelIndex &parent, int first, int last) {
+ // Guard against spurious rowsInserted signals immediately following a modelReset
+ if (m_isResetting) return;
+
+ Q_UNUSED(parent)
+ const int insertedCount = (last - first) + 1;
+ std::for_each(m_data.begin(), m_data.end(), [this, first, insertedCount](auto &data) {
+ if (std::get<1>(data) == m_appsModel && std::get<2>(data) >= first) {
+ data = std::make_tuple(std::get<0>(data), std::get<1>(data), std::get<2>(data) + insertedCount);
+ }
+ });
+ },
+ Qt::DirectConnection);
+
+ // Apps model full rebuild (modelReset): re-resolve every cached sourceRow.
+ connect(
+ m_appsModel,
+ &QAbstractItemModel::modelReset,
+ this,
+ [this]() {
+ m_isResetting = true;
+ for (auto &data : m_data) {
+ if (std::get<1>(data) != m_appsModel)
+ continue;
+ const auto id = std::get<0>(data);
+ auto res = m_appsModel->match(m_appsModel->index(0, 0), TaskManager::DesktopIdRole, id, 1, Qt::MatchExactly);
+ std::get<2>(data) = res.isEmpty() ? -1 : res.first().row();
+ }
+ // Reset the flag after all pending rowsInserted signals are processed
+ QMetaObject::invokeMethod(this, [this]() { m_isResetting = false; }, Qt::QueuedConnection);
+ },
+ Qt::DirectConnection); |
Log: fix docked app icon/name showing another app's data after login
Influence:
fix(dock): 修复登录后驻留应用图标显示错误
插入的行会使驻留项解析到错误的应用,显示错误的图标/名称
Log: 修复登录后驻留应用图标/名称显示为其他应用数据的问题
Influence:
PMS: BUG-372179
Summary by Sourcery
Ensure docked app entries resolve to the correct application after login by keeping cached source rows in sync with the apps model and guarding against invalid indices.
Bug Fixes:
Enhancements: