ParameterEditorDialog.qml 8.7 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
            QGCComboBox {
                id:             factCombo
Don Gagne's avatar
Don Gagne committed
129 130
                anchors.left:   parent.left
                anchors.right:  parent.right
131 132
                visible:        _showCombo
                model:          fact.enumStrings
133

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

136 137 138 139 140 141
                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
                    }
142 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 157 158 159 160
                    delegate : QGCCheckBox {
                        text : modelData
                        checked : fact.value & fact.bitmaskValues[index]
                    }
                }
            }

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

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

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

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

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

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

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

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

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

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

214 215 216 217
            QGCLabel {
                id:         validationError
                width:      parent.width
                wrapMode:   Text.WordWrap
218
                color:      qsTr("yellow")
219
            }
Don Gagne's avatar
Don Gagne committed
220

221 222 223
            QGCCheckBox {
                id:         forceSave
                visible:    false
224
                text:       qsTr("Force save (dangerous!)")
225
            }
Don Gagne's avatar
Don Gagne committed
226

227 228 229 230
            Row {
                width:      parent.width
                spacing:    ScreenTools.defaultFontPixelWidth / 2
                visible:    showRCToParam
Don Gagne's avatar
Don Gagne committed
231

232 233 234 235 236 237
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
Don Gagne's avatar
Don Gagne committed
238

239 240
                QGCCheckBox {
                    id:     _advanced
241
                    text:   qsTr("Advanced settings")
242
                }
Don Gagne's avatar
Don Gagne committed
243

244 245 246 247 248 249 250 251 252
                Rectangle {
                    height: 1
                    width:  ScreenTools.defaultFontPixelWidth * 5
                    color:  qgcPal.text
                    anchors.verticalCenter: _advanced.verticalCenter
                }
            }

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