Skip to content

Commit 8e33b75

Browse files
committed
refactor: replace manual object management with DccRepeater
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. 确保网络设置项的正确权重排序
1 parent aca2936 commit 8e33b75

4 files changed

Lines changed: 86 additions & 189 deletions

File tree

dcc-network/qml/PageDetails.qml

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ DccObject {
2121
description: qsTr("View all network configurations")
2222
icon: "dcc_netinfo"
2323
page: DccSettingsView {}
24-
Component {
25-
id: detailsInfo
26-
DccObject {
27-
property var infoItem: null
24+
DccRepeater {
25+
model: NetItemModel {
26+
root: item
27+
}
28+
delegate: DccObject {
29+
property var infoItem: model.item
2830

2931
name: infoItem.name
3032
parentName: root.name + "/body"
@@ -93,7 +95,6 @@ DccObject {
9395
Repeater {
9496
id: repeater
9597
model: infoItem.details
96-
9798
delegate: ItemDelegate {
9899
implicitHeight: 36
99100
text: modelData[0]
@@ -176,39 +177,4 @@ DccObject {
176177
}
177178
}
178179
}
179-
180-
function updateDetailsItems() {
181-
if (item) {
182-
const delDetailsItems = detailsItems.concat()
183-
for (let i in item.children) {
184-
let child = item.children[i]
185-
let index = delDetailsItems.findIndex(tmpItem => tmpItem.infoItem === child)
186-
if (index >= 0) {
187-
delDetailsItems.splice(index, 1)
188-
} else {
189-
let details = detailsInfo.createObject(root, {
190-
"infoItem": child
191-
})
192-
DccApp.addObject(details)
193-
detailsItems.push(details)
194-
}
195-
}
196-
for (const delItem of delDetailsItems) {
197-
DccApp.removeObject(delItem)
198-
let index = detailsItems.findIndex(item => delItem === item)
199-
if (index >= 0) {
200-
detailsItems.splice(index, 1)
201-
}
202-
delItem.destroy()
203-
}
204-
}
205-
}
206-
207-
onItemChanged: updateDetailsItems()
208-
Connections {
209-
target: item
210-
function onChildrenChanged() {
211-
updateDetailsItems()
212-
}
213-
}
214180
}

dcc-network/qml/network.qml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import org.deepin.dcc 1.0
44

55
DccObject {
66
property string cmd
7+
property var showPageFun
78
function showPage() {
8-
if (cmd.length !== 0 && children.length !== 0) {
9-
children[0].showPage(cmd)
9+
if (cmd.length !== 0 && showPageFun) {
10+
showPageFun(cmd)
1011
cmd = ""
1112
}
1213
}
@@ -15,7 +16,7 @@ DccObject {
1516
displayName: qsTr("Network")
1617
icon: "dcc_network"
1718
weight: 20
18-
onChildrenChanged: showPage()
19+
onShowPageFunChanged: showPage()
1920
onActive: function (cmdParam) {
2021
cmd = cmdParam
2122
showPage()

dcc-network/qml/networkMain.qml

Lines changed: 75 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import QtQuick 2.15
44
import QtQuick.Controls 2.0
55
import QtQuick.Layouts 1.15
6+
import Qt.labs.qmlmodels
67

78
import org.deepin.dtk 1.0 as D
89

@@ -17,100 +18,7 @@ DccObject {
1718
function showPage(cmd) {
1819
dccData.exec(NetManager.ShowPage, cmd, {})
1920
}
20-
function updateDevice() {
21-
const delWiredDevs = wiredDevs.concat()
22-
const delWirelessDevs = wirelessDevs.concat()
23-
for (let i in dccData.root.children) {
24-
let item = dccData.root.children[i]
25-
switch (item.itemType) {
26-
case NetType.WiredDeviceItem:
27-
{
28-
let index = delWiredDevs.findIndex(d => d.item === item)
29-
if (index >= 0) {
30-
delWiredDevs.splice(index, 1)
31-
} else {
32-
let dev = wiredComponent.createObject(root, {
33-
"item": item
34-
})
35-
DccApp.addObject(dev)
36-
wiredDevs.push(dev)
37-
}
38-
}
39-
break
40-
case NetType.WirelessDeviceItem:
41-
{
42-
let index = delWirelessDevs.findIndex(d => d.item === item)
43-
if (index >= 0) {
44-
delWirelessDevs.splice(index, 1)
45-
} else {
46-
let dev = wirelessComponent.createObject(root, {
47-
"item": item,
48-
"airplaneItem": dccData.root
49-
})
50-
DccApp.addObject(dev)
51-
wirelessDevs.push(dev)
52-
}
53-
}
54-
break
55-
case NetType.VPNControlItem:
56-
if (vpnPage.item !== item) {
57-
vpnPage.item = item
58-
}
59-
break
60-
case NetType.SystemProxyControlItem:
61-
if (systemProxyPage.item !== item) {
62-
systemProxyPage.setItem(item)
63-
}
64-
break
65-
case NetType.AppProxyControlItem:
66-
// if (appProxyPage.item !== item) {
67-
// appProxyPage.item = item
68-
// }
69-
break
70-
case NetType.HotspotControlItem:
71-
hotspotPage.setItem(item)
72-
break
73-
case NetType.DSLControlItem:
74-
if (dslPage.item !== item) {
75-
dslPage.item = item
76-
}
77-
break
78-
case NetType.DetailsItem:
79-
if (detailsPage.item !== item) {
80-
detailsPage.item = item
81-
}
82-
break
83-
}
84-
}
85-
for (const delDev of delWiredDevs) {
86-
DccApp.removeObject(delDev)
87-
let index = wiredDevs.findIndex(item => delDev === item)
88-
if (index >= 0) {
89-
wiredDevs.splice(index, 1)
90-
}
91-
delDev.destroy()
92-
}
93-
for (const delDev of delWirelessDevs) {
94-
DccApp.removeObject(delDev)
95-
let index = wirelessDevs.findIndex(item => delDev === item)
96-
if (index >= 0) {
97-
wirelessDevs.splice(index, 1)
98-
}
99-
delDev.destroy()
100-
}
101-
}
102-
Component {
103-
id: wiredComponent
104-
PageWiredDevice {
105-
property var showPage: root.showPage
106-
}
107-
}
108-
Component {
109-
id: wirelessComponent
110-
PageWirelessDevice {
111-
property var showPage: root.showPage
112-
}
113-
}
21+
Component.onCompleted: dccModule.showPageFun = showPage
11422
DccTitleObject {
11523
name: "connectionSettings"
11624
parentName: "network"
@@ -122,20 +30,6 @@ DccObject {
12230
}
12331
}
12432
}
125-
PageVPN {
126-
id: vpnPage
127-
property var showPage: root.showPage
128-
name: "networkVpn"
129-
parentName: "network"
130-
weight: 3010
131-
}
132-
PageDSL {
133-
id: dslPage
134-
property var showPage: root.showPage
135-
name: "dsl"
136-
parentName: "network"
137-
weight: 3020
138-
}
13933
DccTitleObject {
14034
name: "relatedSettings"
14135
parentName: "network"
@@ -147,49 +41,85 @@ DccObject {
14741
}
14842
}
14943
}
150-
PageHotspot {
151-
id: hotspotPage
152-
property var showPage: root.showPage
153-
name: "personalHotspot"
154-
parentName: "network"
155-
isAirplane: dccData.root.isEnabled
156-
weight: 3030
157-
}
15844
PageAirplane {
15945
name: "airplaneMode"
160-
property var showPage: root.showPage
16146
parentName: "network"
16247
weight: 3040
16348
item: dccData.root
16449
}
165-
PageSystemProxy {
166-
id: systemProxyPage
167-
property var showPage: root.showPage
168-
name: "systemProxy"
169-
parentName: "network"
170-
weight: 3050
171-
}
172-
PageAppProxy {
173-
id: appProxyPage
174-
property var showPage: root.showPage
175-
name: "applicationProxy"
176-
parentName: "network"
177-
weight: 3060
178-
}
179-
PageDetails {
180-
id: detailsPage
181-
property var showPage: root.showPage
182-
name: "networkDetails"
183-
parentName: "network"
184-
weight: 3070
185-
}
186-
Connections {
187-
target: dccData.root
188-
function onChildrenChanged() {
189-
updateDevice()
50+
DccRepeater {
51+
model: NetItemModel {
52+
root: dccData.root
53+
}
54+
delegate: DelegateChooser {
55+
role: "type"
56+
DelegateChoice {
57+
roleValue: NetType.WiredDeviceItem
58+
delegate: PageWiredDevice {
59+
item: model.item
60+
}
61+
}
62+
DelegateChoice {
63+
roleValue: NetType.WirelessDeviceItem
64+
delegate: PageWirelessDevice {
65+
item: model.item
66+
}
67+
}
68+
DelegateChoice {
69+
roleValue: NetType.VPNControlItem
70+
delegate: PageVPN {
71+
name: "networkVpn"
72+
parentName: "network"
73+
weight: 3010
74+
item: model.item
75+
}
76+
}
77+
DelegateChoice {
78+
roleValue: NetType.DSLControlItem
79+
delegate: PageDSL {
80+
name: "dsl"
81+
parentName: "network"
82+
weight: 3020
83+
item: model.item
84+
}
85+
}
86+
DelegateChoice {
87+
roleValue: NetType.HotspotControlItem
88+
delegate: PageHotspot {
89+
name: "personalHotspot"
90+
parentName: "network"
91+
isAirplane: dccData.root.isEnabled
92+
weight: 3030
93+
Component.onCompleted: setItem(model.item)
94+
}
95+
}
96+
DelegateChoice {
97+
roleValue: NetType.SystemProxyControlItem
98+
delegate: PageSystemProxy {
99+
name: "systemProxy"
100+
parentName: "network"
101+
weight: 3050
102+
Component.onCompleted: setItem(model.item)
103+
}
104+
}
105+
DelegateChoice {
106+
roleValue: NetType.AppProxyControlItem
107+
delegate: PageAppProxy {
108+
name: "applicationProxy"
109+
parentName: "network"
110+
weight: 3060
111+
item: model.item
112+
}
113+
}
114+
DelegateChoice {
115+
roleValue: NetType.DetailsItem
116+
delegate: PageDetails {
117+
name: "networkDetails"
118+
parentName: "network"
119+
weight: 3070
120+
item: model.item
121+
}
122+
}
190123
}
191-
}
192-
Component.onCompleted: {
193-
updateDevice()
194124
}
195125
}

net-view/operation/nettype.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class NetType
108108
Net_DockFlags = Net_Device | Net_VPN | Net_SysProxy | Net_Airplane | Net_AirplaneTips | Net_VPNTips | Net_tipsLinkEnabled | Net_UseSecretAgent | Net_CheckPortal | Net_8021xToControlCenterUnderConnect | Net_autoUpdateHiddenConfig,
109109
Net_LockFlags = Net_Device | Net_VPN | Net_SysProxy | Net_Airplane | Net_AirplaneTips | Net_VPNTips | Net_UseSecretAgent | Net_CheckPortal | Net_8021xSendNotifyUnderConnect,
110110
Net_GreeterFlags = Net_Device | Net_Airplane | Net_AirplaneTips | Net_ServiceNM | Net_MonitorNotify | Net_AutoAddConnection | Net_UseSecretAgent | Net_CheckPortal | Net_8021xSendNotifyUnderConnect,
111-
Net_DccFlags = Net_Device | Net_VPN | Net_VPNChildren | Net_SysProxy | Net_AppProxy | Net_Hotspot | Net_Airplane | Net_DSL | Net_Details,
111+
Net_DccFlags = Net_Device | Net_VPN | Net_VPNChildren | Net_SysProxy | Net_Hotspot | Net_Airplane | Net_DSL | Net_Details,
112112
//
113113
Net_8021xMask = 0x00000F00,
114114
};

0 commit comments

Comments
 (0)