diff --git a/python/core/auto_additions/qgis.py b/python/core/auto_additions/qgis.py index b57c36e5b0e..3506ee65060 100644 --- a/python/core/auto_additions/qgis.py +++ b/python/core/auto_additions/qgis.py @@ -905,7 +905,9 @@ Qgis.GpsInformationComponent.Location.__doc__ = "2D location (latitude/longitude Qgis.GpsInformationComponent.Altitude.__doc__ = "Altitude/elevation above or below the mean sea level" Qgis.GpsInformationComponent.GroundSpeed.__doc__ = "Ground speed" Qgis.GpsInformationComponent.Bearing.__doc__ = "Bearing measured in degrees clockwise from true north to the direction of travel" -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__ +Qgis.GpsInformationComponent.TotalTrackLength.__doc__ = "Total distance of current GPS track (available from QGIS app library only)" +Qgis.GpsInformationComponent.TrackDistanceFromStart.__doc__ = "Direct distance from first vertex in current GPS track to last vertex (available from QGIS app library 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__ # -- Qgis.GpsInformationComponent.baseClass = Qgis Qgis.GpsInformationComponents.baseClass = Qgis diff --git a/python/core/auto_generated/qgis.sip.in b/python/core/auto_generated/qgis.sip.in index d828d16ecee..5fb18d7434d 100644 --- a/python/core/auto_generated/qgis.sip.in +++ b/python/core/auto_generated/qgis.sip.in @@ -620,6 +620,8 @@ The development version Altitude, GroundSpeed, Bearing, + TotalTrackLength, + TrackDistanceFromStart, }; typedef QFlags GpsInformationComponents; diff --git a/src/app/gps/qgsappgpsdigitizing.cpp b/src/app/gps/qgsappgpsdigitizing.cpp index 8bab6ad7b7f..f63a56a55ac 100644 --- a/src/app/gps/qgsappgpsdigitizing.cpp +++ b/src/app/gps/qgsappgpsdigitizing.cpp @@ -109,7 +109,7 @@ double QgsAppGpsDigitizing::totalTrackLength() const return mDa.measureLine( points ); } -double QgsAppGpsDigitizing::trackDirectLength() const +double QgsAppGpsDigitizing::trackDistanceFromStart() const { if ( mCaptureListWgs84.empty() ) return 0; diff --git a/src/app/gps/qgsappgpsdigitizing.h b/src/app/gps/qgsappgpsdigitizing.h index 11502d92fae..acdb2ced995 100644 --- a/src/app/gps/qgsappgpsdigitizing.h +++ b/src/app/gps/qgsappgpsdigitizing.h @@ -62,7 +62,7 @@ class APP_EXPORT QgsAppGpsDigitizing: public QObject * * The returned length is calculated using ellipsoidal calculations. */ - double trackDirectLength() const; + double trackDistanceFromStart() const; /** * Returns the distance area calculator used to calculate track lengths. diff --git a/src/app/gps/qgsgpsinformationwidget.cpp b/src/app/gps/qgsgpsinformationwidget.cpp index 2ee838aa43d..e519f0bb7eb 100644 --- a/src/app/gps/qgsgpsinformationwidget.cpp +++ b/src/app/gps/qgsgpsinformationwidget.cpp @@ -296,7 +296,7 @@ void QgsGpsInformationWidget::gpsConnected() void QgsGpsInformationWidget::updateTrackInformation() { const double totalTrackLength = mDigitizing->totalTrackLength(); - const double directTrackLength = mDigitizing->trackDirectLength(); + const double directTrackLength = mDigitizing->trackDistanceFromStart(); const QgsSettings settings; const bool keepBaseUnit = settings.value( QStringLiteral( "qgis/measure/keepbaseunit" ), true ).toBool(); diff --git a/src/app/gps/qgsgpstoolbar.cpp b/src/app/gps/qgsgpstoolbar.cpp index 253d0a461e0..a152a067266 100644 --- a/src/app/gps/qgsgpstoolbar.cpp +++ b/src/app/gps/qgsgpstoolbar.cpp @@ -27,6 +27,8 @@ #include "qgsmaplayermodel.h" #include "qgsmaplayerproxymodel.h" #include "qgsgpsconnection.h" +#include "qgsappgpsdigitizing.h" +#include "qgsunittypes.h" #include #include @@ -190,6 +192,13 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *can setFixedWidth( sizeHint().width() ); } +void QgsGpsToolBar::setGpsDigitizing( QgsAppGpsDigitizing *digitizing ) +{ + mDigitizing = digitizing; + connect( mDigitizing, &QgsAppGpsDigitizing::distanceAreaChanged, this, &QgsGpsToolBar::updateLocationLabel ); + connect( mDigitizing, &QgsAppGpsDigitizing::trackChanged, this, &QgsGpsToolBar::updateLocationLabel ); +} + void QgsGpsToolBar::setAddVertexButtonEnabled( bool enabled ) { mEnableAddVertexButton = enabled; @@ -227,6 +236,8 @@ void QgsGpsToolBar::updateLocationLabel() Qgis::GpsInformationComponent::Altitude, Qgis::GpsInformationComponent::Bearing, Qgis::GpsInformationComponent::GroundSpeed, + Qgis::GpsInformationComponent::TotalTrackLength, + Qgis::GpsInformationComponent::TrackDistanceFromStart, } ) { if ( visibleComponents & component ) @@ -246,6 +257,28 @@ void QgsGpsToolBar::updateLocationLabel() case Qgis::GpsInformationComponent::Bearing: parts << QString::number( value.toDouble( ) ) + QChar( 176 ); break; + + case Qgis::GpsInformationComponent::TotalTrackLength: + case Qgis::GpsInformationComponent::TrackDistanceFromStart: + { + if ( mDigitizing ) + { + const double measurement = component == Qgis::GpsInformationComponent::TotalTrackLength + ? mDigitizing->totalTrackLength() + : mDigitizing->trackDistanceFromStart(); + + const QgsSettings settings; + const bool keepBaseUnit = settings.value( QStringLiteral( "qgis/measure/keepbaseunit" ), true ).toBool(); + const int decimalPlaces = settings.value( QStringLiteral( "qgis/measure/decimalplaces" ), 3 ).toInt(); + + if ( measurement > 0 ) + parts << mDigitizing->distanceArea().formatDistance( measurement, decimalPlaces, mDigitizing->distanceArea().lengthUnits(), keepBaseUnit ); + else + parts << QStringLiteral( "0%1" ).arg( QgsUnitTypes::toAbbreviatedString( mDigitizing->distanceArea().lengthUnits() ) ); + } + + break; + } } } } @@ -387,7 +420,10 @@ void QgsGpsToolBar::createLocationWidget() { Qgis::GpsInformationComponent::Location, tr( "Show Location" ) }, { Qgis::GpsInformationComponent::Altitude, tr( "Show Altitude" ) }, { Qgis::GpsInformationComponent::GroundSpeed, tr( "Show Ground Speed" ) }, - { Qgis::GpsInformationComponent::Bearing, tr( "Show Bearing" ) } + { Qgis::GpsInformationComponent::Bearing, tr( "Show Bearing" ) }, + { Qgis::GpsInformationComponent::TotalTrackLength, tr( "Show Total Track Length" ) }, + { Qgis::GpsInformationComponent::TrackDistanceFromStart, tr( "Show Distance from Start of Track" ) } + } ) { const Qgis::GpsInformationComponent component = it.first; diff --git a/src/app/gps/qgsgpstoolbar.h b/src/app/gps/qgsgpstoolbar.h index 45edf6bca64..e01c106239a 100644 --- a/src/app/gps/qgsgpstoolbar.h +++ b/src/app/gps/qgsgpstoolbar.h @@ -28,7 +28,7 @@ class QLabel; class QgsVectorLayer; class QgsMapLayerProxyModel; class QToolButton; - +class QgsAppGpsDigitizing; class QgsGpsToolBar : public QToolBar @@ -43,6 +43,8 @@ class QgsGpsToolBar : public QToolBar QAction *showInfoAction() { return mShowInfoAction; } + void setGpsDigitizing( QgsAppGpsDigitizing *digitizing ); + signals: void addVertexClicked(); @@ -66,6 +68,8 @@ class QgsGpsToolBar : public QToolBar QgsAppGpsConnection *mConnection = nullptr; QgsMapCanvas *mCanvas = nullptr; + QPointer< QgsAppGpsDigitizing > mDigitizing; + QAction *mConnectAction = nullptr; QAction *mRecenterAction = nullptr; QAction *mShowInfoAction = nullptr; diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 0c21f1c4ba2..422f35f993f 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -1408,6 +1408,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers connect( mGpsToolBar, &QgsGpsToolBar::addVertexClicked, mGpsDigitizing, &QgsAppGpsDigitizing::addVertex ); connect( mGpsToolBar, &QgsGpsToolBar::resetFeatureClicked, mGpsDigitizing, &QgsAppGpsDigitizing::resetTrack ); + mGpsToolBar->setGpsDigitizing( mGpsDigitizing ); + mGpsCanvasBridge = new QgsGpsCanvasBridge( mGpsConnection, mMapCanvas ); mGpsCanvasBridge->setLocationMarkerVisible( mGpsSettingsMenu->locationMarkerVisible() ); mGpsCanvasBridge->setBearingLineVisible( mGpsSettingsMenu->bearingLineVisible() ); diff --git a/src/core/gps/qgsgpsconnection.cpp b/src/core/gps/qgsgpsconnection.cpp index a40c6beef70..ed0be8a0e17 100644 --- a/src/core/gps/qgsgpsconnection.cpp +++ b/src/core/gps/qgsgpsconnection.cpp @@ -140,6 +140,10 @@ QVariant QgsGpsInformation::componentValue( Qgis::GpsInformationComponent compon return speed; case Qgis::GpsInformationComponent::Bearing: return std::isnan( direction ) ? QVariant() : direction; + + case Qgis::GpsInformationComponent::TotalTrackLength: + case Qgis::GpsInformationComponent::TrackDistanceFromStart: + return QVariant(); // not available } BUILTIN_UNREACHABLE } diff --git a/src/core/qgis.h b/src/core/qgis.h index 00a069aa605..e6f2442f759 100644 --- a/src/core/qgis.h +++ b/src/core/qgis.h @@ -1012,6 +1012,8 @@ class CORE_EXPORT Qgis Altitude = 1 << 1, //!< Altitude/elevation above or below the mean sea level GroundSpeed = 1 << 2, //!< Ground speed Bearing = 1 << 3, //!< Bearing measured in degrees clockwise from true north to the direction of travel + TotalTrackLength = 1 << 4, //!< Total distance of current GPS track (available from QGIS app library only) + TrackDistanceFromStart = 1 << 5, //!< Direct distance from first vertex in current GPS track to last vertex (available from QGIS app library only) }; /** diff --git a/tests/src/app/testqgsgpsintegration.cpp b/tests/src/app/testqgsgpsintegration.cpp index 3fbbef78bdb..884e857e331 100644 --- a/tests/src/app/testqgsgpsintegration.cpp +++ b/tests/src/app/testqgsgpsintegration.cpp @@ -462,7 +462,7 @@ void TestQgsGpsIntegration::testTrackDistance() QCOMPARE( spy.count(), 1 ); QCOMPARE( gpsDigitizing.totalTrackLength(), 0 ); - QCOMPARE( gpsDigitizing.trackDirectLength(), 0 ); + QCOMPARE( gpsDigitizing.trackDistanceFromStart(), 0 ); info.latitude = 46; info.longitude = 100; @@ -474,11 +474,11 @@ void TestQgsGpsIntegration::testTrackDistance() QgsProject::instance()->setCrs( QgsCoordinateReferenceSystem( "EPSG:3857" ) ); QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "NONE" ) ); QGSCOMPARENEAR( gpsDigitizing.totalTrackLength(), 1, 0.01 ); - QGSCOMPARENEAR( gpsDigitizing.trackDirectLength(), 1, 0.01 ); + QGSCOMPARENEAR( gpsDigitizing.trackDistanceFromStart(), 1, 0.01 ); QgsProject::instance()->setEllipsoid( QStringLiteral( "EPSG:7030" ) ); QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "EPSG:7030" ) ); QGSCOMPARENEAR( gpsDigitizing.totalTrackLength(), 111141.548, 1 ); - QGSCOMPARENEAR( gpsDigitizing.trackDirectLength(), 111141.548, 1 ); + QGSCOMPARENEAR( gpsDigitizing.trackDistanceFromStart(), 111141.548, 1 ); info.latitude = 46; info.longitude = 101; @@ -487,7 +487,7 @@ void TestQgsGpsIntegration::testTrackDistance() gpsDigitizing.addVertex(); QCOMPARE( spy.count(), 3 ); QGSCOMPARENEAR( gpsDigitizing.totalTrackLength(), 188604.338, 1 ); - QGSCOMPARENEAR( gpsDigitizing.trackDirectLength(), 135869.0912, 1 ); + QGSCOMPARENEAR( gpsDigitizing.trackDistanceFromStart(), 135869.0912, 1 ); gpsDigitizing.resetTrack(); QCOMPARE( spy.count(), 4 );