ParameterEditorDialog.qml 9.93 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 91 92 93 94 95 96 97 98 99
    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
100
                id:         validationError
101 102
                width:      parent.width
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
103
                color:      qgcPal.warningText
104
            }
Don Gagne's avatar
Don Gagne committed
105

Don Gagne's avatar
Don Gagne committed
106 107 108 109
            RowLayout {
                spacing:        defaultTextWidth
                anchors.left:   parent.left
                anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
110

111
                QGCTextField {
Don Gagne's avatar
Don Gagne committed
112 113
                    id:                 valueField
                    text:               validate ? validateValue : fact.valueString
114
                    visible:            fact.enumStrings.length == 0 || validate || manualEntry.checked
Don Gagne's avatar
Don Gagne committed
115 116 117
                    unitsLabel:         fact.units
                    showUnits:          fact.units != ""
                    Layout.fillWidth:   true
118 119 120
                    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
121 122 123 124
                }

                QGCButton {
                    anchors.baseline:   valueField.baseline
125
                    visible:            _allowDefaultReset
126
                    text:               qsTr("Reset to default")
127 128 129 130 131 132 133 134

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

136 137
            QGCComboBox {
                id:             factCombo
Don Gagne's avatar
Don Gagne committed
138 139
                anchors.left:   parent.left
                anchors.right:  parent.right
140 141
                visible:        _showCombo
                model:          fact.enumStrings
142

143
                property bool _showCombo: fact.enumStrings.length != 0 && fact.bitmaskStrings.length == 0 && !validate
144

145 146 147 148 149 150
                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
                    }
151
                }
152 153

                onCurrentIndexChanged: {
DonLakeFlyer's avatar
DonLakeFlyer committed
154 155 156
                    if (currentIndex >=0 && currentIndex < model.length) {
                        valueField.text = fact.enumValues[currentIndex]
                    }
157
                }
158 159
            }

160
            Column {
Don Gagne's avatar
Don Gagne committed
161 162 163 164
                id:         bitmaskColumn
                spacing:    ScreenTools.defaultFontPixelHeight / 2
                visible:    fact.bitmaskStrings.length > 0 ? true : false;

165
                Repeater {
Don Gagne's avatar
Don Gagne committed
166 167
                    id:     bitmaskRepeater
                    model:  fact.bitmaskStrings
168

169 170 171
                    delegate : QGCCheckBox {
                        text : modelData
                        checked : fact.value & fact.bitmaskValues[index]
172 173 174 175

                        onClicked: {
                            valueField.text = bitmaskValue()
                        }
176 177 178 179
                    }
                }
            }

180
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
181 182 183 184
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    !longDescriptionLabel.visible
                text:       fact.shortDescription
185
            }
Don Gagne's avatar
Don Gagne committed
186

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

Don Gagne's avatar
Don Gagne committed
195 196
            Row {
                spacing: defaultTextWidth
Don Gagne's avatar
Don Gagne committed
197

Don Gagne's avatar
Don Gagne committed
198 199 200 201
                QGCLabel {
                    id:         minValueDisplay
                    text:       qsTr("Min: ") + fact.minString
                    visible:    !fact.minIsDefaultForType
202
                }
Don Gagne's avatar
Don Gagne committed
203

Don Gagne's avatar
Don Gagne committed
204 205 206
                QGCLabel {
                    text:       qsTr("Max: ") + fact.maxString
                    visible:    !fact.maxIsDefaultForType
207 208 209
                }

                QGCLabel {
Don Gagne's avatar
Don Gagne committed
210
                    text:       qsTr("Default: ") + fact.defaultValueString
211
                    visible:    _allowDefaultReset
212
                }
Don Gagne's avatar
Don Gagne committed
213
            }
Don Gagne's avatar
Don Gagne committed
214

215
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
216 217 218 219 220 221 222
                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"
223
            }
Don Gagne's avatar
Don Gagne committed
224

225 226 227
            QGCLabel {
                width:      parent.width
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
228 229
                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
230
                visible:    fact.componentId != -1
231
            }
Don Gagne's avatar
Don Gagne committed
232

233 234 235
            QGCCheckBox {
                id:         forceSave
                visible:    false
236
                text:       qsTr("Force save (dangerous!)")
237
            }
Don Gagne's avatar
Don Gagne committed
238

239 240 241
            Row {
                width:      parent.width
                spacing:    ScreenTools.defaultFontPixelWidth / 2
242
                visible:    showRCToParam || factCombo.visible || bitmaskColumn.visible
Don Gagne's avatar
Don Gagne committed
243

244 245 246 247 248 249
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
Don Gagne's avatar
Don Gagne committed
250

251 252
                QGCCheckBox {
                    id:     _advanced
253
                    text:   qsTr("Advanced settings")
254
                }
Don Gagne's avatar
Don Gagne committed
255

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

264 265 266 267 268 269 270 271 272 273 274
            // 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
                }
            }

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