GeoFenceEditor.qml 12.9 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

QGCFlickable {
    id:             root
Don Gagne's avatar
Don Gagne committed
13
    contentHeight:  geoFenceEditorRect.height
14 15
    clip:           true

16 17 18
    property var    myGeoFenceController
    property var    flightMap

19
    readonly property real  _editFieldWidth:    Math.min(width - _margin * 2, ScreenTools.defaultFontPixelWidth * 15)
20 21 22
    readonly property real  _margin:            ScreenTools.defaultFontPixelWidth / 2
    readonly property real  _radius:            ScreenTools.defaultFontPixelWidth / 2

Don Gagne's avatar
Don Gagne committed
23 24
    Rectangle {
        id:     geoFenceEditorRect
25 26
        anchors.left:   parent.left
        anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
27 28 29 30 31 32 33 34 35 36 37 38
        height: geoFenceItems.y + geoFenceItems.height + (_margin * 2)
        radius: _radius
        color:  qgcPal.missionItemEditor

        QGCLabel {
            id:                 geoFenceLabel
            anchors.margins:    _margin
            anchors.left:       parent.left
            anchors.top:        parent.top
            text:               qsTr("GeoFence")
            anchors.leftMargin: ScreenTools.defaultFontPixelWidth
        }
39

40
        Rectangle {
Don Gagne's avatar
Don Gagne committed
41 42 43 44 45 46 47 48 49 50 51
            id:                 geoFenceItems
            anchors.margins:    _margin
            anchors.left:       parent.left
            anchors.right:      parent.right
            anchors.top:        geoFenceLabel.bottom
            height:             fenceColumn.y + fenceColumn.height + (_margin * 2)
            color:              qgcPal.windowShadeDark
            radius:             _radius

            Column {
                id:                 fenceColumn
52 53
                anchors.margins:    _margin
                anchors.top:        parent.top
54 55
                anchors.left:       parent.left
                anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
56
                spacing:            ScreenTools.defaultFontPixelHeight / 2
57

Don Gagne's avatar
Don Gagne committed
58
                QGCLabel {
59 60
                    anchors.left:       parent.left
                    anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
61 62 63 64 65 66
                    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.")
                }
67

Don Gagne's avatar
Don Gagne committed
68 69 70 71 72
                Column {
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    spacing:        ScreenTools.defaultFontPixelHeight / 2
                    visible:        myGeoFenceController.supported
73

Don Gagne's avatar
Don Gagne committed
74 75
                    Repeater {
                        model: myGeoFenceController.params
76

Don Gagne's avatar
Don Gagne committed
77 78 79
                        Item {
                            width:  fenceColumn.width
                            height: textField.height
80

Don Gagne's avatar
Don Gagne committed
81
                            property bool showCombo: modelData.enumStrings.length > 0
82

Don Gagne's avatar
Don Gagne committed
83 84 85 86 87
                            QGCLabel {
                                id:                 textFieldLabel
                                anchors.baseline:   textField.baseline
                                text:               myGeoFenceController.paramLabels[index]
                            }
88

Don Gagne's avatar
Don Gagne committed
89 90 91 92 93 94 95 96
                            FactTextField {
                                id:             textField
                                anchors.right:  parent.right
                                width:          _editFieldWidth
                                showUnits:      true
                                fact:           modelData
                                visible:        !parent.showCombo
                            }
97

Don Gagne's avatar
Don Gagne committed
98 99 100 101 102 103 104
                            FactComboBox {
                                id:             comboField
                                anchors.right:  parent.right
                                width:          _editFieldWidth
                                indexModel:     false
                                fact:           showCombo ? modelData : _nullFact
                                visible:        parent.showCombo
105

Don Gagne's avatar
Don Gagne committed
106
                                property var _nullFact: Fact { }
107 108
                            }
                        }
Don Gagne's avatar
Don Gagne committed
109
                    }
110

Don Gagne's avatar
Don Gagne committed
111 112 113 114
                    SectionHeader {
                        id:     insertSection
                        text:   qsTr("Insert GeoFence")
                    }
115

Don Gagne's avatar
Don Gagne committed
116 117 118 119
                    QGCButton {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        text:           qsTr("Polygon Fence")
120

Don Gagne's avatar
Don Gagne committed
121 122 123 124 125
                        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)
126
                        }
Don Gagne's avatar
Don Gagne committed
127
                    }
128

Don Gagne's avatar
Don Gagne committed
129 130 131 132
                    QGCButton {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        text:           qsTr("Circular Fence")
133

Don Gagne's avatar
Don Gagne committed
134 135 136 137 138
                        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)
139
                        }
Don Gagne's avatar
Don Gagne committed
140
                    }
141

Don Gagne's avatar
Don Gagne committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
                    SectionHeader {
                        id:     polygonSection
                        text:   qsTr("Polygon Fences")
                    }

                    QGCLabel {
                        text:       qsTr("None")
                        visible:    polygonSection.checked && myGeoFenceController.polygons.count === 0
                    }

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

                        QGCLabel {
Don Gagne's avatar
Don Gagne committed
160 161 162
                            text:               qsTr("Inclusion")
                            Layout.column:      0
                            Layout.alignment:   Qt.AlignHCenter
163 164
                        }

Don Gagne's avatar
Don Gagne committed
165 166
                        Repeater {
                            model: myGeoFenceController.polygons
167

Don Gagne's avatar
Don Gagne committed
168 169 170
                            QGCCheckBox {
                                checked:            object.inclusion
                                onClicked:          object.inclusion = checked
171 172
                                Layout.alignment:   Qt.AlignHCenter
                            }
Don Gagne's avatar
Don Gagne committed
173
                        }
174

Don Gagne's avatar
Don Gagne committed
175 176 177 178 179
                        QGCLabel {
                            text:               qsTr("Edit")
                            Layout.column:      1
                            Layout.alignment:   Qt.AlignHCenter
                        }
180

Don Gagne's avatar
Don Gagne committed
181 182
                        Repeater {
                            model: myGeoFenceController.polygons
183

Don Gagne's avatar
Don Gagne committed
184 185
                            QGCRadioButton {
                                checked:            _interactive
186 187
                                Layout.alignment:   Qt.AlignHCenter

Don Gagne's avatar
Don Gagne committed
188
                                property bool _interactive: object.interactive
189

Don Gagne's avatar
Don Gagne committed
190
                                on_InteractiveChanged: checked = _interactive
191

Don Gagne's avatar
Don Gagne committed
192 193 194
                                onClicked: {
                                    myGeoFenceController.clearAllInteractive()
                                    object.interactive = checked
195 196
                                }
                            }
Don Gagne's avatar
Don Gagne committed
197
                        }
198

Don Gagne's avatar
Don Gagne committed
199 200 201 202 203
                        QGCLabel {
                            text:               qsTr("Delete")
                            Layout.column:      2
                            Layout.alignment:   Qt.AlignHCenter
                        }
204

Don Gagne's avatar
Don Gagne committed
205 206
                        Repeater {
                            model: myGeoFenceController.polygons
207

Don Gagne's avatar
Don Gagne committed
208 209 210 211 212 213 214
                            QGCButton {
                                text:               qsTr("Del")
                                Layout.alignment:   Qt.AlignHCenter
                                onClicked:          myGeoFenceController.deletePolygon(index)
                            }
                        }
                    } // GridLayout
215

Don Gagne's avatar
Don Gagne committed
216 217 218 219
                    SectionHeader {
                        id:     circleSection
                        text:   qsTr("Circular Fences")
                    }
220

Don Gagne's avatar
Don Gagne committed
221 222 223 224
                    QGCLabel {
                        text:       qsTr("None")
                        visible:    circleSection.checked && myGeoFenceController.circles.count === 0
                    }
225

Don Gagne's avatar
Don Gagne committed
226 227 228 229 230 231
                    GridLayout {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        columns:        4
                        flow:           GridLayout.TopToBottom
                        visible:        polygonSection.checked && myGeoFenceController.circles.count > 0
232 233

                        QGCLabel {
Don Gagne's avatar
Don Gagne committed
234 235 236
                            text:               qsTr("Inclusion")
                            Layout.column:      0
                            Layout.alignment:   Qt.AlignHCenter
237 238
                        }

Don Gagne's avatar
Don Gagne committed
239 240
                        Repeater {
                            model: myGeoFenceController.circles
241

Don Gagne's avatar
Don Gagne committed
242 243 244
                            QGCCheckBox {
                                checked:            object.inclusion
                                onClicked:          object.inclusion = checked
245 246
                                Layout.alignment:   Qt.AlignHCenter
                            }
Don Gagne's avatar
Don Gagne committed
247
                        }
248

Don Gagne's avatar
Don Gagne committed
249 250 251 252 253
                        QGCLabel {
                            text:               qsTr("Edit")
                            Layout.column:      1
                            Layout.alignment:   Qt.AlignHCenter
                        }
254

Don Gagne's avatar
Don Gagne committed
255 256
                        Repeater {
                            model: myGeoFenceController.circles
257

Don Gagne's avatar
Don Gagne committed
258 259
                            QGCRadioButton {
                                checked:            _interactive
260 261
                                Layout.alignment:   Qt.AlignHCenter

Don Gagne's avatar
Don Gagne committed
262
                                property bool _interactive: object.interactive
263

Don Gagne's avatar
Don Gagne committed
264
                                on_InteractiveChanged: checked = _interactive
265

Don Gagne's avatar
Don Gagne committed
266 267 268
                                onClicked: {
                                    myGeoFenceController.clearAllInteractive()
                                    object.interactive = checked
269 270
                                }
                            }
Don Gagne's avatar
Don Gagne committed
271
                        }
272

Don Gagne's avatar
Don Gagne committed
273 274 275 276 277
                        QGCLabel {
                            text:               qsTr("Radius")
                            Layout.column:      2
                            Layout.alignment:   Qt.AlignHCenter
                        }
278

Don Gagne's avatar
Don Gagne committed
279 280
                        Repeater {
                            model: myGeoFenceController.circles
281

Don Gagne's avatar
Don Gagne committed
282 283 284
                            FactTextField {
                                fact:               object.radius
                                Layout.fillWidth:   true
285 286
                                Layout.alignment:   Qt.AlignHCenter
                            }
Don Gagne's avatar
Don Gagne committed
287
                        }
288

Don Gagne's avatar
Don Gagne committed
289 290 291 292 293
                        QGCLabel {
                            text:               qsTr("Delete")
                            Layout.column:      3
                            Layout.alignment:   Qt.AlignHCenter
                        }
294

Don Gagne's avatar
Don Gagne committed
295 296
                        Repeater {
                            model: myGeoFenceController.circles
297

Don Gagne's avatar
Don Gagne committed
298 299 300 301
                            QGCButton {
                                text:               qsTr("Del")
                                Layout.alignment:   Qt.AlignHCenter
                                onClicked:          myGeoFenceController.deleteCircle(index)
302
                            }
Don Gagne's avatar
Don Gagne committed
303 304
                        }
                    } // GridLayout
305
                }
306
            }
Don Gagne's avatar
Don Gagne committed
307 308
        }
    } // Rectangle
309
}