QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
117  public:
119  explicit QgsQuickPositionKit( QObject *parent = nullptr );
120 
122  bool hasPosition() const;
123 
125  QgsPoint position() const;
126 
128  QgsPoint projectedPosition() const;
129 
131  QPointF screenPosition() const;
132 
134  double accuracy() const;
135 
137  double screenAccuracy() const;
138 
142  QgsUnitTypes::DistanceUnit accuracyUnits() const;
143 
145  double direction() const;
146 
148  bool isSimulated() const;
149 
151  void setMapSettings( QgsQuickMapSettings *mapSettings );
152 
154  QgsQuickMapSettings *mapSettings() const;
155 
157  QVector<double> simulatePositionLongLatRad() const;
158 
160  void setSimulatePositionLongLatRad( const QVector<double> &simulatePositionLongLatRad );
161 
165  Q_INVOKABLE QgsCoordinateReferenceSystem positionCRS() const;
166 
180  Q_INVOKABLE void useSimulatedLocation( double longitude, double latitude, double radius );
181 
185  Q_INVOKABLE void useGpsLocation();
186 
187  signals:
189  void positionChanged();
190 
192  void projectedPositionChanged();
193 
195  void screenPositionChanged();
196 
198  void hasPositionChanged();
199 
201  double accuracyChanged() const;
202 
204  double screenAccuracyChanged() const;
205 
207  Q_INVOKABLE QString accuracyUnitsChanged() const;
208 
210  double directionChanged() const;
211 
213  void isSimulatedChanged();
214 
216  void mapSettingsChanged();
217 
219  void simulatePositionLongLatRadChanged( QVector<double> simulatePositionLongLatRad );
220 
221  private slots:
222  void onPositionUpdated( const QGeoPositionInfo &info );
223  void onMapSettingsUpdated();
224  void onUpdateTimeout();
225  void onSimulatePositionLongLatRadChanged( QVector<double> simulatePositionLongLatRad );
226 
227  private:
228  void replacePositionSource( QGeoPositionInfoSource *source );
229  QString calculateStatusLabel();
230  double calculateScreenAccuracy();
231  void updateProjectedPosition();
232  void updateScreenPosition();
233  void updateScreenAccuracy();
234 
235  QGeoPositionInfoSource *gpsSource();
236  QGeoPositionInfoSource *simulatedSource( double longitude, double latitude, double radius );
237 
238  QgsPoint mPosition;
239  QgsPoint mProjectedPosition;
240  QPointF mScreenPosition;
241  double mAccuracy = -1;
242  double mScreenAccuracy = 2;
243  double mDirection = -1;
244  bool mHasPosition = false;
245  bool mIsSimulated = false;
246  QVector<double> mSimulatePositionLongLatRad;
247  std::unique_ptr<QGeoPositionInfoSource> mSource;
248 
249  QgsQuickMapSettings *mMapSettings = nullptr; // not owned
250 };
251 
252 #endif // QGSQUICKPOSITIONKIT_H
Helper functions for various unit types.
Definition: qgsunittypes.h:37
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).