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 property MissionItemIndicatorGroup indicatorGroup
19
20 /// Subclasses must set this to their indicator Component
21 property Component indicatorComponent
22
23 property var _missionItem: object
24 property bool _itemVisualShowing: false
25 property bool _dragAreaShowing: false
26
27 signal clicked(int sequenceNumber)
28
29 function hideItemVisuals() {
30 _hideItemVisuals()
31 }
32
33 function showItemVisuals() {
34 _showItemVisuals()
35 }
36
37 function hideDragArea() {
38 if (_dragAreaShowing) {
39 dragAreaLoader.active = false
40 _dragAreaShowing = false
41 }
42 }
43
44 function showDragArea() {
45 if (!_dragAreaShowing) {
46 dragAreaLoader.active = true
47 _dragAreaShowing = true
48 }
49 }
50
51 function updateDragArea() {
52 if (_missionItem.isCurrentItem && map.planView && _missionItem.specifiesCoordinate && itemVisualLoader.item) {
53 showDragArea()
54 } else {
55 hideDragArea()
56 }
57 }
58
59 function _hideItemVisuals() {
60 if (_itemVisualShowing) {
61 itemVisualLoader.active = false
62 _itemVisualShowing = false
63 }
64 }
65
66 function _showItemVisuals() {
67 if (!_itemVisualShowing) {
68 itemVisualLoader.active = true
69 _itemVisualShowing = true
70 }
71 }
72
73 Component.onCompleted: {
74 showItemVisuals()
75 updateDragArea()
76 }
77
78 Connections {
79 target: _missionItem
80
81 function onIsCurrentItemChanged() { updateDragArea() }
82 function onSpecifiesCoordinateChanged() { updateDragArea() }
83 }
84
85 Loader {
86 id: dragAreaLoader
87
88 asynchronous: true
89 active: false
90
91 sourceComponent: dragAreaComponent
92
93 onLoaded: {
94 if (item) {
95 item.parent = map
96 }
97 }
98 }
99
100 Loader {
101 id: itemVisualLoader
102
103 asynchronous: true
104 active: false
105
106 sourceComponent: control.indicatorComponent
107
108 onLoaded: {
109 if (item) {
110 item.parent = map
111 map.addMapItem(item)
112 updateDragArea()
113 }
114 }
115 }
116
117 // Control which is used to drag items
118 Component {
119 id: dragAreaComponent
120
121 MissionItemIndicatorDrag {
122 mapControl: control.map
123 itemIndicator: itemVisualLoader.item
124 itemCoordinate: _missionItem.coordinate
125 visible: control.interactive
126 onClicked: {
127 const indicator = itemVisualLoader.item
128 if (indicator && indicator.activate) {
129 indicator.activate()
130 } else {
131 control.clicked(control._missionItem.sequenceNumber)
132 }
133 }
134 onItemCoordinateChanged: _missionItem.coordinate = itemCoordinate
135 }
136 }
137}