ParameterEditorDialog.qml 10.1 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
                }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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