QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MissionItemMapVisualBase.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/// Base component for mission item map visuals providing common drag/indicator infrastructure.
11/// Subclasses must provide an indicatorComponent.
12Item {
13 id: control
14
15 property var map ///< Map control to place item in
16 property var vehicle ///< Vehicle associated with this item
17 property bool interactive: true
18
19 /// Subclasses must set this to their indicator Component
20 property Component indicatorComponent
21
22 property var _missionItem: object
23 property bool _itemVisualShowing: false
24 property bool _dragAreaShowing: false
25
26 signal clicked(int sequenceNumber)
27
28 function hideItemVisuals() {
29 _hideItemVisuals()
30 }
31
32 function showItemVisuals() {
33 _showItemVisuals()
34 }
35
36 function hideDragArea() {
37 if (_dragAreaShowing) {
38 dragAreaLoader.active = false
39 _dragAreaShowing = false
40 }
41 }
42
43 function showDragArea() {
44 if (!_dragAreaShowing) {
45 dragAreaLoader.active = true
46 _dragAreaShowing = true
47 }
48 }
49
50 function updateDragArea() {
51 if (_missionItem.isCurrentItem && map.planView && _missionItem.specifiesCoordinate) {
52 showDragArea()
53 } else {
54 hideDragArea()
55 }
56 }
57
58 function _hideItemVisuals() {
59 if (_itemVisualShowing) {
60 itemVisualLoader.active = false
61 _itemVisualShowing = false
62 }
63 }
64
65 function _showItemVisuals() {
66 if (!_itemVisualShowing) {
67 itemVisualLoader.active = true
68 _itemVisualShowing = true
69 }
70 }
71
72 Component.onCompleted: {
73 showItemVisuals()
74 updateDragArea()
75 }
76
77 Connections {
78 target: _missionItem
79
80 function onIsCurrentItemChanged() { updateDragArea() }
81 function onSpecifiesCoordinateChanged() { updateDragArea() }
82 }
83
84 Loader {
85 id: dragAreaLoader
86
87 asynchronous: true
88 active: false
89
90 sourceComponent: dragAreaComponent
91
92 onLoaded: {
93 if (item) {
94 item.parent = map
95 }
96 }
97 }
98
99 Loader {
100 id: itemVisualLoader
101
102 asynchronous: true
103 active: false
104
105 sourceComponent: control.indicatorComponent
106
107 onLoaded: {
108 if (item) {
109 item.parent = map
110 map.addMapItem(item)
111 }
112 }
113 }
114
115 // Control which is used to drag items
116 Component {
117 id: dragAreaComponent
118
119 MissionItemIndicatorDrag {
120 mapControl: control.map
121 itemIndicator: itemVisualLoader.item
122 itemCoordinate: _missionItem.coordinate
123 visible: control.interactive
124 onItemCoordinateChanged: _missionItem.coordinate = itemCoordinate
125 }
126 }
127}