ParameterEditorDialog.qml 8.57 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 13


/// @file
///     @author Don Gagne <don@thegagnes.com>

14
import QtQuick          2.5
Don Gagne's avatar
Don Gagne committed
15 16
import QtQuick.Controls 1.3

17 18 19 20 21 22
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
23 24

QGCViewDialog {
25 26
    id: root

Don Gagne's avatar
Don Gagne committed
27
    property Fact   fact
28
    property bool   showRCToParam:  false
Don Gagne's avatar
Don Gagne committed
29 30 31
    property bool   validate:       false
    property string validateValue

dogmaphobic's avatar
dogmaphobic committed
32 33
    property real   _editFieldWidth:  ScreenTools.defaultFontPixelWidth * 20

Don Gagne's avatar
Don Gagne committed
34 35
    ParameterEditorController { id: controller; factPanel: parent }

36 37
    QGCPalette { id: qgcPal; colorGroupEnabled: true }

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

    Component.onCompleted: {
        if (validate) {
            validationError.text = fact.validate(validateValue, false /* convertOnly */)
            forceSave.visible = true
        }
71
        //valueField.forceActiveFocus()
Don Gagne's avatar
Don Gagne committed
72 73
    }

74 75 76 77 78 79 80 81 82 83 84 85 86 87
    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 {
                width:      parent.width
                wrapMode:   Text.WordWrap
88
                text:       fact.shortDescription ? fact.shortDescription : qsTr("Parameter Description (not defined)")
89
            }
Don Gagne's avatar
Don Gagne committed
90

91 92 93 94 95 96
            QGCLabel {
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    fact.longDescription
                text:       fact.longDescription
            }
Don Gagne's avatar
Don Gagne committed
97

98 99
            Row {
                spacing: defaultTextWidth
Don Gagne's avatar
Don Gagne committed
100

101 102 103 104 105
                QGCTextField {
                    id:         valueField
                    text:       validate ? validateValue : fact.valueString
                    visible:    fact.enumStrings.length == 0 || validate
                    //focus:  true
106

107 108 109
                    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
110 111 112 113 114
                }

                QGCButton {
                    anchors.baseline:   valueField.baseline
                    visible:            fact.defaultValueAvailable
dogmaphobic's avatar
dogmaphobic committed
115
                    width:              _editFieldWidth
116
                    text:               qsTr("Reset to default")
117 118 119 120 121 122 123 124

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

126 127 128 129 130
            QGCComboBox {
                id:             factCombo
                width:          valueField.width
                visible:        _showCombo
                model:          fact.enumStrings
131

132
                property bool _showCombo: fact.enumStrings.length != 0 && fact.bitmaskStrings.length == 0 && !validate
133

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

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

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

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

159
            QGCLabel { text: fact.name }
Don Gagne's avatar
Don Gagne committed
160

161 162 163 164
            Column {
                spacing:        defaultTextHeight / 2
                anchors.left:   parent.left
                anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
165

166 167
                Row {
                    spacing: defaultTextWidth
Don Gagne's avatar
Don Gagne committed
168

169 170 171
                    QGCLabel { text: qsTr("Units:") }
                    QGCLabel { text: fact.units ? fact.units : qsTr("none") }
                }
Don Gagne's avatar
Don Gagne committed
172

173 174 175
                Row {
                    spacing: defaultTextWidth
                    visible: !fact.minIsDefaultForType
Don Gagne's avatar
Don Gagne committed
176

177 178 179
                    QGCLabel { text: qsTr("Minimum value:") }
                    QGCLabel { text: fact.minString }
                }
Don Gagne's avatar
Don Gagne committed
180

181 182 183
                Row {
                    spacing: defaultTextWidth
                    visible: !fact.maxIsDefaultForType
Don Gagne's avatar
Don Gagne committed
184

185 186 187
                    QGCLabel { text: qsTr("Maximum value:") }
                    QGCLabel { text: fact.maxString }
                }
Don Gagne's avatar
Don Gagne committed
188

189 190 191 192 193 194 195 196 197 198 199 200
                Row {
                    spacing: defaultTextWidth

                    QGCLabel { text: qsTr("Default value:") }
                    QGCLabel { text: fact.defaultValueAvailable ? fact.defaultValueString : qsTr("none") }
                }

                QGCLabel {
                    visible:    fact.rebootRequired
                    text:       "Reboot required after change"
                }
            } // Column
Don Gagne's avatar
Don Gagne committed
201

202 203 204
            QGCLabel {
                width:      parent.width
                wrapMode:   Text.WordWrap
205 206
                text:       qsTr("Warning: Modifying parameters 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!")
207
            }
Don Gagne's avatar
Don Gagne committed
208

209 210 211 212
            QGCLabel {
                id:         validationError
                width:      parent.width
                wrapMode:   Text.WordWrap
213
                color:      qsTr("yellow")
214
            }
Don Gagne's avatar
Don Gagne committed
215

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

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

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

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

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

            QGCButton {
248
                text:           qsTr("Set RC to Param...")
dogmaphobic's avatar
dogmaphobic committed
249
                width:          _editFieldWidth
250 251 252 253
                visible:        _advanced.checked && !validate && showRCToParam
                onClicked:      controller.setRCToParam(fact.name)
            }
        } // Column
Don Gagne's avatar
Don Gagne committed
254 255
    }
} // QGCViewDialog