GeoFenceEditor.qml 15.2 KB
Newer Older
1 2
import QtQuick          2.3
import QtQuick.Controls 1.2
3
import QtQuick.Layouts  1.2
4 5 6 7

import QGroundControl               1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
8 9
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
10 11 12 13

QGCFlickable {
    id:             root
    width:          availableWidth
14 15
    height:         availableHeight
    contentHeight:  editorColumn.height
16 17
    clip:           true

18 19 20 21 22
    property real   availableWidth
    property real   availableHeight
    property var    myGeoFenceController
    property var    flightMap

23
    readonly property real  _editFieldWidth:    Math.min(width - _margin * 2, ScreenTools.defaultFontPixelWidth * 15)
24 25 26
    readonly property real  _margin:            ScreenTools.defaultFontPixelWidth / 2
    readonly property real  _radius:            ScreenTools.defaultFontPixelWidth / 2

27 28 29 30
    Column {
        id:             editorColumn
        anchors.left:   parent.left
        anchors.right:  parent.right
31

32 33 34 35 36 37
        Rectangle {
            id:     geoFenceEditorRect
            width:  parent.width
            height: geoFenceItems.y + geoFenceItems.height + (_margin * 2)
            radius: _radius
            color:  qgcPal.missionItemEditor
38

39 40 41 42 43 44
            QGCLabel {
                id:                 geoFenceLabel
                anchors.margins:    _margin
                anchors.left:       parent.left
                anchors.top:        parent.top
                text:               qsTr("GeoFence")
Gus Grubba's avatar
Gus Grubba committed
45
                anchors.leftMargin: ScreenTools.defaultFontPixelWidth
46
            }
47

48 49
            Rectangle {
                id:                 geoFenceItems
50 51 52
                anchors.margins:    _margin
                anchors.left:       parent.left
                anchors.right:      parent.right
53 54 55 56
                anchors.top:        geoFenceLabel.bottom
                height:             fenceColumn.y + fenceColumn.height + (_margin * 2)
                color:              qgcPal.windowShadeDark
                radius:             _radius
57

58 59 60 61
                Column {
                    id:                 fenceColumn
                    anchors.margins:    _margin
                    anchors.top:        parent.top
62 63
                    anchors.left:       parent.left
                    anchors.right:      parent.right
64
                    spacing:            ScreenTools.defaultFontPixelHeight / 2
65

66 67 68 69 70 71 72 73 74
                    QGCLabel {
                        anchors.left:       parent.left
                        anchors.right:      parent.right
                        wrapMode:           Text.WordWrap
                        font.pointSize:     myGeoFenceController.supported ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
                        text:               myGeoFenceController.supported ?
                                                qsTr("GeoFencing allows you to set a virtual ‘fence’ around the area you want to fly in.") :
                                                qsTr("This vehicle does not support GeoFence.")
                    }
75

76 77 78 79 80
                    Column {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        spacing:        ScreenTools.defaultFontPixelHeight / 2
                        visible:        myGeoFenceController.supported
81

82 83
                        Repeater {
                            model: myGeoFenceController.params
84

85 86 87 88 89 90 91 92 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
                            Item {
                                width:  fenceColumn.width
                                height: textField.height

                                property bool showCombo: modelData.enumStrings.length > 0

                                QGCLabel {
                                    id:                 textFieldLabel
                                    anchors.baseline:   textField.baseline
                                    text:               myGeoFenceController.paramLabels[index]
                                }

                                FactTextField {
                                    id:             textField
                                    anchors.right:  parent.right
                                    width:          _editFieldWidth
                                    showUnits:      true
                                    fact:           modelData
                                    visible:        !parent.showCombo
                                }

                                FactComboBox {
                                    id:             comboField
                                    anchors.right:  parent.right
                                    width:          _editFieldWidth
                                    indexModel:     false
                                    fact:           showCombo ? modelData : _nullFact
                                    visible:        parent.showCombo

                                    property var _nullFact: Fact { }
                                }
                            }
                        }

                        SectionHeader {
                            id:     insertSection
                            text:   qsTr("Insert GeoFence")
122 123
                        }

124 125
                        QGCButton {
                            anchors.left:   parent.left
126
                            anchors.right:  parent.right
127 128 129 130 131 132 133 134
                            text:           qsTr("Polygon Fence")

                            onClicked: {
                                var rect = Qt.rect(flightMap.centerViewport.x, flightMap.centerViewport.y, flightMap.centerViewport.width, flightMap.centerViewport.height)
                                var topLeftCoord = flightMap.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */)
                                var bottomRightCoord = flightMap.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */)
                                myGeoFenceController.addInclusionPolygon(topLeftCoord, bottomRightCoord)
                            }
135 136
                        }

137 138
                        QGCButton {
                            anchors.left:   parent.left
139
                            anchors.right:  parent.right
140
                            text:           qsTr("Circular Fence")
141

142 143 144 145 146 147
                            onClicked: {
                                var rect = Qt.rect(flightMap.centerViewport.x, flightMap.centerViewport.y, flightMap.centerViewport.width, flightMap.centerViewport.height)
                                var topLeftCoord = flightMap.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */)
                                var bottomRightCoord = flightMap.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */)
                                myGeoFenceController.addInclusionCircle(topLeftCoord, bottomRightCoord)
                            }
148 149
                        }

150 151 152 153 154 155 156
                        SectionHeader {
                            id:     polygonSection
                            text:   qsTr("Polygon Fences")
                        }

                        QGCLabel {
                            text:       qsTr("None")
157
                            visible:    polygonSection.checked && myGeoFenceController.polygons.count === 0
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
                        }

                        GridLayout {
                            anchors.left:   parent.left
                            anchors.right:  parent.right
                            columns:        3
                            flow:           GridLayout.TopToBottom
                            visible:        polygonSection.checked && myGeoFenceController.polygons.count > 0

                            QGCLabel {
                                text:               qsTr("Inclusion")
                                Layout.column:      0
                                Layout.alignment:   Qt.AlignHCenter
                            }

                            Repeater {
                                model: myGeoFenceController.polygons

                                QGCCheckBox {
                                    checked:            object.inclusion
                                    onClicked:          object.inclusion = checked
                                    Layout.alignment:   Qt.AlignHCenter
                                }
                            }

                            QGCLabel {
                                text:               qsTr("Edit")
                                Layout.column:      1
                                Layout.alignment:   Qt.AlignHCenter
                            }

                            Repeater {
                                model: myGeoFenceController.polygons

                                QGCRadioButton {
                                    checked:            _interactive
                                    Layout.alignment:   Qt.AlignHCenter

                                    property bool _interactive: object.interactive
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 237 238 239 240 241
                                    on_InteractiveChanged: checked = _interactive

                                    onClicked: {
                                        myGeoFenceController.clearAllInteractive()
                                        object.interactive = checked
                                    }
                                }
                            }

                            QGCLabel {
                                text:               qsTr("Delete")
                                Layout.column:      2
                                Layout.alignment:   Qt.AlignHCenter
                            }

                            Repeater {
                                model: myGeoFenceController.polygons

                                QGCColoredImage {
                                    width:              ScreenTools.defaultFontPixelHeight
                                    height:             width
                                    sourceSize.height:  width
                                    source:             "/res/XDelete.svg"
                                    fillMode:           Image.PreserveAspectFit
                                    color:              qgcPal.text
                                    Layout.alignment:   Qt.AlignHCenter

                                    property int _polygonIndex: index

                                    QGCMouseArea {
                                        fillItem:   parent
                                        onClicked:  myGeoFenceController.deletePolygon(parent._polygonIndex)
                                    }
                                }
                            }
                        } // GridLayout

                        SectionHeader {
                            id:     circleSection
                            text:   qsTr("Circular Fences")
                        }

                        QGCLabel {
                            text:       qsTr("None")
242
                            visible:    circleSection.checked && myGeoFenceController.circles.count === 0
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
                        }

                        GridLayout {
                            anchors.left:   parent.left
                            anchors.right:  parent.right
                            columns:        4
                            flow:           GridLayout.TopToBottom
                            visible:        polygonSection.checked && myGeoFenceController.circles.count > 0

                            QGCLabel {
                                text:               qsTr("Inclusion")
                                Layout.column:      0
                                Layout.alignment:   Qt.AlignHCenter
                            }

                            Repeater {
                                model: myGeoFenceController.circles

                                QGCCheckBox {
                                    checked:            object.inclusion
                                    onClicked:          object.inclusion = checked
                                    Layout.alignment:   Qt.AlignHCenter
                                }
                            }

                            QGCLabel {
                                text:               qsTr("Edit")
                                Layout.column:      1
                                Layout.alignment:   Qt.AlignHCenter
                            }

                            Repeater {
                                model: myGeoFenceController.circles

                                QGCRadioButton {
                                    checked:            _interactive
                                    Layout.alignment:   Qt.AlignHCenter

                                    property bool _interactive: object.interactive

                                    on_InteractiveChanged: checked = _interactive

                                    onClicked: {
                                        myGeoFenceController.clearAllInteractive()
                                        object.interactive = checked
                                    }
                                }
                            }

                            QGCLabel {
                                text:               qsTr("Radius")
                                Layout.column:      2
                                Layout.alignment:   Qt.AlignHCenter
                            }

                            Repeater {
                                model: myGeoFenceController.circles

                                FactTextField {
                                    fact:               object.radius
                                    Layout.fillWidth:   true
                                    Layout.alignment:   Qt.AlignHCenter
                                }
                            }

                            QGCLabel {
                                text:               qsTr("Delete")
                                Layout.column:      3
                                Layout.alignment:   Qt.AlignHCenter
                            }

                            Repeater {
                                model: myGeoFenceController.circles

                                QGCColoredImage {
                                    width:              ScreenTools.defaultFontPixelHeight
                                    height:             width
                                    sourceSize.height:  width
                                    source:             "/res/XDelete.svg"
                                    fillMode:           Image.PreserveAspectFit
                                    color:              qgcPal.text
                                    Layout.alignment:   Qt.AlignHCenter

                                    property int _circleIndex: index

                                    QGCMouseArea {
                                        fillItem:   parent
                                        onClicked:  myGeoFenceController.deleteCircle(parent._polygonIndex)
                                    }
                                }
                            }
                        } // GridLayout
                    }
336
                }
337
            }
338
        } // Rectangle
339 340
    }
}