Skip to content

Commit

Permalink
[gps] If a GPS devices is connected and set to follow the GPS location,
Browse files Browse the repository at this point in the history
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 0521c2e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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 )
Expand Down
7 changes: 5 additions & 2 deletions src/app/gps/qgsgpsinformationwidget.h
Expand Up @@ -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>
Expand All @@ -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 );

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 0521c2e

Please sign in to comment.