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