Skip to content
Permalink
Browse files

[gps] Ensure that the status bar GPS distance readout only shows

in response to a mouse action and doesn't always re-show as a
result of a GPS position change

Otherwise as soon as the message appears, it will endlessly
re-show as the GPS position is constantly changing. Instead
ensure that the message starts showing for a maximum of
2 seconds in response to a mouse movement, yet will update
during these 2 seconds if the GPS position is updated during
this time.
  • Loading branch information
nyalldawson committed Oct 8, 2020
1 parent 9efa05b commit 429ffde9670f997004eab8a7a05afedcb1abe648
Showing with 21 additions and 7 deletions.
  1. +19 −6 src/app/gps/qgsgpsinformationwidget.cpp
  2. +2 −1 src/app/gps/qgsgpsinformationwidget.h
@@ -107,7 +107,7 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsMapCanvas *mapCanvas, QWidg
connect( QgsProject::instance()->displaySettings(), &QgsProjectDisplaySettings::bearingFormatChanged, this, [ = ]
{
mBearingNumericFormat.reset( QgsProject::instance()->displaySettings()->bearingFormat()->clone() );
updateGpsDistanceStatusMessage();
updateGpsDistanceStatusMessage( false );
} );

mCanvasToWgs84Transform = QgsCoordinateTransform( mMapCanvas->mapSettings().destinationCrs(), mWgs84CRS, QgsProject::instance() );
@@ -1005,7 +1005,7 @@ void QgsGpsInformationWidget::displayGPSInformation( const QgsGpsInformation &in
addVertex();
}

updateGpsDistanceStatusMessage();
updateGpsDistanceStatusMessage( false );
}

if ( !std::isnan( info.direction ) || ( mTravelBearingCheckBox->isChecked() && !mSecondLastGpsPosition.isEmpty() ) )
@@ -1621,27 +1621,40 @@ void QgsGpsInformationWidget::cursorCoordinateChanged( const QgsPointXY &point )
try
{
mLastCursorPosWgs84 = mCanvasToWgs84Transform.transform( point );
updateGpsDistanceStatusMessage();
updateGpsDistanceStatusMessage( true );
}
catch ( QgsCsException & )
{

}
}

void QgsGpsInformationWidget::updateGpsDistanceStatusMessage()
void QgsGpsInformationWidget::updateGpsDistanceStatusMessage( bool forceDisplay )
{
if ( !mNmea )
return;

if ( !forceDisplay )
{
// if we aren't forcing the display of the message (i.e. in direct response to a mouse cursor movement),
// then only show an updated message when the GPS position changes if the previous forced message occurred < 2 seconds ago.
// otherwise we end up showing infinite messages as the GPS position constantly changes...
if ( mLastForcedStatusUpdate.hasExpired( 2000 ) )
return;
}
else
{
mLastForcedStatusUpdate.restart();
}

const double distance = mDistanceCalculator.convertLengthMeasurement( mDistanceCalculator.measureLine( QVector< QgsPointXY >() << mLastCursorPosWgs84 << mLastGpsPosition ),
QgsProject::instance()->distanceUnits() );
const double bearing = 180 * mDistanceCalculator.bearing( mLastGpsPosition, mLastCursorPosWgs84 ) / M_PI;
const int distanceDecimalPlaces = QgsSettings().value( QStringLiteral( "qgis/measure/decimalplaces" ), "3" ).toInt();
const QString distanceString = QgsDistanceArea::formatDistance( distance, distanceDecimalPlaces, QgsProject::instance()->distanceUnits() );
const QString bearingString = mBearingNumericFormat->formatDouble( bearing, QgsNumericFormatContext() );

QgisApp::instance()->statusBarIface()->showMessage( tr( "%1 (%2) from GPS location" ).arg( distanceString, bearingString ), 2000 );
QgisApp::instance()->statusBarIface()->showMessage( tr( "%1 (%2) from GPS location" ).arg( distanceString, bearingString ), forceDisplay ? 2000 : 2000 - mLastForcedStatusUpdate.elapsed() );
}

void QgsGpsInformationWidget::updateTimestampDestinationFields( QgsMapLayer *mapLayer )
@@ -1686,7 +1699,7 @@ void QgsGpsInformationWidget::tapAndHold( const QgsPointXY &mapPoint, QTapAndHol
try
{
mLastCursorPosWgs84 = mCanvasToWgs84Transform.transform( mapPoint );
updateGpsDistanceStatusMessage();
updateGpsDistanceStatusMessage( true );
}
catch ( QgsCsException & )
{
@@ -136,7 +136,7 @@ class APP_EXPORT QgsGpsInformationWidget: public QgsPanelWidget, public QgsMapCa
#endif
void createRubberBand();

void updateGpsDistanceStatusMessage();
void updateGpsDistanceStatusMessage( bool forceDisplay );

QgsCoordinateReferenceSystem mWgs84CRS;
QgsCoordinateTransform mCanvasToWgs84Transform;
@@ -170,6 +170,7 @@ class APP_EXPORT QgsGpsInformationWidget: public QgsPanelWidget, public QgsMapCa
std::unique_ptr< QgsBearingNumericFormat > mBearingNumericFormat;

QElapsedTimer mLastRotateTimer;
QElapsedTimer mLastForcedStatusUpdate;

friend class TestQgsGpsInformationWidget;
};

0 comments on commit 429ffde

Please sign in to comment.
You can’t perform that action at this time.