mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-07 00:03:52 -05:00
Allow track length and distance from start to be shown in floating
GPS toolbar
This commit is contained in:
parent
187da086cf
commit
5c6c63d0e7
@ -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.Altitude.__doc__ = "Altitude/elevation above or below the mean sea level"
|
||||||
Qgis.GpsInformationComponent.GroundSpeed.__doc__ = "Ground speed"
|
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.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.GpsInformationComponent.baseClass = Qgis
|
||||||
Qgis.GpsInformationComponents.baseClass = Qgis
|
Qgis.GpsInformationComponents.baseClass = Qgis
|
||||||
|
|||||||
@ -620,6 +620,8 @@ The development version
|
|||||||
Altitude,
|
Altitude,
|
||||||
GroundSpeed,
|
GroundSpeed,
|
||||||
Bearing,
|
Bearing,
|
||||||
|
TotalTrackLength,
|
||||||
|
TrackDistanceFromStart,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QFlags<Qgis::GpsInformationComponent> GpsInformationComponents;
|
typedef QFlags<Qgis::GpsInformationComponent> GpsInformationComponents;
|
||||||
|
|||||||
@ -109,7 +109,7 @@ double QgsAppGpsDigitizing::totalTrackLength() const
|
|||||||
return mDa.measureLine( points );
|
return mDa.measureLine( points );
|
||||||
}
|
}
|
||||||
|
|
||||||
double QgsAppGpsDigitizing::trackDirectLength() const
|
double QgsAppGpsDigitizing::trackDistanceFromStart() const
|
||||||
{
|
{
|
||||||
if ( mCaptureListWgs84.empty() )
|
if ( mCaptureListWgs84.empty() )
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -62,7 +62,7 @@ class APP_EXPORT QgsAppGpsDigitizing: public QObject
|
|||||||
*
|
*
|
||||||
* The returned length is calculated using ellipsoidal calculations.
|
* The returned length is calculated using ellipsoidal calculations.
|
||||||
*/
|
*/
|
||||||
double trackDirectLength() const;
|
double trackDistanceFromStart() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the distance area calculator used to calculate track lengths.
|
* Returns the distance area calculator used to calculate track lengths.
|
||||||
|
|||||||
@ -296,7 +296,7 @@ void QgsGpsInformationWidget::gpsConnected()
|
|||||||
void QgsGpsInformationWidget::updateTrackInformation()
|
void QgsGpsInformationWidget::updateTrackInformation()
|
||||||
{
|
{
|
||||||
const double totalTrackLength = mDigitizing->totalTrackLength();
|
const double totalTrackLength = mDigitizing->totalTrackLength();
|
||||||
const double directTrackLength = mDigitizing->trackDirectLength();
|
const double directTrackLength = mDigitizing->trackDistanceFromStart();
|
||||||
|
|
||||||
const QgsSettings settings;
|
const QgsSettings settings;
|
||||||
const bool keepBaseUnit = settings.value( QStringLiteral( "qgis/measure/keepbaseunit" ), true ).toBool();
|
const bool keepBaseUnit = settings.value( QStringLiteral( "qgis/measure/keepbaseunit" ), true ).toBool();
|
||||||
|
|||||||
@ -27,6 +27,8 @@
|
|||||||
#include "qgsmaplayermodel.h"
|
#include "qgsmaplayermodel.h"
|
||||||
#include "qgsmaplayerproxymodel.h"
|
#include "qgsmaplayerproxymodel.h"
|
||||||
#include "qgsgpsconnection.h"
|
#include "qgsgpsconnection.h"
|
||||||
|
#include "qgsappgpsdigitizing.h"
|
||||||
|
#include "qgsunittypes.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
@ -190,6 +192,13 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *can
|
|||||||
setFixedWidth( sizeHint().width() );
|
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 )
|
void QgsGpsToolBar::setAddVertexButtonEnabled( bool enabled )
|
||||||
{
|
{
|
||||||
mEnableAddVertexButton = enabled;
|
mEnableAddVertexButton = enabled;
|
||||||
@ -227,6 +236,8 @@ void QgsGpsToolBar::updateLocationLabel()
|
|||||||
Qgis::GpsInformationComponent::Altitude,
|
Qgis::GpsInformationComponent::Altitude,
|
||||||
Qgis::GpsInformationComponent::Bearing,
|
Qgis::GpsInformationComponent::Bearing,
|
||||||
Qgis::GpsInformationComponent::GroundSpeed,
|
Qgis::GpsInformationComponent::GroundSpeed,
|
||||||
|
Qgis::GpsInformationComponent::TotalTrackLength,
|
||||||
|
Qgis::GpsInformationComponent::TrackDistanceFromStart,
|
||||||
} )
|
} )
|
||||||
{
|
{
|
||||||
if ( visibleComponents & component )
|
if ( visibleComponents & component )
|
||||||
@ -246,6 +257,28 @@ void QgsGpsToolBar::updateLocationLabel()
|
|||||||
case Qgis::GpsInformationComponent::Bearing:
|
case Qgis::GpsInformationComponent::Bearing:
|
||||||
parts << QString::number( value.toDouble( ) ) + QChar( 176 );
|
parts << QString::number( value.toDouble( ) ) + QChar( 176 );
|
||||||
break;
|
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::Location, tr( "Show Location" ) },
|
||||||
{ Qgis::GpsInformationComponent::Altitude, tr( "Show Altitude" ) },
|
{ Qgis::GpsInformationComponent::Altitude, tr( "Show Altitude" ) },
|
||||||
{ Qgis::GpsInformationComponent::GroundSpeed, tr( "Show Ground Speed" ) },
|
{ 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;
|
const Qgis::GpsInformationComponent component = it.first;
|
||||||
|
|||||||
@ -28,7 +28,7 @@ class QLabel;
|
|||||||
class QgsVectorLayer;
|
class QgsVectorLayer;
|
||||||
class QgsMapLayerProxyModel;
|
class QgsMapLayerProxyModel;
|
||||||
class QToolButton;
|
class QToolButton;
|
||||||
|
class QgsAppGpsDigitizing;
|
||||||
|
|
||||||
|
|
||||||
class QgsGpsToolBar : public QToolBar
|
class QgsGpsToolBar : public QToolBar
|
||||||
@ -43,6 +43,8 @@ class QgsGpsToolBar : public QToolBar
|
|||||||
|
|
||||||
QAction *showInfoAction() { return mShowInfoAction; }
|
QAction *showInfoAction() { return mShowInfoAction; }
|
||||||
|
|
||||||
|
void setGpsDigitizing( QgsAppGpsDigitizing *digitizing );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void addVertexClicked();
|
void addVertexClicked();
|
||||||
@ -66,6 +68,8 @@ class QgsGpsToolBar : public QToolBar
|
|||||||
|
|
||||||
QgsAppGpsConnection *mConnection = nullptr;
|
QgsAppGpsConnection *mConnection = nullptr;
|
||||||
QgsMapCanvas *mCanvas = nullptr;
|
QgsMapCanvas *mCanvas = nullptr;
|
||||||
|
QPointer< QgsAppGpsDigitizing > mDigitizing;
|
||||||
|
|
||||||
QAction *mConnectAction = nullptr;
|
QAction *mConnectAction = nullptr;
|
||||||
QAction *mRecenterAction = nullptr;
|
QAction *mRecenterAction = nullptr;
|
||||||
QAction *mShowInfoAction = nullptr;
|
QAction *mShowInfoAction = nullptr;
|
||||||
|
|||||||
@ -1408,6 +1408,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers
|
|||||||
connect( mGpsToolBar, &QgsGpsToolBar::addVertexClicked, mGpsDigitizing, &QgsAppGpsDigitizing::addVertex );
|
connect( mGpsToolBar, &QgsGpsToolBar::addVertexClicked, mGpsDigitizing, &QgsAppGpsDigitizing::addVertex );
|
||||||
connect( mGpsToolBar, &QgsGpsToolBar::resetFeatureClicked, mGpsDigitizing, &QgsAppGpsDigitizing::resetTrack );
|
connect( mGpsToolBar, &QgsGpsToolBar::resetFeatureClicked, mGpsDigitizing, &QgsAppGpsDigitizing::resetTrack );
|
||||||
|
|
||||||
|
mGpsToolBar->setGpsDigitizing( mGpsDigitizing );
|
||||||
|
|
||||||
mGpsCanvasBridge = new QgsGpsCanvasBridge( mGpsConnection, mMapCanvas );
|
mGpsCanvasBridge = new QgsGpsCanvasBridge( mGpsConnection, mMapCanvas );
|
||||||
mGpsCanvasBridge->setLocationMarkerVisible( mGpsSettingsMenu->locationMarkerVisible() );
|
mGpsCanvasBridge->setLocationMarkerVisible( mGpsSettingsMenu->locationMarkerVisible() );
|
||||||
mGpsCanvasBridge->setBearingLineVisible( mGpsSettingsMenu->bearingLineVisible() );
|
mGpsCanvasBridge->setBearingLineVisible( mGpsSettingsMenu->bearingLineVisible() );
|
||||||
|
|||||||
@ -140,6 +140,10 @@ QVariant QgsGpsInformation::componentValue( Qgis::GpsInformationComponent compon
|
|||||||
return speed;
|
return speed;
|
||||||
case Qgis::GpsInformationComponent::Bearing:
|
case Qgis::GpsInformationComponent::Bearing:
|
||||||
return std::isnan( direction ) ? QVariant() : direction;
|
return std::isnan( direction ) ? QVariant() : direction;
|
||||||
|
|
||||||
|
case Qgis::GpsInformationComponent::TotalTrackLength:
|
||||||
|
case Qgis::GpsInformationComponent::TrackDistanceFromStart:
|
||||||
|
return QVariant(); // not available
|
||||||
}
|
}
|
||||||
BUILTIN_UNREACHABLE
|
BUILTIN_UNREACHABLE
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1012,6 +1012,8 @@ class CORE_EXPORT Qgis
|
|||||||
Altitude = 1 << 1, //!< Altitude/elevation above or below the mean sea level
|
Altitude = 1 << 1, //!< Altitude/elevation above or below the mean sea level
|
||||||
GroundSpeed = 1 << 2, //!< Ground speed
|
GroundSpeed = 1 << 2, //!< Ground speed
|
||||||
Bearing = 1 << 3, //!< Bearing measured in degrees clockwise from true north to the direction of travel
|
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)
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -462,7 +462,7 @@ void TestQgsGpsIntegration::testTrackDistance()
|
|||||||
QCOMPARE( spy.count(), 1 );
|
QCOMPARE( spy.count(), 1 );
|
||||||
|
|
||||||
QCOMPARE( gpsDigitizing.totalTrackLength(), 0 );
|
QCOMPARE( gpsDigitizing.totalTrackLength(), 0 );
|
||||||
QCOMPARE( gpsDigitizing.trackDirectLength(), 0 );
|
QCOMPARE( gpsDigitizing.trackDistanceFromStart(), 0 );
|
||||||
|
|
||||||
info.latitude = 46;
|
info.latitude = 46;
|
||||||
info.longitude = 100;
|
info.longitude = 100;
|
||||||
@ -474,11 +474,11 @@ void TestQgsGpsIntegration::testTrackDistance()
|
|||||||
QgsProject::instance()->setCrs( QgsCoordinateReferenceSystem( "EPSG:3857" ) );
|
QgsProject::instance()->setCrs( QgsCoordinateReferenceSystem( "EPSG:3857" ) );
|
||||||
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "NONE" ) );
|
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "NONE" ) );
|
||||||
QGSCOMPARENEAR( gpsDigitizing.totalTrackLength(), 1, 0.01 );
|
QGSCOMPARENEAR( gpsDigitizing.totalTrackLength(), 1, 0.01 );
|
||||||
QGSCOMPARENEAR( gpsDigitizing.trackDirectLength(), 1, 0.01 );
|
QGSCOMPARENEAR( gpsDigitizing.trackDistanceFromStart(), 1, 0.01 );
|
||||||
QgsProject::instance()->setEllipsoid( QStringLiteral( "EPSG:7030" ) );
|
QgsProject::instance()->setEllipsoid( QStringLiteral( "EPSG:7030" ) );
|
||||||
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "EPSG:7030" ) );
|
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "EPSG:7030" ) );
|
||||||
QGSCOMPARENEAR( gpsDigitizing.totalTrackLength(), 111141.548, 1 );
|
QGSCOMPARENEAR( gpsDigitizing.totalTrackLength(), 111141.548, 1 );
|
||||||
QGSCOMPARENEAR( gpsDigitizing.trackDirectLength(), 111141.548, 1 );
|
QGSCOMPARENEAR( gpsDigitizing.trackDistanceFromStart(), 111141.548, 1 );
|
||||||
|
|
||||||
info.latitude = 46;
|
info.latitude = 46;
|
||||||
info.longitude = 101;
|
info.longitude = 101;
|
||||||
@ -487,7 +487,7 @@ void TestQgsGpsIntegration::testTrackDistance()
|
|||||||
gpsDigitizing.addVertex();
|
gpsDigitizing.addVertex();
|
||||||
QCOMPARE( spy.count(), 3 );
|
QCOMPARE( spy.count(), 3 );
|
||||||
QGSCOMPARENEAR( gpsDigitizing.totalTrackLength(), 188604.338, 1 );
|
QGSCOMPARENEAR( gpsDigitizing.totalTrackLength(), 188604.338, 1 );
|
||||||
QGSCOMPARENEAR( gpsDigitizing.trackDirectLength(), 135869.0912, 1 );
|
QGSCOMPARENEAR( gpsDigitizing.trackDistanceFromStart(), 135869.0912, 1 );
|
||||||
|
|
||||||
gpsDigitizing.resetTrack();
|
gpsDigitizing.resetTrack();
|
||||||
QCOMPARE( spy.count(), 4 );
|
QCOMPARE( spy.count(), 4 );
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user