QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ParameterEditor.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Dialogs
4import QtQuick.Layouts
5
6import QGroundControl
7import QGroundControl.Controls
8import QGroundControl.FactControls
9
10Item {
11 id: _root
12
13 property Fact _editorDialogFact: Fact { }
14 property int _rowHeight: ScreenTools.defaultFontPixelHeight * 2
15 property int _rowWidth: 10 // Dynamic adjusted at runtime
16 property bool _searchFilter: searchText.text.trim() != "" || controller.showModifiedOnly || controller.showFavoritesOnly ///< true: showing results of search
17 property var _searchResults ///< List of parameter names from search results
18 property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
19 property bool _showRCToParam: _activeVehicle.px4Firmware
20 property var _appSettings: QGroundControl.settingsManager.appSettings
21 property var _controller: controller
22 property var _favorites: controller.favoriteParameterNames
23 property real _margins: ScreenTools.defaultFontPixelHeight / 2
24
25 ParameterEditorController {
26 id: controller
27 }
28
29 Timer {
30 id: clearTimer
31 interval: 100;
32 running: false;
33 repeat: false
34 onTriggered: {
35 searchText.text = ""
36 controller.searchText = ""
37 }
38 }
39
40 QGCMenu {
41 id: toolsMenu
42 QGCMenuItem {
43 text: qsTr("Refresh")
44 onTriggered: controller.refresh()
45 }
46 QGCMenuItem {
47 text: qsTr("Reset all to firmware's defaults")
48 onTriggered: QGroundControl.showMessageDialog(_root, qsTr("Reset All"),
49 qsTr("Select Reset to reset all parameters to their defaults.\n\nNote that this will also completely reset everything, including UAVCAN nodes, all vehicle settings, setup and calibrations."),
50 Dialog.Cancel | Dialog.Reset,
51 function() { controller.resetAllToDefaults() })
52 }
53 QGCMenuItem {
54 text: qsTr("Reset to vehicle's configuration defaults")
55 visible: !_activeVehicle.apmFirmware
56 onTriggered: QGroundControl.showMessageDialog(_root, qsTr("Reset All"),
57 qsTr("Select Reset to reset all parameters to the vehicle's configuration defaults."),
58 Dialog.Cancel | Dialog.Reset,
59 function() { controller.resetAllToVehicleConfiguration() })
60 }
61 QGCMenuSeparator { }
62 QGCMenuItem {
63 objectName: "parameterEditor_toolLoadFromFile"
64 text: qsTr("Load from file for review...")
65 onTriggered: {
66 fileDialog.title = qsTr("Load Parameters")
67 fileDialog.openForLoad()
68 }
69 }
70 QGCMenuItem {
71 text: qsTr("Save to file...")
72 onTriggered: {
73 fileDialog.title = qsTr("Save Parameters")
74 fileDialog.openForSave()
75 }
76 }
77 QGCMenuSeparator { }
78 QGCMenuItem {
79 text: qsTr("Clear all favorites")
80 onTriggered: controller.clearAllFavorites()
81 }
82 QGCMenuSeparator { visible: _showRCToParam }
83 QGCMenuItem {
84 text: qsTr("Clear all RC to Param")
85 onTriggered: _activeVehicle.clearAllParamMapRC()
86 visible: _showRCToParam
87 }
88 QGCMenuSeparator { }
89 QGCMenuItem {
90 text: qsTr("Reboot Vehicle")
91 onTriggered: QGroundControl.showMessageDialog(_root, qsTr("Reboot Vehicle"),
92 qsTr("Select Ok to reboot vehicle."),
93 Dialog.Cancel | Dialog.Ok,
94 function() { _activeVehicle.rebootVehicle() })
95 }
96 }
97
98
99 QGCFileDialog {
100 id: fileDialog
101 folder: _appSettings.parameterSavePath
102 nameFilters: [ qsTr("Parameter Files (*.%1)").arg(_appSettings.parameterFileExtension), qsTr("Mission Planner Files (*.param)"), qsTr("All Files (*)") ]
103
104 onAcceptedForSave: (file) => {
105 controller.saveToFile(file)
106 close()
107 }
108
109 onAcceptedForLoad: (file) => {
110 close()
111 if (controller.buildDiffFromFile(file)) {
112 parameterDiffDialogFactory.open()
113 }
114 }
115 }
116
117 QGCPopupDialogFactory {
118 id: editorDialogFactory
119
120 dialogComponent: editorDialogComponent
121 }
122
123 Component {
124 id: editorDialogComponent
125
126 ParameterEditorDialog {
127 fact: _editorDialogFact
128 showRCToParam: _showRCToParam
129 }
130 }
131
132 QGCPopupDialogFactory {
133 id: parameterDiffDialogFactory
134
135 dialogComponent: parameterDiffDialog
136 }
137
138 Component {
139 id: parameterDiffDialog
140
141 ParameterDiffDialog {
142 paramController: _controller
143 }
144 }
145
146 RowLayout {
147 id: header
148 anchors.left: parent.left
149 anchors.right: parent.right
150
151 RowLayout {
152 Layout.alignment: Qt.AlignLeft
153 spacing: ScreenTools.defaultFontPixelWidth
154
155 QGCTextField {
156 id: searchText
157 placeholderText: qsTr("Search")
158 onDisplayTextChanged: controller.searchText = displayText
159 }
160
161 QGCButton {
162 text: qsTr("Clear")
163 onClicked: {
164 if(ScreenTools.isMobile) {
165 Qt.inputMethod.hide();
166 }
167 clearTimer.start()
168 }
169 }
170
171 QGCCheckBox {
172 text: qsTr("Hide read-only")
173 checked: controller.hideReadOnly
174 onClicked: controller.hideReadOnly = checked
175 }
176 }
177
178 QGCButton {
179 Layout.alignment: Qt.AlignRight
180 objectName: "parameterEditor_toolsButton"
181 text: qsTr("Tools")
182 onClicked: toolsMenu.popup()
183 }
184 }
185
186 QGCGroupBox {
187 anchors.left: parent.left
188 anchors.right: parent.right
189 anchors.top: header.bottom
190 anchors.topMargin: _margins
191 anchors.bottom: parent.bottom
192 showDividers: false
193 contentSpacing: 0
194
195 onCurrentIndexChanged: {
196 controller.showModifiedOnly = (currentIndex === 1)
197 controller.showFavoritesOnly = (currentIndex === 2)
198 }
199
200 QGCGroupBoxTab { title: qsTr("Full List") }
201 QGCGroupBoxTab { title: qsTr("Modified") }
202 QGCGroupBoxTab { title: qsTr("Favorites") }
203
204 Item {
205 Layout.fillWidth: true
206 Layout.fillHeight: true
207
208 /// Group buttons
209 QGCFlickable {
210 id : groupScroll
211 width: ScreenTools.defaultFontPixelWidth * 25
212 anchors.top: parent.top
213 anchors.bottom: parent.bottom
214 clip: true
215 pixelAligned: true
216 contentHeight: groupedViewCategoryColumn.height
217 flickableDirection: Flickable.VerticalFlick
218 visible: !_searchFilter
219
220 ColumnLayout {
221 id: groupedViewCategoryColumn
222 anchors.left: parent.left
223 anchors.right: parent.right
224 spacing: Math.ceil(ScreenTools.defaultFontPixelHeight * 0.25)
225
226 Repeater {
227 model: controller.categories
228
229 Column {
230 Layout.fillWidth: true
231 spacing: Math.ceil(ScreenTools.defaultFontPixelHeight * 0.25)
232
233
234 SectionHeader {
235 id: categoryHeader
236 anchors.left: parent.left
237 anchors.right: parent.right
238 text: object.name
239 checked: object == controller.currentCategory
240
241 onCheckedChanged: {
242 if (checked) {
243 controller.currentCategory = object
244 }
245 }
246 }
247
248 Repeater {
249 model: categoryHeader.checked ? object.groups : 0
250
251 QGCButton {
252 width: ScreenTools.defaultFontPixelWidth * 25
253 text: object.name
254 height: _rowHeight
255 checked: object == controller.currentGroup
256 autoExclusive: true
257
258 onClicked: {
259 if (!checked) _rowWidth = 10
260 checked = true
261 controller.currentGroup = object
262 }
263 }
264 }
265 }
266 }
267 }
268 }
269
270 HorizontalHeaderView {
271 id: headerView
272 anchors.left: tableView.left
273 anchors.right: tableView.right
274 anchors.top: parent.top
275 syncView: tableView
276 clip: true
277
278 delegate: Rectangle {
279 implicitWidth: column === 0 ? ScreenTools.implicitCheckBoxHeight + ScreenTools.defaultFontPixelWidth
280 : headerLabel.contentWidth + ScreenTools.defaultFontPixelWidth
281 implicitHeight: headerLabel.contentHeight + ScreenTools.defaultFontPixelHeight * 0.5
282 color: qgcPal.windowCard
283
284 QGCLabel {
285 id: headerLabel
286 anchors.left: parent.left
287 anchors.leftMargin: ScreenTools.defaultFontPixelWidth / 2
288 anchors.verticalCenter: parent.verticalCenter
289 text: display
290 font.bold: true
291 }
292
293 // Top border
294 Rectangle {
295 anchors.top: parent.top
296 width: parent.width
297 height: 1
298 color: qgcPal.borderSubtle
299 }
300
301 // Left border
302 Rectangle {
303 anchors.left: parent.left
304 height: parent.height
305 width: 1
306 color: qgcPal.borderSubtle
307 }
308
309 // Right border (last column only)
310 Rectangle {
311 anchors.right: parent.right
312 height: parent.height
313 width: 1
314 color: qgcPal.borderSubtle
315 visible: column == 3
316 }
317
318 // Bottom border
319 Rectangle {
320 anchors.bottom: parent.bottom
321 width: parent.width
322 height: 1
323 color: qgcPal.borderSubtle
324 }
325 }
326 }
327
328 TableView {
329 id: tableView
330 anchors.leftMargin: ScreenTools.defaultFontPixelWidth
331 anchors.top: headerView.bottom
332 anchors.bottom: parent.bottom
333 anchors.left: _searchFilter ? parent.left : groupScroll.right
334 anchors.right: parent.right
335 columnSpacing: 0
336 rowSpacing: 0
337 model: controller.parameters
338 contentWidth: width
339 clip: true
340
341 // Qt is supposed to adjust column widths automatically when larger widths come into view.
342 // But it doesn't work. So we have to do it force a layout manually when we scroll.
343 Timer {
344 id: forceLayoutTimer
345 interval: 500
346 repeat: false
347 onTriggered: tableView.forceLayout()
348 }
349
350 onTopRowChanged: forceLayoutTimer.start()
351 onModelChanged: {
352 positionViewAtRow(0, TableView.AlignLeft | TableView.AlignTop)
353 forceLayoutTimer.start()
354 }
355
356 delegate: Rectangle {
357 implicitWidth: column === 0 ? ScreenTools.implicitCheckBoxHeight + ScreenTools.defaultFontPixelWidth
358 : column === 1 ? nameRow.implicitWidth + ScreenTools.defaultFontPixelWidth
359 : column === 2 ? ScreenTools.defaultFontPixelWidth * 16
360 : label.contentWidth + ScreenTools.defaultFontPixelWidth
361 implicitHeight: label.contentHeight + ScreenTools.defaultFontPixelHeight * 0.5
362 color: row % 2 === 0 ? "transparent" : qgcPal.windowCard
363 clip: true
364
365 // Bottom grid line
366 Rectangle {
367 anchors.bottom: parent.bottom
368 width: parent.width
369 height: 1
370 color: qgcPal.borderSubtle
371 }
372
373 // Left grid line
374 Rectangle {
375 anchors.left: parent.left
376 height: parent.height
377 width: 1
378 color: qgcPal.borderSubtle
379 }
380
381 // Right grid line (last column only)
382 Rectangle {
383 anchors.right: parent.right
384 height: parent.height
385 width: 1
386 color: qgcPal.borderSubtle
387 visible: column == 3
388 }
389
390 QGCCheckBox {
391 visible: column === 0
392 anchors.centerIn: parent
393 checked: _root._favorites.indexOf(fact.name) >= 0
394 z: 1
395 onClicked: controller.toggleFavorite(fact.name)
396 }
397
398 Row {
399 id: nameRow
400 visible: column === 1
401 anchors.left: parent.left
402 anchors.leftMargin: ScreenTools.defaultFontPixelWidth / 2
403 anchors.verticalCenter: parent.verticalCenter
404 spacing: lockIcon.visible ? ScreenTools.defaultFontPixelWidth / 3 : 0
405
406 QGCLabel {
407 text: column === 1 ? display : ""
408 anchors.verticalCenter: parent.verticalCenter
409 }
410
411 QGCColoredImage {
412 id: lockIcon
413 visible: fact.readOnly
414 source: "qrc:/InstrumentValueIcons/lock-closed.svg"
415 color: qgcPal.textPrimary
416 width: ScreenTools.defaultFontPixelHeight * 0.8
417 height: width
418 sourceSize.width: width
419 anchors.verticalCenter: parent.verticalCenter
420 }
421 }
422
423 QGCLabel {
424 id: label
425 visible: column !== 0 && column !== 1
426 anchors.left: parent.left
427 anchors.leftMargin: ScreenTools.defaultFontPixelWidth / 2
428 anchors.verticalCenter: parent.verticalCenter
429 width: column == 2 ? ScreenTools.defaultFontPixelWidth * 15 : implicitWidth
430 text: column == 2 ? col1String() : display
431 color: column == 2 && fact.defaultValueAvailable && !fact.valueEqualsDefault ? qgcPal.modifiedParamValue : qgcPal.textPrimary
432 font.bold: column == 2 && fact.defaultValueAvailable && !fact.valueEqualsDefault
433 maximumLineCount: 1
434 elide: column == 2 ? Text.ElideRight : Text.ElideNone
435
436 function col1String() {
437 if (fact.enumStrings.length === 0) {
438 return fact.valueString + " " + fact.units
439 }
440 if (fact.bitmaskStrings.length != 0) {
441 return fact.selectedBitmaskStrings.join(',')
442 }
443 return fact.enumStringValue
444 }
445 }
446
447 QGCMouseArea {
448 anchors.fill: parent
449 visible: column !== 0
450 onClicked: mouse => {
451 _editorDialogFact = fact
452 editorDialogFactory.open()
453 }
454 }
455 }
456 }
457 }
458 }
459}