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/QLoggingCategory>
4#include <QtCore/QObject>
5#include <QtCore/QPointer>
6#include <QtCore/QQueue>
7#include <QtCore/QVariant>
8#include <QtPositioning/QGeoCoordinate>
9
11
12class QTimer;
13
14Q_DECLARE_LOGGING_CATEGORY(TerrainQueryLog)
15Q_DECLARE_LOGGING_CATEGORY(TerrainQueryVerboseLog)
16
17// IMPORTANT NOTE: The terrain query objects below must continue to live until the the terrain system signals data back through them.
18// Because of that it makes object lifetime tricky. Normally you would use autoDelete = true such they delete themselves when they
19// complete. The case for using autoDelete=false is where the query has not been "newed" as a standalone object.
20//
21// Another typical use case is to query some terrain data and while you are waiting for it to come back the underlying reason
22// 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
23// in the results of the previous query. The way to do that is to disconnect the data received signal on the old stale query
24// when you create the new query.
25
26/*===========================================================================*/
27
29
30class TerrainAtCoordinateBatchManager : public QObject
31{
32 Q_OBJECT
33
34public:
35 explicit TerrainAtCoordinateBatchManager(QObject *parent = nullptr);
37
39
40 void addQuery(TerrainAtCoordinateQuery *terrainAtCoordinateQuery, const QList<QGeoCoordinate> &coordinates);
41
44
45private slots:
46 void _sendNextBatch();
47 void _coordinateHeights(bool success, const QList<double> &heights);
48
49private:
50 struct QueuedRequestInfo_t {
51 QPointer<TerrainAtCoordinateQuery> terrainAtCoordinateQuery;
52 QList<QGeoCoordinate> coordinates;
53 };
54
55 struct SentRequestInfo_t {
56 QPointer<TerrainAtCoordinateQuery> terrainAtCoordinateQuery;
57 qsizetype cCoord;
58 };
59
60 void _batchFailed();
61 QString _stateToString(TerrainQuery::State state);
62
63 QQueue<QueuedRequestInfo_t> _requestQueue;
64 QList<SentRequestInfo_t> _sentRequests;
66 QTimer *_batchTimer = nullptr;
67 TerrainQueryInterface *_terrainQuery = nullptr;
68 static constexpr int _batchTimeout = 500;
69};
70
71/*===========================================================================*/
72
74class TerrainAtCoordinateQuery : public QObject
75{
76 Q_OBJECT
77
78public:
80 explicit TerrainAtCoordinateQuery(bool autoDelete, QObject *parent = nullptr);
82
86 void requestData(const QList<QGeoCoordinate> &coordinates);
87
91 static bool getAltitudesForCoordinates(const QList<QGeoCoordinate> &coordinates, QList<double> &altitudes, bool &error);
92
93 void signalTerrainData(bool success, const QList<double> &heights);
94
95signals:
96 void terrainDataReceived(bool success, const QList<double> &heights);
97
98private:
99 bool _autoDelete = false;
100};
101
102/*===========================================================================*/
103
104class TerrainPathQuery : public QObject
105{
106 Q_OBJECT
107
108public:
110 explicit TerrainPathQuery(bool autoDelete, QObject *parent = nullptr);
112
116 void requestData(const QGeoCoordinate &fromCoord, const QGeoCoordinate &toCoord);
117
121 QList<double> heights;
122 };
123
124signals:
126 void terrainDataReceived(bool success, const TerrainPathQuery::PathHeightInfo_t &pathHeightInfo);
127
128private slots:
129 void _pathHeights(bool success, double distanceBetween, double finalDistanceBetween, const QList<double> &heights);
130
131private:
132 bool _autoDelete = false;
133 TerrainQueryInterface *_terrainQuery = nullptr;
134};
136Q_DECLARE_METATYPE(QList<TerrainPathQuery::PathHeightInfo_t>)
137
138/*===========================================================================*/
139
140class TerrainAreaQuery : public QObject
141{
142 Q_OBJECT
143
144public:
146 explicit TerrainAreaQuery(bool autoDelete, QObject *parent = nullptr);
148
153 void requestData(const QGeoCoordinate &swCoord, const QGeoCoordinate &neCoord);
154
156 double minHeight;
157 double maxHeight;
158 QList<QList<double>> carpet;
159 };
160
161signals:
162 void terrainDataReceived(bool success, const TerrainAreaQuery::CarpetHeightInfo_t &carpetHeightInfo);
163
164private slots:
165 void _carpetHeights(bool success, double minHeight, double maxHeight, const QList<QList<double>> &carpet);
166
167private:
168 bool _autoDelete = false;
169 TerrainQueryInterface *_terrainQuery = nullptr;
170};
172
173/*===========================================================================*/
174
175class TerrainPolyPathQuery : public QObject
176{
177 Q_OBJECT
178
179public:
181 explicit TerrainPolyPathQuery(bool autoDelete, QObject *parent = nullptr);
183
187 void requestData(const QVariantList &polyPath);
188 void requestData(const QList<QGeoCoordinate> &polyPath);
189
190signals:
192 void terrainDataReceived(bool success, const QList<TerrainPathQuery::PathHeightInfo_t> &rgPathHeightInfo);
193
194private slots:
195 void _terrainDataReceived(bool success, const TerrainPathQuery::PathHeightInfo_t &pathHeightInfo);
196
197private:
198 bool _autoDelete = false;
199 int _curIndex = 0;
200 QList<QGeoCoordinate> _rgCoords;
201 QList<TerrainPathQuery::PathHeightInfo_t> _rgPathHeightInfo;
202 TerrainPathQuery *_pathQuery = nullptr;
203};
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
Error error
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
double distanceBetween
Distance between each height value.
double finalDistanceBetween
Distance between final two height values.
QList< double > heights
Terrain heights along path.