ParameterEditorDialog.qml 8.15 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
            Row {
                spacing: defaultTextWidth
Don Gagne's avatar
Don Gagne committed
163

164 165
                QGCLabel { text: qsTr("Units:") }
                QGCLabel { text: fact.units ? fact.units : qsTr("none") }
166
            }
Don Gagne's avatar
Don Gagne committed
167

168 169 170
            Row {
                spacing: defaultTextWidth
                visible: !fact.minIsDefaultForType
Don Gagne's avatar
Don Gagne committed
171

172
                QGCLabel { text: qsTr("Minimum value:") }
173 174
                QGCLabel { text: fact.minString }
            }
Don Gagne's avatar
Don Gagne committed
175

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

180
                QGCLabel { text: qsTr("Maximum value:") }
181 182
                QGCLabel { text: fact.maxString }
            }
Don Gagne's avatar
Don Gagne committed
183

184 185
            Row {
                spacing: defaultTextWidth
Don Gagne's avatar
Don Gagne committed
186

187 188
                QGCLabel { text: qsTr("Default value:") }
                QGCLabel { text: fact.defaultValueAvailable ? fact.defaultValueString : qsTr("none") }
189
            }
Don Gagne's avatar
Don Gagne committed
190

191 192 193
            QGCLabel {
                width:      parent.width
                wrapMode:   Text.WordWrap
194 195
                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!")
196
            }
Don Gagne's avatar
Don Gagne committed
197

198 199 200 201
            QGCLabel {
                id:         validationError
                width:      parent.width
                wrapMode:   Text.WordWrap
202
                color:      qsTr("yellow")
203
            }
Don Gagne's avatar
Don Gagne committed
204

205 206 207
            QGCCheckBox {
                id:         forceSave
                visible:    false
208
                text:       qsTr("Force save (dangerous!)")
209
            }
Don Gagne's avatar
Don Gagne committed
210

211 212 213 214
            Row {
                width:      parent.width
                spacing:    ScreenTools.defaultFontPixelWidth / 2
                visible:    showRCToParam
Don Gagne's avatar
Don Gagne committed
215

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

223 224
                QGCCheckBox {
                    id:     _advanced
225
                    text:   qsTr("Advanced settings")
226
                }
Don Gagne's avatar
Don Gagne committed
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
Don Gagne's avatar
Don Gagne committed
243 244
    }
} // QGCViewDialog