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
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
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
31 ParameterEditorController { id: controller; }
33 QGCPalette { id: qgcPal; colorGroupEnabled: true }
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
43 var errorString = fact.validate(valueField.text, forceSave.checked)
44 if (errorString === "") {
45 fact.value = valueField.text
46 fact.valueChanged(fact.value)
48 validationError.text = errorString
49 if (_allowForceSave) {
50 forceSave.visible = true
57 function bitmaskValue() {
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];
68 Component.onCompleted: {
69 valueField.text = fact.valueString
73 width: Math.min(mainWindow.width * .75, Math.max(ScreenTools.defaultFontPixelWidth * 60, editRow.width))
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
88 Layout.fillWidth: true
89 wrapMode: Text.WordWrap
90 color: qgcPal.warningText
96 spacing: _columnSpacing
97 visible: !_readOnlyDisplay
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
107 Qt.ImhFormattedNumbersOnly // Forces use of virtual numeric keyboard
108 visible: !_showCombo || manualEntry.checked
113 width: _editFieldWidth
114 model: fact.enumStrings
117 focus: setFocus && visible
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.
123 currentIndex = fact.enumIndex
127 onCurrentIndexChanged: {
128 if (currentIndex >=0 && currentIndex < model.length) {
129 valueField.text = fact.enumValues[currentIndex]
135 visible: _allowDefaultReset
136 text: qsTr("Reset To Default")
139 fact.value = fact.defaultValue
140 fact.valueChanged(fact.value)
147 visible: _readOnlyDisplay
148 text: qsTr("Value: ") + fact.valueString + (fact.units != "" ? (" " + fact.units) : "")
154 visible: fact.bitmaskStrings.length > 0 && !_readOnlyDisplay
158 model: fact.bitmaskStrings
160 delegate : QGCCheckBox {
162 checked : fact.value & fact.bitmaskValues[index]
165 valueField.text = bitmaskValue()
172 Layout.fillWidth: true
173 wrapMode: Text.WordWrap
174 visible: !longDescriptionLabel.visible
175 text: fact.shortDescription
179 id: longDescriptionLabel
180 Layout.fillWidth: true
181 wrapMode: Text.WordWrap
182 visible: fact.longDescription != ""
183 text: fact.longDescription
187 spacing: _columnSpacing
191 text: qsTr("Min: ") + fact.minString
192 visible: !fact.minIsDefaultForType
196 text: qsTr("Max: ") + fact.maxString
197 visible: !fact.maxIsDefaultForType
201 text: qsTr("Default: ") + fact.defaultValueString
202 visible: _allowDefaultReset
207 visible: fact.vehicleRebootRequired
208 text: qsTr("Vehicle reboot required after change")
212 visible: fact.qgcRebootRequired
213 text: qsTr("Application restart required after change")
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
227 text: qsTr("Force save (dangerous!)")
232 text: qsTr("Advanced settings")
233 visible: _allowForceEdit || (!_readOnlyDisplay && (showRCToParam || factCombo.visible || bitmaskColumn.visible))
236 // Force-edit escape hatch for read-only params. Nested under the
237 // Advanced settings checkbox so it is never shown without opt-in.
240 visible: _allowForceEdit && advancedCheckbox.checked
241 text: qsTr("Force edit read-only param")
243 // Re-lock the param if Advanced settings is unchecked, so edit
244 // mode can never persist without the Advanced checkbox checked.
251 // Clear any stale validation/force-save state when the param is re-locked.
254 validationError.text = ""
255 forceSave.visible = false
260 // Checkbox to allow manual entry of enumerated or bitmask parameters
263 visible: advancedCheckbox.checked && !_readOnlyDisplay && (factCombo.visible || bitmaskColumn.visible)
264 text: qsTr("Manual Entry")
267 valueField.text = fact.valueString
272 text: qsTr("Set RC to Param")
273 visible: advancedCheckbox.checked && !_readOnlyDisplay && showRCToParam
274 onClicked: rcToParamDialogFactory.open()
278 QGCPopupDialogFactory {
279 id: rcToParamDialogFactory
281 dialogComponent: rcToParamDialog