Skip to content

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Nov 13, 2025

Fixed the visual index assignment for collapsed tray items. Previously when collapsed, collapsable items were incorrectly assigned visual index of currentVisualIndex-1, which could cause display issues. Now correctly set visual index to -1 for hidden items when tray is collapsed, ensuring proper visual representation and preventing potential rendering problems.

fix: 修复折叠托盘项的可视索引

修复了折叠托盘项的可视索引分配问题。之前当托盘折叠时,可折叠项被错误地分
配了 currentVisualIndex-1 的可视索引,这可能导致显示问题。现在当托盘折叠
时,正确地将隐藏项的可视索引设置为 -1,确保正确的视觉表示并防止潜在的渲
染问题。

PMS: BUG-325429 BUG-339837

Summary by Sourcery

Bug Fixes:

  • Correct the visual index assignment for collapsed tray items to use -1 for hidden items instead of currentVisualIndex-1, preventing rendering issues when the tray is collapsed.

Fixed the visual index assignment for collapsed tray items. Previously
when collapsed, collapsable items were incorrectly assigned visual index
of currentVisualIndex-1, which could cause display issues. Now correctly
set visual index to -1 for hidden items when tray is collapsed,
ensuring proper visual representation and preventing potential rendering
problems.

fix: 修复折叠托盘项的可视索引

修复了折叠托盘项的可视索引分配问题。之前当托盘折叠时,可折叠项被错误地分
配了 currentVisualIndex-1 的可视索引,这可能导致显示问题。现在当托盘折叠
时,正确地将隐藏项的可视索引设置为 -1,确保正确的视觉表示并防止潜在的渲
染问题。

PMS: BUG-325429 BUG-339837
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 13, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR corrects the visual index assignment for tray items when the tray is collapsed by replacing the erroneous currentVisualIndex-1 value with -1, ensuring hidden items are properly represented and avoiding rendering glitches.

Class diagram for updated TraySortOrderModel visual index logic

classDiagram
class TraySortOrderModel {
  +updateVisualIndexes()
  VisualIndexRole
  m_collapsed : bool
  results : QList<Item>
}
class Item {
  +setData(value, role)
}
TraySortOrderModel --> Item
Loading

Flow diagram for visual index assignment when tray is collapsed

flowchart TD
    A["updateVisualIndexes() called"] --> B["Is tray collapsed? (m_collapsed)"]
    B -- Yes --> C["Set visual index of collapsable items to -1 (hidden)"]
    B -- No --> D["Set visual index of collapsable items to currentVisualIndex++"]
Loading

File-Level Changes

Change Details Files
Correct collapsed-state visual index logic
  • Replaced currentVisualIndex-1 with -1 for hidden items
  • Added comment explaining collapsed behavior
panels/dock/tray/traysortordermodel.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 there - I've reviewed your changes - here's some feedback:

  • Replace the magic number -1 with a named constant (e.g. HIDDEN_VISUAL_INDEX) to clarify its purpose as the hidden-item sentinel.
  • Verify that all rendering logic treats negative visual indices as hidden to ensure no unintended display issues occur downstream.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Replace the magic number -1 with a named constant (e.g. HIDDEN_VISUAL_INDEX) to clarify its purpose as the hidden-item sentinel.
- Verify that all rendering logic treats negative visual indices as hidden to ensure no unintended display issues occur downstream.

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

deepin pr auto review

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

  1. 代码逻辑分析:
    这段代码是处理托盘图标排序和折叠状态的逻辑。当托盘处于折叠状态(m_collapsed为true)时,可折叠的图标项会被隐藏。

  2. 修改评价:
    原代码在折叠状态下设置visualIndex为currentVisualIndex-1,这个实现有以下问题:

  • 可能导致visualIndex为负数
  • 逻辑不够清晰,不能明确表达"隐藏"的意图
  • 可能影响后续的排序和显示逻辑
  1. 改进建议:
    修改后的代码使用-1作为隐藏状态的标识,这是一个很好的改进,因为:
  • 使用-1作为隐藏标识更加明确和直观
  • 避免了潜在的索引计算错误
  • 提高了代码的可读性和维护性
  • 符合常见的编程惯例,使用特殊值(-1)表示无效或隐藏状态
  1. 其他建议:
  • 可以考虑添加一个常量来定义这个隐藏状态的值,比如:

    static const int HIDDEN_VISUAL_INDEX = -1;

    这样可以让代码更容易维护,如果将来需要修改这个值,只需要修改一处。

  • 建议在设置visualIndex之前,可以添加一些断言或日志,以确保数据的一致性:

    Q_ASSERT(results[0] != nullptr);
    qDebug() << "Setting visual index to" << (m_collapsed ? -1 : currentVisualIndex);

总体来说,这是一个很好的改进,使代码更加健壮和易于理解。修改后的逻辑更加清晰,也更符合代码的预期行为。

@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

@wjyrich wjyrich merged commit 391f735 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