ParameterEditorDialog.qml 10.2 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * 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
Don Gagne's avatar
Don Gagne committed
13

14
import QGroundControl               1.0
15 16 17 18 19 20
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
21 22

QGCViewDialog {
23 24
    id: root

Don Gagne's avatar
Don Gagne committed
25
    property Fact   fact
26
    property bool   showRCToParam:  false
Don Gagne's avatar
Don Gagne committed
27 28 29
    property bool   validate:       false
    property string validateValue

Don Gagne's avatar
Don Gagne committed
30 31
    property real   _editFieldWidth:            ScreenTools.defaultFontPixelWidth * 20
    property bool   _longDescriptionAvailable:  fact.longDescription != ""
32 33 34
    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
35

Don Gagne's avatar
Don Gagne committed
36 37
    ParameterEditorController { id: controller; factPanel: parent }

38 39
    QGCPalette { id: qgcPal; colorGroupEnabled: true }

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

63 64 65 66 67
    function reject() {
        fact.valueChanged(fact.value)
        hideDialog();
    }

68 69 70 71 72 73 74 75 76 77 78
    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
79 80 81
    Component.onCompleted: {
        if (validate) {
            validationError.text = fact.validate(validateValue, false /* convertOnly */)
82 83 84
            if (_allowForceSave) {
                forceSave.visible = true
            }
Don Gagne's avatar
Don Gagne committed
85 86 87
        }
    }

88 89 90
	// set focus to the text field when becoming visible (in case of an Enum,
	// the valueField is not visible, but it's not an issue because the combo
	// box cannot have a focus)
91
	onVisibleChanged: if (visible && !ScreenTools.isMobile) valueField.forceActiveFocus()
92

93 94 95 96 97 98 99 100 101 102 103 104
    QGCFlickable {
        anchors.fill:       parent
        contentHeight:      _column.y + _column.height
        flickableDirection: Flickable.VerticalFlick

        Column {
            id:             _column
            spacing:        defaultTextHeight
            anchors.left:   parent.left
            anchors.right:  parent.right

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
105
                id:         validationError
106 107
                width:      parent.width
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
108
                color:      qgcPal.warningText
109
            }
Don Gagne's avatar
Don Gagne committed
110

Don Gagne's avatar
Don Gagne committed
111 112 113 114
            RowLayout {
                spacing:        defaultTextWidth
                anchors.left:   parent.left
                anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
115

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

                QGCButton {
                    anchors.baseline:   valueField.baseline
130
                    visible:            _allowDefaultReset
131
                    text:               qsTr("Reset to default")
132 133 134 135 136 137 138 139

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

141 142
            QGCComboBox {
                id:             factCombo
Don Gagne's avatar
Don Gagne committed
143 144
                anchors.left:   parent.left
                anchors.right:  parent.right
145 146
                visible:        _showCombo
                model:          fact.enumStrings
147

148
                property bool _showCombo: fact.enumStrings.length != 0 && fact.bitmaskStrings.length == 0 && !validate
149

150 151 152 153 154 155
                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
                    }
156
                }
157 158

                onCurrentIndexChanged: {
DonLakeFlyer's avatar
DonLakeFlyer committed
159 160 161
                    if (currentIndex >=0 && currentIndex < model.length) {
                        valueField.text = fact.enumValues[currentIndex]
                    }
162
                }
163 164
            }

165
            Column {
Don Gagne's avatar
Don Gagne committed
166 167 168 169
                id:         bitmaskColumn
                spacing:    ScreenTools.defaultFontPixelHeight / 2
                visible:    fact.bitmaskStrings.length > 0 ? true : false;

170
                Repeater {
Don Gagne's avatar
Don Gagne committed
171 172
                    id:     bitmaskRepeater
                    model:  fact.bitmaskStrings
173

174 175 176
                    delegate : QGCCheckBox {
                        text : modelData
                        checked : fact.value & fact.bitmaskValues[index]
177 178 179 180

                        onClicked: {
                            valueField.text = bitmaskValue()
                        }
181 182 183 184
                    }
                }
            }

185
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
186 187 188 189
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    !longDescriptionLabel.visible
                text:       fact.shortDescription
190
            }
Don Gagne's avatar
Don Gagne committed
191

Don Gagne's avatar
Don Gagne committed
192 193 194 195 196 197 198
            QGCLabel {
                id:         longDescriptionLabel
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    fact.longDescription != ""
                text:       fact.longDescription
            }
Don Gagne's avatar
Don Gagne committed
199

Don Gagne's avatar
Don Gagne committed
200 201
            Row {
                spacing: defaultTextWidth
Don Gagne's avatar
Don Gagne committed
202

Don Gagne's avatar
Don Gagne committed
203 204 205 206
                QGCLabel {
                    id:         minValueDisplay
                    text:       qsTr("Min: ") + fact.minString
                    visible:    !fact.minIsDefaultForType
207
                }
Don Gagne's avatar
Don Gagne committed
208

Don Gagne's avatar
Don Gagne committed
209 210 211
                QGCLabel {
                    text:       qsTr("Max: ") + fact.maxString
                    visible:    !fact.maxIsDefaultForType
212 213 214
                }

                QGCLabel {
Don Gagne's avatar
Don Gagne committed
215
                    text:       qsTr("Default: ") + fact.defaultValueString
216
                    visible:    _allowDefaultReset
217
                }
Don Gagne's avatar
Don Gagne committed
218
            }
Don Gagne's avatar
Don Gagne committed
219

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

            QGCLabel {
                visible:    fact.rebootRequired
                text:       "Reboot required after change"
228
            }
Don Gagne's avatar
Don Gagne committed
229

230 231 232
            QGCLabel {
                width:      parent.width
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
233 234
                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
235
                visible:    fact.componentId != -1
236
            }
Don Gagne's avatar
Don Gagne committed
237

238 239 240
            QGCCheckBox {
                id:         forceSave
                visible:    false
241
                text:       qsTr("Force save (dangerous!)")
242
            }
Don Gagne's avatar
Don Gagne committed
243

244 245 246
            Row {
                width:      parent.width
                spacing:    ScreenTools.defaultFontPixelWidth / 2
247
                visible:    showRCToParam || factCombo.visible || bitmaskColumn.visible
Don Gagne's avatar
Don Gagne committed
248

249 250 251 252 253 254
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
Don Gagne's avatar
Don Gagne committed
255

256 257
                QGCCheckBox {
                    id:     _advanced
258
                    text:   qsTr("Advanced settings")
259
                }
Don Gagne's avatar
Don Gagne committed
260

261 262 263 264 265 266 267 268
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
            }

269 270 271 272 273 274 275 276 277 278 279
            // 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
                }
            }

280
            QGCButton {
281
                text:           qsTr("Set RC to Param...")
dogmaphobic's avatar
dogmaphobic committed
282
                width:          _editFieldWidth
283 284 285 286
                visible:        _advanced.checked && !validate && showRCToParam
                onClicked:      controller.setRCToParam(fact.name)
            }
        } // Column
Don Gagne's avatar
Don Gagne committed
287 288
    }
} // QGCViewDialog