Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 14, 2022
1 parent bbd0a23 commit 09b0d0c
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 50 deletions.
19 changes: 19 additions & 0 deletions python/core/auto_generated/gps/qgsgpslogger.sip.in
Expand Up @@ -136,6 +136,20 @@ the GPS position is changed.
void updateGpsSettings();
%Docstring
Should be called whenever the QGIS GPS settings are changed.
%End

double totalTrackLength() const;
%Docstring
Returns the total length of the current digitized track (in meters).

The returned length is calculated using ellipsoidal calculations.
%End

double trackDistanceFromStart() const;
%Docstring
Returns the direct length from the first vertex in the track to the last (in meters).

The returned length is calculated using ellipsoidal calculations.
%End

signals:
Expand All @@ -160,6 +174,11 @@ The ``vertex`` point will be in WGS84 coordinate reference system.
void stateChanged( const QgsGpsInformation &info );
%Docstring
Emitted whenever the associated GPS device state is changed.
%End

void distanceAreaChanged();
%Docstring
Emitted whenever the distance area used to calculate track distances is changed.
%End

protected:
Expand Down
15 changes: 0 additions & 15 deletions src/app/gps/qgsappgpsdigitizing.cpp
Expand Up @@ -96,21 +96,6 @@ QgsAppGpsDigitizing::~QgsAppGpsDigitizing()
mRubberBand = nullptr;
}

double QgsAppGpsDigitizing::totalTrackLength() const
{
QVector<QgsPointXY> points;
QgsGeometry::convertPointList( mCaptureListWgs84, points );
return mDa.measureLine( points );
}

double QgsAppGpsDigitizing::trackDistanceFromStart() const
{
if ( mCaptureListWgs84.empty() )
return 0;

return mDa.measureLine( { QgsPointXY( mCaptureListWgs84.constFirst() ), QgsPointXY( mCaptureListWgs84.constLast() )} );
}

const QgsDistanceArea &QgsAppGpsDigitizing::distanceArea() const
{
return mDa;
Expand Down
26 changes: 0 additions & 26 deletions src/app/gps/qgsappgpsdigitizing.h
Expand Up @@ -47,20 +47,6 @@ class APP_EXPORT QgsAppGpsDigitizing: public QgsGpsLogger
QgsAppGpsDigitizing( QgsAppGpsConnection *connection, QgsMapCanvas *canvas, QObject *parent = nullptr );
~QgsAppGpsDigitizing() override;

/**
* Returns the total length of the current digitized track (in meters).
*
* The returned length is calculated using ellipsoidal calculations.
*/
double totalTrackLength() const;

/**
* Returns the direct length from the first vertex in the track to the last (in meters).
*
* The returned length is calculated using ellipsoidal calculations.
*/
double trackDistanceFromStart() const;

/**
* Returns the distance area calculator used to calculate track lengths.
*/
Expand All @@ -73,16 +59,6 @@ class APP_EXPORT QgsAppGpsDigitizing: public QgsGpsLogger

void createVertexAtCurrentLocation();

/**
* Emitted whenever the recorded track is changed.
*/
void trackChanged();

/**
* Emitted whenever the distance area used to calculate track distances is changed.
*/
void distanceAreaChanged();

private slots:
void addVertex( const QgsPoint &wgs84Point );
void onTrackReset();
Expand All @@ -97,8 +73,6 @@ class APP_EXPORT QgsAppGpsDigitizing: public QgsGpsLogger
void startLogging();
void stopLogging();

void updateDistanceArea();

private:
void createRubberBand();
QVariant timestamp( QgsVectorLayer *vlayer, int idx );
Expand Down
3 changes: 2 additions & 1 deletion src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -208,7 +208,8 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsAppGpsConnection *connectio
}
} );

connect( mDigitizing, &QgsAppGpsDigitizing::trackChanged, this, &QgsGpsInformationWidget::updateTrackInformation );
connect( mDigitizing, &QgsAppGpsDigitizing::trackVertexAdded, this, &QgsGpsInformationWidget::updateTrackInformation );
connect( mDigitizing, &QgsAppGpsDigitizing::trackReset, this, &QgsGpsInformationWidget::updateTrackInformation );
connect( mDigitizing, &QgsAppGpsDigitizing::distanceAreaChanged, this, &QgsGpsInformationWidget::updateTrackInformation );
}

Expand Down
3 changes: 2 additions & 1 deletion src/app/gps/qgsgpstoolbar.cpp
Expand Up @@ -196,7 +196,8 @@ void QgsGpsToolBar::setGpsDigitizing( QgsAppGpsDigitizing *digitizing )
{
mDigitizing = digitizing;
connect( mDigitizing, &QgsAppGpsDigitizing::distanceAreaChanged, this, &QgsGpsToolBar::updateLocationLabel );
connect( mDigitizing, &QgsAppGpsDigitizing::trackChanged, this, &QgsGpsToolBar::updateLocationLabel );
connect( mDigitizing, &QgsAppGpsDigitizing::trackVertexAdded, this, &QgsGpsToolBar::updateLocationLabel );
connect( mDigitizing, &QgsAppGpsDigitizing::trackReset, this, &QgsGpsToolBar::updateLocationLabel );
}

void QgsGpsToolBar::setAddVertexButtonEnabled( bool enabled )
Expand Down
18 changes: 18 additions & 0 deletions src/core/gps/qgsgpslogger.cpp
Expand Up @@ -16,6 +16,7 @@
#include "qgsgpslogger.h"
#include "qgsgpsconnection.h"
#include "gmath.h"
#include "qgsgeometry.h"

#include <QTimer>
#include <QTimeZone>
Expand Down Expand Up @@ -66,12 +67,14 @@ void QgsGpsLogger::setConnection( QgsGpsConnection *connection )
void QgsGpsLogger::setEllipsoid( const QString &ellipsoid )
{
mDistanceCalculator.setEllipsoid( ellipsoid );
emit distanceAreaChanged();
}

void QgsGpsLogger::setTransformContext( const QgsCoordinateTransformContext &context )
{
mTransformContext = context;
mDistanceCalculator.setSourceCrs( mWgs84CRS, mTransformContext );
emit distanceAreaChanged();
}

QgsCoordinateTransformContext QgsGpsLogger::transformContext() const
Expand Down Expand Up @@ -162,6 +165,21 @@ void QgsGpsLogger::updateGpsSettings()
switchAcquisition();
}

double QgsGpsLogger::totalTrackLength() const
{
QVector<QgsPointXY> points;
QgsGeometry::convertPointList( mCaptureListWgs84, points );
return mDistanceCalculator.measureLine( points );
}

double QgsGpsLogger::trackDistanceFromStart() const
{
if ( mCaptureListWgs84.empty() )
return 0;

return mDistanceCalculator.measureLine( { QgsPointXY( mCaptureListWgs84.constFirst() ), QgsPointXY( mCaptureListWgs84.constLast() )} );
}

void QgsGpsLogger::switchAcquisition()
{
if ( mAcquisitionInterval > 0 )
Expand Down
19 changes: 19 additions & 0 deletions src/core/gps/qgsgpslogger.h
Expand Up @@ -160,6 +160,20 @@ class CORE_EXPORT QgsGpsLogger : public QObject
*/
void updateGpsSettings();

/**
* Returns the total length of the current digitized track (in meters).
*
* The returned length is calculated using ellipsoidal calculations.
*/
double totalTrackLength() const;

/**
* Returns the direct length from the first vertex in the track to the last (in meters).
*
* The returned length is calculated using ellipsoidal calculations.
*/
double trackDistanceFromStart() const;

signals:

/**
Expand All @@ -184,6 +198,11 @@ class CORE_EXPORT QgsGpsLogger : public QObject
*/
void stateChanged( const QgsGpsInformation &info );

/**
* Emitted whenever the distance area used to calculate track distances is changed.
*/
void distanceAreaChanged();

protected:

//! WGS84 coordinate reference system
Expand Down
13 changes: 6 additions & 7 deletions tests/src/app/testqgsgpsintegration.cpp
Expand Up @@ -27,8 +27,6 @@
#include "options/qgsgpsoptions.h"
#include "qgsprojectgpssettings.h"
#include "qgsgpsconnection.h"
#include "nmeatime.h"

#include <QSignalSpy>

/**
Expand Down Expand Up @@ -451,14 +449,14 @@ void TestQgsGpsIntegration::testTrackDistance()
QCOMPARE( QgsProject::instance()->gpsSettings()->destinationLayer(), lineString );
lineString->startEditing();

QSignalSpy spy( &gpsDigitizing, &QgsAppGpsDigitizing::trackChanged );
QSignalSpy spy( &gpsDigitizing, &QgsAppGpsDigitizing::trackVertexAdded );

QgsGpsInformation info;
info.latitude = 45;
info.longitude = 100;

gpsDigitizing.gpsStateChanged( info );
gpsDigitizing.addVertex();
gpsDigitizing.createVertexAtCurrentLocation();
QCOMPARE( spy.count(), 1 );

QCOMPARE( gpsDigitizing.totalTrackLength(), 0 );
Expand All @@ -468,7 +466,7 @@ void TestQgsGpsIntegration::testTrackDistance()
info.longitude = 100;

gpsDigitizing.gpsStateChanged( info );
gpsDigitizing.addVertex();
gpsDigitizing.createVertexAtCurrentLocation();
QCOMPARE( spy.count(), 2 );

QgsProject::instance()->setCrs( QgsCoordinateReferenceSystem( "EPSG:3857" ) );
Expand All @@ -484,13 +482,14 @@ void TestQgsGpsIntegration::testTrackDistance()
info.longitude = 101;

gpsDigitizing.gpsStateChanged( info );
gpsDigitizing.addVertex();
gpsDigitizing.createVertexAtCurrentLocation();
QCOMPARE( spy.count(), 3 );
QGSCOMPARENEAR( gpsDigitizing.totalTrackLength(), 188604.338, 1 );
QGSCOMPARENEAR( gpsDigitizing.trackDistanceFromStart(), 135869.0912, 1 );

QSignalSpy spyReset( &gpsDigitizing, &QgsGpsLogger::trackReset );
gpsDigitizing.resetTrack();
QCOMPARE( spy.count(), 4 );
QCOMPARE( spyReset.count(), 1 );
}


Expand Down

0 comments on commit 09b0d0c

Please sign in to comment.