Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented May 19, 2025

修正未来 dataModel 切换到 DockItemModel 后,无应用图标的应用不会将窗口图标作为 fallback 图标的问题.

(当前还未切换,不构成影响)

Summary by Sourcery

Add missing WinIconRole to DockCombineModel role mappings to ensure window icons can be used as fallback for applications without an icon.

Bug Fixes:

  • Include WinIconRole in the constructor’s role mapping to surface the window icon role.
  • Add WinIconRole entry to the roleNames() method to complete the model’s role definitions.

这个问题可以修正未来 dataModel 切换到 DockItemModel 后,无应用图标的
应用不会将窗口图标作为 fallback 图标的问题.

Log:
@BLumia BLumia requested review from 18202781743 and tsic404 May 19, 2025 07:53
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. 代码格式和风格

    • 在新增的代码行中,{TaskManager::WinIconRole, RoleCombineModel::roleNames().key(MODEL_WINICON)}{TaskManager::WinIconRole, MODEL_WINICON} 之间缺少空格,建议保持代码风格的一致性。
  2. 代码重复

    • 新增的代码行 RoleCombineModel::roleNames().key(MODEL_WINICON)MODEL_WINICON 的重复使用,如果 MODEL_WINICON 是一个常量,建议直接使用常量,避免重复调用方法。
  3. 代码可读性

    • 如果 MODEL_WINICON 是一个常量,建议在 DockCombineModel 类的构造函数和 roleNames 方法中统一使用常量,以提高代码的可读性和维护性。
  4. 代码逻辑

    • 检查 RoleCombineModel::roleNames().key(MODEL_WINICON) 是否在所有情况下都返回有效的键,如果 MODEL_WINICON 的值在 RoleCombineModelroleNames 方法中没有对应的键,可能会导致运行时错误。
  5. 性能考虑

    • 如果 RoleCombineModel::roleNames() 方法在每次调用时都会重新计算或查询,建议将其结果缓存起来,避免重复计算。
  6. 安全性

    • 没有发现明显的安全问题,但是建议在添加新角色时,确保这些角色的值是安全的,不会引起潜在的注入攻击。

综合以上意见,建议对代码进行如下修改:

// 在DockCombineModel类中
static const int WinIconRole = RoleCombineModel::roleNames().key(MODEL_WINICON);

DockCombineModel::DockCombineModel(QAbstractItemModel *major, QAbstractItemModel *minor)
    : QAbstractItemModel(major, minor)
{
    m_roles = {
        {TaskManager::ActionsRole, RoleCombineModel::roleNames().key(MODEL_ACTIONS)},
        {TaskManager::NameRole, RoleCombineModel::roleNames().key(MODEL_NAME)},
        {TaskManager::WinIdRole, RoleCombineModel::roleNames().key(MODEL_WINID)},
        {TaskManager::WinIconRole, WinIconRole},
        {TaskManager::WinTitleRole, RoleCombineModel::roleNames().key(MODEL_TITLE)}
    };
}

// 在RoleCombineModel类中
QHash<int, QByteArray> RoleCombineModel::roleNames() const
{
    static const QHash<int, QByteArray> roles = {
        {TaskManager::ActionsRole, MODEL_ACTIONS},
        {TaskManager::NameRole, MODEL_NAME},
        {TaskManager::WinIdRole, MODEL_WINID},
        {TaskManager::WinIconRole, MODEL_WINICON},
        {TaskManager::WinTitleRole, MODEL_TITLE}
    };
    return roles;
}

这样修改后,代码更加简洁、可读,并且避免了重复调用 RoleCombineModel::roleNames().key() 方法。

@sourcery-ai
Copy link

sourcery-ai bot commented May 19, 2025

Reviewer's Guide

Include the missing WinIconRole in DockCombineModel’s role mappings so that window icons can be used as fallback when application icons are unavailable.

Sequence Diagram: Enabled Fallback Icon Retrieval via DockCombineModel

sequenceDiagram
    participant IconResolver as "Icon Resolution Logic"
    participant DBM as DockCombineModel

    IconResolver->>DBM: Request Application Icon (e.g., using AppIconRole)
    DBM-->>IconResolver: Application Icon Data (or indicates unavailability)

    alt Application Icon Unavailable
        IconResolver->>DBM: Request Window Icon (using TaskManager::WinIconRole)
        Note over DBM: Now correctly maps and handles TaskManager::WinIconRole due to PR changes.
        DBM-->>IconResolver: Window Icon Data (fallback, if available from underlying source)
    end
Loading

File-Level Changes

Change Details Files
Added WinIconRole to the combined model’s role map in the constructor
  • Inserted a mapping for TaskManager::WinIconRole to MODEL_WINICON in the initializer list
panels/dock/taskmanager/dockcombinemodel.cpp
Registered WinIconRole in the roleNames() QHash
  • Added TaskManager::WinIconRole to the returned QHash with MODEL_WINICON
panels/dock/taskmanager/dockcombinemodel.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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @BLumia - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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 225dc72 into linuxdeepin:master May 21, 2025
7 of 10 checks passed
@BLumia BLumia deleted the fix-future-bug branch May 21, 2025 02:54
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