Skip to content

refactor: replace manual object management with DccRepeater#437

Merged
caixr23 merged 1 commit intolinuxdeepin:masterfrom
caixr23:master
Dec 9, 2025
Merged

refactor: replace manual object management with DccRepeater#437
caixr23 merged 1 commit intolinuxdeepin:masterfrom
caixr23:master

Conversation

@caixr23
Copy link
Contributor

@caixr23 caixr23 commented Nov 19, 2025

  1. Replaced Component-based manual object creation/destruction with DccRepeater for dynamic content
  2. Simplified PageDetails.qml by removing updateDetailsItems function and connections
  3. Restructured networkMain.qml to use DelegateChooser with role-based delegation
  4. Removed complex manual device tracking arrays (wiredDevs, wirelessDevs)
  5. Eliminated updateDevice function and its associated cleanup logic
  6. Added Qt.labs.qmlmodels import for DelegateChooser support

The changes simplify dynamic object management by leveraging QML's built-in repeater components instead of manual JavaScript object lifecycle management. This reduces code complexity and potential memory leaks while improving maintainability.

Influence:

  1. Test network device list display with various device types
  2. Verify dynamic addition/removal of network devices
  3. Check that all device types (wired, wireless, VPN, DSL, hotspot, proxy) render correctly
  4. Test airplane mode toggle and its effect on hotspot availability
  5. Verify network details page shows proper information for different connections
  6. Ensure proper weight ordering of network settings items

refactor: 使用 DccRepeater 替换手动对象管理

  1. 使用 DccRepeater 替换基于 Component 的手动对象创建/销毁逻辑
  2. 简化 PageDetails.qml,移除 updateDetailsItems 函数和相关连接
  3. 重构 networkMain.qml 使用基于角色的 DelegateChooser 委托机制
  4. 移除复杂的手动设备跟踪数组(wiredDevs、wirelessDevs)
  5. 消除 updateDevice 函数及其相关的清理逻辑
  6. 添加 Qt.labs.qmlmodels 导入以支持 DelegateChooser

这些更改通过利用 QML 内置的重复器组件简化了动态对象管理,替代了手动
JavaScript 对象生命周期管理。这降低了代码复杂性和潜在的内存泄漏风险,同
时提高了可维护性。

Influence:

  1. 测试各种设备类型的网络设备列表显示
  2. 验证网络设备的动态添加/移除功能
  3. 检查所有设备类型(有线、无线、VPN、DSL、热点、代理)是否正确渲染
  4. 测试飞行模式切换及其对热点可用性的影响
  5. 验证网络详情页面显示不同连接的正确信息
  6. 确保网络设置项的正确权重排序

Summary by Sourcery

Refactor dynamic object management in networkMain.qml and PageDetails.qml to use QML’s built-in repeater components and delegate chooser, simplifying code and reducing potential memory leaks.

Enhancements:

  • Replace manual component-based object creation and destruction in networkMain.qml with DccRepeater and DelegateChooser for dynamic device items
  • Remove custom updateDetailsItems logic in PageDetails.qml and leverage DccRepeater for listing detail entries
  • Eliminate manual device tracking arrays and updateDevice/updateDetailsItems functions to simplify QML layers
  • Import Qt.labs.qmlmodels to enable DelegateChooser support

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 19, 2025

Reviewer's Guide

Replaces manual JavaScript-based object creation and cleanup with QML’s DccRepeater and DelegateChooser in networkMain.qml and PageDetails.qml, removing custom tracking arrays and update functions to simplify dynamic content management and improve maintainability.

Class diagram for refactored dynamic object management in networkMain.qml

classDiagram
    class DccObject {
        +showPage(cmd)
    }
    class DccRepeater {
        +model
        +delegate
    }
    class DelegateChooser {
        +role
        +DelegateChoice[]
    }
    class DelegateChoice {
        +roleValue
        +delegate
    }
    class PageWiredDevice {
        +showPage
        +item
    }
    class PageWirelessDevice {
        +showPage
        +item
    }
    class PageVPN {
        +showPage
        +item
        +name
        +parentName
        +weight
    }
    class PageDSL {
        +showPage
        +item
        +name
        +parentName
        +weight
    }
    class PageHotspot {
        +showPage
        +name
        +parentName
        +isAirplane
        +weight
    }
    class PageSystemProxy {
        +showPage
        +name
        +parentName
        +weight
    }
    class PageDetails {
        +showPage
        +item
        +name
        +parentName
        +weight
    }
    DccObject --> DccRepeater
    DccRepeater --> DelegateChooser
    DelegateChooser --> DelegateChoice
    DelegateChoice --> PageWiredDevice
    DelegateChoice --> PageWirelessDevice
    DelegateChoice --> PageVPN
    DelegateChoice --> PageDSL
    DelegateChoice --> PageHotspot
    DelegateChoice --> PageSystemProxy
    DelegateChoice --> PageDetails
Loading

Class diagram for refactored details item management in PageDetails.qml

classDiagram
    class DccObject {
        +infoItem
        +name
        +parentName
        +description
        +icon
        +page
    }
    class DccRepeater {
        +model
        +delegate
    }
    DccObject --> DccRepeater
    DccRepeater --> DccObject : delegate
Loading

File-Level Changes

Change Details Files
Use DccRepeater with DelegateChooser for dynamic device item handling
  • Imported Qt.labs.qmlmodels for repeater support
  • Removed updateDevice function, wiredDevs/wirelessDevs arrays, and manual Component definitions
  • Replaced manual object creation/destruction and component.onCompleted logic with DccRepeater bound to dccData.root.children and role-based DelegateChoice entries
dcc-network/qml/networkMain.qml
Simplify PageDetails.qml by replacing manual detail item management with DccRepeater
  • Removed updateDetailsItems function, detailsInfo Component, detailsItems tracking, and associated Connections
  • Added DccRepeater over item.children with modelData binding in delegate
  • Eliminated manual object lifecycle code for detail entries
dcc-network/qml/PageDetails.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 there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `dcc-network/qml/networkMain.qml:96` </location>
<code_context>
+                    parentName: "network"
+                    isAirplane: dccData.root.isEnabled
+                    weight: 3030
+                    Component.onCompleted: setItem(modelData)
+                }
+            }
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Using Component.onCompleted for setItem may cause timing issues.

This approach may not update the delegate if the model changes or the delegate is recreated. Consider using property binding or direct assignment to ensure the delegate stays in sync with model changes.

Suggested implementation:

```
                    weight: 3030
                    onModelDataChanged: setItem(modelData)

```

```

```

If `modelData` is not a property of the delegate, you may need to expose it or ensure that the delegate has access to it. Also, make sure that the delegate supports the `onModelDataChanged` signal handler. If not, you may need to use a property binding or a custom signal.
</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.

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 4, 2025

TAG Bot

New tag: 2.0.75
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #443

1. Replaced Component-based manual object creation/destruction with
DccRepeater for dynamic content
2. Simplified PageDetails.qml by removing updateDetailsItems function
and connections
3. Restructured networkMain.qml to use DelegateChooser with role-based
delegation
4. Removed complex manual device tracking arrays (wiredDevs,
wirelessDevs)
5. Eliminated updateDevice function and its associated cleanup logic
6. Added Qt.labs.qmlmodels import for DelegateChooser support

The changes simplify dynamic object management by leveraging QML's
built-in repeater components instead of manual JavaScript object
lifecycle management. This reduces code complexity and potential memory
leaks while improving maintainability.

Influence:
1. Test network device list display with various device types
2. Verify dynamic addition/removal of network devices
3. Check that all device types (wired, wireless, VPN, DSL, hotspot,
proxy) render correctly
4. Test airplane mode toggle and its effect on hotspot availability
5. Verify network details page shows proper information for different
connections
6. Ensure proper weight ordering of network settings items

refactor: 使用 DccRepeater 替换手动对象管理

1. 使用 DccRepeater 替换基于 Component 的手动对象创建/销毁逻辑
2. 简化 PageDetails.qml,移除 updateDetailsItems 函数和相关连接
3. 重构 networkMain.qml 使用基于角色的 DelegateChooser 委托机制
4. 移除复杂的手动设备跟踪数组(wiredDevs、wirelessDevs)
5. 消除 updateDevice 函数及其相关的清理逻辑
6. 添加 Qt.labs.qmlmodels 导入以支持 DelegateChooser

这些更改通过利用 QML 内置的重复器组件简化了动态对象管理,替代了手动
JavaScript 对象生命周期管理。这降低了代码复杂性和潜在的内存泄漏风险,同
时提高了可维护性。

Influence:
1. 测试各种设备类型的网络设备列表显示
2. 验证网络设备的动态添加/移除功能
3. 检查所有设备类型(有线、无线、VPN、DSL、热点、代理)是否正确渲染
4. 测试飞行模式切换及其对热点可用性的影响
5. 验证网络详情页面显示不同连接的正确信息
6. 确保网络设置项的正确权重排序
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个 Git diff 进行代码审查:

  1. 代码结构改进:
  • 使用 DccRepeater 和 NetItemModel 替代了原有的手动更新逻辑,这是一个很好的改进。这使得代码更加声明式,减少了手动管理对象生命周期的复杂性。
  • 移除了大量的手动更新函数(updateDetailsItems, updateDevice),改用模型-视图架构,提高了代码的可维护性。
  1. 性能优化:
  • 使用 DelegateChooser 进行类型分发,比原来的 switch-case 更高效,因为它利用了 QML 的类型系统。
  • 移除了不必要的数组操作(splice)和对象查找(findIndex),这些操作在大量设备时可能会造成性能问题。
  1. 代码安全:
  • 移除了手动对象创建和销毁(createObject/destroy),减少了内存泄漏的风险。
  • 使用模型-视图架构后,对象的生命周期管理更加安全。
  1. 可维护性提升:
  • 代码结构更清晰,每个组件的职责更明确。
  • 减少了重复代码,比如 showPage 属性的传递被简化了。
  • 使用 NetType 枚举进行类型分发,比字符串比较更安全。
  1. 潜在问题和建议:
  • 在 networkMain.qml 中,一些页面组件(如 PageVPN, PageDSL)被移到了 DccRepeater 中,这可能会影响它们的初始化顺序。建议确保这些组件的初始化顺序不会影响功能。
  • NetType.h 中移除了 Net_AppProxy 标志,这可能是故意的,但建议确认这个改动不会影响应用代理功能。
  • 在 PageDetails.qml 中,原来的 updateDetailsItems 函数被移除,建议确保 NetItemModel 能正确处理所有原来需要处理的场景。
  1. 其他建议:
  • 考虑为 NetItemModel 添加单元测试,确保它能正确处理各种网络设备类型。
  • 建议在 DelegateChoice 中添加默认情况处理,以防遇到未知的设备类型。
  • 在使用 Component.onCompleted 时,建议添加错误处理机制。

总的来说,这次重构提升了代码质量,使代码更加现代化和可维护。但建议进行充分的测试,确保所有功能都能正常工作。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23, mhduiy

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

@caixr23 caixr23 merged commit 8e33b75 into linuxdeepin:master Dec 9, 2025
16 of 18 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