ParameterEditorDialog.qml 10.6 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
Don Gagne's avatar
Don Gagne committed
9

10 11 12
import QtQuick          2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts  1.2
13
import QtQuick.Dialogs  1.3
Don Gagne's avatar
Don Gagne committed
14

15
import QGroundControl               1.0
16 17 18 19 20 21
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controllers   1.0
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
import QGroundControl.ScreenTools   1.0
Don Gagne's avatar
Don Gagne committed
22 23

QGCViewDialog {
24 25
    id:     root
    focus:  true
26

Don Gagne's avatar
Don Gagne committed
27
    property Fact   fact
28
    property bool   showRCToParam:  false
Don Gagne's avatar
Don Gagne committed
29 30
    property bool   validate:       false
    property string validateValue
31
    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
Don Gagne's avatar
Don Gagne committed
32

33 34
    signal valueChanged

Don Gagne's avatar
Don Gagne committed
35 36
    property real   _editFieldWidth:            ScreenTools.defaultFontPixelWidth * 20
    property bool   _longDescriptionAvailable:  fact.longDescription != ""
37 38 39
    property bool   _editingParameter:          fact.componentId != 0
    property bool   _allowForceSave:            QGroundControl.corePlugin.showAdvancedUI || !_editingParameter
    property bool   _allowDefaultReset:         fact.defaultValueAvailable && (QGroundControl.corePlugin.showAdvancedUI || !_editingParameter)
dogmaphobic's avatar
dogmaphobic committed
40

41
    ParameterEditorController { id: controller; }
Don Gagne's avatar
Don Gagne committed
42

43 44
    QGCPalette { id: qgcPal; colorGroupEnabled: true }

Don Gagne's avatar
Don Gagne committed
45
    function accept() {
46 47
        if (bitmaskColumn.visible && !manualEntry.checked) {
            fact.value = bitmaskValue();
48
            fact.valueChanged(fact.value)
49
            valueChanged()
50
            hideDialog();
51
        } else if (factCombo.visible && !manualEntry.checked) {
52
            fact.enumIndex = factCombo.currentIndex
53
            valueChanged()
Don Gagne's avatar
Don Gagne committed
54 55
            hideDialog()
        } else {
56
            var errorString = fact.validate(valueField.text, forceSave.checked)
57
            if (errorString === "") {
58 59
                fact.value = valueField.text
                fact.valueChanged(fact.value)
60
                valueChanged()
61 62 63
                hideDialog()
            } else {
                validationError.text = errorString
64 65 66
                if (_allowForceSave) {
                    forceSave.visible = true
                }
67
            }
Don Gagne's avatar
Don Gagne committed
68 69 70
        }
    }

71 72 73 74 75
    function reject() {
        fact.valueChanged(fact.value)
        hideDialog();
    }

76 77 78 79 80 81 82 83 84 85 86
    function bitmaskValue() {
        var value = 0;
        for (var i = 0; i < fact.bitmaskValues.length; ++i) {
            var checkbox = bitmaskRepeater.itemAt(i)
            if (checkbox.checked) {
                value |= fact.bitmaskValues[i];
            }
        }
        return value
    }

Don Gagne's avatar
Don Gagne committed
87 88 89
    Component.onCompleted: {
        if (validate) {
            validationError.text = fact.validate(validateValue, false /* convertOnly */)
90 91 92
            if (_allowForceSave) {
                forceSave.visible = true
            }
Don Gagne's avatar
Don Gagne committed
93 94 95
        }
    }

96
    QGCFlickable {
97
        id:                 flickable
98 99 100 101 102 103
        anchors.fill:       parent
        contentHeight:      _column.y + _column.height
        flickableDirection: Flickable.VerticalFlick

        Column {
            id:             _column
104
            spacing:        globals.defaultTextHeight
105 106 107 108
            anchors.left:   parent.left
            anchors.right:  parent.right

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
109
                id:         validationError
110 111
                width:      parent.width
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
112
                color:      qgcPal.warningText
113
            }
Don Gagne's avatar
Don Gagne committed
114

Don Gagne's avatar
Don Gagne committed
115
            RowLayout {
116
                spacing:        ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
117 118
                anchors.left:   parent.left
                anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
119

120
                QGCTextField {
Don Gagne's avatar
Don Gagne committed
121 122
                    id:                 valueField
                    text:               validate ? validateValue : fact.valueString
123
                    visible:            fact.enumStrings.length === 0 || validate || manualEntry.checked
Don Gagne's avatar
Don Gagne committed
124 125 126
                    unitsLabel:         fact.units
                    showUnits:          fact.units != ""
                    Layout.fillWidth:   true
127
                    focus:              setFocus
128
                    inputMethodHints:   (fact.typeIsString || ScreenTools.isiOS) ?
129 130
                                            Qt.ImhNone :                // iOS numeric keyboard has no done button, we can't use it
                                            Qt.ImhFormattedNumbersOnly  // Forces use of virtual numeric keyboard
131 132 133
                }

                QGCButton {
DonLakeFlyer's avatar
DonLakeFlyer committed
134 135
                    visible:    _allowDefaultReset
                    text:       qsTr("Reset to default")
136 137 138 139 140 141 142 143

                    onClicked: {
                        fact.value = fact.defaultValue
                        fact.valueChanged(fact.value)
                        hideDialog()
                    }
                }
            }
Don Gagne's avatar
Don Gagne committed
144

145 146
            QGCComboBox {
                id:             factCombo
Don Gagne's avatar
Don Gagne committed
147 148
                anchors.left:   parent.left
                anchors.right:  parent.right
149 150
                visible:        _showCombo
                model:          fact.enumStrings
151

152
                property bool _showCombo: fact.enumStrings.length !== 0 && fact.bitmaskStrings.length === 0 && !validate
153

154 155 156 157 158 159
                Component.onCompleted: {
                    // We can't bind directly to fact.enumIndex since that would add an unknown value
                    // if there are no enum strings.
                    if (_showCombo) {
                        currentIndex = fact.enumIndex
                    }
160
                }
161 162

                onCurrentIndexChanged: {
DonLakeFlyer's avatar
DonLakeFlyer committed
163 164 165
                    if (currentIndex >=0 && currentIndex < model.length) {
                        valueField.text = fact.enumValues[currentIndex]
                    }
166
                }
167 168
            }

169
            Column {
Don Gagne's avatar
Don Gagne committed
170 171 172 173
                id:         bitmaskColumn
                spacing:    ScreenTools.defaultFontPixelHeight / 2
                visible:    fact.bitmaskStrings.length > 0 ? true : false;

174
                Repeater {
Don Gagne's avatar
Don Gagne committed
175 176
                    id:     bitmaskRepeater
                    model:  fact.bitmaskStrings
177

178 179 180
                    delegate : QGCCheckBox {
                        text : modelData
                        checked : fact.value & fact.bitmaskValues[index]
181 182 183 184

                        onClicked: {
                            valueField.text = bitmaskValue()
                        }
185 186 187 188
                    }
                }
            }

189
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
190 191 192 193
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    !longDescriptionLabel.visible
                text:       fact.shortDescription
194
            }
Don Gagne's avatar
Don Gagne committed
195

Don Gagne's avatar
Don Gagne committed
196 197 198 199 200 201 202
            QGCLabel {
                id:         longDescriptionLabel
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    fact.longDescription != ""
                text:       fact.longDescription
            }
Don Gagne's avatar
Don Gagne committed
203

Don Gagne's avatar
Don Gagne committed
204
            Row {
205
                spacing: ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
206

Don Gagne's avatar
Don Gagne committed
207 208 209 210
                QGCLabel {
                    id:         minValueDisplay
                    text:       qsTr("Min: ") + fact.minString
                    visible:    !fact.minIsDefaultForType
211
                }
Don Gagne's avatar
Don Gagne committed
212

Don Gagne's avatar
Don Gagne committed
213 214 215
                QGCLabel {
                    text:       qsTr("Max: ") + fact.maxString
                    visible:    !fact.maxIsDefaultForType
216 217 218
                }

                QGCLabel {
Don Gagne's avatar
Don Gagne committed
219
                    text:       qsTr("Default: ") + fact.defaultValueString
220
                    visible:    _allowDefaultReset
221
                }
Don Gagne's avatar
Don Gagne committed
222
            }
Don Gagne's avatar
Don Gagne committed
223

224
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
225 226 227 228 229
                text:       qsTr("Parameter name: ") + fact.name
                visible:    fact.componentId > 0 // > 0 means it's a parameter fact
            }

            QGCLabel {
230 231 232 233 234 235
                visible:    fact.vehicleRebootRequired
                text:       "Vehicle reboot required after change"
            }

            QGCLabel {
                visible:    fact.qgcRebootRequired
236
                text:       "Application restart required after change"
237
            }
Don Gagne's avatar
Don Gagne committed
238

239 240 241
            QGCLabel {
                width:      parent.width
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
242 243
                text:       qsTr("Warning: Modifying values while vehicle is in flight can lead to vehicle instability and possible vehicle loss. ") +
                            qsTr("Make sure you know what you are doing and double-check your values before Save!")
DonLakeFlyer's avatar
DonLakeFlyer committed
244
                visible:    fact.componentId != -1
245
            }
Don Gagne's avatar
Don Gagne committed
246

247 248 249
            QGCCheckBox {
                id:         forceSave
                visible:    false
250
                text:       qsTr("Force save (dangerous!)")
251
            }
Don Gagne's avatar
Don Gagne committed
252

253 254 255
            Row {
                width:      parent.width
                spacing:    ScreenTools.defaultFontPixelWidth / 2
256
                visible:    showRCToParam || factCombo.visible || bitmaskColumn.visible
Don Gagne's avatar
Don Gagne committed
257

258 259 260 261 262 263
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
Don Gagne's avatar
Don Gagne committed
264

265 266
                QGCCheckBox {
                    id:     _advanced
267
                    text:   qsTr("Advanced settings")
268
                }
Don Gagne's avatar
Don Gagne committed
269

270 271 272 273 274 275 276 277
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
            }

278 279 280 281 282 283 284 285 286 287 288
            // Checkbox to allow manual entry of enumerated or bitmask parameters
            QGCCheckBox {
                id:         manualEntry
                visible:    _advanced.checked && (factCombo.visible || bitmaskColumn.visible)
                text:       qsTr("Manual Entry")

                onClicked: {
                    valueField.text = fact.valueString
                }
            }

289
            QGCButton {
290 291 292 293
                text:       qsTr("Set RC to Param")
                width:      _editFieldWidth
                visible:    _advanced.checked && !validate && showRCToParam
                onClicked:  mainWindow.showPopupDialogFromComponent(rcToParamDialog)
294 295
            }
        } // Column
Don Gagne's avatar
Don Gagne committed
296
    }
297 298 299 300 301 302 303 304

    Component {
        id: rcToParamDialog

        RCToParamDialog {
            tuningFact: fact
        }
    }
Don Gagne's avatar
Don Gagne committed
305
} // QGCViewDialog