Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Nov 11, 2025

修复关闭 WinSCP 窗口时,dock 上仍会有一个残留的 WinSCP 图标的问题. (相关帖子

注:仍然注意到这个问题可能导致其他窗口 hover preview 数量变多,出现重复窗口.此问题待继续排查.

Summary by Sourcery

Improve DockGlobalElementModel signal-slot connections by switching to queued connections and adding missing removal handling on the active apps model to prevent stale dock icons when windows close.

Bug Fixes:

  • Fix leftover WinSCP dock icon after closing its window.

Enhancements:

  • Use Qt::QueuedConnection for rowsRemoved, rowsInserted, and dataChanged handlers on both appsModel and activeAppModel to ensure proper update ordering.
  • Add explicit rowsRemoved handler for activeAppModel to remove dock entries when windows are closed.

修复关闭 WinSCP 窗口时,dock 上仍会有一个残留的 WinSCP 图标的问题.

注:仍然注意到这个问题可能导致其他窗口 hover preview 数量变多,出现重
复窗口.此问题待继续排查.

Log:
@BLumia BLumia requested a review from wjyrich November 11, 2025 12:55
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 11, 2025

Reviewer's Guide

This PR refactors DockGlobalElementModel to use queued connections for all model-change signals and streamlines the rowsRemoved/rowsInserted logic to correctly prune stale entries (e.g. WinSCP icons) and adjust indices, while enhancing dataChanged handling to include ItemIdRole when desktop or identity roles update.

Sequence diagram for dock icon removal on window close

sequenceDiagram
    participant "QAbstractItemModel (m_activeAppModel)"
    participant "DockGlobalElementModel"
    participant "Dock UI"
    "QAbstractItemModel (m_activeAppModel)"->>"DockGlobalElementModel": rowsRemoved (QueuedConnection)
    activate "DockGlobalElementModel"
    "DockGlobalElementModel"->>"DockGlobalElementModel": Prune stale entries from m_data
    "DockGlobalElementModel"->>"Dock UI": beginRemoveRows / endRemoveRows
    deactivate "DockGlobalElementModel"
Loading

Class diagram for DockGlobalElementModel signal handling changes

classDiagram
    class DockGlobalElementModel {
        - m_appsModel: QAbstractItemModel*
        - m_activeAppModel: QAbstractItemModel*
        - m_data: QVector<Tuple>
        + DockGlobalElementModel(QAbstractItemModel*, DockActiveAppModel*)
        + loadDockedElements()
        <<signal handling>>
        + connect rowsRemoved (QueuedConnection)
        + connect rowsInserted (QueuedConnection)
        + connect dataChanged (QueuedConnection)
    }
    class QAbstractItemModel {
        <<Qt Model>>
        + rowsRemoved
        + rowsInserted
        + dataChanged
    }
    class DockActiveAppModel {
        <<inherits QAbstractItemModel>>
    }
    DockGlobalElementModel o-- QAbstractItemModel : uses
    DockGlobalElementModel o-- DockActiveAppModel : uses
Loading

File-Level Changes

Change Details Files
Adopt Qt::QueuedConnection for all model-change signal handlers
  • Added Qt::QueuedConnection parameter to connect calls for rowsRemoved on m_appsModel
  • Added Qt::QueuedConnection to rowsInserted and rowsRemoved connects on m_activeAppModel
  • Moved dataChanged connect to queued connection
panels/dock/taskmanager/dockglobalelementmodel.cpp
Streamline and merge rowsRemoved/rowsInserted lambdas
  • Unified find_if and removal/update logic in rowsRemoved for m_appsModel and m_activeAppModel
  • Merged insertion logic to update existing entries or append new rows based on desktopId
  • Removed duplicated loops and redundant branches, consolidating index adjustments
panels/dock/taskmanager/dockglobalelementmodel.cpp
Enhance dataChanged slot to handle identity and desktop role changes
  • In dataChanged lambda, detect DesktopIdRole or IdentityRole changes and append TaskManager::ItemIdRole
  • Emit dataChanged with augmented roles list
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

@deepin-ci-robot
Copy link

deepin pr auto review

我来分析一下这个diff的改进建议:

  1. 代码格式化改进:
  • 主要变化是将connect语句的参数分行显示,提高了可读性
  • 添加了Qt::QueuedConnection参数,这是一个重要的改进
  1. 性能优化:
  • 使用Qt::QueuedConnection可以避免信号槽的递归调用,减少潜在的死锁风险
  • 将信号处理延迟到事件循环中,可以提高UI响应性
  1. 代码逻辑改进:
  • 保持了原有的功能逻辑不变
  • 改进了代码结构,使其更易于维护
  1. 潜在问题建议:
  • 在std::find_if中使用引用捕获[&i]可能存在风险,建议使用值捕获[i]
  • 考虑添加边界检查,特别是在访问数组索引时
  • 可以考虑使用QModelIndexList的constBegin()和constEnd()来避免不必要的拷贝
  1. 安全性改进:
  • Qt::QueuedConnection的使用提高了线程安全性
  • 建议在处理m_data时添加互斥锁保护,以防多线程访问问题
  1. 其他建议:
  • 可以考虑将一些重复的lambda表达式提取为独立的成员函数
  • 添加更多的错误处理和日志记录
  • 考虑使用QVector代替QList,如果频繁进行随机访问的话

总体来说,这次改动主要是代码格式化和线程安全性的改进,是一个好的重构。建议在后续版本中考虑上述其他改进点。

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:

  • Refactor the duplicated lambdas handling rowsInserted/rowsRemoved into helper functions to reduce repetition and improve readability.
  • Replace the std::tuple entries in m_data with a dedicated struct having named fields to make the code more self-documenting.
  • Add a brief note or assertion around using Qt::QueuedConnection to clarify the intended update ordering and guard against subtle race conditions.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Refactor the duplicated lambdas handling rowsInserted/rowsRemoved into helper functions to reduce repetition and improve readability.
- Replace the std::tuple entries in m_data with a dedicated struct having named fields to make the code more self-documenting.
- Add a brief note or assertion around using Qt::QueuedConnection to clarify the intended update ordering and guard against subtle race conditions.

## Individual Comments

### Comment 1
<location> `panels/dock/taskmanager/dockglobalelementmodel.cpp:32` </location>
<code_context>
     , m_activeAppModel(activeAppModel)
 {
     connect(TaskManagerSettings::instance(), &TaskManagerSettings::dockedElementsChanged, this, &DockGlobalElementModel::loadDockedElements);
-    connect(m_appsModel, &QAbstractItemModel::rowsRemoved, this, [this](const QModelIndex &parent, int first, int last) {
-        Q_UNUSED(parent)
-        for (int i = first; i <= last; ++i) {
</code_context>

<issue_to_address>
**issue (complexity):** Consider extracting repeated lambda logic into private helper functions to simplify and reduce duplication in signal handlers.

You have four very similar lambdas here doing almost the same thing (find-and-remove, find-and-update, shift indices, emit dataChanged, etc.). You can collapse a lot of that into small private helpers and reduce each lambda to a single call. For example, extract the “shift everything after row X by ±N” logic into:

```cpp
// in DockGlobalElementModel.h
private:
    void shiftRowIndices(QAbstractItemModel *src, int first, int last, int delta);

// in DockGlobalElementModel.cpp
void DockGlobalElementModel::shiftRowIndices(QAbstractItemModel *src,
                                             int first, int last,
                                             int delta)
{
    for (auto &entry : m_data) {
        if (std::get<1>(entry) == src && std::get<2>(entry) >= first) {
            std::get<2>(entry) += delta;
        }
    }
}
```

Then your `rowsRemoved` for `m_appsModel` becomes:

```cpp
connect(m_appsModel, &QAbstractItemModel::rowsRemoved, this,
        [this](const QModelIndex&, int first, int last) {
            // remove any exact-match rows
            for (int i = first; i <= last; ++i) {
                auto it = std::find_if(m_data.begin(), m_data.end(),
                    [this, i](auto &d){ return std::get<1>(d) == m_appsModel
                                            && std::get<2>(d) == i; });
                if (it != m_data.end()) {
                    int pos = it - m_data.begin();
                    beginRemoveRows(QModelIndex(), pos, pos);
                    m_data.remove(pos);
                    endRemoveRows();
                }
            }
            // shift everything after “first” down by (last-first+1)
            shiftRowIndices(m_appsModel, first, last, -((last-first)+1));
        },
        Qt::QueuedConnection);
```

You can apply the same pattern to

- insert (use `shiftRowIndices(..., +((last-first)+1))`),  
- active-model removal (extract its special remove/replace logic into e.g. `handleActiveRowsRemoved(...)`),  
- dataChanged (just find & emit).  

This cuts out ~20–30 lines of duplicated lambdas and makes each `connect()` a one-liner to a helper.
</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.

@BLumia BLumia requested a review from tsic404 November 11, 2025 13:10
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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 a455f40 into linuxdeepin:master Nov 12, 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