7import QGroundControl.Controls
8import QGroundControl.FactControls
12 title: fact.componentId > 0 ? fact.name : qsTr("Value Editor")
14 buttons: _readOnlyDisplay ? Dialog.Close : (Dialog.Save | Dialog.Cancel)
17 property bool showRCToParam: false
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
30 ParameterEditorController { id: controller; }
32 QGCPalette { id: qgcPal; colorGroupEnabled: true }
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
42 var errorString = fact.validate(valueField.text, forceSave.checked)
43 if (errorString === "") {
44 fact.value = valueField.text
45 fact.valueChanged(fact.value)
47 validationError.text = errorString
48 if (_allowForceSave) {
49 forceSave.visible = true
56 function bitmaskValue() {
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];
67 Component.onCompleted: {
68 valueField.text = fact.valueString
72 width: Math.min(mainWindow.width * .75, Math.max(ScreenTools.defaultFontPixelWidth * 60, editRow.width))
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
87 Layout.fillWidth: true
88 wrapMode: Text.WordWrap
89 color: qgcPal.warningText
95 spacing: _columnSpacing
96 visible: !_readOnlyDisplay
100 width: _editFieldWidth
101 unitsLabel: fact.units
102 showUnits: fact.units != ""
104 inputMethodHints: (fact.typeIsString || ScreenTools.isiOS) ? // iOS numeric keyboard has no done button, we can't use it
106 Qt.ImhFormattedNumbersOnly // Forces use of virtual numeric keyboard
107 visible: !_showCombo || manualEntry.checked
112 width: _editFieldWidth
113 model: fact.enumStrings
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.
122 currentIndex = fact.enumIndex
126 onCurrentIndexChanged: {
127 if (currentIndex >=0 && currentIndex < model.length) {
128 valueField.text = fact.enumValues[currentIndex]
134 visible: _allowDefaultReset
135 text: qsTr("Reset To Default")
138 fact.value = fact.defaultValue
139 fact.valueChanged(fact.value)
146 visible: _readOnlyDisplay
147 text: qsTr("Value: ") + fact.valueString + (fact.units != "" ? (" " + fact.units) : "")
153 visible: fact.bitmaskStrings.length > 0 && !_readOnlyDisplay
157 model: fact.bitmaskStrings
159 delegate : QGCCheckBox {
161 checked : fact.value & fact.bitmaskValues[index]
164 valueField.text = bitmaskValue()
171 Layout.fillWidth: true
172 wrapMode: Text.WordWrap
173 visible: !longDescriptionLabel.visible
174 text: fact.shortDescription
178 id: longDescriptionLabel
179 Layout.fillWidth: true
180 wrapMode: Text.WordWrap
181 visible: fact.longDescription != ""
182 text: fact.longDescription
186 spacing: _columnSpacing
190 text: qsTr("Min: ") + fact.minString
191 visible: !fact.minIsDefaultForType
195 text: qsTr("Max: ") + fact.maxString
196 visible: !fact.maxIsDefaultForType
200 text: qsTr("Default: ") + fact.defaultValueString
201 visible: _allowDefaultReset
206 visible: fact.vehicleRebootRequired
207 text: qsTr("Vehicle reboot required after change")
211 visible: fact.qgcRebootRequired
212 text: qsTr("Application restart required after change")
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
226 text: qsTr("Force save (dangerous!)")
231 text: qsTr("Advanced settings")
232 visible: _allowForceEdit || (!_readOnlyDisplay && (showRCToParam || factCombo.visible || bitmaskColumn.visible))
235 // Force-edit escape hatch for read-only params. Nested under the
236 // Advanced settings checkbox so it is never shown without opt-in.
239 visible: _allowForceEdit && advancedCheckbox.checked
240 text: qsTr("Force edit read-only param")
242 // Re-lock the param if Advanced settings is unchecked, so edit
243 // mode can never persist without the Advanced checkbox checked.
250 // Clear any stale validation/force-save state when the param is re-locked.
253 validationError.text = ""
254 forceSave.visible = false
259 // Checkbox to allow manual entry of enumerated or bitmask parameters
262 visible: advancedCheckbox.checked && !_readOnlyDisplay && (factCombo.visible || bitmaskColumn.visible)
263 text: qsTr("Manual Entry")
266 valueField.text = fact.valueString
271 text: qsTr("Set RC to Param")
272 visible: advancedCheckbox.checked && !_readOnlyDisplay && showRCToParam
273 onClicked: rcToParamDialogFactory.open()
277 QGCPopupDialogFactory {
278 id: rcToParamDialogFactory
280 dialogComponent: rcToParamDialog