AreaDataEditor.qml 8.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
    width: mainColumn.width
    height: mainColumn.height
17 18
    color: qgcPal.windowShadeDark

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

25
    property var _areaData: missionItem.areaData
26
    property real _margin: ScreenTools.defaultFontPixelWidth / 2
27 28

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

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

44 45
    ColumnLayout {
        id: mainColumn
46
        width: availableWidth
47 48 49 50 51 52 53 54 55 56 57 58 59
        spacing: _margin

        QGCButton {
            id: editButton
            text: _root.editing ? qsTr("Done") : qsTr("Edit")
            enabled: (_root.editing && _root.areasCorrect) || !_root.editing
            onClicked: {
                if (_root.editing) {
                    _root.missionItem.stopEditing()
                } else {
                    _root.missionItem.startEditing()
                }
            }
60 61
            Layout.fillWidth: true
        }
62

63
        GridLayout {
64

65 66 67 68 69 70
            width: availableWidth
            columnSpacing: _margin
            Layout.fillWidth: true
            rowSpacing: _margin
            columns: 2
            enabled: _root.editing
71

72 73 74 75 76 77
            QGCLabel {
                text: _root.errorString
                wrapMode: Text.WordWrap
                horizontalAlignment: Text.AlignLeft
                color: "orange"
                Layout.columnSpan: parent.columns
78
                Layout.fillWidth: true
79 80
                visible: !_root.areasCorrect
            }
81

82 83
            ExclusiveGroup {
                id: areaGroup
84 85
            }

86 87
            Repeater {
                id: areaSelector
88

89 90 91 92 93 94 95 96 97 98 99
                property int selectedIndex: -1

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

                    onCheckedChanged: {
                        if (checked) {
                            areaSelector.selectedIndex = index
100
                        }
101 102
                    }

103 104 105 106 107 108 109
                    Component.onCompleted: {
                        if (index === 0) {
                            checked = true
                        }
                        object.interactive = Qt.binding(function () {
                            return checked && _root.editing && _missionItem.isCurrentItem
                        })
110
                    }
111
                }
112
            } // area Repeater
113

114 115 116 117 118 119
            ColumnLayout {
                id: editorParent
                Layout.fillWidth: true
                Layout.maximumWidth: parent.width
                Layout.columnSpan: 2
            }
120

121 122 123 124 125 126 127 128 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 161 162 163 164 165
            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
                                                                      })
                                            })
                            }
                        }
                    }

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

167 168
            SectionHeader {
                id: commandsHeader
169 170
                Layout.fillWidth: true
                Layout.columnSpan: parent.columns
171
                text: qsTr("Commands")
172 173
            }

174 175 176 177 178
            GridLayout {
                columnSpacing: _margin
                rowSpacing: _margin
                columns: 2
                Layout.columnSpan: 2
179
                Layout.fillWidth: true
180 181 182 183 184 185 186 187 188 189
                visible: commandsHeader.checked

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

191 192 193 194 195 196 197
                QGCButton {
                    text: "Reset"
                    Layout.fillWidth: true
                    Layout.columnSpan: parent.columns
                    onClicked: {
                        missionItem.reset()
                    }
198
                }
199
            }
200

201 202 203 204 205 206
            SectionHeader {
                id: hintHeader
                Layout.fillWidth: true
                Layout.columnSpan: parent.columns
                text: qsTr("Hints")
            }
207

208 209 210 211 212 213 214
            GridLayout {
                columnSpacing: _margin
                rowSpacing: _margin
                columns: 2
                Layout.columnSpan: 2
                Layout.fillWidth: true
                visible: hintHeader.checked
215

216 217 218 219 220
                QGCLabel {
                    id: hintLabel
                    wrapMode: Text.WordWrap
                    horizontalAlignment: Text.AlignLeft
                    text: qsTr("Use the Intersection button to clip the Measurement Area(s).
221 222
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.")
223 224 225
                    Layout.fillWidth: true
                    Layout.columnSpan: parent.columns
                }
226
            }
227

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
            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 = ""
                    }
243
                }
244
            }
245

246 247 248 249
            Settings {
                property alias showHint: hintHeader.checked
            }
        } // GridLayout
250 251
    } // GridLayout
} // Rectangle