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