QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SimpleItemMapVisual.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtLocation
4import QtPositioning
5
6import QGroundControl
7import QGroundControl.Controls
8import QGroundControl.FlightMap
9
10/// Simple Mission Item visuals
11Item {
12 id: _root
13
14 property var map ///< Map control to place item in
15 property var vehicle ///< Vehicle associated with this item
16 property bool interactive: true
17
18 property var _missionItem: object
19 property bool _itemVisualShowing: false
20 property bool _dragAreaShowing: false
21
22 signal clicked(int sequenceNumber)
23
24 function hideItemVisuals() {
25 if (_itemVisualShowing) {
26 itemVisualLoader.active = false
27 loiterVisualLoader.active = false
28 _itemVisualShowing = false
29 }
30 }
31
32 function showItemVisuals() {
33 if (!_itemVisualShowing) {
34 itemVisualLoader.active = true
35 loiterVisualLoader.active = true
36 _itemVisualShowing = true
37 }
38 }
39
40 function hideDragArea() {
41 if (_dragAreaShowing) {
42 dragAreaLoader.active = false
43 _dragAreaShowing = false
44 }
45 }
46
47 function showDragArea() {
48 if (!_dragAreaShowing) {
49 dragAreaLoader.active = true
50 _dragAreaShowing = true
51 }
52 }
53
54 function updateDragArea() {
55 if (_missionItem.isCurrentItem && map.planView && _missionItem.specifiesCoordinate) {
56 showDragArea()
57 } else {
58 hideDragArea()
59 }
60 }
61
62 Component.onCompleted: {
63 showItemVisuals()
64 updateDragArea()
65 }
66
67 Connections {
68 target: _missionItem
69
70 function onIsCurrentItemChanged() { updateDragArea() }
71 function onSpecifiesCoordinateChanged() { updateDragArea() }
72 }
73
74 Connections {
75 target: _missionItem.isSimpleItem ? _missionItem : null
76
77 function onLoiterRadiusChanged(loiterRadius) {
78 if (loiterVisualLoader.item) {
79 loiterVisualLoader.item.handleLoiterRadiusChange()
80 }
81 }
82
83 function onCoordinateChanged(coordinate) {
84 if (loiterVisualLoader.item) {
85 loiterVisualLoader.item.handleCoordinateChange()
86 }
87 }
88 }
89
90 Loader {
91 id: dragAreaLoader
92
93 asynchronous: true
94 active: false
95
96 sourceComponent: dragAreaComponent
97
98 onLoaded: {
99 if (item) {
100 item.parent = map
101 }
102 }
103 }
104
105 Loader {
106 id: itemVisualLoader
107
108 asynchronous: true
109 active: false
110
111 sourceComponent: indicatorComponent
112
113 onLoaded: {
114 if (item) {
115 item.parent = map
116 map.addMapItem(item)
117 }
118 }
119 }
120
121 Loader {
122 id: loiterVisualLoader
123
124 asynchronous: true
125 active: false
126
127 sourceComponent: loiterComponent
128
129 onLoaded: {
130 if (item) {
131 item.parent = map
132 map.addMapItem(item)
133 }
134 }
135 }
136
137 // Control which is used to drag items
138 Component {
139 id: dragAreaComponent
140
141 MissionItemIndicatorDrag {
142 mapControl: _root.map
143 itemIndicator: itemVisualLoader.item
144 itemCoordinate: _missionItem.coordinate
145 visible: _root.interactive
146 onItemCoordinateChanged: _missionItem.coordinate = itemCoordinate
147 }
148 }
149
150 Component {
151 id: indicatorComponent
152
153 MissionItemIndicator {
154 coordinate: _missionItem.coordinate
155 visible: _missionItem.specifiesCoordinate
156 z: QGroundControl.zOrderMapItems
157 missionItem: _missionItem
158 sequenceNumber: _missionItem.sequenceNumber
159 onClicked: if(_root.interactive) _root.clicked(_missionItem.sequenceNumber)
160 opacity: _root.opacity
161 }
162 }
163
164 Component {
165 id: loiterComponent
166
167 MapQuickItem {
168 id: loiterMapQuickItem
169 coordinate: _root._missionItem.coordinate
170 visible: _root.interactive && _missionItem.isSimpleItem && _missionItem.showLoiterRadius
171
172 property alias blockSignals: loiterMapCircleVisuals.blockSignals
173 property alias radius: _mapCircle.radius
174 property alias clockwiseRotation: _mapCircle.clockwiseRotation
175
176 function handleLoiterRadiusChange() {
177 blockSignals = true
178 clockwiseRotation = _missionItem.loiterRadius>= 0
179 blockSignals = false
180 radius.rawValue = Math.abs(_missionItem.loiterRadius)
181 }
182
183 function handleCoordinateChange() {
184 coordinate = _missionItem.coordinate
185 }
186
187 onCoordinateChanged: _mapCircle.center = coordinate
188
189 sourceItem: QGCMapCircleVisuals {
190 id: loiterMapCircleVisuals
191 mapControl: _root.map
192 mapCircle: _mapCircle
193 centerDragHandleVisible: false
194 borderColor: _missionItem.terrainCollision ? "red" : QGroundControl.globalPalette.mapMissionTrajectory
195
196 property bool blockSignals: false
197
198 function updateMissionItem() {
199 _missionItem.loiterRadius = _mapCircle.clockwiseRotation ? _mapCircle.radius.rawValue : -_mapCircle.radius.rawValue
200 }
201
202 QGCMapCircle {
203 id: _mapCircle
204 center: loiterMapQuickItem.coordinate
205 interactive: _root.interactive && _missionItem.isCurrentItem && map.planView
206 showRotation: true
207 onClockwiseRotationChanged: if(!blockSignals) loiterMapCircleVisuals.updateMissionItem()
208 }
209
210 Connections {
211 target: _mapCircle.radius
212 function onRawValueChanged() {
213 if(!blockSignals) loiterMapCircleVisuals.updateMissionItem()
214 }
215 }
216 }
217
218 Component.onCompleted: {
219 handleLoiterRadiusChange()
220 handleCoordinateChange()
221 }
222 }
223 }
224}