ParameterEditorDialog.qml 8.49 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
import QtQuick          2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts  1.2
Don Gagne's avatar
Don Gagne committed
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
Don Gagne's avatar
Don Gagne committed
20 21

QGCViewDialog {
22 23
    id: root

Don Gagne's avatar
Don Gagne committed
24
    property Fact   fact
25
    property bool   showRCToParam:  false
Don Gagne's avatar
Don Gagne committed
26 27 28
    property bool   validate:       false
    property string validateValue

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

Don Gagne's avatar
Don Gagne committed
32 33
    ParameterEditorController { id: controller; factPanel: parent }

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

Don Gagne's avatar
Don Gagne committed
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
Don Gagne's avatar
Don Gagne committed
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
            }
Don Gagne's avatar
Don Gagne committed
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 {
Don Gagne's avatar
Don Gagne committed
83
                id:         validationError
84 85
                width:      parent.width
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
86
                color:      qgcPal.warningText
87
            }
Don Gagne's avatar
Don Gagne committed
88

Don Gagne's avatar
Don Gagne committed
89 90 91 92
            RowLayout {
                spacing:        defaultTextWidth
                anchors.left:   parent.left
                anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
93

94
                QGCTextField {
Don Gagne's avatar
Don Gagne committed
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()
                    }
                }
            }
Don Gagne's avatar
Don Gagne committed
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 {
Don Gagne's avatar
Don Gagne committed
154 155 156 157
                width:      parent.width
                wrapMode:   Text.WordWrap
                visible:    !longDescriptionLabel.visible
                text:       fact.shortDescription
158
            }
Don Gagne's avatar
Don Gagne committed
159

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

Don Gagne's avatar
Don Gagne committed
168 169
            Row {
                spacing: defaultTextWidth
Don Gagne's avatar
Don Gagne committed
170

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

Don Gagne's avatar
Don Gagne committed
177 178 179
                QGCLabel {
                    text:       qsTr("Max: ") + fact.maxString
                    visible:    !fact.maxIsDefaultForType
180 181 182
                }

                QGCLabel {
Don Gagne's avatar
Don Gagne committed
183 184
                    text:       qsTr("Default: ") + fact.defaultValueString
                    visible:    fact.defaultValueAvailable
185
                }
Don Gagne's avatar
Don Gagne committed
186
            }
Don Gagne's avatar
Don Gagne committed
187

188
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
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
            }
Don Gagne's avatar
Don Gagne committed
197

198 199 200
            QGCLabel {
                width:      parent.width
                wrapMode:   Text.WordWrap
Don Gagne's avatar
Don Gagne committed
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!")
DonLakeFlyer's avatar
DonLakeFlyer committed
203
                visible:    fact.componentId != -1
204
            }
Don Gagne's avatar
Don Gagne committed
205

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

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

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

224 225
                QGCCheckBox {
                    id:     _advanced
226
                    text:   qsTr("Advanced settings")
227
                }
Don Gagne's avatar
Don Gagne committed
228

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

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