QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
TerrainStatus.qml
Go to the documentation of this file.
1import QtQuick
2import QtGraphs
3
4import QGroundControl
5import QGroundControl.Controls
6
7Rectangle {
8 id: root
9 radius: ScreenTools.defaultFontPixelWidth * 0.5
10 color: qgcPal.window
11 opacity: 0.80
12 clip: true
13
14 property var missionController
15
16 signal setCurrentSeqNum(int seqNum)
17
18 property real _margins: ScreenTools.defaultFontPixelWidth / 2
19 property var _visualItems: missionController.visualItems
20 property real _altRange: _maxAMSLAltitude - _minAMSLAltitude
21 property real _indicatorSpacing: 5
22 property real _minAMSLAltitude: isNaN(terrainProfile.minAMSLAlt) ? 0 : terrainProfile.minAMSLAlt
23 property real _maxAMSLAltitude: isNaN(terrainProfile.maxAMSLAlt) ? 100 : terrainProfile.maxAMSLAlt
24 property real _missionTotalDistance: isNaN(missionController.missionTotalDistance) ? 100 : missionController.missionTotalDistance
25 property var _unitsConversion: QGroundControl.unitsConversion
26
27 QGCPalette { id: qgcPal }
28
29 QGCLabel {
30 id: titleLabel
31 anchors.top: parent.bottom
32 width: parent.height
33 font.pointSize: ScreenTools.smallFontPointSize
34 text: qsTr("Height AMSL (%1)").arg(_unitsConversion.appSettingsVerticalDistanceUnitsString)
35 horizontalAlignment: Text.AlignHCenter
36 rotation: -90
37 transformOrigin: Item.TopLeft
38 }
39
40 QGCFlickable {
41 id: terrainProfileFlickable
42 anchors.top: parent.top
43 anchors.bottom: parent.bottom
44 anchors.leftMargin: titleLabel.contentHeight
45 anchors.left: parent.left
46 anchors.right: parent.right
47 clip: true
48
49 Item {
50 height: terrainProfileFlickable.height
51 width: terrainProfileFlickable.width
52
53 GraphsView {
54 id: chart
55 anchors.fill: parent
56 marginTop: ScreenTools.defaultFontPixelHeight / 2 // Fixes top clipping problem
57 marginRight: ScreenTools.defaultFontPixelWidth * 2 // Prevents clipping last tick mark
58 marginBottom: -ScreenTools.defaultFontPixelHeight / 2 // For some reason you can't get rid of bottom margin by setting to 0
59 marginLeft: 0
60
61 theme: GraphsTheme {
62 colorScheme: qgcPal.globalTheme === QGCPalette.Light ? GraphsTheme.ColorScheme.Light : GraphsTheme.ColorScheme.Dark
63 backgroundColor: "transparent"
64 backgroundVisible: false
65 plotAreaBackgroundColor: qgcPal.window
66 grid.mainColor: applyOpacity(qgcPal.text, 0.5)
67 grid.subColor: applyOpacity(qgcPal.text, 0.3)
68 grid.mainWidth: 1
69 labelBackgroundVisible: false
70 labelTextColor: qgcPal.text
71 axisXLabelFont.family: ScreenTools.fixedFontFamily
72 axisXLabelFont.pointSize: ScreenTools.smallFontPointSize
73 axisYLabelFont.family: ScreenTools.fixedFontFamily
74 axisYLabelFont.pointSize: ScreenTools.smallFontPointSize
75 }
76
77 axisX: ValueAxis {
78 id: axisX
79 min: 0
80 max: _unitsConversion.metersToAppSettingsHorizontalDistanceUnits(_missionTotalDistance)
81 lineVisible: true
82 tickInterval: max > 0 ? max / 4 : 1
83 labelDecimals: 1
84 }
85
86 axisY: ValueAxis {
87 id: axisY
88 min: _unitsConversion.metersToAppSettingsVerticalDistanceUnits(_minAMSLAltitude)
89 max: _unitsConversion.metersToAppSettingsVerticalDistanceUnits(_maxAMSLAltitude)
90 lineVisible: true
91 tickInterval: (max - min) > 0 ? (max - min) / 3 : 1
92 labelDecimals: 1
93 }
94
95 // The order of the LineSeries is important to work around nasty bugs in QtGraphs where series just don't display. If you put
96 // terrain and flight first you end up with cases where flight doesn't display no matter what other sorts of workarounds you try.
97 // Putting missing and collision first seems to prevent the problem.
98
99 LineSeries {
100 id: missingSeries
101 color: "yellow"
102 width: 2
103 }
104
105 LineSeries {
106 id: collisionSeries
107 color: "red"
108 width: flightSeries.width * 3
109 }
110
111 LineSeries {
112 id: terrainSeries
113 color: "green"
114 width: 2
115 }
116
117 LineSeries {
118 id: flightSeries
119 color: "orange"
120 width: 2
121 }
122 }
123
124 TerrainProfile {
125 id: terrainProfile
126 x: chart.plotArea.x
127 y: chart.plotArea.y
128 height: chart.plotArea.height
129 visibleWidth: chart.plotArea.width
130 missionController: root.missionController
131 horizontalScale: _unitsConversion.metersToAppSettingsHorizontalDistanceUnits(1)
132 verticalScale: _unitsConversion.metersToAppSettingsVerticalDistanceUnits(1)
133
134 onProfileChanged: terrainProfile.updateSeries(terrainSeries, flightSeries, missingSeries, collisionSeries)
135
136 Repeater {
137 model: missionController.visualItems
138
139 Item {
140 id: topLevelItem
141 anchors.fill: parent
142 visible: object.specifiesCoordinate && !object.standaloneCoordinate
143
144 Rectangle {
145 id: simpleItem
146 height: terrainProfile.height
147 width: 1
148 color: qgcPal.text
149 x: (object.distanceFromStart * terrainProfile.pixelsPerMeter)
150 visible: object.isSimpleItem || object.isSingleItem
151
152 MissionItemIndexLabel {
153 anchors.horizontalCenter: parent.horizontalCenter
154 anchors.bottom: parent.bottom
155 small: true
156 checked: object.isCurrentItem
157 label: object.abbreviation.charAt(0)
158 index: object.abbreviation.charAt(0) > 'A' && object.abbreviation.charAt(0) < 'z' ? -1 : object.sequenceNumber
159 onClicked: root.setCurrentSeqNum(object.sequenceNumber)
160 }
161 }
162
163 Rectangle {
164 id: complexItemEntry
165 height: terrainProfile.height
166 width: 1
167 color: qgcPal.text
168 x: (object.distanceFromStart * terrainProfile.pixelsPerMeter)
169 visible: complexItem.visible
170
171 MissionItemIndexLabel {
172 anchors.horizontalCenter: parent.horizontalCenter
173 anchors.bottom: parent.bottom
174 small: true
175 checked: object.isCurrentItem
176 index: object.sequenceNumber
177 onClicked: root.setCurrentSeqNum(object.sequenceNumber)
178 }
179 }
180
181 Rectangle {
182 id: complexItemExit
183 height: terrainProfile.height
184 width: 1
185 color: qgcPal.text
186 x: ((object.distanceFromStart + object.complexDistance) * terrainProfile.pixelsPerMeter)
187 visible: complexItem.visible
188
189 MissionItemIndexLabel {
190 anchors.horizontalCenter: parent.horizontalCenter
191 anchors.bottom: parent.bottom
192 small: true
193 checked: object.isCurrentItem
194 index: object.lastSequenceNumber
195 onClicked: root.setCurrentSeqNum(object.sequenceNumber)
196 }
197 }
198
199 Rectangle {
200 id: complexItem
201 anchors.bottom: parent.bottom
202 x: (object.distanceFromStart * terrainProfile.pixelsPerMeter)
203 width: complexItem.visible ? object.complexDistance * terrainProfile.pixelsPerMeter : 0
204 height: patternNameLabel.height
205 color: "green"
206 opacity: 0.5
207 visible: !object.isSimpleItem && !object.isSingleItem
208
209 QGCMouseArea {
210 anchors.fill: parent
211 onClicked: root.setCurrentSeqNum(object.sequenceNumber)
212 }
213
214 QGCLabel {
215 id: patternNameLabel
216 anchors.horizontalCenter: parent.horizontalCenter
217 text: complexItem.visible ? object.patternName : ""
218 }
219 }
220 }
221 }
222 }
223 }
224 }
225
226 function applyOpacity(colorIn, opacity){
227 return Qt.rgba(colorIn.r, colorIn.g, colorIn.b, opacity)
228 }
229}