Skip to content

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Feb 9, 2026

  1. Added leftEdgeClicked signal in DockPanel to handle clicks on the left margin area
  2. Implemented MouseArea in QML to capture clicks on the left margin of the dock
  3. The signal emits the minimum dockOrder value among all applet items when clicked
  4. This allows special handling for edge interactions in the dock panel

Log: Added left edge click functionality for dock panel

Influence:

  1. Test clicking on the left margin area of the dock panel
  2. Verify that leftEdgeClicked signal is emitted with correct dockOrder value
  3. Check that the signal works with different numbers of applet items
  4. Test with various dock configurations and orientations
  5. Verify that the click area doesn't interfere with existing applet functionality

feat: 为任务栏面板添加左侧边缘点击信号

  1. 在DockPanel中添加leftEdgeClicked信号以处理左侧边距区域的点击
  2. 在QML中实现MouseArea来捕获任务栏左侧边距的点击
  3. 这使得任务栏面板能够特殊处理边缘交互

Log: 新增任务栏面板左侧边缘点击功能

Influence:

  1. 测试点击任务栏面板的左侧边距区域
  2. 验证leftEdgeClicked信号是否以正确的dockOrder值发射
  3. 检查信号在不同数量的小程序项下的工作情况
  4. 使用不同的任务栏配置和方向进行测试
  5. 验证点击区域不会干扰现有小程序功能

PMS: BUG-345931

Summary by Sourcery

Add support for handling left-edge click interactions on the dock panel and exposing them via a new signal.

New Features:

  • Introduce a leftEdgeClicked signal on DockPanel to notify consumers when the dock's left margin area is clicked.
  • Add a dedicated MouseArea in the dock panel QML to capture clicks on the left margin and emit the associated applet dock order.

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 9, 2026

Reviewer's Guide

Adds a left-edge click interaction to the dock panel by introducing a new DockPanel signal and a QML MouseArea that computes and emits the minimum dockOrder among applet items when the left margin is clicked.

Sequence diagram for left edge click handling in dock panel

sequenceDiagram
    actor User
    participant LeftMarginMouseArea
    participant AppletModel as Applet_appletItems
    participant Panel
    participant DockPanel

    User->>LeftMarginMouseArea: Click on left margin
    LeftMarginMouseArea->>LeftMarginMouseArea: Iterate items to find min dockOrder
    loop For each applet item
        LeftMarginMouseArea->>AppletModel: index(i, 0)
        AppletModel-->>LeftMarginMouseArea: itemData
        LeftMarginMouseArea->>LeftMarginMouseArea: Update minOrder if itemData.dockOrder < minOrder
    end
    LeftMarginMouseArea->>Panel: leftEdgeClicked(minOrder)
    Panel->>DockPanel: leftEdgeClicked(QString itemName)
    DockPanel-->>Panel: Handle edge interaction
Loading

Updated class diagram for DockPanel with leftEdgeClicked slot

classDiagram
    class DockPanel {
        +void dockScreenChanged(QScreen* screen)
        +void screenNameChanged()
        +void requestClosePopup()
        +void leftEdgeClicked(QString itemName)
        +void devicePixelRatioChanged(qreal ratio)
        +void lockedChanged(bool locked)
    }

    class Panel {
        +void leftEdgeClicked(int minDockOrder)
    }

    class LeftMarginMouseArea {
        +int width
        +int height
        +void onClicked()
    }

    class Applet_appletItems {
        +int rowCount()
        +QModelIndex index(int row,int column)
        +QVariant data(QModelIndex modelIndex,int role)
    }

    LeftMarginMouseArea --> Applet_appletItems : reads_dockOrder
    LeftMarginMouseArea --> Panel : emits_leftEdgeClicked
    Panel --> DockPanel : invokes_leftEdgeClicked
Loading

File-Level Changes

Change Details Files
Introduce a left-margin MouseArea in the dock panel QML to detect and handle clicks at the left edge and emit the minimum dockOrder via a new signal.
  • Add a MouseArea over the left margin whose width/height depend on whether a column layout is used, anchored to the left/top of the parent and rendered above other content (z: 1).
  • On click, iterate over Applet.appletItems, reading each item’s data at Qt.UserRole + 1 to determine its dockOrder, and compute the minimum value.
  • Invoke Panel.leftEdgeClicked with the computed minimum dockOrder value, enabling special handling of left-edge interactions without interfering with existing applet areas.
panels/dock/package/main.qml
Extend the DockPanel C++ interface to handle the new left-edge click signal coming from QML.
  • Declare a new private slot leftEdgeClicked(const QString &itemName) on DockPanel to receive and process left-edge click events from QML logic.
panels/dock/dockpanel.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 found 2 issues, and left some high level feedback:

  • The new leftEdgeClicked slot is declared as void leftEdgeClicked(const QString &itemName); in C++, but QML is invoking Panel.leftEdgeClicked(minOrder) with a numeric dockOrder, so the parameter type and semantics should be aligned (e.g., use an integer/variant or pass the actual item name).
  • When there are no applet items, minOrder remains Number.MAX_VALUE and is still emitted; consider explicitly handling the empty case (e.g., not emitting or emitting a sentinel/null value) to avoid confusing downstream logic.
  • The MouseArea width/height are bound to gridLayout.columnSpacing/rowSpacing, which may be 0 or very small in some layouts; it might be clearer and more robust to use an explicit, fixed edge thickness or a value derived from a known margin rather than spacing.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `leftEdgeClicked` slot is declared as `void leftEdgeClicked(const QString &itemName);` in C++, but QML is invoking `Panel.leftEdgeClicked(minOrder)` with a numeric `dockOrder`, so the parameter type and semantics should be aligned (e.g., use an integer/variant or pass the actual item name).
- When there are no applet items, `minOrder` remains `Number.MAX_VALUE` and is still emitted; consider explicitly handling the empty case (e.g., not emitting or emitting a sentinel/null value) to avoid confusing downstream logic.
- The `MouseArea` width/height are bound to `gridLayout.columnSpacing`/`rowSpacing`, which may be 0 or very small in some layouts; it might be clearer and more robust to use an explicit, fixed edge thickness or a value derived from a known margin rather than spacing.

## Individual Comments

### Comment 1
<location> `panels/dock/dockpanel.h:130` </location>
<code_context>
     void dockScreenChanged(QScreen *screen);
     void screenNameChanged();
     void requestClosePopup();
+    void leftEdgeClicked(const QString &itemName);
     void devicePixelRatioChanged(qreal ratio);
     void lockedChanged(bool locked);
</code_context>

<issue_to_address>
**issue (bug_risk):** The `leftEdgeClicked` parameter type/name does not match what QML is passing (`dockOrder` numeric value).

In QML, `Panel.leftEdgeClicked(minOrder)` is invoked with a numeric `dockOrder`, but this slot takes a `QString &itemName`, implying a name rather than an order and relying on implicit conversion. Please change the signature to use the actual numeric type of `dockOrder` (e.g. `void leftEdgeClicked(int dockOrder);`) and rename the parameter to match, to keep the semantics clear and type-safe.
</issue_to_address>

### Comment 2
<location> `panels/dock/package/main.qml:458-467` </location>
<code_context>
+            height: useColumnLayout ? gridLayout.rowSpacing : parent.height                                                                             
+            anchors.left: parent.left
+            anchors.top: parent.top
+            onClicked: {
+                let minOrder = Number.MAX_VALUE
+                
+                for (let i = 0; i < Applet.appletItems.rowCount(); i++) {
+                    let itemData = Applet.appletItems.data(Applet.appletItems.index(i, 0), Qt.UserRole + 1)
+                    if (itemData && itemData.dockOrder < minOrder) {
+                        minOrder = itemData.dockOrder
+                    }
+                }
+                Panel.leftEdgeClicked(minOrder)
+            }                                                                       
+        } 
</code_context>

<issue_to_address>
**issue:** No handling for the case where there are no applet items, so `minOrder` remains `Number.MAX_VALUE`.

If `Applet.appletItems.rowCount()` is zero, `minOrder` stays `Number.MAX_VALUE` and is passed to `Panel.leftEdgeClicked`, which may misbehave. Either return early when `rowCount() === 0`, or pass a sentinel value (e.g. `-1`/`null`) and handle that explicitly in the C++ slot.
</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.

1. Added leftEdgeClicked signal in DockPanel to handle clicks on the
left margin area
2. Implemented MouseArea in QML to capture clicks on the left margin of
the dock
3. The signal emits the minimum dockOrder value among all applet items
when clicked
4. This allows special handling for edge interactions in the dock panel

Log: Added left edge click functionality for dock panel

Influence:
1. Test clicking on the left margin area of the dock panel
2. Verify that leftEdgeClicked signal is emitted with correct dockOrder
value
3. Check that the signal works with different numbers of applet items
4. Test with various dock configurations and orientations
5. Verify that the click area doesn't interfere with existing applet
functionality

feat: 为任务栏面板添加左侧边缘点击信号

1. 在DockPanel中添加leftEdgeClicked信号以处理左侧边距区域的点击
2. 在QML中实现MouseArea来捕获任务栏左侧边距的点击
3. 这使得任务栏面板能够特殊处理边缘交互

Log: 新增任务栏面板左侧边缘点击功能

Influence:
1. 测试点击任务栏面板的左侧边距区域
2. 验证leftEdgeClicked信号是否以正确的dockOrder值发射
3. 检查信号在不同数量的小程序项下的工作情况
4. 使用不同的任务栏配置和方向进行测试
5. 验证点击区域不会干扰现有小程序功能

PMS: BUG-345931
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码主要实现了一个功能:点击 Dock(任务栏)左侧的空白区域(边距区域)时,计算当前 Dock 上所有小部件中最小的 dockOrder 值,并将其传递给 C++ 层的 leftEdgeClicked 槽函数。

以下是对该代码的详细审查意见,包括语法逻辑、代码质量、代码性能和代码安全方面的改进建议:

1. 语法与逻辑审查

  • QML 语法:代码在语法上是正确的,能够被 QML 引擎解析。
  • 逻辑正确性
    • 逻辑意图是找到最小的 dockOrder。通过遍历模型并比较 itemData.dockOrder 来实现是可行的。
    • leftMarginArea 的定位和尺寸计算逻辑(widthheight 基于 useColumnLayout 切换)看起来是为了适配水平 Dock 和垂直 Dock 两种模式,逻辑上合理。
  • 潜在逻辑缺陷
    • 空列表处理:如果 Applet.appletItems 为空(即没有图标),循环不会执行,minOrder 保持为 Number.MAX_VALUE。这会导致 C++ 端接收到一个字符串 "1.7976931348623157e+308"。虽然这不会导致崩溃,但 C++ 端需要处理这种“无图标”的边界情况,否则后续逻辑可能出错(例如尝试将这个极大值作为索引或 ID 使用)。
    • 数据有效性:代码假设 itemData 存在且包含 dockOrder 属性。如果模型中的数据不完整,访问 itemData.dockOrder 可能会报错或返回 undefined。

2. 代码质量审查

  • 注释//此处为边距区域的点击实践特殊处理。 中存在错别字,“实践”应为“事件”。
  • 代码风格
    • leftMarginArea 定义在 GridLayout 之前,且使用了 anchors。这通常意味着它是一个覆盖层。需要注意它是否会遮挡 GridLayout 中的交互元素。根据 widthheight 的设置,它似乎只覆盖了左侧/上侧的间距区域,这看起来是设计意图,但需确保 gridLayout.columnSpacingrowSpacing 足够大,或者该区域确实是用户期望点击的盲区。
    • Magic NumberQt.UserRole + 1 是一个硬编码的角色值。建议在 C++ 侧定义一个枚举常量(如 DockOrderRole),并通过单例导出到 QML,以提高代码可读性和维护性。

3. 代码性能审查

  • O(N) 遍历onClicked 事件处理中包含一个 for 循环,遍历了模型中的所有项。
    • 影响:每次点击左侧边距都会触发一次全量遍历。如果 Dock 上的图标数量非常多(虽然通常不会太多),这会引入微小的延迟。
    • 优化建议
      • 如果 minOrder 是一个相对静态的值(不随点击频繁变化),可以在 C++ 端维护这个值,或者在模型数据变化时计算一次并缓存,而不是在点击时实时计算。
      • 如果必须实时计算,目前的 O(N) 复杂度在 N 较小时是可以接受的。

4. 代码安全审查

  • 类型安全
    • minOrder 初始化为 Number.MAX_VALUE,但在传递给 C++ 时被转换为字符串(const QString &minOrder)。C++ 端接收到的是字符串形式的数字。
    • 建议:确认 C++ 端 leftEdgeClicked 函数内部是否正确处理了字符串到数字的转换。如果 C++ 期望的是整数,最好在 QML 中使用 Math.floorparseInt 处理后再传递,或者修改 C++ 签名为 int / qreal
  • 空指针/数据安全
    • 如前所述,itemData 可能为空。建议增加判空保护:if (itemData && itemData.dockOrder !== undefined && ...)

5. 综合改进代码示例

针对上述问题,建议的优化代码如下:

        // 修正注释错别字
        // 此处为边距区域的点击事件特殊处理
        MouseArea {
            id: leftMarginArea
            // 建议确保此区域不会意外遮挡可交互元素,必要时可设置 z 属性
            width: useColumnLayout ? parent.width : gridLayout.columnSpacing
            height: useColumnLayout ? gridLayout.rowSpacing : parent.height
            anchors.left: parent.left
            anchors.top: parent.top
            
            onClicked: {
                let minOrder = Number.MAX_VALUE
                const count = Applet.appletItems.rowCount()
                
                // 性能优化:如果列表为空,直接处理
                if (count === 0) {
                    console.warn("No applets found when clicking left edge.")
                    // 根据业务逻辑,可能需要传递特定值(如 -1 或 "0")或不调用
                    // Panel.leftEdgeClicked("-1") 
                    return
                }

                for (let i = 0; i < count; i++) {
                    // 建议将 Qt.UserRole + 1 替换为有意义的常量,例如 AppletModel.DockOrderRole
                    let itemData = Applet.appletItems.data(Applet.appletItems.index(i, 0), Qt.UserRole + 1)
                    
                    // 增加数据有效性检查
                    if (itemData && typeof itemData.dockOrder === 'number') {
                        if (itemData.dockOrder < minOrder) {
                            minOrder = itemData.dockOrder
                        }
                    }
                }
                
                // 安全转换:如果 minOrder 未更新(即没有有效数据),进行兜底处理
                if (minOrder === Number.MAX_VALUE) {
                    minOrder = 0 // 或者其他表示无效的默认值
                }

                // 确保传递的是字符串或数字,与 C++ 签名匹配
                Panel.leftEdgeClicked(minOrder.toString())
            }
        }

总结

这段代码实现了基本功能,但在边界情况处理(空列表、无效数据)和类型安全方面存在改进空间。同时,修正注释错别字和优化硬编码常量能提升代码质量。如果 Dock 图标数量巨大,建议考虑在 C++ 端缓存最小值以避免 QML 中的遍历开销。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, 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 b992926 into linuxdeepin:master Feb 9, 2026
9 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