QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GeoFenceEditor.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4import QtPositioning
5
6import QGroundControl
7import QGroundControl.Controls
8import QGroundControl.FactControls
9
10Rectangle {
11 id: geoFenceEditorRect
12 height: geoFenceItems.y + geoFenceItems.height + (_margin * 2)
13 radius: _radius
14 color: qgcPal.buttonHighlight
15
16 property var myGeoFenceController
17 property var flightMap
18
19 readonly property real _editFieldWidth: Math.min(width - _margin * 2, ScreenTools.defaultFontPixelWidth * 15)
20 readonly property real _margin: ScreenTools.defaultFontPixelWidth / 2
21 readonly property real _radius: ScreenTools.defaultFontPixelWidth / 2
22
23 QGCLabel {
24 id: geoFenceLabel
25 anchors.margins: _margin
26 anchors.left: parent.left
27 anchors.top: parent.top
28 text: qsTr("GeoFence")
29 anchors.leftMargin: ScreenTools.defaultFontPixelWidth
30 }
31
32 Rectangle {
33 id: geoFenceItems
34 anchors.margins: _margin
35 anchors.left: parent.left
36 anchors.right: parent.right
37 anchors.top: geoFenceLabel.bottom
38 height: fenceColumn.y + fenceColumn.height + (_margin * 2)
39 color: qgcPal.windowShadeDark
40 radius: _radius
41
42 Column {
43 id: fenceColumn
44 anchors.margins: _margin
45 anchors.top: parent.top
46 anchors.left: parent.left
47 anchors.right: parent.right
48 spacing: _margin
49
50 QGCLabel {
51 anchors.left: parent.left
52 anchors.right: parent.right
53 wrapMode: Text.WordWrap
54 font.pointSize: myGeoFenceController.supported ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
55 text: myGeoFenceController.supported ?
56 qsTr("GeoFencing allows you to set a virtual fence around the area you want to fly in.") :
57 qsTr("This vehicle does not support GeoFence.")
58 }
59
60 Column {
61 anchors.left: parent.left
62 anchors.right: parent.right
63 spacing: _margin
64 visible: myGeoFenceController.supported
65
66 Repeater {
67 model: myGeoFenceController.params
68
69 Item {
70 width: fenceColumn.width
71 height: textField.height
72
73 property bool showCombo: modelData.enumStrings.length > 0
74
75 QGCLabel {
76 id: textFieldLabel
77 anchors.baseline: textField.baseline
78 text: myGeoFenceController.paramLabels[index]
79 }
80
81 FactTextField {
82 id: textField
83 anchors.right: parent.right
84 width: _editFieldWidth
85 showUnits: true
86 fact: modelData
87 visible: !parent.showCombo
88 }
89
90 FactComboBox {
91 id: comboField
92 anchors.right: parent.right
93 width: _editFieldWidth
94 indexModel: false
95 fact: showCombo ? modelData : _nullFact
96 visible: parent.showCombo
97
98 property var _nullFact: Fact { }
99 }
100 }
101 }
102
103 SectionHeader {
104 id: insertSection
105 anchors.left: parent.left
106 anchors.right: parent.right
107 text: qsTr("Insert GeoFence")
108 }
109
110 QGCButton {
111 Layout.fillWidth: true
112 text: qsTr("Polygon Fence")
113
114 onClicked: {
115 var rect = Qt.rect(flightMap.centerViewport.x, flightMap.centerViewport.y, flightMap.centerViewport.width, flightMap.centerViewport.height)
116 var topLeftCoord = flightMap.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */)
117 var bottomRightCoord = flightMap.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */)
118 myGeoFenceController.addInclusionPolygon(topLeftCoord, bottomRightCoord)
119 }
120 }
121
122 QGCButton {
123 Layout.fillWidth: true
124 text: qsTr("Circular Fence")
125
126 onClicked: {
127 var rect = Qt.rect(flightMap.centerViewport.x, flightMap.centerViewport.y, flightMap.centerViewport.width, flightMap.centerViewport.height)
128 var topLeftCoord = flightMap.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */)
129 var bottomRightCoord = flightMap.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */)
130 myGeoFenceController.addInclusionCircle(topLeftCoord, bottomRightCoord)
131 }
132 }
133
134 SectionHeader {
135 id: polygonSection
136 anchors.left: parent.left
137 anchors.right: parent.right
138 text: qsTr("Polygon Fences")
139 }
140
141 QGCLabel {
142 text: qsTr("None")
143 visible: polygonSection.checked && myGeoFenceController.polygons.count === 0
144 }
145
146 GridLayout {
147 Layout.fillWidth: true
148 columns: 3
149 flow: GridLayout.TopToBottom
150 visible: polygonSection.checked && myGeoFenceController.polygons.count > 0
151
152 QGCLabel {
153 text: qsTr("Inclusion")
154 Layout.column: 0
155 Layout.alignment: Qt.AlignHCenter
156 }
157
158 Repeater {
159 model: myGeoFenceController.polygons
160
161 QGCCheckBox {
162 checked: object.inclusion
163 onClicked: object.inclusion = checked
164 Layout.alignment: Qt.AlignHCenter
165 }
166 }
167
168 QGCLabel {
169 text: qsTr("Edit")
170 Layout.column: 1
171 Layout.alignment: Qt.AlignHCenter
172 }
173
174 Repeater {
175 model: myGeoFenceController.polygons
176
177 QGCRadioButton {
178 checked: _interactive
179 Layout.alignment: Qt.AlignHCenter
180
181 property bool _interactive: object.interactive
182
183 on_InteractiveChanged: checked = _interactive
184
185 onClicked: {
186 myGeoFenceController.clearAllInteractive()
187 object.interactive = checked
188 }
189 }
190 }
191
192 QGCLabel {
193 text: qsTr("Delete")
194 Layout.column: 2
195 Layout.alignment: Qt.AlignHCenter
196 }
197
198 Repeater {
199 model: myGeoFenceController.polygons
200
201 QGCButton {
202 text: qsTr("Del")
203 Layout.alignment: Qt.AlignHCenter
204 onClicked: myGeoFenceController.deletePolygon(index)
205 }
206 }
207 } // GridLayout
208
209 SectionHeader {
210 id: circleSection
211 anchors.left: parent.left
212 anchors.right: parent.right
213 text: qsTr("Circular Fences")
214 }
215
216 QGCLabel {
217 text: qsTr("None")
218 visible: circleSection.checked && myGeoFenceController.circles.count === 0
219 }
220
221 GridLayout {
222 anchors.left: parent.left
223 anchors.right: parent.right
224 columns: 4
225 flow: GridLayout.TopToBottom
226 visible: polygonSection.checked && myGeoFenceController.circles.count > 0
227
228 QGCLabel {
229 text: qsTr("Inclusion")
230 Layout.column: 0
231 Layout.alignment: Qt.AlignHCenter
232 }
233
234 Repeater {
235 model: myGeoFenceController.circles
236
237 QGCCheckBox {
238 checked: object.inclusion
239 onClicked: object.inclusion = checked
240 Layout.alignment: Qt.AlignHCenter
241 }
242 }
243
244 QGCLabel {
245 text: qsTr("Edit")
246 Layout.column: 1
247 Layout.alignment: Qt.AlignHCenter
248 }
249
250 Repeater {
251 model: myGeoFenceController.circles
252
253 QGCRadioButton {
254 checked: _interactive
255 Layout.alignment: Qt.AlignHCenter
256
257 property bool _interactive: object.interactive
258
259 on_InteractiveChanged: checked = _interactive
260
261 onClicked: {
262 myGeoFenceController.clearAllInteractive()
263 object.interactive = checked
264 }
265 }
266 }
267
268 QGCLabel {
269 text: qsTr("Radius")
270 Layout.column: 2
271 Layout.alignment: Qt.AlignHCenter
272 }
273
274 Repeater {
275 model: myGeoFenceController.circles
276
277 FactTextField {
278 fact: object.radius
279 Layout.fillWidth: true
280 Layout.alignment: Qt.AlignHCenter
281 }
282 }
283
284 QGCLabel {
285 text: qsTr("Delete")
286 Layout.column: 3
287 Layout.alignment: Qt.AlignHCenter
288 }
289
290 Repeater {
291 model: myGeoFenceController.circles
292
293 QGCButton {
294 text: qsTr("Del")
295 Layout.alignment: Qt.AlignHCenter
296 onClicked: myGeoFenceController.deleteCircle(index)
297 }
298 }
299 } // GridLayout
300
301 SectionHeader {
302 id: breachReturnSection
303 anchors.left: parent.left
304 anchors.right: parent.right
305 text: qsTr("Breach Return Point")
306 }
307
308 QGCButton {
309 text: qsTr("Add Breach Return Point")
310 visible: breachReturnSection.visible && !myGeoFenceController.breachReturnPoint.isValid
311 anchors.left: parent.left
312 anchors.right: parent.right
313
314 onClicked: myGeoFenceController.breachReturnPoint = flightMap.center
315 }
316
317 QGCButton {
318 text: qsTr("Remove Breach Return Point")
319 visible: breachReturnSection.visible && myGeoFenceController.breachReturnPoint.isValid
320 anchors.left: parent.left
321 anchors.right: parent.right
322
323 onClicked: myGeoFenceController.breachReturnPoint = QtPositioning.coordinate()
324 }
325
326 ColumnLayout {
327 anchors.left: parent.left
328 anchors.right: parent.right
329 spacing: _margin
330 visible: breachReturnSection.visible && myGeoFenceController.breachReturnPoint.isValid
331
332 QGCLabel {
333 text: qsTr("Altitude")
334 }
335
336 FactTextField {
337 fact: myGeoFenceController.breachReturnAltitude
338 }
339 }
340
341 }
342 }
343 }
344}