QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
58 
63  Q_PROPERTY( QPointF screenPosition READ screenPosition NOTIFY screenPositionChanged )
64 
65 
70  Q_PROPERTY( bool hasPosition READ hasPosition NOTIFY hasPositionChanged )
71 
72 
77  Q_PROPERTY( double accuracy READ accuracy NOTIFY accuracyChanged )
78 
79 
84  Q_PROPERTY( double screenAccuracy READ screenAccuracy NOTIFY screenAccuracyChanged )
85 
86 
91  Q_PROPERTY( double direction READ direction NOTIFY directionChanged )
92 
93 
98  Q_PROPERTY( bool isSimulated READ isSimulated NOTIFY isSimulatedChanged )
99 
100 
105  Q_PROPERTY( QgsQuickMapSettings *mapSettings READ mapSettings WRITE setMapSettings NOTIFY mapSettingsChanged )
106 
107 
115  Q_PROPERTY( QVector<double> simulatePositionLongLatRad READ simulatePositionLongLatRad WRITE setSimulatePositionLongLatRad NOTIFY simulatePositionLongLatRadChanged )
116 
117 
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:
202 
205 
208 
211 
213  double accuracyChanged() const;
214 
216  double screenAccuracyChanged() const;
217 
219  Q_INVOKABLE QString accuracyUnitsChanged() const;
220 
222  double directionChanged() const;
223 
226 
229 
231  void simulatePositionLongLatRadChanged( QVector<double> simulatePositionLongLatRad );
232 
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
QgsQuickPositionKit::projectedPositionChanged
void projectedPositionChanged()
GPS position in map coords.
QgsQuickPositionKit::directionChanged
double directionChanged() const
GPS direction, bearing in degrees clockwise from north to direction of travel.
QgsQuickPositionKit::isSimulatedChanged
void isSimulatedChanged()
GPS position and accuracy is simulated (not real from GPS sensor).
QgsQuickPositionKit::hasPositionChanged
void hasPositionChanged()
hasPosition changed
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
QgsQuickPositionKit::accuracyChanged
double accuracyChanged() const
GPS horizontal accuracy in accuracyUnits, -1 if not available.
QgsQuickPositionKit::positionChanged
void positionChanged()
GPS position in WGS84 coords.
QgsQuickPositionKit::screenPositionChanged
void screenPositionChanged()
GPS position in device coords (pixels).
QgsQuickPositionKit
Convenient set of tools to read GPS position and accuracy.
Definition: qgsquickpositionkit.h:41
qgspoint.h
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
QgsQuickMapSettings
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
Definition: qgsquickmapsettings.h:47
QgsQuickPositionKit::simulatePositionLongLatRadChanged
void simulatePositionLongLatRadChanged(QVector< double > simulatePositionLongLatRad)
Uses of GPS and simulated position and sets its parameters.
QgsQuickPositionKit::mapSettingsChanged
void mapSettingsChanged()
Associated map settings.
QgsQuickPositionKit::accuracyUnitsChanged
Q_INVOKABLE QString accuracyUnitsChanged() const
GPS horizontal accuracy units - meters (constant)
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
qgsquickcoordinatetransformer.h
QgsQuickPositionKit::screenAccuracyChanged
double screenAccuracyChanged() const
Screen horizontal accuracy, 2 if not available or resolution is too small.
QgsQuickPositionKit::sourceChanged
void sourceChanged()
Emitted when the internal source of GPS location data has been replaced.
qgsquickmapsettings.h