QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
32 &QgsQuickPositionKit::onSimulatePositionLongLatRadChanged );
37 QGeoPositionInfoSource *QgsQuickPositionKit::gpsSource()
41 std::unique_ptr<QGeoPositionInfoSource>
source( QGeoPositionInfoSource::createDefaultSource(
nullptr ) );
42 if ( ( !
source ) || (
source->error() != QGeoPositionInfoSource::NoError ) )
45 .arg( tr(
"Unable to create default GPS Position Source" ) )
46 .arg( QString::number( (
long )
source->error() ) )
47 , QStringLiteral(
"QgsQuick" )
57 QGeoPositionInfoSource *QgsQuickPositionKit::simulatedSource(
double longitude,
double latitude,
double radius )
59 return new QgsQuickSimulatedPositionSource(
this, longitude, latitude, radius );
69 std::unique_ptr<QGeoPositionInfoSource>
source( simulatedSource( longitude, latitude, radius ) );
71 replacePositionSource(
source.release() );
74 void QgsQuickPositionKit::updateScreenPosition()
87 void QgsQuickPositionKit::updateScreenAccuracy()
102 QGeoPositionInfoSource *
source = gpsSource();
103 mIsSimulated =
false;
104 replacePositionSource(
source );
107 void QgsQuickPositionKit::replacePositionSource( QGeoPositionInfoSource *source )
109 if ( mSource.get() ==
source )
114 mSource->disconnect();
122 connect( mSource.get(), &QGeoPositionInfoSource::positionUpdated,
this, &QgsQuickPositionKit::onPositionUpdated );
123 connect( mSource.get(), &QGeoPositionInfoSource::updateTimeout,
this, &QgsQuickPositionKit::onUpdateTimeout );
125 mSource->startUpdates();
127 QgsDebugMsg( QStringLiteral(
"Position source changed: %1" ).arg( mSource->sourceName() ) );
136 void QgsQuickPositionKit::updateProjectedPosition()
153 QgsDebugMsg( QStringLiteral(
"Failed to transform GPS position: " ) + srcPoint.
toString() );
166 void QgsQuickPositionKit::onPositionUpdated(
const QGeoPositionInfo &info )
177 info.coordinate().longitude(),
178 info.coordinate().latitude(),
179 info.coordinate().altitude() );
188 if ( info.hasAttribute( QGeoPositionInfo::HorizontalAccuracy ) )
189 accuracy = info.attribute( QGeoPositionInfo::HorizontalAccuracy );
200 if ( info.hasAttribute( QGeoPositionInfo::Direction ) )
201 direction = info.attribute( QGeoPositionInfo::Direction );
211 onMapSettingsUpdated();
214 void QgsQuickPositionKit::onMapSettingsUpdated()
216 updateProjectedPosition();
218 updateScreenAccuracy();
219 updateScreenPosition();
222 void QgsQuickPositionKit::onSimulatePositionLongLatRadChanged( QVector<double> simulatePositionLongLatRad )
229 QgsDebugMsg( QStringLiteral(
"Use simulated position around longlat: %1, %2, %3" ).arg( longitude ).arg( latitude ).arg( radius ) );
232 else if ( mIsSimulated )
234 QgsDebugMsg( QStringLiteral(
"Switching from simulated to GPS location" ) );
239 double QgsQuickPositionKit::calculateScreenAccuracy()
255 void QgsQuickPositionKit::onUpdateTimeout()
259 mHasPosition =
false;
266 return mScreenPosition;
271 return mScreenAccuracy;
276 return mSimulatePositionLongLatRad;
292 return mProjectedPosition;
332 mMapSettings->disconnect();
void projectedPositionChanged()
GPS position in map coords.
double directionChanged() const
GPS direction, bearing in degrees clockwise from north to direction of travel.
Q_INVOKABLE void useGpsLocation()
Use real GPS source (not simulated)
void hasPositionChanged()
hasPosition changed
void extentChanged()
Geographical coordinates of the rectangle that should be rendered.
void destinationCrsChanged()
CRS of destination coordinate reference system.
Point geometry type, with support for z-dimension and m-values.
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
double accuracyChanged() const
GPS horizontal accuracy in accuracyUnits, -1 if not available.
void positionChanged()
GPS position in WGS84 coords.
Q_INVOKABLE void useSimulatedLocation(double longitude, double latitude, double radius)
Use simulated GPS source.
void screenPositionChanged()
GPS position in device coords (pixels).
QgsPoint position
GPS position in WGS84 coords.
Q_INVOKABLE QPointF coordinateToScreen(const QgsPoint &point) const
Convert a map coordinate to screen pixel coordinates.
DistanceUnit
Units of distance.
QGeoPositionInfoSource source
Internal source of GPS location data.
QgsQuickMapSettings mapSettings
Associated map settings.
double accuracy
GPS horizontal accuracy in accuracyUnits, -1 if not available.
QgsCoordinateReferenceSystem destinationCrs
CRS of destination coordinate reference system.
QPointF screenPosition
GPS position in device coords (pixels).
void outputDpiChanged()
Output DPI used for conversion between real world units (e.g.
QString toString(int precision=-1) const
Returns a string representation of the point (x, y) with a preset precision.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void simulatePositionLongLatRadChanged(QVector< double > simulatePositionLongLatRad)
Uses of GPS and simulated position and sets its parameters.
void mapSettingsChanged()
Associated map settings.
void setMapSettings(QgsQuickMapSettings *mapSettings)
Associated map settings.
void mapUnitsPerPixelChanged()
Returns the distance in geographical coordinates that equals to one pixel in the map.
QVector< double > simulatePositionLongLatRad
Uses of GPS and simulated position and sets its parameters.
double direction
GPS direction, bearing in degrees clockwise from north to direction of travel.
Q_INVOKABLE QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
void outputSizeChanged()
The size of the resulting map image.
double screenAccuracyChanged() const
Screen horizontal accuracy, 2 if not available or resolution is too small.
Q_INVOKABLE QgsCoordinateReferenceSystem positionCRS() const
Coordinate reference system of position - WGS84 (constant)
bool hasPosition
GPS position is available (position property is a valid number).
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
double screenAccuracy
Screen horizontal accuracy, 2 if not available or resolution is too small.
void sourceChanged()
Emitted when the internal source of GPS location data has been replaced.
static Q_INVOKABLE double screenUnitsToMeters(QgsQuickMapSettings *mapSettings, int baseLengthPixels)
Calculates the distance in meter representing baseLengthPixels pixels on the screen based on the curr...
QgsQuickPositionKit(QObject *parent=nullptr)
Creates new position kit.
static Q_INVOKABLE QgsCoordinateReferenceSystem fromEpsgId(long epsg)
Creates a CRS from a given EPSG ID.
QgsUnitTypes::DistanceUnit accuracyUnits() const
GPS horizontal accuracy units - meters (constant)
static Q_INVOKABLE QgsPointXY transformPoint(const QgsCoordinateReferenceSystem &srcCrs, const QgsCoordinateReferenceSystem &destCrs, const QgsCoordinateTransformContext &context, const QgsPointXY &srcPoint)
Transforms point between different crs from QML.
void visibleExtentChanged()
Returns the actual extent derived from requested extent that takes takes output image size into accou...
QgsPoint projectedPosition
GPS position in map coords.
void setSimulatePositionLongLatRad(const QVector< double > &simulatePositionLongLatRad)
Uses of GPS and simulated position and sets its parameters.
bool isSimulated
GPS position and accuracy is simulated (not real from GPS sensor).