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
    focus:  true
25

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

31 32
    signal valueChanged

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

Don Gagne's avatar
Don Gagne committed
39 40
    ParameterEditorController { id: controller; factPanel: parent }

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

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

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

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

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

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

118
                QGCTextField {
Don Gagne's avatar
Don Gagne committed
119 120
                    id:                 valueField
                    text:               validate ? validateValue : fact.valueString
121
                    visible:            fact.enumStrings.length === 0 || validate || manualEntry.checked
Don Gagne's avatar
Don Gagne committed
122 123 124
                    unitsLabel:         fact.units
                    showUnits:          fact.units != ""
                    Layout.fillWidth:   true
125 126 127 128
                    focus:              true
                    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
129 130 131 132
                }

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

                    onClicked: {
                        fact.value = fact.defaultValue
                        fact.valueChanged(fact.value)
                        hideDialog()
                    }
                }
            }
Don Gagne's avatar
Don Gagne committed
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 {
Don Gagne's avatar
Don Gagne committed
189 190 191 192
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    !longDescriptionLabel.visible
                text:       fact.shortDescription
193
            }
Don Gagne's avatar
Don Gagne committed
194

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

Don Gagne's avatar
Don Gagne committed
203 204
            Row {
                spacing: defaultTextWidth
Don Gagne's avatar
Don Gagne committed
205

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

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

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

223
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
224 225 226 227 228 229 230
                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"
231
            }
Don Gagne's avatar
Don Gagne committed
232

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

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

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

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

259 260
                QGCCheckBox {
                    id:     _advanced
261
                    text:   qsTr("Advanced settings")
262
                }
Don Gagne's avatar
Don Gagne committed
263

264 265 266 267 268 269 270 271
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
            }

272 273 274 275 276 277 278 279 280 281 282
            // 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
                }
            }

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