QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
TerrainQuery.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QObject>
4#include <QtCore/QPointer>
5#include <QtCore/QQueue>
6#include <QtCore/QVariant>
7#include <QtPositioning/QGeoCoordinate>
8
11
12class QTimer;
13
14// IMPORTANT NOTE: The terrain query objects below must continue to live until the the terrain system signals data back through them.
15// Because of that it makes object lifetime tricky. Normally you would use autoDelete = true such they delete themselves when they
16// complete. The case for using autoDelete=false is where the query has not been "newed" as a standalone object.
17//
18// Another typical use case is to query some terrain data and while you are waiting for it to come back the underlying reason
19// for that query changes and you end up needed to query again for a new set of data. In this case you are no longer interested
20// in the results of the previous query. The way to do that is to disconnect the data received signal on the old stale query
21// when you create the new query.
22
23/*===========================================================================*/
24
26
27class TerrainAtCoordinateBatchManager : public QObject
28{
29 Q_OBJECT
30
31public:
32 explicit TerrainAtCoordinateBatchManager(QObject *parent = nullptr);
34
36
37 void addQuery(TerrainAtCoordinateQuery *terrainAtCoordinateQuery, const QList<QGeoCoordinate> &coordinates);
38
41
42private slots:
43 void _sendNextBatch();
44 void _coordinateHeights(bool success, const QList<double> &heights);
45
46private:
47 struct QueuedRequestInfo_t {
48 QPointer<TerrainAtCoordinateQuery> terrainAtCoordinateQuery;
49 QList<QGeoCoordinate> coordinates;
50 };
51
52 struct SentRequestInfo_t {
53 QPointer<TerrainAtCoordinateQuery> terrainAtCoordinateQuery;
54 qsizetype cCoord;
55 };
56
57 void _batchFailed();
58 QString _stateToString(TerrainQuery::State state);
59
60 QQueue<QueuedRequestInfo_t> _requestQueue;
61 QList<SentRequestInfo_t> _sentRequests;
63 QTimer *_batchTimer = nullptr;
64 TerrainQueryInterface *_terrainQuery = nullptr;
65 static constexpr int _batchTimeout = 500;
66};
67
68/*===========================================================================*/
69
72class TerrainAtCoordinateQuery : public QObject
73{
74 Q_OBJECT
75
76public:
78 explicit TerrainAtCoordinateQuery(bool autoDelete, QObject *parent = nullptr);
80
84 void requestData(const QList<QGeoCoordinate> &coordinates);
85
89 static bool getAltitudesForCoordinates(const QList<QGeoCoordinate> &coordinates, QList<double> &altitudes, bool &error);
90
91 void signalTerrainData(bool success, const QList<double> &heights);
92
93signals:
94 void terrainDataReceived(bool success, const QList<double> &heights);
95
96private:
97 bool _autoDelete = false;
98};
99
100/*===========================================================================*/
101
102class TerrainPathQuery : public QObject
103{
104 Q_OBJECT
105
106public:
108 explicit TerrainPathQuery(bool autoDelete, QObject *parent = nullptr);
110
114 void requestData(const QGeoCoordinate &fromCoord, const QGeoCoordinate &toCoord);
115
117
118signals:
120 void terrainDataReceived(bool success, const TerrainPathQuery::PathHeightInfo_t &pathHeightInfo);
121
122private slots:
123 void _pathHeights(bool success, double distanceBetween, double finalDistanceBetween, const QList<double> &heights);
124
125private:
126 bool _autoDelete = false;
127 TerrainQueryInterface *_terrainQuery = nullptr;
128};
129
130/*===========================================================================*/
131
132class TerrainAreaQuery : public QObject
133{
134 Q_OBJECT
135
136public:
138 explicit TerrainAreaQuery(bool autoDelete, QObject *parent = nullptr);
140
145 void requestData(const QGeoCoordinate &swCoord, const QGeoCoordinate &neCoord);
146
148 double minHeight;
149 double maxHeight;
150 QList<QList<double>> carpet;
151 };
152
153signals:
154 void terrainDataReceived(bool success, const TerrainAreaQuery::CarpetHeightInfo_t &carpetHeightInfo);
155
156private slots:
157 void _carpetHeights(bool success, double minHeight, double maxHeight, const QList<QList<double>> &carpet);
158
159private:
160 bool _autoDelete = false;
161 TerrainQueryInterface *_terrainQuery = nullptr;
162};
164
165/*===========================================================================*/
166
167class TerrainPolyPathQuery : public QObject
168{
169 Q_OBJECT
170
171public:
173 explicit TerrainPolyPathQuery(bool autoDelete, QObject *parent = nullptr);
175
179 void requestData(const QVariantList &polyPath);
180 void requestData(const QList<QGeoCoordinate> &polyPath);
181
182signals:
184 void terrainDataReceived(bool success, const QList<TerrainPathQuery::PathHeightInfo_t> &rgPathHeightInfo);
185
186private slots:
187 void _terrainDataReceived(bool success, const TerrainPathQuery::PathHeightInfo_t &pathHeightInfo);
188
189private:
190 bool _autoDelete = false;
191 int _curIndex = 0;
192 QList<QGeoCoordinate> _rgCoords;
193 QList<TerrainPathQuery::PathHeightInfo_t> _rgPathHeightInfo;
194 TerrainPathQuery *_pathQuery = nullptr;
195};
Error error
void requestData(const QGeoCoordinate &swCoord, const QGeoCoordinate &neCoord)
void terrainDataReceived(bool success, const TerrainAreaQuery::CarpetHeightInfo_t &carpetHeightInfo)
void addQuery(TerrainAtCoordinateQuery *terrainAtCoordinateQuery, const QList< QGeoCoordinate > &coordinates)
static TerrainAtCoordinateBatchManager * instance()
void setTerrainQueryInterface(TerrainQueryInterface *terrainQuery)
Set custom terrain query interface (for testing). Takes ownership.
NOTE: TerrainAtCoordinateQuery is not thread safe. All instances/calls to ElevationProvider must be o...
void terrainDataReceived(bool success, const QList< double > &heights)
void requestData(const QList< QGeoCoordinate > &coordinates)
void signalTerrainData(bool success, const QList< double > &heights)
static bool getAltitudesForCoordinates(const QList< QGeoCoordinate > &coordinates, QList< double > &altitudes, bool &error)
void terrainDataReceived(bool success, const TerrainPathQuery::PathHeightInfo_t &pathHeightInfo)
Signalled when terrain data comes back from server.
void requestData(const QGeoCoordinate &fromCoord, const QGeoCoordinate &toCoord)
void terrainDataReceived(bool success, const QList< TerrainPathQuery::PathHeightInfo_t > &rgPathHeightInfo)
Signalled when terrain data comes back from server.
Base class for offline/online terrain queries.
Q_DECLARE_METATYPE(satellite_info_s)
QList< QList< double > > carpet