Skip to content
Permalink
Browse files

[gps] If a GPS devices is connected and set to follow the GPS location,

block the single click navigation mode to avoid accidental map canvas
pans away from the GPS location.

(for now, we don't block click-and-drag pans, as they are less likely
to be accidentally triggered)
  • Loading branch information
nyalldawson committed May 21, 2020
1 parent 3ebd097 commit 0521c2ef164a93f58cdf50ef1b564f374371b588
Showing with 27 additions and 2 deletions.
  1. +22 −0 src/app/gps/qgsgpsinformationwidget.cpp
  2. +5 −2 src/app/gps/qgsgpsinformationwidget.h
@@ -427,6 +427,8 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsMapCanvas *mapCanvas, QWidg
this, &QgsGpsInformationWidget::cboAcquisitionIntervalEdited );
connect( mCboDistanceThreshold, qgis::overload< const QString & >::of( &QComboBox::currentTextChanged ),
this, &QgsGpsInformationWidget::cboDistanceThresholdEdited );

mMapCanvas->installInteractionBlocker( this );
}

QgsGpsInformationWidget::~QgsGpsInformationWidget()
@@ -502,6 +504,26 @@ QgsGpsInformationWidget::~QgsGpsInformationWidget()
QDomElement elem = QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "Symbol" ), mBearingLineStyleButton->symbol(), doc, QgsReadWriteContext() );
doc.appendChild( elem );
mySettings.setValue( QStringLiteral( "gps/bearingLineSymbol" ), doc.toString() );

if ( mMapCanvas )
mMapCanvas->removeInteractionBlocker( this );
}

bool QgsGpsInformationWidget::blockCanvasInteraction( QgsMapCanvasInteractionBlocker::Interaction interaction ) const
{
switch ( interaction )
{
case QgsMapCanvasInteractionBlocker::Interaction::MapPanOnSingleClick:
// if we're connected and set to follow the GPS location, block the single click navigation mode
// to avoid accidental map canvas pans away from the GPS location.
// (for now, we don't block click-and-drag pans, as they are less likely to be accidentally triggered)
if ( mNmea && ( radRecenterMap->isChecked() || radRecenterWhenNeeded->isChecked() ) )
return true;

break;
}

return false;
}

void QgsGpsInformationWidget::mSpinTrackWidth_valueChanged( int value )
@@ -25,6 +25,7 @@
#include "qgsgpsmarker.h"
#include "qgsmaptoolcapture.h"
#include "qgspanelwidget.h"
#include "qgsmapcanvasinteractionblocker.h"
#include <qwt_plot_curve.h>
#ifdef WITH_QWTPOLAR
#include <qwt_polar_plot.h>
@@ -48,13 +49,15 @@ class QColor;
* A dock widget that displays information from a GPS device and
* allows the user to capture features using gps readings to
* specify the geometry.*/
class APP_EXPORT QgsGpsInformationWidget: public QgsPanelWidget, private Ui::QgsGpsInformationWidgetBase
class APP_EXPORT QgsGpsInformationWidget: public QgsPanelWidget, public QgsMapCanvasInteractionBlocker, private Ui::QgsGpsInformationWidgetBase
{
Q_OBJECT
public:
QgsGpsInformationWidget( QgsMapCanvas *mapCanvas, QWidget *parent = nullptr );
~QgsGpsInformationWidget() override;

bool blockCanvasInteraction( Interaction interaction ) const override;

public slots:
void tapAndHold( const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture );

@@ -111,7 +114,7 @@ class APP_EXPORT QgsGpsInformationWidget: public QgsPanelWidget, private Ui::Qgs
void updateTimeZones();
QVariant timestamp( QgsVectorLayer *vlayer, int idx );
QgsGpsConnection *mNmea = nullptr;
QgsMapCanvas *mMapCanvas = nullptr;
QPointer< QgsMapCanvas > mMapCanvas;
QgsGpsMarker *mMapMarker = nullptr;
QgsGpsBearingItem *mMapBearingItem = nullptr;

0 comments on commit 0521c2e

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