ParameterEditorDialog.qml 9.24 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 141 142

                onCurrentIndexChanged: {
                    valueField.text = fact.enumValues[currentIndex]
                }
143 144
            }

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

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

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

                        onClicked: {
                            valueField.text = bitmaskValue()
                        }
161 162 163 164
                    }
                }
            }

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

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

Don Gagne's avatar
Don Gagne committed
180 181
            Row {
                spacing: defaultTextWidth
Don Gagne's avatar
Don Gagne committed
182

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

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

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

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

210 211 212
            QGCLabel {
                width:      parent.width
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
213 214
                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!")
215
            }
Don Gagne's avatar
Don Gagne committed
216

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

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

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

235 236
                QGCCheckBox {
                    id:     _advanced
237
                    text:   qsTr("Advanced settings")
238
                }
Don Gagne's avatar
Don Gagne committed
239

240 241 242 243 244 245 246 247
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
            }

248 249 250 251 252 253 254 255 256 257 258
            // 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
                }
            }

259
            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