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

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

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

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

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

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

109 110 111 112 113 114 115
                    // At this point all Facts are numeric
                    inputMethodHints:   Qt.ImhFormattedNumbersOnly
                }

                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 {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
145
                spacing: ScreenTools.defaultFontPixelHeight / 2
146
                visible: fact.bitmaskStrings.length > 0 ? true : false;
147 148 149
                Repeater {
                    id: bitmaskEditor
                    model: fact.bitmaskStrings
150

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

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

160 161
            Row {
                spacing: defaultTextWidth
Don Gagne's avatar
Don Gagne committed
162

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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