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
39private slots:
40 void _sendNextBatch();
41 void _coordinateHeights(bool success, const QList<double> &heights);
42
43private:
44 struct QueuedRequestInfo_t {
45 QPointer<TerrainAtCoordinateQuery> terrainAtCoordinateQuery;
46 QList<QGeoCoordinate> coordinates;
47 };
48
49 struct SentRequestInfo_t {
50 QPointer<TerrainAtCoordinateQuery> terrainAtCoordinateQuery;
51 qsizetype cCoord;
52 };
53
54 void _batchFailed();
55 QString _stateToString(TerrainQuery::State state);
56
57 QQueue<QueuedRequestInfo_t> _requestQueue;
58 QList<SentRequestInfo_t> _sentRequests;
60 QTimer *_batchTimer = nullptr;
61 TerrainQueryInterface *_terrainQuery = nullptr;
62 static constexpr int _batchTimeout = 500;
63};
64
65/*===========================================================================*/
66
69class TerrainAtCoordinateQuery : public QObject
70{
71 Q_OBJECT
72
73public:
75 explicit TerrainAtCoordinateQuery(bool autoDelete, QObject *parent = nullptr);
77
81 void requestData(const QList<QGeoCoordinate> &coordinates);
82
86 static bool getAltitudesForCoordinates(const QList<QGeoCoordinate> &coordinates, QList<double> &altitudes, bool &error);
87
88 void signalTerrainData(bool success, const QList<double> &heights);
89
90signals:
91 void terrainDataReceived(bool success, const QList<double> &heights);
92
93private:
94 bool _autoDelete = false;
95};
96
97/*===========================================================================*/
98
99class TerrainPathQuery : public QObject
100{
101 Q_OBJECT
102
103public:
105 explicit TerrainPathQuery(bool autoDelete, QObject *parent = nullptr);
107
111 void requestData(const QGeoCoordinate &fromCoord, const QGeoCoordinate &toCoord);
112
114
115signals:
117 void terrainDataReceived(bool success, const TerrainPathQuery::PathHeightInfo_t &pathHeightInfo);
118
119private slots:
120 void _pathHeights(bool success, double distanceBetween, double finalDistanceBetween, const QList<double> &heights);
121
122private:
123 bool _autoDelete = false;
124 TerrainQueryInterface *_terrainQuery = nullptr;
125};
126
127/*===========================================================================*/
128
129class TerrainAreaQuery : public QObject
130{
131 Q_OBJECT
132
133public:
135 explicit TerrainAreaQuery(bool autoDelete, QObject *parent = nullptr);
137
142 void requestData(const QGeoCoordinate &swCoord, const QGeoCoordinate &neCoord);
143
145 double minHeight;
146 double maxHeight;
147 QList<QList<double>> carpet;
148 };
149
150signals:
151 void terrainDataReceived(bool success, const TerrainAreaQuery::CarpetHeightInfo_t &carpetHeightInfo);
152
153private slots:
154 void _carpetHeights(bool success, double minHeight, double maxHeight, const QList<QList<double>> &carpet);
155
156private:
157 bool _autoDelete = false;
158 TerrainQueryInterface *_terrainQuery = nullptr;
159};
161
162/*===========================================================================*/
163
164class TerrainPolyPathQuery : public QObject
165{
166 Q_OBJECT
167
168public:
170 explicit TerrainPolyPathQuery(bool autoDelete, QObject *parent = nullptr);
172
176 void requestData(const QVariantList &polyPath);
177 void requestData(const QList<QGeoCoordinate> &polyPath);
178
179signals:
181 void terrainDataReceived(bool success, const QList<TerrainPathQuery::PathHeightInfo_t> &rgPathHeightInfo);
182
183private slots:
184 void _terrainDataReceived(bool success, const TerrainPathQuery::PathHeightInfo_t &pathHeightInfo);
185
186private:
187 bool _autoDelete = false;
188 int _curIndex = 0;
189 QList<QGeoCoordinate> _rgCoords;
190 QList<TerrainPathQuery::PathHeightInfo_t> _rgPathHeightInfo;
191 TerrainPathQuery *_pathQuery = nullptr;
192};
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()
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