QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsquickpositionkit.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsquickpositionkit.h
3  --------------------------------------
4  Date : Dec. 2017
5  Copyright : (C) 2017 Peter Petrik
6  Email : zilolv at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSQUICKPOSITIONKIT_H
17 #define QGSQUICKPOSITIONKIT_H
18 
19 #include <QObject>
20 #include <QtPositioning>
21 
22 #include "qgspoint.h"
23 
24 #include "qgis_quick.h"
25 #include "qgsquickmapsettings.h"
27 
40 class QUICK_EXPORT QgsQuickPositionKit : public QObject
41 {
42  Q_OBJECT
43 
49  Q_PROPERTY( QgsPoint position READ position NOTIFY positionChanged )
50 
51 
56  Q_PROPERTY( QgsPoint projectedPosition READ projectedPosition NOTIFY projectedPositionChanged )
57 
63  Q_PROPERTY( QPointF screenPosition READ screenPosition NOTIFY screenPositionChanged )
64 
70  Q_PROPERTY( bool hasPosition READ hasPosition NOTIFY hasPositionChanged )
71 
77  Q_PROPERTY( double accuracy READ accuracy NOTIFY accuracyChanged )
78 
84  Q_PROPERTY( double screenAccuracy READ screenAccuracy NOTIFY screenAccuracyChanged )
85 
91  Q_PROPERTY( double direction READ direction NOTIFY directionChanged )
92 
98  Q_PROPERTY( bool isSimulated READ isSimulated NOTIFY isSimulatedChanged )
99 
105  Q_PROPERTY( QgsQuickMapSettings *mapSettings READ mapSettings WRITE setMapSettings NOTIFY mapSettingsChanged )
106 
115  Q_PROPERTY( QVector<double> simulatePositionLongLatRad READ simulatePositionLongLatRad WRITE setSimulatePositionLongLatRad NOTIFY simulatePositionLongLatRadChanged )
116 
121  Q_PROPERTY( QGeoPositionInfoSource *source READ source NOTIFY sourceChanged )
122 
123  public:
125  explicit QgsQuickPositionKit( QObject *parent = nullptr );
126 
128  bool hasPosition() const;
129 
131  QgsPoint position() const;
132 
134  QgsPoint projectedPosition() const;
135 
137  QPointF screenPosition() const;
138 
140  double accuracy() const;
141 
143  double screenAccuracy() const;
144 
148  QgsUnitTypes::DistanceUnit accuracyUnits() const;
149 
151  double direction() const;
152 
154  bool isSimulated() const;
155 
157  void setMapSettings( QgsQuickMapSettings *mapSettings );
158 
160  QgsQuickMapSettings *mapSettings() const;
161 
163  QVector<double> simulatePositionLongLatRad() const;
164 
166  void setSimulatePositionLongLatRad( const QVector<double> &simulatePositionLongLatRad );
167 
172  QGeoPositionInfoSource *source() const;
173 
177  Q_INVOKABLE QgsCoordinateReferenceSystem positionCRS() const;
178 
192  Q_INVOKABLE void useSimulatedLocation( double longitude, double latitude, double radius );
193 
197  Q_INVOKABLE void useGpsLocation();
198 
199  signals:
201  void positionChanged();
202 
204  void projectedPositionChanged();
205 
207  void screenPositionChanged();
208 
210  void hasPositionChanged();
211 
213  double accuracyChanged() const;
214 
216  double screenAccuracyChanged() const;
217 
219  Q_INVOKABLE QString accuracyUnitsChanged() const;
220 
222  double directionChanged() const;
223 
225  void isSimulatedChanged();
226 
228  void mapSettingsChanged();
229 
231  void simulatePositionLongLatRadChanged( QVector<double> simulatePositionLongLatRad );
232 
234  void sourceChanged();
235 
236  private slots:
237  void onPositionUpdated( const QGeoPositionInfo &info );
238  void onMapSettingsUpdated();
239  void onUpdateTimeout();
240  void onSimulatePositionLongLatRadChanged( QVector<double> simulatePositionLongLatRad );
241 
242  private:
243  void replacePositionSource( QGeoPositionInfoSource *source );
244  QString calculateStatusLabel();
245  double calculateScreenAccuracy();
246  void updateProjectedPosition();
247  void updateScreenPosition();
248  void updateScreenAccuracy();
249 
250  QGeoPositionInfoSource *gpsSource();
251  QGeoPositionInfoSource *simulatedSource( double longitude, double latitude, double radius );
252 
253  QgsPoint mPosition;
254  QgsPoint mProjectedPosition;
255  QPointF mScreenPosition;
256  double mAccuracy = -1;
257  double mScreenAccuracy = 2;
258  double mDirection = -1;
259  bool mHasPosition = false;
260  bool mIsSimulated = false;
261  QVector<double> mSimulatePositionLongLatRad;
262  std::unique_ptr<QGeoPositionInfoSource> mSource;
263 
264  QgsQuickMapSettings *mMapSettings = nullptr; // not owned
265 };
266 
267 #endif // QGSQUICKPOSITIONKIT_H
Helper functions for various unit types.
Definition: qgsunittypes.h:38
Convenient set of tools to read GPS position and accuracy.
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
This class represents a coordinate reference system (CRS).