Skip to content

Commit

Permalink
Make QgsVectorLayerGpsLogger API easier to use, and add capacity
Browse files Browse the repository at this point in the history
to store all GPS information components
  • Loading branch information
nyalldawson committed Nov 14, 2022
1 parent b572e54 commit 281f1d0
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 317 deletions.
4 changes: 3 additions & 1 deletion python/core/auto_additions/qgis.py
Expand Up @@ -917,7 +917,9 @@
Qgis.GpsInformationComponent.Timestamp.__doc__ = "Timestamp"
Qgis.GpsInformationComponent.TrackStartTime.__doc__ = "Timestamp at start of current track (available from QgsGpsLogger class only)"
Qgis.GpsInformationComponent.TrackEndTime.__doc__ = "Timestamp at end (current point) of current track (available from QgsGpsLogger class only)"
Qgis.GpsInformationComponent.__doc__ = 'GPS information component.\n\n.. versionadded:: 3.30\n\n' + '* ``Location``: ' + Qgis.GpsInformationComponent.Location.__doc__ + '\n' + '* ``Altitude``: ' + Qgis.GpsInformationComponent.Altitude.__doc__ + '\n' + '* ``GroundSpeed``: ' + Qgis.GpsInformationComponent.GroundSpeed.__doc__ + '\n' + '* ``Bearing``: ' + Qgis.GpsInformationComponent.Bearing.__doc__ + '\n' + '* ``TotalTrackLength``: ' + Qgis.GpsInformationComponent.TotalTrackLength.__doc__ + '\n' + '* ``TrackDistanceFromStart``: ' + Qgis.GpsInformationComponent.TrackDistanceFromStart.__doc__ + '\n' + '* ``Pdop``: ' + Qgis.GpsInformationComponent.Pdop.__doc__ + '\n' + '* ``Hdop``: ' + Qgis.GpsInformationComponent.Hdop.__doc__ + '\n' + '* ``Vdop``: ' + Qgis.GpsInformationComponent.Vdop.__doc__ + '\n' + '* ``HorizontalAccuracy``: ' + Qgis.GpsInformationComponent.HorizontalAccuracy.__doc__ + '\n' + '* ``VerticalAccuracy``: ' + Qgis.GpsInformationComponent.VerticalAccuracy.__doc__ + '\n' + '* ``HvAccuracy``: ' + Qgis.GpsInformationComponent.HvAccuracy.__doc__ + '\n' + '* ``SatellitesUsed``: ' + Qgis.GpsInformationComponent.SatellitesUsed.__doc__ + '\n' + '* ``Timestamp``: ' + Qgis.GpsInformationComponent.Timestamp.__doc__ + '\n' + '* ``TrackStartTime``: ' + Qgis.GpsInformationComponent.TrackStartTime.__doc__ + '\n' + '* ``TrackEndTime``: ' + Qgis.GpsInformationComponent.TrackEndTime.__doc__
Qgis.GpsInformationComponent.TrackDistanceSinceLastPoint.__doc__ = "Distance since last recorded location (available from QgsGpsLogger class only)"
Qgis.GpsInformationComponent.TrackTimeSinceLastPoint.__doc__ = "Time since last recorded location (available from QgsGpsLogger class only)"
Qgis.GpsInformationComponent.__doc__ = 'GPS information component.\n\n.. versionadded:: 3.30\n\n' + '* ``Location``: ' + Qgis.GpsInformationComponent.Location.__doc__ + '\n' + '* ``Altitude``: ' + Qgis.GpsInformationComponent.Altitude.__doc__ + '\n' + '* ``GroundSpeed``: ' + Qgis.GpsInformationComponent.GroundSpeed.__doc__ + '\n' + '* ``Bearing``: ' + Qgis.GpsInformationComponent.Bearing.__doc__ + '\n' + '* ``TotalTrackLength``: ' + Qgis.GpsInformationComponent.TotalTrackLength.__doc__ + '\n' + '* ``TrackDistanceFromStart``: ' + Qgis.GpsInformationComponent.TrackDistanceFromStart.__doc__ + '\n' + '* ``Pdop``: ' + Qgis.GpsInformationComponent.Pdop.__doc__ + '\n' + '* ``Hdop``: ' + Qgis.GpsInformationComponent.Hdop.__doc__ + '\n' + '* ``Vdop``: ' + Qgis.GpsInformationComponent.Vdop.__doc__ + '\n' + '* ``HorizontalAccuracy``: ' + Qgis.GpsInformationComponent.HorizontalAccuracy.__doc__ + '\n' + '* ``VerticalAccuracy``: ' + Qgis.GpsInformationComponent.VerticalAccuracy.__doc__ + '\n' + '* ``HvAccuracy``: ' + Qgis.GpsInformationComponent.HvAccuracy.__doc__ + '\n' + '* ``SatellitesUsed``: ' + Qgis.GpsInformationComponent.SatellitesUsed.__doc__ + '\n' + '* ``Timestamp``: ' + Qgis.GpsInformationComponent.Timestamp.__doc__ + '\n' + '* ``TrackStartTime``: ' + Qgis.GpsInformationComponent.TrackStartTime.__doc__ + '\n' + '* ``TrackEndTime``: ' + Qgis.GpsInformationComponent.TrackEndTime.__doc__ + '\n' + '* ``TrackDistanceSinceLastPoint``: ' + Qgis.GpsInformationComponent.TrackDistanceSinceLastPoint.__doc__ + '\n' + '* ``TrackTimeSinceLastPoint``: ' + Qgis.GpsInformationComponent.TrackTimeSinceLastPoint.__doc__
# --
Qgis.GpsInformationComponent.baseClass = Qgis
Qgis.GpsInformationComponents.baseClass = Qgis
Expand Down
122 changes: 27 additions & 95 deletions python/core/auto_generated/gps/qgsvectorlayergpslogger.sip.in
Expand Up @@ -72,112 +72,44 @@ May be ``None`` if tracks are not being stored.
.. seealso:: :py:func:`pointsLayer`
%End

QString pointTimeField() const;
void setDestinationField( Qgis::GpsInformationComponent component, const QString &field );
%Docstring
Returns the destination time field name from the :py:func:`~QgsVectorLayerGpsLogger.pointsLayer`.
Sets a destination ``field`` name for a specific GPS information ``component``.

If specified, timestamps for recorded points will be stored in this field.
Depending on the ``component``, the field will either refer to the :py:func:`~QgsVectorLayerGpsLogger.pointsLayer` or :py:func:`~QgsVectorLayerGpsLogger.tracksLayer`.

.. seealso:: :py:func:`setPointTimeField`
%End

void setPointTimeField( const QString &field );
%Docstring
Sets the destination time ``field`` name from the :py:func:`~QgsVectorLayerGpsLogger.pointsLayer`.

If specified, timestamps for recorded points will be stored in this field.

.. seealso:: :py:func:`pointTimeField`
%End

QString pointDistanceFromPreviousField() const;
%Docstring
Returns the destination distance from previous point field name from the :py:func:`~QgsVectorLayerGpsLogger.pointsLayer`.

If specified, the distance from the previous recorded point will be stored in this field.

.. seealso:: :py:func:`setPointDistanceFromPreviousField`
%End

void setPointDistanceFromPreviousField( const QString &field );
%Docstring
Sets the destination distance from previous point ``field`` name from the :py:func:`~QgsVectorLayerGpsLogger.pointsLayer`.

If specified, the distance from the previous recorded point will be stored in this field.

.. seealso:: :py:func:`pointDistanceFromPreviousField`
%End

QString pointTimeDeltaFromPreviousField() const;
%Docstring
Returns the destination time delta from previous point field name from the :py:func:`~QgsVectorLayerGpsLogger.pointsLayer`.
Fields stored in the :py:func:`~QgsVectorLayerGpsLogger.pointsLayer` are:

If specified, the time difference from the previous recorded point will be stored in this field.
- Qgis.GpsInformationComponent.Location:
- Qgis.GpsInformationComponent.Altitude:
- Qgis.GpsInformationComponent.GroundSpeed:
- Qgis.GpsInformationComponent.Bearing:
- Qgis.GpsInformationComponent.Pdop:
- Qgis.GpsInformationComponent.Hdop:
- Qgis.GpsInformationComponent.Vdop:
- Qgis.GpsInformationComponent.HorizontalAccuracy:
- Qgis.GpsInformationComponent.VerticalAccuracy:
- Qgis.GpsInformationComponent.HvAccuracy:
- Qgis.GpsInformationComponent.SatellitesUsed:
- Qgis.GpsInformationComponent.Timestamp:
- Qgis.GpsInformationComponent.TrackDistanceSinceLastPoint:
- Qgis.GpsInformationComponent.TrackTimeSinceLastPoint:

.. seealso:: :py:func:`setPointTimeDeltaFromPreviousField`
%End

void setPointTimeDeltaFromPreviousField( const QString &field );
%Docstring
Sets the destination time delta from previous point ``field`` name from the :py:func:`~QgsVectorLayerGpsLogger.pointsLayer`.
Fields stored in the :py:func:`~QgsVectorLayerGpsLogger.tracksLayer` are:

If specified, the time difference from the previous recorded point will be stored in this field.
- Qgis.GpsInformationComponent.TrackStartTime:
- Qgis.GpsInformationComponent.TrackEndTime:
- Qgis.GpsInformationComponent.TotalTrackLength:
- Qgis.GpsInformationComponent.TrackDistanceFromStart:

.. seealso:: :py:func:`pointTimeDeltaFromPreviousField`
.. seealso:: :py:func:`destinationField`
%End

QString trackStartTimeField() const;
QString destinationField( Qgis::GpsInformationComponent component ) const;
%Docstring
Returns the destination start time field name from the :py:func:`~QgsVectorLayerGpsLogger.tracksLayer`.

If specified, the start timestamps for recorded tracks will be stored in this field.

.. seealso:: :py:func:`setTrackStartTimeField`
%End

void setTrackStartTimeField( const QString &field );
%Docstring
Sets the destination start time ``field`` name from the :py:func:`~QgsVectorLayerGpsLogger.tracksLayer`.

If specified, the start timestamps for recorded tracks will be stored in this field.

.. seealso:: :py:func:`trackStartTimeField`
%End

QString trackEndTimeField() const;
%Docstring
Returns the destination end time field name from the :py:func:`~QgsVectorLayerGpsLogger.tracksLayer`.

If specified, the end timestamps for recorded tracks will be stored in this field.

.. seealso:: :py:func:`setTrackEndTimeField`
%End

void setTrackEndTimeField( const QString &field );
%Docstring
Sets the destination end time ``field`` name from the :py:func:`~QgsVectorLayerGpsLogger.tracksLayer`.

If specified, the end timestamps for recorded tracks will be stored in this field.

.. seealso:: :py:func:`trackEndTimeField`
%End

QString trackLengthField() const;
%Docstring
Returns the destination track length field name from the :py:func:`~QgsVectorLayerGpsLogger.tracksLayer`.

If specified, the total track length recorded tracks will be stored in this field.

.. seealso:: :py:func:`setTrackLengthField`
%End

void setTrackLengthField( const QString &field );
%Docstring
Sets the destination track length ``field`` name from the :py:func:`~QgsVectorLayerGpsLogger.tracksLayer`.

If specified, the total track length recorded tracks will be stored in this field.
Returns the destination field name for a specific GPS information ``component``.

.. seealso:: :py:func:`trackLengthField`
.. seealso:: :py:func:`setDestinationField`
%End

virtual void setTransformContext( const QgsCoordinateTransformContext &context );
Expand Down
2 changes: 2 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -632,6 +632,8 @@ The development version
Timestamp,
TrackStartTime,
TrackEndTime,
TrackDistanceSinceLastPoint,
TrackTimeSinceLastPoint,
};

typedef QFlags<Qgis::GpsInformationComponent> GpsInformationComponents;
Expand Down
4 changes: 3 additions & 1 deletion src/app/gps/qgsgpstoolbar.cpp
Expand Up @@ -291,7 +291,9 @@ void QgsGpsToolBar::updateLocationLabel()
case Qgis::GpsInformationComponent::Timestamp:
case Qgis::GpsInformationComponent::TrackStartTime:
case Qgis::GpsInformationComponent::TrackEndTime:
// not supported yet
case Qgis::GpsInformationComponent::TrackDistanceSinceLastPoint:
case Qgis::GpsInformationComponent::TrackTimeSinceLastPoint:
// not supported here
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/gps/qgsgpsconnection.cpp
Expand Up @@ -163,6 +163,8 @@ QVariant QgsGpsInformation::componentValue( Qgis::GpsInformationComponent compon
case Qgis::GpsInformationComponent::TrackDistanceFromStart:
case Qgis::GpsInformationComponent::TrackStartTime:
case Qgis::GpsInformationComponent::TrackEndTime:
case Qgis::GpsInformationComponent::TrackDistanceSinceLastPoint:
case Qgis::GpsInformationComponent::TrackTimeSinceLastPoint:
return QVariant(); // not available
}
BUILTIN_UNREACHABLE
Expand Down
8 changes: 8 additions & 0 deletions src/core/gps/qgsgpslogger.cpp
Expand Up @@ -211,6 +211,11 @@ QVariant QgsGpsLogger::componentValue( Qgis::GpsInformationComponent component )
return trackStartTime();
case Qgis::GpsInformationComponent::TrackEndTime:
return lastTimestamp();

case Qgis::GpsInformationComponent::TrackDistanceSinceLastPoint:
return mPreviousTrackPoint.isEmpty() ? QVariant() : distanceArea().measureLine( mPreviousTrackPoint, lastPosition() );
case Qgis::GpsInformationComponent::TrackTimeSinceLastPoint:
return mPreviousTrackPointTime.isValid() ? static_cast< double >( mPreviousTrackPointTime.msecsTo( lastTimestamp() ) ) / 1000 : QVariant();
}
BUILTIN_UNREACHABLE
}
Expand Down Expand Up @@ -282,6 +287,9 @@ void QgsGpsLogger::gpsStateChanged( const QgsGpsInformation &info )
}

emit stateChanged( info );

mPreviousTrackPointTime = lastTimestamp();
mPreviousTrackPoint = mLastGpsPositionWgs84;
}

void QgsGpsLogger::addTrackVertex()
Expand Down
3 changes: 3 additions & 0 deletions src/core/gps/qgsgpslogger.h
Expand Up @@ -240,6 +240,9 @@ class CORE_EXPORT QgsGpsLogger : public QObject
nmeaPOS mLastNmeaPosition;
QDateTime mLastTime;

QDateTime mPreviousTrackPointTime;
QgsPointXY mPreviousTrackPoint;

QDateTime mTrackStartTime;

QVector<QgsPoint> mCaptureListWgs84;
Expand Down

0 comments on commit 281f1d0

Please sign in to comment.