Skip to content

fix: handle source model reset in dock item proxy - #1798

Open
wjyrich wants to merge 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-dock-model-reset
Open

wjyrich wants to merge 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-dock-model-reset

Conversation

@wjyrich

@wjyrich wjyrich commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor
  1. Connect to source model's modelAboutToBeReset and modelReset signals in DockItemModel to properly begin and end model resets, setting m_isUpdating flag to prevent redundant row operations during reset
  2. Replace unconditional rebuildTreeSource on grouping role changes in RoleGroupModel with selective validation that checks whether grouping actually changed
  3. Handle cases where grouping role is in the changed roles list but the actual grouping value remains the same, avoiding unnecessary full tree rebuilds
  4. Add handling for rows that lose their grouping id (empty group), ensuring they are removed from their previous group
  5. Include algorithm header for std::any_of

These changes fix model consistency issues during source model resets and reduce unnecessary rebuilds when dataChanged signals fire for grouping-related roles without actual grouping changes.

Influence:

  1. Test dock task manager behavior when source model resets (e.g., application list changes)
  2. Verify dock items update correctly when application metadata changes
  3. Test grouping behavior when app grouping ids change
  4. Verify rows that lose grouping ids are properly removed from groups
  5. Test performance with frequent dataChanged signals on grouping roles
  6. Verify no visual glitches or crashes during model resets
  7. Test with applications that have empty grouping ids

fix: 处理停靠项代理中的源模型重置

  1. 在 DockItemModel 中连接源模型的 modelAboutToBeReset 和 modelReset 信 号,正确开始和结束模型重置,设置 m_isUpdating 标志以避免重置期间冗余的行
    操作
  2. 将 RoleGroupModel 中分组角色变化时的无条件 rebuildTreeSource 替换为选 择性验证,检查分组是否实际发生变化
  3. 处理分组角色在变化角色列表中但实际分组值未变的情况,避免不必要的完整 树重建
  4. 添加对失去分组 id(空分组)的行的处理,确保从之前的分组中移除
  5. 包含 algorithm 头文件以使用 std::any_of

这些变更修复了源模型重置期间的模型一致性问题,并减少了当分组相关角色触发
dataChanged 信号但实际分组未变时的不必要重建。

Influence:

  1. 测试源模型重置时停靠任务管理器的行为(例如应用程序列表变化)
  2. 验证应用程序元数据变化时停靠项正确更新
  3. 测试应用程序分组 id 变化时的分组行为
  4. 验证失去分组 id 的行正确从分组中移除
  5. 测试分组角色频繁触发 dataChanged 信号时的性能
  6. 验证模型重置期间无视觉故障或崩溃
  7. 测试分组 id 为空的应用程序

PMS: TASK-398199

Summary by Sourcery

Synchronize dock item resets with the source model and make grouping updates rebuild the tree only when grouping membership actually changes.

Bug Fixes:

  • Keep the dock item proxy consistent while the source model is being reset.
  • Remove rows from their previous groups when their grouping identifier becomes empty.
  • Avoid unnecessary tree rebuilds when grouping-related data changes do not alter actual grouping.

Enhancements:

  • Preserve existing grouped items during ordinary metadata updates by selectively validating grouping changes.

1. Connect to source model's modelAboutToBeReset and modelReset signals
in DockItemModel to properly begin and end model resets, setting
m_isUpdating flag to prevent redundant row operations during reset
2. Replace unconditional rebuildTreeSource on grouping role changes in
RoleGroupModel with selective validation that checks whether grouping
actually changed
3. Handle cases where grouping role is in the changed roles list but
the actual grouping value remains the same, avoiding unnecessary full
tree rebuilds
4. Add handling for rows that lose their grouping id (empty group),
ensuring they are removed from their previous group
5. Include algorithm header for std::any_of

These changes fix model consistency issues during source model resets
and reduce unnecessary rebuilds when dataChanged signals fire for
grouping-related roles without actual grouping changes.

Influence:
1. Test dock task manager behavior when source model resets (e.g.,
application list changes)
2. Verify dock items update correctly when application metadata changes
3. Test grouping behavior when app grouping ids change
4. Verify rows that lose grouping ids are properly removed from groups
5. Test performance with frequent dataChanged signals on grouping roles
6. Verify no visual glitches or crashes during model resets
7. Test with applications that have empty grouping ids

fix: 处理停靠项代理中的源模型重置

1. 在 DockItemModel 中连接源模型的 modelAboutToBeReset 和 modelReset 信
号,正确开始和结束模型重置,设置 m_isUpdating 标志以避免重置期间冗余的行
操作
2. 将 RoleGroupModel 中分组角色变化时的无条件 rebuildTreeSource 替换为选
择性验证,检查分组是否实际发生变化
3. 处理分组角色在变化角色列表中但实际分组值未变的情况,避免不必要的完整
树重建
4. 添加对失去分组 id(空分组)的行的处理,确保从之前的分组中移除
5. 包含 algorithm 头文件以使用 std::any_of

这些变更修复了源模型重置期间的模型一致性问题,并减少了当分组相关角色触发
dataChanged 信号但实际分组未变时的不必要重建。

Influence:
1. 测试源模型重置时停靠任务管理器的行为(例如应用程序列表变化)
2. 验证应用程序元数据变化时停靠项正确更新
3. 测试应用程序分组 id 变化时的分组行为
4. 验证失去分组 id 的行正确从分组中移除
5. 测试分组角色频繁触发 dataChanged 信号时的性能
6. 验证模型重置期间无视觉故障或崩溃
7. 测试分组 id 为空的应用程序

PMS: TASK-398199
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wjyrich

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Nov 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

The proxy models now remain consistent across source-model resets while avoiding unnecessary grouped-tree rebuilds when dataChanged notifications do not alter row membership, including correct removal of rows that lose their grouping identifier.

Sequence diagram for source model reset propagation

sequenceDiagram
    participant SourceModel
    participant DockItemModel

    SourceModel->>DockItemModel: modelAboutToBeReset
    DockItemModel->>DockItemModel: beginResetModel
    DockItemModel->>DockItemModel: m_isUpdating = true
    SourceModel->>DockItemModel: modelReset
    DockItemModel->>DockItemModel: endResetModel
    DockItemModel->>DockItemModel: m_isUpdating = false
Loading

Flow diagram for selective grouping validation

flowchart TD
    A[dataChanged] --> B{"roles.isEmpty() or roles.contains(m_roleForDeduplication)?"}
    B -- No --> C[Propagate ordinary row updates]
    B -- Yes --> D[Read grouping value for each affected row]
    D --> E{Grouping membership changed?}
    E -- No --> C
    E -- Yes --> F[rebuildTreeSource]
    D --> G{Grouping id is empty?}
    G -- Yes --> H{Row exists in a previous group?}
    H -- Yes --> F
    H -- No --> C
Loading

File-Level Changes

Change Details Files
Synchronize DockItemModel with source-model resets and suppress incremental row handling during the reset transaction.
  • Begin and end proxy reset notifications around source model reset signals.
  • Toggle the update guard so row insert/remove operations are ignored while resetting.
panels/dock/taskmanager/dockitemmodel.cpp
Make grouping updates conditional on actual group membership changes instead of rebuilding the tree for every grouping-role notification.
  • Check affected rows against their current group before rebuilding.
  • Avoid rebuilds when grouping data is unchanged, including all-role updates.
  • Remove rows from prior groups when their grouping identifier becomes empty.
  • Add the algorithm dependency for membership checks.
panels/dock/taskmanager/rolegroupmodel.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="panels/dock/taskmanager/rolegroupmodel.cpp" line_range="107" />
<code_context>
+                // 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<int> *rows) { return rows->contains(i); })
+                    : !rows || !rows->contains(i);
+                if (changed) {
</code_context>
<issue_to_address>
**Broad updates stall the dock**

When frequent `dataChanged` signals cover many rows with empty grouping IDs in a large model, `std::any_of` scans every group and its row list for each such row, making broad updates do work proportional to empty rows times grouped rows and stalling the caller.

Use a direct row-to-group membership lookup instead of scanning every group for each ungrouped row.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

// 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<int> *rows) { return rows->contains(i); })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Broad updates stall the dock

When frequent dataChanged signals cover many rows with empty grouping IDs in a large model, std::any_of scans every group and its row list for each such row, making broad updates do work proportional to empty rows times grouped rows and stalling the caller.

Use a direct row-to-group membership lookup instead of scanning every group for each ungrouped row.

Prompt for AI agents
In `panels/dock/taskmanager/rolegroupmodel.cpp` at line 107:

**Broad updates stall the dock**

When frequent `dataChanged` signals cover many rows with empty grouping IDs in a large model, `std::any_of` scans every group and its row list for each such row, making broad updates do work proportional to empty rows times grouped rows and stalling the caller.

Use a direct row-to-group membership lookup instead of scanning every group for each ungrouped row.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 98 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了 dock item proxy 中源模型重置的处理逻辑,在 dockitemmodel.cpp 中正确添加了 modelAboutToBeReset/modelReset 信号连接以防止重置期间的虚假行信号处理,在 rolegroupmodel.cpp 中优化了 dataChanged 处理逻辑以避免不必要的树重建。代码逻辑正确、注释清晰、性能有所提升、无安全漏洞。仅存在一处变量遮蔽的可读性建议。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['将 std::any_of lambda 中的参数名 rows 重命名为 groupRows,避免与外层变量遮蔽']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// rolegroupmodel.cpp - 建议将 lambda 参数 rows 重命名为 groupRows 以避免变量遮蔽
const bool changed = group.isEmpty()
    ? std::any_of(m_rowMap.cbegin(), m_rowMap.cend(), [i](const QList<int> *groupRows) { return groupRows->contains(i); })
    : !rows || !rows->contains(i);

本报告由 AI 代码审查工具自动生成

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants