ParameterEditorDialog.qml 10.4 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.
 *
 ****************************************************************************/
9

10 11 12
import QtQuick          2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts  1.2
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
21 22

QGCViewDialog {
23 24
    id:     root
    focus:  true
25

26
    property Fact   fact
27
    property bool   showRCToParam:  false
28 29
    property bool   validate:       false
    property string validateValue
30
    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
31

32 33
    signal valueChanged

34 35
    property real   _editFieldWidth:            ScreenTools.defaultFontPixelWidth * 20
    property bool   _longDescriptionAvailable:  fact.longDescription != ""
36 37 38
    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
39

40 41
    ParameterEditorController { id: controller; factPanel: parent }

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

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

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

75 76 77 78 79 80 81 82 83 84 85
    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
    }

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

95
    QGCFlickable {
96
        id:                 flickable
97 98 99 100 101 102 103 104 105 106 107
        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 {
108
                id:         validationError
109 110
                width:      parent.width
                wrapMode:   Text.WordWrap
111
                color:      qgcPal.warningText
112
            }
113

114 115 116 117
            RowLayout {
                spacing:        defaultTextWidth
                anchors.left:   parent.left
                anchors.right:  parent.right
118

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

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

                    onClicked: {
                        fact.value = fact.defaultValue
                        fact.valueChanged(fact.value)
                        hideDialog()
                    }
                }
            }
143

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

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

153 154 155 156 157 158
                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
                    }
159
                }
160 161

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

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

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

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

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

188
            QGCLabel {
189 190 191 192
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    !longDescriptionLabel.visible
                text:       fact.shortDescription
193
            }
194

195 196 197 198 199 200 201
            QGCLabel {
                id:         longDescriptionLabel
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    fact.longDescription != ""
                text:       fact.longDescription
            }
202

203 204
            Row {
                spacing: defaultTextWidth
205

206 207 208 209
                QGCLabel {
                    id:         minValueDisplay
                    text:       qsTr("Min: ") + fact.minString
                    visible:    !fact.minIsDefaultForType
210
                }
211

212 213 214
                QGCLabel {
                    text:       qsTr("Max: ") + fact.maxString
                    visible:    !fact.maxIsDefaultForType
215 216 217
                }

                QGCLabel {
218
                    text:       qsTr("Default: ") + fact.defaultValueString
219
                    visible:    _allowDefaultReset
220
                }
221
            }
222

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

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

            QGCLabel {
                visible:    fact.qgcRebootRequired
                text:       "Appliction restart required after change"
236
            }
237

238 239 240
            QGCLabel {
                width:      parent.width
                wrapMode:   Text.WordWrap
241 242
                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!")
243
                visible:    fact.componentId != -1
244
            }
245

246 247 248
            QGCCheckBox {
                id:         forceSave
                visible:    false
249
                text:       qsTr("Force save (dangerous!)")
250
            }
251

252 253 254
            Row {
                width:      parent.width
                spacing:    ScreenTools.defaultFontPixelWidth / 2
255
                visible:    showRCToParam || factCombo.visible || bitmaskColumn.visible
256

257 258 259 260 261 262
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
263

264 265
                QGCCheckBox {
                    id:     _advanced
266
                    text:   qsTr("Advanced settings")
267
                }
268

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

277 278 279 280 281 282 283 284 285 286 287
            // 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
                }
            }

288
            QGCButton {
289
                text:           qsTr("Set RC to Param...")
dogmaphobic's avatar
dogmaphobic committed
290
                width:          _editFieldWidth
291 292 293 294
                visible:        _advanced.checked && !validate && showRCToParam
                onClicked:      controller.setRCToParam(fact.name)
            }
        } // Column
295 296
    }
} // QGCViewDialog