NemoEditor.qml 6.49 KB
Newer Older
1 2 3 4
import QtQuick 2.0
import Qt.labs.settings 1.0
import QtQuick.Layouts 1.11
import QtQuick.Controls 1.4
5

6 7 8
import QGroundControl.Controls 1.0
import QGroundControl.FactControls 1.0
import QGroundControl.ScreenTools 1.0
9
import QGroundControl.Palette 1.0
10 11 12

import MeasurementComplexItem 1.0 as MCI

13
Rectangle {
14 15
    id: _root

16 17 18 19
    width: mainGrid.width
    height: mainGrid.height
    color: qgcPal.windowShadeDark

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    property bool checked: true
    property var missionItem: undefined
    property int availableWidth: 300
    property bool error: errorString.lenght >= 0
    readonly property bool running: _nemoInterface.running
    property string errorString: ""

    signal abort

    property var _areaData: missionItem.areaData
    property real _margin: ScreenTools.defaultFontPixelWidth / 2
    property var _nemoInterface: MCI.NemoInterface
    property bool _holding

    Component.onCompleted: {
        console.assert(missionItem !== undefined,
                       "please set the missionItem property")
        _holding = false
        _stopHolding()
    }

    GridLayout {
42 43 44
        id: mainGrid

        width: availableWidth
45 46 47 48
        columnSpacing: _margin
        rowSpacing: _margin
        columns: 2

49 50 51 52 53 54
        QGCLabel {
            text: _root.errorString
            wrapMode: Text.WordWrap
            horizontalAlignment: Text.AlignLeft
            color: "orange"
            Layout.columnSpan: parent.columns
55
            Layout.fillWidth: true
56 57 58 59 60
            visible: !_root.areasCorrect
        }

        QGCButton {
            text: running ? qsTr("Stop") : qsTr("Start")
61
            Layout.columnSpan: parent.columns
62
            Layout.fillWidth: true
63
            onPressed: {
64 65
                if (running) {
                    _nemoInterface.stop()
66
                } else {
67
                    _nemoInterface.start()
68 69 70 71
                }
            }
        }

72 73 74 75
        QGCLabel {
            text: qsTr("Status: ") + _nemoInterface.statusString
            wrapMode: Text.WordWrap
            horizontalAlignment: Text.AlignVCenter
76 77 78 79
            Layout.columnSpan: parent.columns
            Layout.fillWidth: true
        }

80 81 82 83 84 85 86 87 88 89 90
        SectionHeader {
            id: progressHeader
            Layout.fillWidth: true
            Layout.columnSpan: parent.columns
            text: qsTr("Progress")
        }

        GridLayout {
            columnSpacing: _margin
            rowSpacing: _margin
            columns: 2
91 92
            Layout.columnSpan: parent.columns
            Layout.fillWidth: true
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
            visible: progressHeader.checked

            QGCButton {
                text: !_holding ? qsTr("Hold") : qsTr("Stop Holding")
                Layout.fillWidth: true
                Layout.columnSpan: parent.columns
                onPressed: {
                    if (_holding) {
                        _stopHolding()
                        _holding = false
                    } else {
                        _holdProgress()
                        _holding = true
                    }
                }
            }

            QGCButton {
                text: qsTr("Random")
                Layout.columnSpan: parent.columns
                Layout.fillWidth: true
                onPressed: {
                    _randomProgress()
                }
            }

            QGCButton {
                text: qsTr("Reset")
                Layout.columnSpan: parent.columns
                Layout.fillWidth: true
                onPressed: {
                    _resetProgress()
                }
126 127 128
            }
        }

129 130 131 132 133
        // bussy indicator
        ColumnLayout {
            Layout.fillWidth: true
            spacing: _margin
            Layout.maximumWidth: parent.width
134

135 136
            BusyIndicator {
                id: indicator
137

138
                property bool calculating: missionItem.calculating
139

140 141
                running: calculating
                visible: calculating || timer.running
142

143 144 145 146 147
                onCalculatingChanged: {
                    if (!calculating) {
                        // defer hiding
                        timer.restart()
                    }
148 149
                }

150 151 152 153 154 155
                Timer {
                    id: timer
                    interval: 1000
                    repeat: false
                    running: false
                }
156
            }
157
        } // indicator column
158

159 160 161 162 163 164
        SectionHeader {
            id: hintHeader
            Layout.fillWidth: true
            Layout.columnSpan: parent.columns
            text: qsTr("Hints")
        }
165

166 167 168 169 170 171 172
        GridLayout {
            columnSpacing: _margin
            rowSpacing: _margin
            columns: 2
            Layout.columnSpan: 2
            Layout.fillWidth: true
            visible: hintHeader.checked
173

174 175 176 177 178
            QGCLabel {
                id: hintLabel
                wrapMode: Text.WordWrap
                horizontalAlignment: Text.AlignLeft
                text: qsTr("Use this tab to connect to a device implementing the Nemo Interface.
179
Use the Random button to simulate measurement progress.")
180 181 182
                Layout.fillWidth: true
                Layout.columnSpan: parent.columns
            }
183 184
        }

185 186 187 188
        Settings {
            property alias showHint: hintHeader.checked
        }
    } // GridLayout
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236

    function _holdProgress() {
        var areaArray = _areaData.measurementAreaList
        for (var i = 0; i < areaArray.count; ++i) {
            var area = areaArray.get(i)
            if (area) {
                area.holdProgress = true
            } else {
                console.log("empty area!")
            }
        }
    }

    function _stopHolding() {
        var areaArray = _areaData.measurementAreaList
        for (var i = 0; i < areaArray.count; ++i) {
            var area = areaArray.get(i)
            if (area) {
                area.holdProgress = false
            } else {
                console.log("empty area!")
            }
        }
    }

    function _randomProgress() {
        var areaArray = _areaData.measurementAreaList
        for (var i = 0; i < areaArray.count; ++i) {
            var area = areaArray.get(i)
            if (area) {
                area.randomProgress()
            } else {
                console.log("empty area!")
            }
        }
    }

    function _resetProgress() {
        var areaArray = _areaData.measurementAreaList
        for (var i = 0; i < areaArray.count; ++i) {
            var area = areaArray.get(i)
            if (area) {
                area.resetProgress()
            } else {
                console.log("empty area!")
            }
        }
    }
237
} // Rectangle