Skip to content

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Nov 5, 2025

Fixed a bug where the wrong index variable was being used when adding new dock elements to the model. Changed from using 'first' variable to using the loop counter 'i' to ensure proper indexing and element ordering. This prevents potential issues with element positioning and ensures consistent behavior when managing dock items.

fix: 修复添加dock元素时使用错误索引的问题

主要处理hover后,偶现hover某应用图标,显示了另外一个应用的预览窗口,问题在于taskmanager的model的源头数据出现问题, 导致了hover后显示为其他的图标,目前修改了这个索引后(这个索引是存在问题的),未复现,后续再偶现此问题需要继续分析。

PMS: BUG-339065

Summary by Sourcery

Bug Fixes:

  • Use loop counter instead of incorrect variable when appending new dock elements to the model

Fixed a bug where the wrong index variable was being used when adding
new dock elements to the model. Changed from using 'first' variable
to using the loop counter 'i' to ensure proper indexing and element
ordering. This prevents potential issues with element positioning and
ensures consistent behavior when managing dock items.

fix: 修复添加dock元素时使用错误索引的问题

主要处理hover后,偶现hover某应用图标,显示了另外一个应用的预览窗口,问题在于taskmanager的model的源头数据出现问题,
导致了hover后显示为其他的图标,目前修改了这个索引后(这个索引是存在问题的),未复现,后续再偶现此问题需要继续分析。

PMS: BUG-339065
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 5, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replaced the incorrect ‘first’ index with the loop counter ‘i’ when inserting new dock elements to ensure proper ordering and prevent hover-preview bugs.

Class diagram for updated DockGlobalElementModel data insertion

classDiagram
class DockGlobalElementModel {
  m_data : list of tuple(desktopId, appModel, index)
  DockGlobalElementModel(appsModel, dockModel)
}
DockGlobalElementModel : +beginInsertRows(parent, first, last)
DockGlobalElementModel : +endInsertRows()
DockGlobalElementModel : +m_data.append(tuple)

note for DockGlobalElementModel "Index in tuple changed from 'first' to 'i' for correct ordering"
Loading

File-Level Changes

Change Details Files
Use loop index for correct dock element positioning
  • Changed tuple append to use ‘i’ instead of ‘first’
  • Ensured beginInsertRows/endInsertRows calls wrap the updated append operation
panels/dock/taskmanager/dockglobalelementmodel.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 and they look great!


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_data.append(std::make_tuple(desktopId, m_activeAppModel, first));
+ m_data.append(std::make_tuple(desktopId, m_activeAppModel, i));
  1. 代码审查意见:

a) 逻辑正确性:

  • 这个改动将元组的第三个参数从 first 改为 i。从上下文来看,i 很可能是循环变量,而 first 可能是某个特定值。
  • 如果这是一个循环内部的代码,使用 i 可能更合适,因为它可以表示当前处理的索引位置。但需要确认这是否符合业务逻辑。

b) 代码质量:

  • 使用 std::make_tuple 是好的实践,但建议考虑使用结构化绑定或自定义结构体来提高代码可读性。
  • 元组中的第三个参数从 first 改为 i 后,应该确保变量命名能够清晰表达其含义。

c) 性能考虑:

  • append 操作本身的时间复杂度是 O(1),但如果频繁调用,可能会触发多次内存重分配。
  • 如果知道最终大小,建议先 reserve 容量。

d) 安全性:

  • 需要确保 i 的值是有效的,不会越界访问。
  • 应该检查 m_activeAppModel 是否为空指针。
  1. 改进建议:
// 1. 使用结构体替代元组提高可读性
struct DockElement {
    QString desktopId;
    QAbstractItemModel* appModel;
    int index;
};

// 2. 在循环前预留空间
if (m_data.capacity() < m_data.size() + expectedSize) {
    m_data.reserve(m_data.size() + expectedSize);
}

// 3. 添加空指针检查
if (!m_activeAppModel) {
    qWarning() << "Active app model is null";
    return;
}

// 4. 使用更清晰的变量名
m_data.append(DockElement{
    desktopId,
    m_activeAppModel,
    currentIndex  // 使用更有意义的变量名代替 i
});
  1. 其他建议:
  • 添加适当的注释说明这个数据结构中各个字段的用途
  • 考虑添加断言来确保 i 的值在有效范围内
  • 如果这个数据结构会被频繁访问,考虑使用更高效的数据结构

这些修改将提高代码的可读性、安全性和可维护性。但最终是否采纳这些建议,需要根据具体的项目需求和上下文来决定。

@wjyrich wjyrich requested review from 18202781743 and BLumia November 5, 2025 07:14
@BLumia BLumia requested a review from tsic404 November 5, 2025 07:21
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tsic404, 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 3a72276 into linuxdeepin:master Nov 5, 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.

4 participants