QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
LinkConfigurationManager.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7import QGroundControl.FactControls
8
9SettingsGroupLayout {
10 id: _root
11 heading: qsTr("Links")
12
13 property var _linkManager: QGroundControl.linkManager
14
15 Repeater {
16 model: _linkManager.linkConfigurations
17
18 RowLayout {
19 Layout.fillWidth: true
20 visible: !object.dynamic
21
22 QGCLabel {
23 Layout.fillWidth: true
24 text: object.name
25 }
26 QGCColoredImage {
27 height: ScreenTools.minTouchPixels
28 width: height
29 sourceSize.height: height
30 fillMode: Image.PreserveAspectFit
31 mipmap: true
32 smooth: true
33 color: qgcPalEdit.text
34 source: "/res/pencil.svg"
35 enabled: !object.link
36
37 QGCPalette {
38 id: qgcPalEdit
39 colorGroupEnabled: parent.enabled
40 }
41
42 QGCMouseArea {
43 fillItem: parent
44 onClicked: {
45 var editingConfig = _linkManager.startConfigurationEditing(object)
46 linkDialogFactory.open({ editingConfig: editingConfig, originalConfig: object })
47 }
48 }
49 }
50 QGCColoredImage {
51 height: ScreenTools.minTouchPixels
52 width: height
53 sourceSize.height: height
54 fillMode: Image.PreserveAspectFit
55 mipmap: true
56 smooth: true
57 color: qgcPalDelete.text
58 source: "/res/TrashDelete.svg"
59
60 QGCPalette {
61 id: qgcPalDelete
62 colorGroupEnabled: parent.enabled
63 }
64
65 QGCMouseArea {
66 fillItem: parent
67 onClicked: QGroundControl.showMessageDialog(
68 _root,
69 qsTr("Delete Link"),
70 qsTr("Are you sure you want to delete '%1'?").arg(object.name),
71 Dialog.Ok | Dialog.Cancel,
72 function () {
73 _linkManager.removeConfiguration(object)
74 })
75 }
76 }
77 QGCButton {
78 text: object.link ? qsTr("Disconnect") : qsTr("Connect")
79 onClicked: {
80 if (object.link) {
81 object.link.disconnect()
82 } else {
83 _linkManager.createConnectedLink(object)
84 }
85 }
86 }
87 }
88 }
89
90 LabelledButton {
91 label: qsTr("Add New Link")
92 buttonText: qsTr("Add")
93
94 onClicked: {
95 var editingConfig = _linkManager.createConfiguration(ScreenTools.isSerialAvailable ? LinkConfiguration.TypeSerial : LinkConfiguration.TypeUdp, "")
96 linkDialogFactory.open({ editingConfig: editingConfig, originalConfig: null })
97 }
98 }
99
100 QGCPopupDialogFactory {
101 id: linkDialogFactory
102
103 dialogComponent: linkDialogComponent
104 }
105
106 Component {
107 id: linkDialogComponent
108
109 QGCPopupDialog {
110 title: originalConfig ? qsTr("Edit Link") : qsTr("Add New Link")
111 buttons: Dialog.Save | Dialog.Cancel
112 acceptButtonEnabled: nameField.text !== ""
113
114 property var originalConfig
115 property var editingConfig
116
117 onAccepted: {
118 linkSettingsLoader.item.saveSettings()
119 editingConfig.name = nameField.text
120 if (originalConfig) {
121 _linkManager.endConfigurationEditing(originalConfig, editingConfig)
122 } else {
123 editingConfig.dynamic = false
124 _linkManager.endCreateConfiguration(editingConfig)
125 }
126 }
127
128 onRejected: _linkManager.cancelConfigurationEditing(editingConfig)
129
130 ColumnLayout {
131 spacing: ScreenTools.defaultFontPixelHeight / 2
132
133 RowLayout {
134 Layout.fillWidth: true
135 spacing: ScreenTools.defaultFontPixelWidth
136
137 QGCLabel { text: qsTr("Name") }
138 QGCTextField {
139 id: nameField
140 Layout.fillWidth: true
141 text: editingConfig.name
142 placeholderText: qsTr("Enter name")
143 }
144 }
145
146 QGCCheckBoxSlider {
147 Layout.fillWidth: true
148 text: qsTr("Automatically Connect on Start")
149 checked: editingConfig.autoConnect
150 onCheckedChanged: editingConfig.autoConnect = checked
151 }
152
153 QGCCheckBoxSlider {
154 Layout.fillWidth: true
155 text: qsTr("High Latency")
156 checked: editingConfig.highLatency
157 onCheckedChanged: editingConfig.highLatency = checked
158 }
159
160 LabelledComboBox {
161 label: qsTr("Type")
162 enabled: originalConfig == null
163 model: _linkManager.linkTypeStrings
164 Component.onCompleted: comboBox.currentIndex = editingConfig.linkType
165
166 onActivated: (index) => {
167 if (index !== editingConfig.linkType) {
168 var name = nameField.text
169 editingConfig = _linkManager.createConfiguration(index, name)
170 }
171 }
172 }
173
174 Loader {
175 id: linkSettingsLoader
176 source: editingConfig && editingConfig.settingsURL ? editingConfig.settingsURL : ""
177 asynchronous: true
178
179 property var subEditConfig: editingConfig
180 property int _firstColumnWidth: ScreenTools.defaultFontPixelWidth * 12
181 property int _secondColumnWidth: ScreenTools.defaultFontPixelWidth * 30
182 property int _rowSpacing: ScreenTools.defaultFontPixelHeight / 2
183 property int _colSpacing: ScreenTools.defaultFontPixelWidth / 2
184
185 onStatusChanged: {
186 if (status === Loader.Error) {
187 console.warn("Failed to load link settings page:", source)
188 }
189 }
190 }
191 }
192 }
193 }
194}