AreaDataEditor.qml 6.25 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

GridLayout {
11
    id: _root
12 13 14 15

    property bool checked: true
    property var missionItem: undefined
    property int availableWidth: 300
16 17 18 19
    property bool areasCorrect: false
    property string errorString: ""

    signal abort
20 21

    property var _areaData: missionItem.areaData
22
    property real _margin: ScreenTools.defaultFontPixelWidth / 2
23

24 25 26
    columnSpacing: _margin
    rowSpacing: _margin
    columns: 2
27 28

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

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

44
    QGCLabel {
45
        text: _root.errorString
46
        wrapMode: Text.WordWrap
47 48
        horizontalAlignment: Text.AlignLeft
        color: "orange"
49
        Layout.columnSpan: parent.columns
50 51 52 53 54 55
        Layout.fillWidth: true
        visible: !_root.areasCorrect
    }

    ExclusiveGroup {
        id: areaGroup
56 57 58
    }

    Repeater {
59 60 61 62 63 64 65 66 67 68 69 70
        id: areaSelector

        property int selectedIndex: -1

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

            onCheckedChanged: {
71
                if (checked) {
72 73 74 75 76
                    areaSelector.selectedIndex = index
                }
            }

            Component.onCompleted: {
77
                if (index === 0) {
78 79
                    checked = true
                }
80 81 82
                object.interactive = Qt.binding(function () {
                    return checked && _root.checked
                })
83 84 85 86 87
            }
        }
    } // area Repeater

    ColumnLayout {
88
        id: editorParent
89
        Layout.fillWidth: true
90
        Layout.maximumWidth: parent.width
91 92 93
        Layout.columnSpan: 2
    }

94 95
    Repeater {
        id: areaEditorRepeater
96

97 98
        Layout.maximumWidth: parent.width

99
        model: _missionItem.areaData.areaList
100 101
        delegate: Item {
            id: editor
102 103 104 105 106 107 108 109 110
            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) {
111 112
                        console.log("Error loading Qml: ", geoArea.editorQML,
                                    component.errorString())
113 114
                    } else {
                        _visualItem = component.createObject(editorParent, {
115 116 117 118 119 120 121 122 123
                                                                 "geoArea": editor.geoArea,
                                                                 "visible": Qt.binding(function () {
                                                                     return editor.visible
                                                                 }),
                                                                 "availableWidth": Qt.binding(
                                                                                       function () {
                                                                                           return editorParent.width
                                                                                       })
                                                             })
124 125 126 127 128 129 130 131 132 133 134 135
                    }
                }
            }

            Component.onDestruction: {
                if (_visualItem) {
                    _visualItem.destroy()
                }
            }
        } // editor
    } // areaEditorRepeater

136 137 138 139
    SectionHeader {
        id: commandsHeader
        Layout.fillWidth: true
        Layout.columnSpan: parent.columns
140
        text: qsTr("Commands")
141
    }
142

143 144 145 146 147
    GridLayout {
        columnSpacing: _margin
        rowSpacing: _margin
        columns: 2
        Layout.columnSpan: 2
148
        Layout.fillWidth: true
149 150 151 152 153 154 155 156 157 158 159 160 161 162
        visible: commandsHeader.checked

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

        QGCButton {
            text: "Reset"
163 164 165 166 167 168 169 170
            onClicked: {
                _root.reset()
            }
            Layout.fillWidth: true
        }

        QGCButton {
            text: "Abort"
171 172 173 174
            onClicked: {
                _root.abort()
            }
            Layout.fillWidth: true
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
        }
    }

    SectionHeader {
        id: hintHeader
        Layout.fillWidth: true
        Layout.columnSpan: parent.columns
        text: qsTr("Hints")
    }

    GridLayout {
        columnSpacing: _margin
        rowSpacing: _margin
        columns: 2
        Layout.columnSpan: 2
        Layout.fillWidth: true
        visible: hintHeader.checked

        QGCLabel {
            id: hintLabel
            wrapMode: Text.WordWrap
            horizontalAlignment: Text.AlignLeft
            text: qsTr("Use the Intersection button to clip the Measurement Area(s).
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.")
            Layout.fillWidth: true
201
            Layout.columnSpan: parent.columns
202 203 204
        }
    }

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
    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 = ""
            }
220 221
        }
    }
222 223 224 225

    Settings {
        property alias showHint: hintHeader.checked
    }
226
}