ParameterEditorDialog.qml 9.39 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 15 16 17 18 19
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
20 21

QGCViewDialog {
22 23
    id: root

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

Don Gagne's avatar
Don Gagne committed
29 30
    property real   _editFieldWidth:            ScreenTools.defaultFontPixelWidth * 20
    property bool   _longDescriptionAvailable:  fact.longDescription != ""
dogmaphobic's avatar
dogmaphobic committed
31

Don Gagne's avatar
Don Gagne committed
32 33
    ParameterEditorController { id: controller; factPanel: parent }

34 35
    QGCPalette { id: qgcPal; colorGroupEnabled: true }

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

57 58 59 60 61 62 63 64 65 66 67
    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
68 69 70 71 72 73 74
    Component.onCompleted: {
        if (validate) {
            validationError.text = fact.validate(validateValue, false /* convertOnly */)
            forceSave.visible = true
        }
    }

75 76 77 78 79 80 81 82 83 84 85 86
    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
87
                id:         validationError
88 89
                width:      parent.width
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
90
                color:      qgcPal.warningText
91
            }
Don Gagne's avatar
Don Gagne committed
92

Don Gagne's avatar
Don Gagne committed
93 94 95 96
            RowLayout {
                spacing:        defaultTextWidth
                anchors.left:   parent.left
                anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
97

98
                QGCTextField {
Don Gagne's avatar
Don Gagne committed
99 100
                    id:                 valueField
                    text:               validate ? validateValue : fact.valueString
101
                    visible:            fact.enumStrings.length == 0 || validate || manualEntry.checked
Don Gagne's avatar
Don Gagne committed
102 103 104
                    unitsLabel:         fact.units
                    showUnits:          fact.units != ""
                    Layout.fillWidth:   true
105 106 107
                    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
108 109 110 111 112
                }

                QGCButton {
                    anchors.baseline:   valueField.baseline
                    visible:            fact.defaultValueAvailable
113
                    text:               qsTr("Reset to default")
114 115 116 117 118 119 120 121

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

123 124
            QGCComboBox {
                id:             factCombo
Don Gagne's avatar
Don Gagne committed
125 126
                anchors.left:   parent.left
                anchors.right:  parent.right
127 128
                visible:        _showCombo
                model:          fact.enumStrings
129

130
                property bool _showCombo: fact.enumStrings.length != 0 && fact.bitmaskStrings.length == 0 && !validate
131

132 133 134 135 136 137
                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
                    }
138
                }
139 140

                onCurrentIndexChanged: {
DonLakeFlyer's avatar
DonLakeFlyer committed
141 142 143
                    if (currentIndex >=0 && currentIndex < model.length) {
                        valueField.text = fact.enumValues[currentIndex]
                    }
144
                }
145 146
            }

147
            Column {
Don Gagne's avatar
Don Gagne committed
148 149 150 151
                id:         bitmaskColumn
                spacing:    ScreenTools.defaultFontPixelHeight / 2
                visible:    fact.bitmaskStrings.length > 0 ? true : false;

152
                Repeater {
Don Gagne's avatar
Don Gagne committed
153 154
                    id:     bitmaskRepeater
                    model:  fact.bitmaskStrings
155

156 157 158
                    delegate : QGCCheckBox {
                        text : modelData
                        checked : fact.value & fact.bitmaskValues[index]
159 160 161 162

                        onClicked: {
                            valueField.text = bitmaskValue()
                        }
163 164 165 166
                    }
                }
            }

167
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
168 169 170 171
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    !longDescriptionLabel.visible
                text:       fact.shortDescription
172
            }
Don Gagne's avatar
Don Gagne committed
173

Don Gagne's avatar
Don Gagne committed
174 175 176 177 178 179 180
            QGCLabel {
                id:         longDescriptionLabel
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    fact.longDescription != ""
                text:       fact.longDescription
            }
Don Gagne's avatar
Don Gagne committed
181

Don Gagne's avatar
Don Gagne committed
182 183
            Row {
                spacing: defaultTextWidth
Don Gagne's avatar
Don Gagne committed
184

Don Gagne's avatar
Don Gagne committed
185 186 187 188
                QGCLabel {
                    id:         minValueDisplay
                    text:       qsTr("Min: ") + fact.minString
                    visible:    !fact.minIsDefaultForType
189
                }
Don Gagne's avatar
Don Gagne committed
190

Don Gagne's avatar
Don Gagne committed
191 192 193
                QGCLabel {
                    text:       qsTr("Max: ") + fact.maxString
                    visible:    !fact.maxIsDefaultForType
194 195 196
                }

                QGCLabel {
Don Gagne's avatar
Don Gagne committed
197 198
                    text:       qsTr("Default: ") + fact.defaultValueString
                    visible:    fact.defaultValueAvailable
199
                }
Don Gagne's avatar
Don Gagne committed
200
            }
Don Gagne's avatar
Don Gagne committed
201

202
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
203 204 205 206 207 208 209
                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"
210
            }
Don Gagne's avatar
Don Gagne committed
211

212 213 214
            QGCLabel {
                width:      parent.width
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
215 216
                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
217
                visible:    fact.componentId != -1
218
            }
Don Gagne's avatar
Don Gagne committed
219

220 221 222
            QGCCheckBox {
                id:         forceSave
                visible:    false
223
                text:       qsTr("Force save (dangerous!)")
224
            }
Don Gagne's avatar
Don Gagne committed
225

226 227 228
            Row {
                width:      parent.width
                spacing:    ScreenTools.defaultFontPixelWidth / 2
229
                visible:    showRCToParam || factCombo.visible || bitmaskColumn.visible
Don Gagne's avatar
Don Gagne committed
230

231 232 233 234 235 236
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
Don Gagne's avatar
Don Gagne committed
237

238 239
                QGCCheckBox {
                    id:     _advanced
240
                    text:   qsTr("Advanced settings")
241
                }
Don Gagne's avatar
Don Gagne committed
242

243 244 245 246 247 248 249 250
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
            }

251 252 253 254 255 256 257 258 259 260 261
            // 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
                }
            }

262
            QGCButton {
263
                text:           qsTr("Set RC to Param...")
dogmaphobic's avatar
dogmaphobic committed
264
                width:          _editFieldWidth
265 266 267 268
                visible:        _advanced.checked && !validate && showRCToParam
                onClicked:      controller.setRCToParam(fact.name)
            }
        } // Column
Don Gagne's avatar
Don Gagne committed
269 270
    }
} // QGCViewDialog