ParameterEditor.qml 6.77 KB
Newer Older
1
import QtQuick 2.3
2 3
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.4
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import QtQuick.Dialogs 1.2
import QtQuick.Extras 1.4
import QtQuick.Layouts 1.2

import QGroundControl 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.Vehicle 1.0
import QGroundControl.Controls 1.0
import QGroundControl.FactSystem 1.0
import QGroundControl.FactControls 1.0
import QGroundControl.Palette 1.0
import QGroundControl.FlightMap 1.0

Rectangle {
    id: _root

    width: mainGrid.width
    height: mainGrid.height
    color: qgcPal.windowShadeDark
23 24

    property bool checked: true
25 26
    property var missionItem: undefined
    property int availableWidth: 300
27

28 29 30
    property real _margin: ScreenTools.defaultFontPixelWidth / 2
    property var _generator: missionItem.generator
    property var _generatorEditor: undefined
31 32

    Component.onCompleted: {
33 34
        console.assert(missionItem !== undefined,
                       "please set the missionItem property")
35 36 37 38 39 40 41 42 43 44 45 46
        _addGeneratorEditor()
    }

    Component.onDestruction: {
        _destroyGeneratorEditor()
    }

    on_GeneratorChanged: {
        _destroyGeneratorEditor()
        _addGeneratorEditor()
    }

47 48
    GridLayout {
        id: mainGrid
49

50 51 52 53
        columnSpacing: _margin
        rowSpacing: _margin
        columns: 2
        width: availableWidth
54

55 56
        SectionHeader {
            id: generalHeader
57
            Layout.fillWidth: true
58
            Layout.columnSpan: parent.columns
59 60
            Layout.maximumWidth: parent.width
            text: qsTr("General")
61
        }
62

63 64 65
        GridLayout {
            id: generalGrid
            Layout.fillWidth: true
66 67
            Layout.columnSpan: parent.columns
            Layout.maximumWidth: parent.width
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
            columnSpacing: _margin
            rowSpacing: _margin
            columns: 2
            visible: generalHeader.checked

            QGCLabel {
                text: qsTr("Altitude")
                Layout.fillWidth: true
            }
            FactTextField {
                fact: missionItem.altitude
                Layout.fillWidth: true
            }

            QGCLabel {
                text: qsTr("Variant")
                Layout.columnSpan: parent.columns
                visible: variantRepeater.len > 0
            }

            ExclusiveGroup {
                id: variantGroup
            }
91

92 93 94 95
            GridLayout {
                Layout.columnSpan: parent.columns
                Layout.maximumWidth: parent.width
                columns: 3
96

97 98
                columnSpacing: _margin
                rowSpacing: _margin
99

100 101
                Repeater {
                    id: variantRepeater
102

103 104
                    property var names: missionItem.variantNames
                    property int len: missionItem.variantNames.length
105

106 107 108 109 110
                    model: len
                    delegate: QGCRadioButton {
                        checked: index === variantIndex
                        text: variantRepeater.names[index] ? variantRepeater.names[index] : ""
                        Layout.fillWidth: true
111

112 113 114 115 116 117
                        property int variantIndex: missionItem.variantIndex.value

                        onVariantIndexChanged: {
                            if (variantIndex === index) {
                                checked = true
                            }
118 119
                        }

120 121 122 123
                        onCheckedChanged: {
                            if (checked && variantIndex !== index) {
                                missionItem.variantIndex.value = index
                            }
124 125
                        }
                    }
126 127 128
                } // variant repeater
            } // variant grid
        } // general grid
129

130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
        // Generator Editor
        SectionHeader {
            id: generatorHeader
            Layout.fillWidth: true
            Layout.columnSpan: parent.columns
            text: qsTr("Generator")
        }

        GridLayout {
            Layout.fillWidth: true
            columnSpacing: _margin
            Layout.maximumWidth: parent.width
            Layout.columnSpan: parent.columns
            rowSpacing: _margin
            columns: 2
            visible: generatorHeader.checked

            QGCComboBox {
                property var names: missionItem.generatorNameList
                property int length: names.length

                enabled: _root.checked
                anchors.margins: ScreenTools.defaultFontPixelWidth
                currentIndex: missionItem.generatorIndex
                Layout.columnSpan: 2
                model: missionItem.generatorNameList

                onActivated: {
                    if (index != -1) {
                        missionItem.switchToGenerator(index)
                    }
161 162 163 164
                }
            }
        }

165 166 167 168 169 170 171
        ColumnLayout {
            id: generatorEditorParent
            Layout.fillWidth: true
            Layout.columnSpan: parent.columns
            Layout.maximumWidth: parent.width
            visible: generatorHeader.checked
        }
172

173 174 175 176 177 178
        QGCButton {
            text: qsTr("Reverse")
            onClicked: missionItem.reverseRoute()
            Layout.columnSpan: 2
            Layout.fillWidth: true
        }
179

180 181 182 183 184
        // bussy indicator
        ColumnLayout {
            Layout.fillWidth: true
            spacing: _margin
            Layout.maximumWidth: parent.width
185

186 187
            BusyIndicator {
                id: indicator
188

189
                property bool calculating: missionItem.calculating
190

191 192
                running: calculating
                visible: calculating || timer.running
193

194 195 196 197 198
                onCalculatingChanged: {
                    if (!calculating) {
                        // defer hiding
                        timer.restart()
                    }
199 200
                }

201 202 203 204 205 206
                Timer {
                    id: timer
                    interval: 1000
                    repeat: false
                    running: false
                }
207
            }
208 209
        } // indicator column
    } // GridLayout
210

211
    function _addGeneratorEditor() {
212
        if (_generator && _generator.editorQml && !_generatorEditor) {
213 214
            var component = Qt.createComponent(_generator.editorQml)
            if (component.status === Component.Error) {
215 216
                console.log("Error loading Qml: ", _generator.editorQml,
                            component.errorString())
217
            } else {
218
                _generatorEditor = component.createObject(
219
                            generatorEditorParent, {
220
                                "generator": _root._generator,
221
                                "availableWidth": generatorEditorParent.width
222 223 224 225 226
                            })
            }
        }
    }

227 228
    function _destroyGeneratorEditor() {
        if (_generatorEditor) {
229 230 231 232
            _generatorEditor.destroy()
            _generatorEditor = undefined
        }
    }
233
} // Rectangle