ParameterEditorDialog.qml 8.67 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 89
                visible:    fact.shortDescription
                text:       fact.shortDescription
90
            }
Don Gagne's avatar
Don Gagne committed
91

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

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

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

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

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

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

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

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

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

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

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

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

160 161 162 163
            QGCLabel {
                text:       fact.name
                visible:    fact.componentId > 0 // > 0 means it's a parameter fact
            }
Don Gagne's avatar
Don Gagne committed
164

165 166 167 168
            Column {
                spacing:        defaultTextHeight / 2
                anchors.left:   parent.left
                anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
169

170 171
                Row {
                    spacing: defaultTextWidth
Don Gagne's avatar
Don Gagne committed
172

173 174 175
                    QGCLabel { text: qsTr("Units:") }
                    QGCLabel { text: fact.units ? fact.units : qsTr("none") }
                }
Don Gagne's avatar
Don Gagne committed
176

177 178 179
                Row {
                    spacing: defaultTextWidth
                    visible: !fact.minIsDefaultForType
Don Gagne's avatar
Don Gagne committed
180

181 182 183
                    QGCLabel { text: qsTr("Minimum value:") }
                    QGCLabel { text: fact.minString }
                }
Don Gagne's avatar
Don Gagne committed
184

185 186 187
                Row {
                    spacing: defaultTextWidth
                    visible: !fact.maxIsDefaultForType
Don Gagne's avatar
Don Gagne committed
188

189 190 191
                    QGCLabel { text: qsTr("Maximum value:") }
                    QGCLabel { text: fact.maxString }
                }
Don Gagne's avatar
Don Gagne committed
192

193 194 195 196 197 198 199 200 201 202 203 204
                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
205

206 207 208
            QGCLabel {
                width:      parent.width
                wrapMode:   Text.WordWrap
209
                text:       qsTr("Warning: Modifying values while vehicle is in flight can lead to vehicle instability and possible vehicle loss. ") +
210
                            qsTr("Make sure you know what you are doing and double-check your values before Save!")
211
            }
Don Gagne's avatar
Don Gagne committed
212

213 214 215 216
            QGCLabel {
                id:         validationError
                width:      parent.width
                wrapMode:   Text.WordWrap
217
                color:      qsTr("yellow")
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 229
            Row {
                width:      parent.width
                spacing:    ScreenTools.defaultFontPixelWidth / 2
                visible:    showRCToParam
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 251
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
            }

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