ParameterEditorDialog.qml 8.44 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.
 *
 ****************************************************************************/
9

10
import QtQuick          2.5
11
import QtQuick.Controls 1.3
12
import QtQuick.Layouts  1.2
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
20 21

QGCViewDialog {
22 23
    id: root

24
    property Fact   fact
25
    property bool   showRCToParam:  false
26 27 28
    property bool   validate:       false
    property string validateValue

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

32 33
    ParameterEditorController { id: controller; factPanel: parent }

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

36
    function accept() {
Don Gagne's avatar
Don Gagne committed
37
        if (bitmaskColumn.visible) {
38 39
            var value = 0;
            for (var i = 0; i < fact.bitmaskValues.length; ++i) {
Don Gagne's avatar
Don Gagne committed
40
                var checkbox = bitmaskRepeater.itemAt(i)
41 42 43 44 45 46
                if (checkbox.checked) {
                    value |= fact.bitmaskValues[i];
                }
            }
            fact.value = value;
            fact.valueChanged(fact.value)
47
            hideDialog();
Don Gagne's avatar
Don Gagne committed
48
        } else if (factCombo.visible) {
49
            fact.enumIndex = factCombo.currentIndex
50 51
            hideDialog()
        } else {
52
            var errorString = fact.validate(valueField.text, forceSave.checked)
53
            if (errorString === "") {
54 55 56 57 58 59 60
                fact.value = valueField.text
                fact.valueChanged(fact.value)
                hideDialog()
            } else {
                validationError.text = errorString
                forceSave.visible = true
            }
61 62 63 64 65 66 67 68 69 70
        }
    }

    Component.onCompleted: {
        if (validate) {
            validationError.text = fact.validate(validateValue, false /* convertOnly */)
            forceSave.visible = true
        }
    }

71 72 73 74 75 76 77 78 79 80 81 82
    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 {
83
                id:         validationError
84 85
                width:      parent.width
                wrapMode:   Text.WordWrap
86
                color:      qgcPal.warningText
87
            }
88

89 90 91 92
            RowLayout {
                spacing:        defaultTextWidth
                anchors.left:   parent.left
                anchors.right:  parent.right
93

94
                QGCTextField {
95 96 97 98 99 100
                    id:                 valueField
                    text:               validate ? validateValue : fact.valueString
                    visible:            fact.enumStrings.length == 0 || validate
                    unitsLabel:         fact.units
                    showUnits:          fact.units != ""
                    Layout.fillWidth:   true
101 102 103
                    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
104 105 106 107 108
                }

                QGCButton {
                    anchors.baseline:   valueField.baseline
                    visible:            fact.defaultValueAvailable
109
                    text:               qsTr("Reset to default")
110 111 112 113 114 115 116 117

                    onClicked: {
                        fact.value = fact.defaultValue
                        fact.valueChanged(fact.value)
                        hideDialog()
                    }
                }
            }
118

119 120
            QGCComboBox {
                id:             factCombo
Don Gagne's avatar
Don Gagne committed
121 122
                anchors.left:   parent.left
                anchors.right:  parent.right
123 124
                visible:        _showCombo
                model:          fact.enumStrings
125

126
                property bool _showCombo: fact.enumStrings.length != 0 && fact.bitmaskStrings.length == 0 && !validate
127

128 129 130 131 132 133
                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
                    }
134 135 136
                }
            }

137
            Column {
Don Gagne's avatar
Don Gagne committed
138 139 140 141
                id:         bitmaskColumn
                spacing:    ScreenTools.defaultFontPixelHeight / 2
                visible:    fact.bitmaskStrings.length > 0 ? true : false;

142
                Repeater {
Don Gagne's avatar
Don Gagne committed
143 144
                    id:     bitmaskRepeater
                    model:  fact.bitmaskStrings
145

146 147 148 149 150 151 152
                    delegate : QGCCheckBox {
                        text : modelData
                        checked : fact.value & fact.bitmaskValues[index]
                    }
                }
            }

153
            QGCLabel {
154 155 156 157
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    !longDescriptionLabel.visible
                text:       fact.shortDescription
158
            }
159

160 161 162 163 164 165 166
            QGCLabel {
                id:         longDescriptionLabel
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    fact.longDescription != ""
                text:       fact.longDescription
            }
167

168 169
            Row {
                spacing: defaultTextWidth
170

171 172 173 174
                QGCLabel {
                    id:         minValueDisplay
                    text:       qsTr("Min: ") + fact.minString
                    visible:    !fact.minIsDefaultForType
175
                }
176

177 178 179
                QGCLabel {
                    text:       qsTr("Max: ") + fact.maxString
                    visible:    !fact.maxIsDefaultForType
180 181 182
                }

                QGCLabel {
183 184
                    text:       qsTr("Default: ") + fact.defaultValueString
                    visible:    fact.defaultValueAvailable
185
                }
186
            }
187

188
            QGCLabel {
189 190 191 192 193 194 195
                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"
196
            }
197

198 199 200
            QGCLabel {
                width:      parent.width
                wrapMode:   Text.WordWrap
201 202
                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!")
203
            }
204

205 206 207
            QGCCheckBox {
                id:         forceSave
                visible:    false
208
                text:       qsTr("Force save (dangerous!)")
209
            }
210

211 212 213 214
            Row {
                width:      parent.width
                spacing:    ScreenTools.defaultFontPixelWidth / 2
                visible:    showRCToParam
215

216 217 218 219 220 221
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
222

223 224
                QGCCheckBox {
                    id:     _advanced
225
                    text:   qsTr("Advanced settings")
226
                }
227

228 229 230 231 232 233 234 235 236
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
            }

            QGCButton {
237
                text:           qsTr("Set RC to Param...")
dogmaphobic's avatar
dogmaphobic committed
238
                width:          _editFieldWidth
239 240 241 242
                visible:        _advanced.checked && !validate && showRCToParam
                onClicked:      controller.setRCToParam(fact.name)
            }
        } // Column
243 244
    }
} // QGCViewDialog