Skip to content

chore: add itemData implementation for RoleGroupModel - #1693

Merged
BLumia merged 1 commit into
linuxdeepin:masterfrom
BLumia:itemData
Aug 7, 2026
Merged

chore: add itemData implementation for RoleGroupModel#1693
BLumia merged 1 commit into
linuxdeepin:masterfrom
BLumia:itemData

Conversation

@BLumia

@BLumia BLumia commented Aug 7, 2026

Copy link
Copy Markdown
Member

为 RoleGroupModel 补充 itemData() 实现. 这可以使调试 RoleGroupModel 时看到的信息稍佳清晰.

Log:

Summary by Sourcery

Enhancements:

  • Add an itemData() override in RoleGroupModel to return all valid role values for a given index, including both standard and custom roles.

为 RoleGroupModel 补充 itemData() 实现. 这可以使调试 RoleGroupModel
时看到的信息稍佳清晰.

Log:

@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.

Sorry @BLumia, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implements RoleGroupModel::itemData to expose both standard and custom role values for a given index, improving debuggability and tooling support, and wires it into the model interface by declaring the override in the header.

Sequence diagram for RoleGroupModel itemData implementation

sequenceDiagram
    participant Caller
    participant RoleGroupModel

    Caller->>RoleGroupModel: itemData(index)
    activate RoleGroupModel
    loop standard_roles
        RoleGroupModel->>RoleGroupModel: data(index, role)
        RoleGroupModel-->>RoleGroupModel: QVariant
    end
    RoleGroupModel->>RoleGroupModel: roleNames()
    RoleGroupModel-->>RoleGroupModel: QHash<int, QByteArray>
    loop custom_roles
        RoleGroupModel->>RoleGroupModel: data(index, roleKey)
        RoleGroupModel-->>RoleGroupModel: QVariant
    end
    RoleGroupModel-->>Caller: QMap<int, QVariant>
    deactivate RoleGroupModel
Loading

File-Level Changes

Change Details Files
Implement itemData to return a map of all valid standard and custom role values for a given index.
  • Add RoleGroupModel::itemData override definition in the source file that iterates over standard roles below Qt::UserRole and collects valid data values.
  • Extend itemData implementation to also iterate over roleNames() for custom roles, querying data() with each role key and inserting valid values into the returned map.
  • Return the aggregated QMap<int, QVariant> so that callers can inspect all role values for a model index.
panels/dock/taskmanager/rolegroupmodel.cpp
Declare the itemData override in RoleGroupModel's public interface.
  • Add itemData(const QModelIndex &index) const override declaration to RoleGroupModel in the header so it is part of the model's API.
panels/dock/taskmanager/rolegroupmodel.h

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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码正确覆写了QAbstractProxyModel的itemData方法以修复数据获取缺失问题,实现严谨且无安全风险
逻辑正确、质量良好、性能无问题且无安全漏洞,符合满分标准

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

函数通过遍历0到Qt::UserRole的标准角色和roleNames返回的自定义角色,统一调用data方法获取数据并过滤无效值,逻辑清晰且符合Qt标准实现模式
潜在问题:未显式检查传入的index.isValid(),过度依赖底层data函数的容错处理
建议:在函数入口处增加if (!index.isValid()) return {};的防御性检查,提高代码健壮性

  • 2.代码质量(良好)✓

使用了const auto和cbegin/cend等现代C++特性,变量命名清晰,结构紧凑,完全符合Qt及C++编码规范
潜在问题:无明显问题
建议:可在头文件或实现文件中补充简要的Doxygen注释说明覆写此函数的缘由

  • 3.代码性能(无性能问题)✓

遍历的角色数量通常在可控范围内,且仅涉及内存数据读取与QMap插入,时间复杂度与空间复杂度均在合理预期内
潜在问题:roleNames()的调用可能产生QHash的拷贝开销,但在该场景下可忽略不计
建议:无需优化,若未来角色数量激增可考虑缓存roleNames结果

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码仅涉及模型层数据的内存读取与映射,无任何外部输入交互、文件操作或命令执行,无安全风险

  • 建议:保持当前的纯内存操作模式,无需额外安全加固

■ 【改进建议代码示例】

QMap<int, QVariant> RoleGroupModel::itemData(const QModelIndex &index) const
{
    QMap<int, QVariant> roles;
    if (!index.isValid()) {
        return roles;
    }

    for (int i = 0; i < Qt::UserRole; ++i) {
        const QVariant value = data(index, i);
        if (value.isValid())
            roles.insert(i, value);
    }

    const auto names = roleNames();
    for (auto it = names.cbegin(); it != names.cend(); ++it) {
        const QVariant value = data(index, it.key());
        if (value.isValid())
            roles.insert(it.key(), value);
    }

    return roles;
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, Ivy233

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

@BLumia
BLumia merged commit 8da156c into linuxdeepin:master Aug 7, 2026
12 of 13 checks passed
@BLumia
BLumia deleted the itemData branch August 7, 2026 09:29
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.

3 participants