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