QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ParameterEditorDialog.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4import QtQuick.Dialogs
5
6import QGroundControl
7import QGroundControl.Controls
8import QGroundControl.FactControls
9
10QGCPopupDialog {
11 id: root
12 title: fact.componentId > 0 ? fact.name : qsTr("Value Editor")
13
14 buttons: _readOnlyDisplay ? Dialog.Close : (Dialog.Save | Dialog.Cancel)
15
16 property Fact fact
17 property bool showRCToParam: false
18
19 property real _editFieldWidth: ScreenTools.defaultFontPixelWidth * 20
20 property bool _longDescriptionAvailable: fact.longDescription != ""
21 property bool _editingParameter: fact.componentId != 0
22 property bool _allowForceSave: QGroundControl.corePlugin.showAdvancedUI && _editingParameter
23 property bool _allowDefaultReset: fact.defaultValueAvailable
24 property bool _showCombo: fact.enumStrings.length !== 0 && fact.bitmaskStrings.length === 0
25 property bool _readOnlyDisplay: fact.readOnly && !forceEdit.checked
26 property bool _allowForceEdit: fact.readOnly && _allowForceSave
27 property real _rowSpacing: ScreenTools.defaultFontPixelHeight / 2
28 property real _columnSpacing: ScreenTools.defaultFontPixelWidth
29
30 ParameterEditorController { id: controller; }
31
32 QGCPalette { id: qgcPal; colorGroupEnabled: true }
33
34 onAccepted: {
35 if (_readOnlyDisplay) return
36 if (bitmaskColumn.visible && !manualEntry.checked) {
37 fact.value = bitmaskValue();
38 fact.valueChanged(fact.value)
39 } else if (factCombo.visible && !manualEntry.checked) {
40 fact.enumIndex = factCombo.currentIndex
41 } else {
42 var errorString = fact.validate(valueField.text, forceSave.checked)
43 if (errorString === "") {
44 fact.value = valueField.text
45 fact.valueChanged(fact.value)
46 } else {
47 validationError.text = errorString
48 if (_allowForceSave) {
49 forceSave.visible = true
50 }
51 preventClose = true
52 }
53 }
54 }
55
56 function bitmaskValue() {
57 var value = 0;
58 for (var i = 0; i < fact.bitmaskValues.length; ++i) {
59 var checkbox = bitmaskRepeater.itemAt(i)
60 if (checkbox.checked) {
61 value |= fact.bitmaskValues[i];
62 }
63 }
64 return value
65 }
66
67 Component.onCompleted: {
68 valueField.text = fact.valueString
69 }
70
71 ColumnLayout {
72 width: Math.min(mainWindow.width * .75, Math.max(ScreenTools.defaultFontPixelWidth * 60, editRow.width))
73 spacing: _rowSpacing
74
75 QGCLabel {
76 Layout.fillWidth: true
77 wrapMode: Text.WordWrap
78 text: forceEdit.checked
79 ? qsTr("Warning: This parameter is read-only. Force edit is enabled.")
80 : qsTr("This parameter is read-only and cannot be modified.")
81 color: forceEdit.checked ? qgcPal.warningText : qgcPal.text
82 visible: fact.readOnly
83 }
84
85 QGCLabel {
86 id: validationError
87 Layout.fillWidth: true
88 wrapMode: Text.WordWrap
89 color: qgcPal.warningText
90 visible: text !== ""
91 }
92
93 RowLayout {
94 id: editRow
95 spacing: _columnSpacing
96 visible: !_readOnlyDisplay
97
98 QGCTextField {
99 id: valueField
100 width: _editFieldWidth
101 unitsLabel: fact.units
102 showUnits: fact.units != ""
103 focus: visible
104 inputMethodHints: (fact.typeIsString || ScreenTools.isiOS) ? // iOS numeric keyboard has no done button, we can't use it
105 Qt.ImhNone :
106 Qt.ImhFormattedNumbersOnly // Forces use of virtual numeric keyboard
107 visible: !_showCombo || manualEntry.checked
108 }
109
110 QGCComboBox {
111 id: factCombo
112 width: _editFieldWidth
113 model: fact.enumStrings
114 sizeToContents: true
115 visible: _showCombo
116 focus: visible
117
118 Component.onCompleted: {
119 // We can't bind directly to fact.enumIndex since that would add an unknown value
120 // if there are no enum strings.
121 if (_showCombo) {
122 currentIndex = fact.enumIndex
123 }
124 }
125
126 onCurrentIndexChanged: {
127 if (currentIndex >=0 && currentIndex < model.length) {
128 valueField.text = fact.enumValues[currentIndex]
129 }
130 }
131 }
132
133 QGCButton {
134 visible: _allowDefaultReset
135 text: qsTr("Reset To Default")
136
137 onClicked: {
138 fact.value = fact.defaultValue
139 fact.valueChanged(fact.value)
140 close()
141 }
142 }
143 }
144
145 QGCLabel {
146 visible: _readOnlyDisplay
147 text: qsTr("Value: ") + fact.valueString + (fact.units != "" ? (" " + fact.units) : "")
148 }
149
150 Column {
151 id: bitmaskColumn
152 spacing: _rowSpacing
153 visible: fact.bitmaskStrings.length > 0 && !_readOnlyDisplay
154
155 Repeater {
156 id: bitmaskRepeater
157 model: fact.bitmaskStrings
158
159 delegate : QGCCheckBox {
160 text : modelData
161 checked : fact.value & fact.bitmaskValues[index]
162
163 onClicked: {
164 valueField.text = bitmaskValue()
165 }
166 }
167 }
168 }
169
170 QGCLabel {
171 Layout.fillWidth: true
172 wrapMode: Text.WordWrap
173 visible: !longDescriptionLabel.visible
174 text: fact.shortDescription
175 }
176
177 QGCLabel {
178 id: longDescriptionLabel
179 Layout.fillWidth: true
180 wrapMode: Text.WordWrap
181 visible: fact.longDescription != ""
182 text: fact.longDescription
183 }
184
185 RowLayout {
186 spacing: _columnSpacing
187
188 QGCLabel {
189 id: minValueDisplay
190 text: qsTr("Min: ") + fact.minString
191 visible: !fact.minIsDefaultForType
192 }
193
194 QGCLabel {
195 text: qsTr("Max: ") + fact.maxString
196 visible: !fact.maxIsDefaultForType
197 }
198
199 QGCLabel {
200 text: qsTr("Default: ") + fact.defaultValueString
201 visible: _allowDefaultReset
202 }
203 }
204
205 QGCLabel {
206 visible: fact.vehicleRebootRequired
207 text: qsTr("Vehicle reboot required after change")
208 }
209
210 QGCLabel {
211 visible: fact.qgcRebootRequired
212 text: qsTr("Application restart required after change")
213 }
214
215 QGCLabel {
216 Layout.fillWidth: true
217 wrapMode: Text.WordWrap
218 text: qsTr("Warning: Modifying values while vehicle is in flight can lead to vehicle instability and possible vehicle loss. ") +
219 qsTr("Make sure you know what you are doing and double-check your values before Save!")
220 visible: fact.componentId != -1 && !_readOnlyDisplay
221 }
222
223 QGCCheckBox {
224 id: forceSave
225 visible: false
226 text: qsTr("Force save (dangerous!)")
227 }
228
229 QGCCheckBox {
230 id: advancedCheckbox
231 text: qsTr("Advanced settings")
232 visible: _allowForceEdit || (!_readOnlyDisplay && (showRCToParam || factCombo.visible || bitmaskColumn.visible))
233 }
234
235 // Force-edit escape hatch for read-only params. Nested under the
236 // Advanced settings checkbox so it is never shown without opt-in.
237 QGCCheckBox {
238 id: forceEdit
239 visible: _allowForceEdit && advancedCheckbox.checked
240 text: qsTr("Force edit read-only param")
241
242 // Re-lock the param if Advanced settings is unchecked, so edit
243 // mode can never persist without the Advanced checkbox checked.
244 onVisibleChanged: {
245 if (!visible) {
246 checked = false
247 }
248 }
249
250 // Clear any stale validation/force-save state when the param is re-locked.
251 onCheckedChanged: {
252 if (!checked) {
253 validationError.text = ""
254 forceSave.visible = false
255 }
256 }
257 }
258
259 // Checkbox to allow manual entry of enumerated or bitmask parameters
260 QGCCheckBox {
261 id: manualEntry
262 visible: advancedCheckbox.checked && !_readOnlyDisplay && (factCombo.visible || bitmaskColumn.visible)
263 text: qsTr("Manual Entry")
264
265 onClicked: {
266 valueField.text = fact.valueString
267 }
268 }
269
270 QGCButton {
271 text: qsTr("Set RC to Param")
272 visible: advancedCheckbox.checked && !_readOnlyDisplay && showRCToParam
273 onClicked: rcToParamDialogFactory.open()
274 }
275 } // Column
276
277 QGCPopupDialogFactory {
278 id: rcToParamDialogFactory
279
280 dialogComponent: rcToParamDialog
281 }
282
283 Component {
284 id: rcToParamDialog
285
286 RCToParamDialog {
287 tuningFact: fact
288 }
289 }
290}