Skip to content

Commit 5ea17aa

Browse files
52cybdeepin-bot[bot]
authored andcommitted
fix: Optimize the issue of slow entry into the Bluetooth interface
Other Bluetooth devices have more data and have initialized unnecessary controls. Optimization plan: 1. Add Timer and delay setting data model; 2. Use Loader to delay initialization of required controls; 其他蓝牙设备的数据较多,且初始化了一些不需要的控件。优化方案: 1. 添加Timer,延迟设置其他设备的数据model; 2. 使用Loader, 延迟初始化需要的控件; Log: 优化进入蓝牙界面较慢的问题 PMS: BUG-312521 Influence: 1. 可正常进入控制中心-设备-蓝牙界面;2. 进入蓝牙界面,响应速度正常;3.可正常刷新其他设备数据;4.已连接设备的UI效果正常; Revert "fix: Fix the Bluetooth interface opening slowly" This reverts commit 4f9f7f8.
1 parent e60a917 commit 5ea17aa

2 files changed

Lines changed: 145 additions & 131 deletions

File tree

src/plugin-bluetooth/qml/BlueToothDeviceListView.qml

Lines changed: 135 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
22
// SPDX-License-Identifier: GPL-3.0-or-later
33
import QtQuick 2.15
44
import QtQuick.Controls 2.0
@@ -54,7 +54,7 @@ Rectangle {
5454

5555
content: Rectangle {
5656
width: parent.width
57-
implicitHeight: Math.max(50, status.implicitHeight + 10)
57+
implicitHeight: Math.max(50, deviceRow.statusItem.implicitHeight + 10)
5858
color: "transparent"
5959
MouseArea {
6060
anchors.fill: parent
@@ -68,14 +68,15 @@ Rectangle {
6868
}
6969

7070
RowLayout {
71+
id: deviceRow
72+
property alias statusItem: status
7173
width: parent.width
7274
anchors.fill: parent
73-
Layout.fillWidth: true
74-
Layout.fillHeight: true
7575

7676
ColumnLayout {
7777
id: status
7878
Layout.fillHeight: true
79+
Layout.fillWidth: true
7980
spacing: 0
8081
Layout.leftMargin: 10
8182
implicitHeight: Math.max(myDeviceName.implicitHeight, loader.implicitHeight) + 10
@@ -131,32 +132,40 @@ Rectangle {
131132
}
132133
}
133134

134-
D.LineEdit {
135-
id: nameEdit
136-
visible: false
137-
text: model.name
135+
Loader {
136+
id: nameEditLoader
137+
active: false
138+
visible: active
138139
Layout.fillWidth: true
139140
Layout.fillHeight: true
140141
Layout.topMargin: 10
141142
Layout.bottomMargin: 10
142143

143-
onEditingFinished: {
144-
nameEdit.visible = false
145-
status.visible = true
146-
itemCtl.hoverEnabled = true
144+
sourceComponent: D.LineEdit {
145+
id: nameEdit
146+
text: model.name
147147

148-
console.log("set device name ", model.id, nameEdit.text)
149-
dccData.work().setDeviceAlias(model.id, nameEdit.text)
148+
onEditingFinished: {
149+
nameEditLoader.active = false
150+
deviceRow.statusItem.visible = true
151+
itemCtl.hoverEnabled = true
150152

151-
}
152-
onVisibleChanged: {
153-
if (visible) {
154-
text = model.name
153+
console.log("set device name ", model.id, nameEdit.text)
154+
dccData.work().setDeviceAlias(model.id, nameEdit.text)
155155
}
156-
}
157-
Keys.onPressed: function(event) {
158-
if (event.key === Qt.Key_Return) {
159-
nameEdit.forceActiveFocus(false); // 结束编辑
156+
onVisibleChanged: {
157+
if (visible) {
158+
text = model.name
159+
}
160+
}
161+
Keys.onPressed: function(event) {
162+
if (event.key === Qt.Key_Return) {
163+
nameEdit.forceActiveFocus(false); // 结束编辑
164+
}
165+
}
166+
Component.onCompleted: {
167+
nameEdit.forceActiveFocus(true)
168+
nameEdit.selectAll()
160169
}
161170
}
162171
}
@@ -193,135 +202,131 @@ Rectangle {
193202
}
194203
}
195204

196-
D.ActionButton {
197-
id: moreBtn
198-
palette.windowText: D.ColorSelector.textColor
199-
visible: showMoreBtn
205+
Loader {
206+
active: showMoreBtn
207+
visible: active
200208
Layout.alignment: Qt.AlignRight
201-
icon.name: "bluetooth_option"
202-
icon.width: 16
203-
icon.height: 16
204-
205-
implicitHeight: 30
206-
implicitWidth: 30
207-
208-
flat: !hovered
209-
210-
property bool menuShown: false
211-
212-
background: Rectangle {
213-
property D.Palette pressedColor: D.Palette {
214-
normal: Qt.rgba(0, 0, 0, 0.2)
215-
normalDark: Qt.rgba(1, 1, 1, 0.25)
216-
}
217-
property D.Palette hoveredColor: D.Palette {
218-
normal: Qt.rgba(0, 0, 0, 0.1)
219-
normalDark: Qt.rgba(1, 1, 1, 0.1)
220-
}
221-
radius: DS.Style.control.radius
222-
color: parent.pressed ? D.ColorSelector.pressedColor : (parent.hovered ? D.ColorSelector.hoveredColor : "transparent")
223-
border {
224-
color: parent.palette.highlight
225-
width: parent.visualFocus ? DS.Style.control.focusBorderWidth : 0
226-
}
227-
}
228209

229-
D.Menu {
230-
id: contextMenu
231-
implicitWidth: 150
232-
233-
D.MenuItem {
234-
id: connectDev
235-
padding: 0
236-
text: model.connectStatus === 2 ? qsTr("Disconnect") : qsTr("Connect")
237-
enabled: model.connectStatus === 2 || model.connectStatus === 0
238-
onTriggered: {
239-
if (model.connectStatus === 2) {
240-
dccData.work().disconnectDevice(model.id)
241-
} else {
242-
dccData.work().connectDevice(model.id, model.adapterId)
243-
}
210+
sourceComponent: D.ActionButton {
211+
id: moreBtn
212+
palette.windowText: D.ColorSelector.textColor
213+
icon.name: "bluetooth_option"
214+
icon.width: 16
215+
icon.height: 16
216+
implicitHeight: 30
217+
implicitWidth: 30
218+
flat: !hovered
219+
220+
property bool menuShown: false
221+
222+
background: Rectangle {
223+
property D.Palette pressedColor: D.Palette {
224+
normal: Qt.rgba(0, 0, 0, 0.2)
225+
normalDark: Qt.rgba(1, 1, 1, 0.25)
244226
}
245-
}
246-
D.MenuItem {
247-
id: sendFile
248-
padding: 0
249-
text: qsTr("Send Files")
250-
visible: itemCtl.showSendFile
251-
height : sendFile.visible ? implicitHeight : 0
252-
topPadding: sendFile.visible ? undefined : 0
253-
bottomPadding: sendFile.visible ? undefined : 0
254-
255-
onTriggered: {
256-
fileDlg.open()
227+
property D.Palette hoveredColor: D.Palette {
228+
normal: Qt.rgba(0, 0, 0, 0.1)
229+
normalDark: Qt.rgba(1, 1, 1, 0.1)
230+
}
231+
radius: DS.Style.control.radius
232+
color: parent.pressed ? D.ColorSelector.pressedColor : (parent.hovered ? D.ColorSelector.hoveredColor : "transparent")
233+
border {
234+
color: parent.palette.highlight
235+
width: parent.visualFocus ? DS.Style.control.focusBorderWidth : 0
257236
}
258-
259237
}
260238

261-
D.MenuItem {
262-
id: rename
263-
text: qsTr("Rename")
264-
padding: 0
265-
onTriggered: {
266-
nameEdit.visible = true
239+
D.Menu {
240+
id: contextMenu
241+
implicitWidth: 150
242+
243+
D.MenuItem {
244+
id: connectDev
245+
padding: 0
246+
text: model.connectStatus === 2 ? qsTr("Disconnect") : qsTr("Connect")
247+
enabled: model.connectStatus === 2 || model.connectStatus === 0
248+
onTriggered: {
249+
if (model.connectStatus === 2) {
250+
dccData.work().disconnectDevice(model.id)
251+
} else {
252+
dccData.work().connectDevice(model.id, model.adapterId)
253+
}
254+
}
255+
}
256+
D.MenuItem {
257+
id: sendFile
258+
padding: 0
259+
text: qsTr("Send Files")
260+
visible: itemCtl.showSendFile
261+
height : sendFile.visible ? implicitHeight : 0
262+
topPadding: sendFile.visible ? undefined : 0
263+
bottomPadding: sendFile.visible ? undefined : 0
264+
265+
onTriggered: {
266+
fileDlg.open()
267+
}
267268

268-
status.visible = false
269-
itemCtl.hoverEnabled = false
269+
}
270270

271-
nameEdit.forceActiveFocus(true)
272-
nameEdit.selectAll()
271+
D.MenuItem {
272+
id: rename
273+
text: qsTr("Rename")
274+
padding: 0
275+
onTriggered: {
276+
nameEditLoader.active = true
277+
deviceRow.statusItem.visible = false
278+
itemCtl.hoverEnabled = false
279+
}
273280
}
274-
}
275281

276-
D.MenuSeparator {
277-
}
282+
D.MenuSeparator {
283+
}
278284

279-
D.MenuItem {
280-
id: removeDev
281-
text: qsTr("Remove Device")
282-
enabled: model.connectStatus === 2 || model.connectStatus === 0
283-
padding: 0
284-
onTriggered: {
285-
dccData.work().ignoreDevice(model.id, model.adapterId)
285+
D.MenuItem {
286+
id: removeDev
287+
text: qsTr("Remove Device")
288+
enabled: model.connectStatus === 2 || model.connectStatus === 0
289+
padding: 0
290+
onTriggered: {
291+
dccData.work().ignoreDevice(model.id, model.adapterId)
292+
}
286293
}
287294
}
288-
}
289-
290-
FileDialog {
291-
id: fileDlg
292-
title: qsTr("Select file")
293-
fileMode: FileDialog.OpenFiles
294-
folder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
295-
onAccepted: {
296-
console.log(" Select file : ", fileDlg.files)
297-
dccData.work().showBluetoothTransDialog(model.address, fileDlg.files)
298295

296+
FileDialog {
297+
id: fileDlg
298+
title: qsTr("Select file")
299+
fileMode: FileDialog.OpenFiles
300+
folder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
301+
onAccepted: {
302+
console.log(" Select file : ", fileDlg.files)
303+
dccData.work().showBluetoothTransDialog(model.address, fileDlg.files)
304+
}
299305
}
300-
}
301306

302-
MouseArea {
303-
anchors.fill: parent
304-
hoverEnabled: true
305-
onEntered: {
306-
moreBtn.menuShown = contextMenu.visible
307-
}
308-
onClicked: {
309-
console.log(" contextMenu 单击事件 ");
310-
if (moreBtn.menuShown) {
311-
moreBtn.menuShown = false
312-
return
307+
MouseArea {
308+
anchors.fill: parent
309+
hoverEnabled: true
310+
onEntered: {
311+
moreBtn.menuShown = contextMenu.visible
312+
}
313+
onClicked: {
314+
console.log(" contextMenu 单击事件 ");
315+
if (moreBtn.menuShown) {
316+
moreBtn.menuShown = false
317+
return
318+
}
319+
// 在点击位置下方显示菜单
320+
// 获取按钮的全局位置,确保菜单在按钮的正下方显示
321+
var buttonGlobalX = moreBtn.x + moreBtn.width / 2 - contextMenu.width
322+
var buttonGlobalY = moreBtn.y + moreBtn.height + 5
323+
contextMenu.popup(buttonGlobalX, buttonGlobalY)
324+
moreBtn.menuShown = true
313325
}
314-
// 在点击位置下方显示菜单
315-
// 获取按钮的全局位置,确保菜单在按钮的正下方显示
316-
var buttonGlobalX = moreBtn.x + moreBtn.width / 2 - contextMenu.width
317-
var buttonGlobalY = moreBtn.y + moreBtn.height + 5
318-
contextMenu.popup(buttonGlobalX, buttonGlobalY)
319-
moreBtn.menuShown = true
320326
}
321327
}
322328
}
323329
}
324-
325330
}
326331
}
327332
}

src/plugin-bluetooth/qml/OtherDevice.qml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,19 @@ DccObject{
154154
backgroundType: DccObject.Normal
155155
pageType: DccObject.Item
156156
page: BlueToothDeviceListView {
157+
id: deviceListView
157158
showMoreBtn: false
158159
showConnectStatus: false
159160
showPowerStatus: false
160-
deviceModel: model.otherDevice
161+
162+
Timer {
163+
interval: 300
164+
repeat: false
165+
running: true
166+
onTriggered: {
167+
deviceListView.deviceModel = model.otherDevice
168+
}
169+
}
161170

162171
onClicked: function (index, checked) {
163172
}

0 commit comments

Comments
 (0)