Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Nov 13, 2025

简化 HoverPreviewProxyModel, 使 model 本身不与设置项耦合, 过滤规则 在 taskmanager.cpp 控制

Summary by Sourcery

Simplify hover preview filtering by moving rule control to TaskManager and streamlining the proxy model's API and logic

Enhancements:

  • Decouple HoverPreviewProxyModel from TaskManagerSettings and replace filterModelIndex with a new setFilter(string, FilterMode) API
  • Introduce FilterMode enum and internal string filter to support filtering by app id or window id
  • Simplify filterAcceptsRow implementation to switch on filter mode and remove grouping logic
  • Update TaskManager to use windowSplit flag and pass appropriate filter parameters to the proxy model

简化 HoverPreviewProxyModel, 使 model 本身不与设置项耦合, 过滤规则
在 taskmanager.cpp 控制

Log:
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 13, 2025

Reviewer's Guide

This PR refactors the hover preview proxy by removing its dependency on TaskManagerSettings and an index-based API, introducing a simple string filter with a FilterMode enum, and shifting filter decision logic into TaskManager::requestPreview.

Sequence diagram for new filter logic in TaskManager::requestPreview

sequenceDiagram
participant TaskManager
participant HoverPreviewProxyModel

TaskManager->>HoverPreviewProxyModel: setFilter(winId, FilterByWinId) (if windowSplit)
TaskManager->>HoverPreviewProxyModel: setFilter(appId, FilterByAppId) (else)
HoverPreviewProxyModel->>HoverPreviewProxyModel: invalidateFilter()
TaskManager->>HoverPreviewProxyModel: rowCount()
Loading

Class diagram for refactored HoverPreviewProxyModel

classDiagram
class HoverPreviewProxyModel {
    +setFilter(QString filter, FilterMode mode)
    +clearFilter()
    +filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
    -FilterMode m_filterMode
    -QString m_filter
}

HoverPreviewProxyModel --|> QSortFilterProxyModel

class FilterMode {
    <<enumeration>>
    FilterByAppId
    FilterByWinId
}

HoverPreviewProxyModel o-- FilterMode
Loading

File-Level Changes

Change Details Files
Simplify HoverPreviewProxyModel API and internals
  • Remove TaskManagerSettings and QModelIndex members
  • Add QString m_filter and FilterMode enum for filtering
  • Replace setFilterModelIndex/clearFilter with setFilter(filter, mode)
  • Revamp filterAcceptsRow to switch on FilterMode and compare strings/IDs
hoverpreviewproxymodel.cpp
hoverpreviewproxymodel.h
Adapt TaskManager to new filter API
  • In requestPreview, use windowSplit() to choose FilterByWinId or FilterByAppId
  • Pass the appropriate ID string and mode to setFilter
taskmanager.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

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码变更进行审查:

  1. 代码逻辑改进:
  • 原代码使用 QModelIndex 来过滤,新代码改为使用字符串和枚举值,这是一个好的改进,因为:
    • 减少了对 QModelIndex 的依赖
    • 使过滤逻辑更清晰和可控
    • 支持更灵活的过滤模式
  1. 性能优化:
  • 移除了对 TaskManagerSettings 的直接依赖,避免了每次过滤时都要检查设置
  • 使用枚举值替代字符串比较,提高性能
  • 简化了过滤逻辑,减少了不必要的条件判断
  1. 代码质量改进:
  • 代码结构更清晰,通过枚举明确区分了过滤模式
  • 移除了冗余的 filterModelIndex() 方法
  • 代码更易维护,过滤逻辑集中在一处
  1. 安全性考虑:
  • 在 FilterByWinId 模式中,建议添加对 m_filter.toUInt() 转换的验证,确保输入是有效的数字
  • 建议在 setFilter 方法中添加对输入参数的验证

建议改进:

  1. 在 FilterByWinId 模式中添加输入验证:
case FilterByWinId: {
    bool ok;
    uint32_t targetWinId = m_filter.toUInt(&ok);
    if (!ok || targetWinId == 0) {
        return false;
    }
    return winId == targetWinId;
}
  1. 在 setFilter 方法中添加参数验证:
void HoverPreviewProxyModel::setFilter(QString filter, enum FilterMode mode)
{
    if (mode == FilterByWinId) {
        bool ok;
        filter.toUInt(&ok);
        if (!ok) {
            qWarning() << "Invalid window ID filter:" << filter;
            return;
        }
    }
    m_filter = filter;
    m_filterMode = mode;
    invalidateFilter();
}
  1. 考虑添加对空字符串的处理:
void HoverPreviewProxyModel::setFilter(QString filter, enum FilterMode mode)
{
    if (filter.isEmpty()) {
        clearFilter();
        return;
    }
    // ... 其余代码
}

总体来说,这是一个很好的重构,提高了代码的可维护性和性能,但需要加强输入验证来提高代码的健壮性。

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 there - I've reviewed your changes - here's some feedback:

  • Initialize m_filter and m_filterMode in the constructor initializer list to avoid any uninitialized state when filterAcceptsRow is first called.
  • Update the doxygen comment above setFilter to reflect the new QString and FilterMode parameters instead of the old QModelIndex API.
  • Consider renaming FilterByAppId to something like FilterByDesktopId for clarity, since it’s actually matching on DesktopIdRole rather than an application identifier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Initialize m_filter and m_filterMode in the constructor initializer list to avoid any uninitialized state when filterAcceptsRow is first called.
- Update the doxygen comment above setFilter to reflect the new QString and FilterMode parameters instead of the old QModelIndex API.
- Consider renaming FilterByAppId to something like FilterByDesktopId for clarity, since it’s actually matching on DesktopIdRole rather than an application identifier.

## Individual Comments

### Comment 1
<location> `panels/dock/taskmanager/hoverpreviewproxymodel.cpp:60-61` </location>
<code_context>
+        return currentDesktopId == m_filter;
+    }
+    case FilterByWinId: {
+        uint32_t targetWinId = m_filter.toUInt();
         bool result = (winId == targetWinId && targetWinId != 0);
-        // 在 WindowSplit 模式下,精确匹配单个窗口
-        return result;
</code_context>

<issue_to_address>
**issue (bug_risk):** Potential silent conversion issue when using QString::toUInt().

If m_filter is not numeric, toUInt() returns 0, which may cause incorrect filtering. Please validate m_filter or handle conversion errors.
</issue_to_address>

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.

Comment on lines +60 to 61
uint32_t targetWinId = m_filter.toUInt();
bool result = (winId == targetWinId && targetWinId != 0);
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Potential silent conversion issue when using QString::toUInt().

If m_filter is not numeric, toUInt() returns 0, which may cause incorrect filtering. Please validate m_filter or handle conversion errors.

@BLumia BLumia requested a review from 18202781743 November 13, 2025 03:57
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, 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

@BLumia BLumia merged commit 1618613 into linuxdeepin:master Nov 13, 2025
10 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