AreaDataEditor.qml 7.12 KB
Newer Older
1 2
import QtQuick 2.0

3
import Qt.labs.settings 1.0
4 5 6 7
import QtQuick.Layouts 1.11
import QtQuick.Controls 1.4
import QGroundControl.Controls 1.0
import QGroundControl.FactControls 1.0
8
import QGroundControl.ScreenTools 1.0
9

10 11 12
import QGroundControl.Palette 1.0

Rectangle {
13
    id: _root
14

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

19 20 21
    property bool checked: true
    property var missionItem: undefined
    property int availableWidth: 300
22 23 24 25
    property bool areasCorrect: false
    property string errorString: ""

    signal abort
26 27

    property var _areaData: missionItem.areaData
28
    property real _margin: ScreenTools.defaultFontPixelWidth / 2
29 30

    Component.onCompleted: {
31 32 33 34 35
        console.assert(missionItem !== undefined,
                       "please set the missionItem property")
        if (checked) {
            areasCorrectTimer.start()
        }
36 37
    }

38 39 40 41 42 43 44
    onCheckedChanged: {
        if (checked) {
            areasCorrectTimer.start()
        } else {
            areasCorrectTimer.stop()
        }
    }
45

46 47
    GridLayout {
        id: mainGrid
48

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

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

64 65 66
        ExclusiveGroup {
            id: areaGroup
        }
67

68 69
        Repeater {
            id: areaSelector
70

71 72 73 74 75 76 77 78 79 80 81 82 83
            property int selectedIndex: -1

            model: _missionItem.areaData.areaList
            delegate: QGCRadioButton {
                text: object.objectName
                checkable: _root.checked
                Layout.fillWidth: true
                Layout.columnSpan: 2

                onCheckedChanged: {
                    if (checked) {
                        areaSelector.selectedIndex = index
                    }
84 85
                }

86 87 88 89 90 91 92
                Component.onCompleted: {
                    if (index === 0) {
                        checked = true
                    }
                    object.interactive = Qt.binding(function () {
                        return checked && _root.checked
                    })
93 94
                }
            }
95
        } // area Repeater
96

97 98 99 100 101 102
        ColumnLayout {
            id: editorParent
            Layout.fillWidth: true
            Layout.maximumWidth: parent.width
            Layout.columnSpan: 2
        }
103

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
        Repeater {
            id: areaEditorRepeater

            Layout.maximumWidth: parent.width

            model: _missionItem.areaData.areaList
            delegate: Item {
                id: editor
                visible: index == areaSelector.selectedIndex

                property var _visualItem: undefined
                property var geoArea: object

                Component.onCompleted: {
                    if (geoArea.editorQML && !_visualItem) {
                        var component = Qt.createComponent(geoArea.editorQML)
                        if (component.status === Component.Error) {
                            console.log("Error loading Qml: ",
                                        geoArea.editorQML,
                                        component.errorString())
                        } else {
                            _visualItem = component.createObject(editorParent, {
                                                                     "geoArea": editor.geoArea,
                                                                     "visible": Qt.binding(
                                                                                    function () {
                                                                                        return editor.visible
                                                                                    }),
                                                                     "availableWidth": Qt.binding(function () {
                                                                         return editorParent.width
                                                                     })
                                                                 })
                        }
136 137 138
                    }
                }

139 140 141 142
                Component.onDestruction: {
                    if (_visualItem) {
                        _visualItem.destroy()
                    }
143
                }
144 145
            } // editor
        } // areaEditorRepeater
146

147 148
        SectionHeader {
            id: commandsHeader
149 150
            Layout.fillWidth: true
            Layout.columnSpan: parent.columns
151
            text: qsTr("Commands")
152 153
        }

154 155 156 157 158
        GridLayout {
            columnSpacing: _margin
            rowSpacing: _margin
            columns: 2
            Layout.columnSpan: 2
159
            Layout.fillWidth: true
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
            visible: commandsHeader.checked

            QGCButton {
                text: "Intersection"
                enabled: _root.checked
                Layout.fillWidth: true
                Layout.columnSpan: parent.columns
                onClicked: {
                    _areaData.intersection()
                }
            }

            QGCButton {
                text: "Reset"
                onClicked: {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
175
                    missionItem.reset()
176 177 178
                }
                Layout.fillWidth: true
            }
179

180 181 182 183 184 185
            QGCButton {
                text: "Abort"
                onClicked: {
                    _root.abort()
                }
                Layout.fillWidth: true
186
            }
187 188
        }

189 190 191 192 193 194
        SectionHeader {
            id: hintHeader
            Layout.fillWidth: true
            Layout.columnSpan: parent.columns
            text: qsTr("Hints")
        }
195

196 197 198 199 200 201 202
        GridLayout {
            columnSpacing: _margin
            rowSpacing: _margin
            columns: 2
            Layout.columnSpan: 2
            Layout.fillWidth: true
            visible: hintHeader.checked
203

204 205 206 207 208
            QGCLabel {
                id: hintLabel
                wrapMode: Text.WordWrap
                horizontalAlignment: Text.AlignLeft
                text: qsTr("Use the Intersection button to clip the Measurement Area(s).
209 210
Use the Reset button to restore the areas to the state before entering this tab.
Use the Abort button to reset the areas and leave the tab.")
211 212 213
                Layout.fillWidth: true
                Layout.columnSpan: parent.columns
            }
214 215
        }

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
        Timer {
            id: areasCorrectTimer
            running: false
            interval: 100
            repeat: true

            onTriggered: {
                _root.areasCorrect = _missionItem.areaData.isCorrect(
                            false /*show gui message*/
                            )
                if (!_root.areasCorrect) {
                    _root.errorString = _missionItem.areaData.errorString
                } else {
                    _root.errorString = ""
                }
231
            }
232
        }
233

234 235 236 237 238
        Settings {
            property alias showHint: hintHeader.checked
        }
    } // GridLayout
} // Rectangle