Skip to content

Comments

feat: reorder task manager role enum for compatibility#1412

Merged
BLumia merged 1 commit intolinuxdeepin:masterfrom
mhduiy:enum
Jan 28, 2026
Merged

feat: reorder task manager role enum for compatibility#1412
BLumia merged 1 commit intolinuxdeepin:masterfrom
mhduiy:enum

Conversation

@mhduiy
Copy link
Contributor

@mhduiy mhduiy commented Jan 28, 2026

Moved CategoriesRole enum value to the end of the Roles enumeration list in taskmanager.h. This change ensures maximum backward compatibility when adding new enum values by maintaining existing numerical values for previously defined roles. The reordering follows the principle that new enum values should be added at the end to prevent breaking changes in serialized data or external integrations that might rely on specific integer mappings.

Influence:

  1. Verify task manager functionality still works correctly
  2. Test that any serialization/deserialization of role data remains intact
  3. Confirm that UI components using these roles display properly
  4. Check that any external integrations using the enum values continue to function

feat: 重新排序任务管理器角色枚举以保证兼容性

将 CategoriesRole 枚举值移动到 taskmanager.h 中 Roles 枚举列表的末尾。此 更改通过保持先前定义角色的现有数值,确保在添加新枚举值时具有最大的向后兼
容性。重新排序遵循新枚举值应添加在末尾的原则,以防止序列化数据或可能依赖
特定整数映射的外部集成出现破坏性更改。

Influence:

  1. 验证任务管理器功能是否仍正常工作
  2. 测试角色数据的任何序列化/反序列化是否保持完整
  3. 确认使用这些角色的UI组件显示正常
  4. 检查使用枚举值的任何外部集成是否继续正常运行

Summary by Sourcery

Enhancements:

  • Move the CategoriesRole value to the end of the Roles enum to improve backward compatibility with serialized role data and external integrations.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 28, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Reorders the TaskManager::Roles enum so that CategoriesRole is moved to the end of the list to preserve existing integer values for prior enum entries and maintain backward compatibility with serialized data and external integrations.

Updated class diagram for TaskManager Roles enum ordering

classDiagram
    class TaskManager {
        <<QObject>>
    }

    class Roles {
        <<enumeration>>
        NoDisplayRole
        ActionsRole
        DDECategoryRole
        InstalledTimeRole
        LastLaunchedTimeRole
        LaunchedTimesRole
        OnDesktopRole
        AutoStartRole
        AppTypeRole
        CategoriesRole
    }

    TaskManager ..> Roles : uses
Loading

File-Level Changes

Change Details Files
Reordered a role within the TaskManager::Roles enum to preserve numeric enum stability.
  • Moved CategoriesRole from its previous position between DDECategoryRole and InstalledTimeRole to the end of the Roles enumeration, after AppTypeRole.
  • Left the rest of the enum values and the Q_ENUM(Roles) declaration unchanged to avoid altering other role mappings.
panels/dock/taskmanager/taskmanager.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

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 - I've left some high level feedback:

  • If backward compatibility of integer mappings is critical, consider assigning explicit values to the Roles enum members so that future insertions cannot accidentally change existing numeric mappings again.
  • Given that CategoriesRole is being renumbered, double-check whether any persisted or external data already uses the previous CategoriesRole integer and, if so, consider a migration or compatibility path rather than silently changing its value.
  • You may want to add a brief comment above the Roles enum indicating that new values must be appended at the end to preserve numeric compatibility, so future changes follow the same convention.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- If backward compatibility of integer mappings is critical, consider assigning explicit values to the Roles enum members so that future insertions cannot accidentally change existing numeric mappings again.
- Given that CategoriesRole is being renumbered, double-check whether any persisted or external data already uses the previous CategoriesRole integer and, if so, consider a migration or compatibility path rather than silently changing its value.
- You may want to add a brief comment above the Roles enum indicating that new values must be appended at the end to preserve numeric compatibility, so future changes follow the same convention.

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.

Moved CategoriesRole enum value to the end of the Roles enumeration list
in taskmanager.h. This change ensures maximum backward compatibility
when adding new enum values by maintaining existing numerical values
for previously defined roles. The reordering follows the principle that
new enum values should be added at the end to prevent breaking changes
in serialized data or external integrations that might rely on specific
integer mappings.

Influence:
1. Verify task manager functionality still works correctly
2. Test that any serialization/deserialization of role data remains
intact
3. Confirm that UI components using these roles display properly
4. Check that any external integrations using the enum values continue
to function

feat: 重新排序任务管理器角色枚举以保证兼容性

将 CategoriesRole 枚举值移动到 taskmanager.h 中 Roles 枚举列表的末尾。此
更改通过保持先前定义角色的现有数值,确保在添加新枚举值时具有最大的向后兼
容性。重新排序遵循新枚举值应添加在末尾的原则,以防止序列化数据或可能依赖
特定整数映射的外部集成出现破坏性更改。

Influence:
1. 验证任务管理器功能是否仍正常工作
2. 测试角色数据的任何序列化/反序列化是否保持完整
3. 确认使用这些角色的UI组件显示正常
4. 检查使用枚举值的任何外部集成是否继续正常运行
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见

针对提供的 git diff 内容,主要涉及 TaskManager 类中 Roles 枚举的修改。以下是关于语法逻辑、代码质量、代码性能和代码安全方面的详细审查意见:

1. 语法逻辑

  • 修改操作:代码将 CategoriesRole 从枚举的中间位置(第 54 行)移动到了末尾(第 63 行),并新增了 XLingLongRoleIdRoleXCreatedByRoleExecsRole 四个枚举值。
  • 逻辑正确性:在 C++ 中,未显式指定值的枚举值会自动在前一个值的基础上加 1。虽然移动 CategoriesRole 改变了其整数值,但在 Qt 的模型/视图架构(如 QAbstractItemModel::data)中,通常使用枚举名称而非整数值来索引角色,因此只要所有调用方都使用 TaskManager::CategoriesRole 这种方式访问,逻辑上通常是安全的。
  • 潜在风险:如果有代码直接使用了硬编码的整数值(例如 model->data(index, 5))来获取该角色,或者将此整数值序列化(保存到文件/数据库)并在新版本中读取,移动枚举值将导致逻辑错误或数据错乱。

2. 代码质量

  • 可读性与维护性
    • CategoriesRole 移动到末尾,打破了原有分组。原代码中 CategoriesRole 紧跟在 DDECategoryRole 之后,逻辑上属于同一类属性(应用分类)。建议将新增的 XLingLongRole 等插入到合适的位置,或者将 CategoriesRole 移回原位,以保持相关属性的聚合,提高代码可读性。
  • 命名规范
    • 新增的 XLingLongRoleXCreatedByRole 采用了 X 前缀。在 Qt 和 DDE 开发惯例中,X 前缀通常用于表示扩展或非标准属性。如果这是为了适配特定的包管理格式(如玲珑 LingLong),命名是可以接受的,但需确保团队内部文档对此有明确说明。

3. 代码性能

  • 影响分析:枚举值的顺序调整属于编译期常量的变更,对程序的运行时性能(CPU、内存)没有影响
  • 二进制兼容性:如果 TaskManager 是一个被外部插件依赖的共享库,改变枚举的数值会破坏 ABI(二进制接口)。这意味着所有依赖该头文件的插件都需要重新编译,否则可能会出现未定义行为。

4. 代码安全

  • 安全性:此修改本身不直接引入内存安全漏洞(如缓冲区溢出)或注入漏洞。
  • 数据完整性:如前所述,如果系统中有持久化存储依赖这些枚举的整数值,修改顺序可能导致旧版本数据无法被新版本正确读取,造成数据损坏或显示异常。

改进建议

  1. 保持枚举顺序或明确分组
    建议将 CategoriesRole 放回 DDECategoryRole 附近,或者将所有新增的 Role 按照功能逻辑插入到列表中,而不是简单地追加到末尾。例如:

    enum Roles {
        // ... 原有角色 ...
        DDECategoryRole,
        CategoriesRole, // 移回此处,保持分类属性在一起
        // ... 时间相关 ...
        InstalledTimeRole,
        // ...
        // 新增属性
        XLingLongRole,
        IdRole,
        XCreatedByRole,
        ExecsRole
    };
  2. 检查硬编码依赖
    请在代码库中全局搜索(Grep)是否有地方直接使用了数字索引来访问这些 Role,例如 data(index, 3)。如果有,请将其替换为枚举名称 data(index, TaskManager::CategoriesRole)

  3. 序列化兼容性检查
    如果这些 Role 的值会被保存到配置文件中,请确保升级逻辑能兼容旧数据,或者确保这些枚举值不作为持久化数据的唯一标识。

  4. 代码注释
    对于新增的 XLingLongRoleXCreatedByRole,建议添加注释说明其具体用途和数据来源,例如:

    /**
     * @brief XLingLongRole 标识应用是否为玲珑包格式
     */
    XLingLongRole,

总结:代码修改在语法上是合法的,但在维护性和潜在的兼容性方面存在风险。建议优化枚举顺序以保持逻辑清晰,并排查是否存在对枚举整数值的硬编码依赖。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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 d535ec2 into linuxdeepin:master Jan 28, 2026
8 of 11 checks passed
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