Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Aug 4, 2025

避免使用固定的任务栏图标宽度来计算当前拖拽的目标项的索引.

这个修改旨在下面两点:

  1. 为后续任务栏图标不固定长度做准备(图标+标题)
  2. 为后续ItemModel解耦做准备,便于重构分支合入(重构分支使用DelegateModel 的 items 属性维护的顺序表示任务栏上的图标顺序,因而无法直接使用此处 原本的下标计算方式)

(下一步是规避使用 ItemModel::moveTo() 接口)

Summary by Sourcery

Remove reliance on fixed cell widths for taskbar item reordering by using ListView.indexAt and DelegateModel indices

Enhancements:

  • Introduce findTargetIndexByPosition using ListView.indexAt and expose indexAt in OverflowContainer
  • Update drag and drop handlers to use the new target index method for dataModel.moveTo
  • Switch visualModel.items.move calls to use DelegateModel.itemsIndex instead of fixed visualIndex

避免使用固定的任务栏图标宽度来计算当前拖拽的目标项的索引.

这个修改旨在下面两点:

1. 为后续任务栏图标不固定长度做准备(图标+标题)
2. 为后续ItemModel解耦做准备,便于重构分支合入(重构分支使用DelegateModel
   的 items 属性维护的顺序表示任务栏上的图标顺序,因而无法直接使用此处
   原本的下标计算方式)

(下一步是规避使用 ItemModel::moveTo() 接口)

Log:
@sourcery-ai
Copy link

sourcery-ai bot commented Aug 4, 2025

Reviewer's Guide

This PR replaces hardcoded cell-width index calculations in TaskManager with a ListView.indexAt-based helper, refactors drag & drop handlers to use the new method and moveTo calls, updates visualModel.items.move to rely on DelegateModel indices, and exposes indexAt in OverflowContainer to prepare for variable icon widths and model decoupling.

Sequence diagram for drag-and-drop index calculation and moveTo update

sequenceDiagram
    participant User as actor User
    participant TaskManager
    participant OverflowContainer
    participant Applet
    participant DataModel
    User->>TaskManager: Drag or drop event (onPositionChanged/onDropped)
    TaskManager->>OverflowContainer: findTargetIndexByPosition(Qt.point(x, y))
    OverflowContainer->>OverflowContainer: indexAt(x, y)
    OverflowContainer-->>TaskManager: targetIndex
    TaskManager->>Applet: desktopIdToAppId(launcherDndDesktopId)
    Applet-->>TaskManager: appId
    TaskManager->>DataModel: moveTo(appId, targetIndex)
Loading

Class diagram for TaskManager and OverflowContainer drag-and-drop refactor

classDiagram
    class TaskManager {
        +findTargetIndexByPosition(dragPosition)
    }
    class OverflowContainer {
        +indexAt(x, y)
    }
    class Applet {
        +dataModel
        +desktopIdToAppId(launcherDndDesktopId)
    }
    class DataModel {
        +moveTo(appId, targetIndex)
    }
    TaskManager --> OverflowContainer : uses indexAt
    TaskManager --> Applet : uses desktopIdToAppId, dataModel
    Applet --> DataModel : has dataModel
    TaskManager ..> DataModel : calls moveTo
Loading

Class diagram for visualModel.items.move refactor to DelegateModel indices

classDiagram
    class visualModel {
        +items
    }
    class DelegateModel {
        +itemsIndex
    }
    visualModel ..> DelegateModel : uses itemsIndex for move
Loading

File-Level Changes

Change Details Files
Encapsulate target index calculation using ListView.indexAt
  • Add findTargetIndexByPosition function
  • Use ListView.indexAt for position mapping
  • Handle empty model and fallback to end index
panels/dock/taskmanager/package/TaskManager.qml
Refactor drag handlers to use helper for target index and update moveTo call
  • Replace manual curX/cellWidth division with findTargetIndexByPosition
  • Use targetIndex in dataModel.moveTo within onPositionChanged and onDropped
  • Remove hardcoded cellWidth logic
panels/dock/taskmanager/package/TaskManager.qml
Switch visualModel.items.move to use DelegateModel.itemsIndex
  • Update onEntered handler to reference DelegateModel.itemsIndex
  • Add TODO comment for future delegateRoot refactor
panels/dock/taskmanager/package/TaskManager.qml
Expose ListView indexAt in OverflowContainer
  • Add indexAt function forwarding to internal listView
  • Enable external index calculation from TaskManager
panels/dock/OverflowContainer.qml

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

  • In findTargetIndexByPosition, ensure you handle both horizontal and vertical modes correctly (e.g., swapping x/y for column layouts) so indexAt returns the expected index.
  • Consider clamping the returned targetIndex within [0, model.count] as a safeguard against invalid indices from indexAt.
  • The onEntered handler still references a TODO and unused code—cleanup or resolve this section to avoid dead code.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In findTargetIndexByPosition, ensure you handle both horizontal and vertical modes correctly (e.g., swapping x/y for column layouts) so indexAt returns the expected index.
- Consider clamping the returned targetIndex within [0, model.count] as a safeguard against invalid indices from indexAt.
- The onEntered handler still references a TODO and unused code—cleanup or resolve this section to avoid dead code.

## Individual Comments

### Comment 1
<location> `panels/dock/taskmanager/package/TaskManager.qml:123` </location>
<code_context>

                 onEntered: function(drag) {
-                    visualModel.items.move((drag.source as AppItem).visualIndex, app.visualIndex)
+                    // TODO: this is actually unused, should change the delegateRoot type from DropArea to Item later.
+                    visualModel.items.move(drag.source.DelegateModel.itemsIndex, delegateRoot.DelegateModel.itemsIndex)
                 }
</code_context>

<issue_to_address>
Remove or address TODO comments in production code.

Consider removing the unused code or opening a tracking issue instead of leaving a TODO.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
                    // TODO: this is actually unused, should change the delegateRoot type from DropArea to Item later.
                    visualModel.items.move(drag.source.DelegateModel.itemsIndex, delegateRoot.DelegateModel.itemsIndex)
=======
                    visualModel.items.move(drag.source.DelegateModel.itemsIndex, delegateRoot.DelegateModel.itemsIndex)
>>>>>>> REPLACE

</suggested_fix>

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 +123 to +124
// TODO: this is actually unused, should change the delegateRoot type from DropArea to Item later.
visualModel.items.move(drag.source.DelegateModel.itemsIndex, delegateRoot.DelegateModel.itemsIndex)
Copy link

Choose a reason for hiding this comment

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

suggestion: Remove or address TODO comments in production code.

Consider removing the unused code or opening a tracking issue instead of leaving a TODO.

Suggested change
// TODO: this is actually unused, should change the delegateRoot type from DropArea to Item later.
visualModel.items.move(drag.source.DelegateModel.itemsIndex, delegateRoot.DelegateModel.itemsIndex)
visualModel.items.move(drag.source.DelegateModel.itemsIndex, delegateRoot.DelegateModel.itemsIndex)

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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 3f4b017 into linuxdeepin:master Aug 4, 2025
5 checks passed
@BLumia BLumia deleted the no-calc-cell-index branch August 4, 2025 06:07
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