ParameterEditorDialog.qml 9.19 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
    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

86 87 88 89 90 91 92 93 94 95 96
            // Checkbox to allow manual entry of enumerated or bitmask parameters
            QGCCheckBox {
                id:         manualEntry
                visible:    factCombo.visible || bitmaskColumn.visible
                text:       qsTr("Manual Entry (Advanced User)")

                onClicked: {
                    valueField.text = fact.valueString
                }
            }

97
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
98
                id:         validationError
99 100
                width:      parent.width
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
101
                color:      qgcPal.warningText
102
            }
Don Gagne's avatar
Don Gagne committed
103

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

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

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

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

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

141
                property bool _showCombo: fact.enumStrings.length != 0 && fact.bitmaskStrings.length == 0 && !validate
142

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

                onCurrentIndexChanged: {
                    valueField.text = fact.enumValues[currentIndex]
                }
154 155
            }

156
            Column {
Don Gagne's avatar
Don Gagne committed
157 158 159 160
                id:         bitmaskColumn
                spacing:    ScreenTools.defaultFontPixelHeight / 2
                visible:    fact.bitmaskStrings.length > 0 ? true : false;

161
                Repeater {
Don Gagne's avatar
Don Gagne committed
162 163
                    id:     bitmaskRepeater
                    model:  fact.bitmaskStrings
164

165 166 167
                    delegate : QGCCheckBox {
                        text : modelData
                        checked : fact.value & fact.bitmaskValues[index]
168 169 170 171

                        onClicked: {
                            valueField.text = bitmaskValue()
                        }
172 173 174 175
                    }
                }
            }

176
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
177 178 179 180
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    !longDescriptionLabel.visible
                text:       fact.shortDescription
181
            }
Don Gagne's avatar
Don Gagne committed
182

Don Gagne's avatar
Don Gagne committed
183 184 185 186 187 188 189
            QGCLabel {
                id:         longDescriptionLabel
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    fact.longDescription != ""
                text:       fact.longDescription
            }
Don Gagne's avatar
Don Gagne committed
190

Don Gagne's avatar
Don Gagne committed
191 192
            Row {
                spacing: defaultTextWidth
Don Gagne's avatar
Don Gagne committed
193

Don Gagne's avatar
Don Gagne committed
194 195 196 197
                QGCLabel {
                    id:         minValueDisplay
                    text:       qsTr("Min: ") + fact.minString
                    visible:    !fact.minIsDefaultForType
198
                }
Don Gagne's avatar
Don Gagne committed
199

Don Gagne's avatar
Don Gagne committed
200 201 202
                QGCLabel {
                    text:       qsTr("Max: ") + fact.maxString
                    visible:    !fact.maxIsDefaultForType
203 204 205
                }

                QGCLabel {
Don Gagne's avatar
Don Gagne committed
206 207
                    text:       qsTr("Default: ") + fact.defaultValueString
                    visible:    fact.defaultValueAvailable
208
                }
Don Gagne's avatar
Don Gagne committed
209
            }
Don Gagne's avatar
Don Gagne committed
210

211
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
212 213 214 215 216 217 218
                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"
219
            }
Don Gagne's avatar
Don Gagne committed
220

221 222 223
            QGCLabel {
                width:      parent.width
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
224 225
                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!")
226
            }
Don Gagne's avatar
Don Gagne committed
227

228 229 230
            QGCCheckBox {
                id:         forceSave
                visible:    false
231
                text:       qsTr("Force save (dangerous!)")
232
            }
Don Gagne's avatar
Don Gagne committed
233

234 235 236 237
            Row {
                width:      parent.width
                spacing:    ScreenTools.defaultFontPixelWidth / 2
                visible:    showRCToParam
Don Gagne's avatar
Don Gagne committed
238

239 240 241 242 243 244
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
Don Gagne's avatar
Don Gagne committed
245

246 247
                QGCCheckBox {
                    id:     _advanced
248
                    text:   qsTr("Advanced settings")
249
                }
Don Gagne's avatar
Don Gagne committed
250

251 252 253 254 255 256 257 258 259
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
            }

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