Show a snap indicator for measure tool

This commit is contained in:
Nyall Dawson 2018-01-19 11:33:06 +10:00
parent 045a17f798
commit 5d264d94c6
2 changed files with 10 additions and 14 deletions

View File

@ -27,6 +27,7 @@
#include "qgsmessagelog.h"
#include "qgssettings.h"
#include "qgsproject.h"
#include "qgssnapindicator.h"
#include <QMessageBox>
#include <QMouseEvent>
@ -34,6 +35,7 @@
QgsMeasureTool::QgsMeasureTool( QgsMapCanvas *canvas, bool measureArea )
: QgsMapTool( canvas )
, mWrongProjectProjection( false )
, mSnapIndicator( new QgsSnapIndicator( canvas ) )
{
mMeasureArea = measureArea;
@ -98,6 +100,8 @@ void QgsMeasureTool::activate()
void QgsMeasureTool::deactivate()
{
mSnapIndicator->setMatch( QgsPointLocator::Match() );
mDialog->hide();
QgsMapTool::deactivate();
}
@ -182,10 +186,11 @@ void QgsMeasureTool::canvasPressEvent( QgsMapMouseEvent *e )
void QgsMeasureTool::canvasMoveEvent( QgsMapMouseEvent *e )
{
QgsPointXY point = e->snapPoint();
mSnapIndicator->setMatch( e->mapPointMatch() );
if ( ! mDone )
{
QgsPointXY point = snapPoint( e->pos() );
mRubberBand->movePoint( point );
mDialog->mouseMove( point );
}
@ -194,7 +199,7 @@ void QgsMeasureTool::canvasMoveEvent( QgsMapMouseEvent *e )
void QgsMeasureTool::canvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsPointXY point = snapPoint( e->pos() );
QgsPointXY point = e->snapPoint();
if ( mDone ) // if we have stopped measuring any mouse click restart measuring
{
@ -281,10 +286,3 @@ void QgsMeasureTool::addPoint( const QgsPointXY &point )
mDialog->addPoint();
}
}
QgsPointXY QgsMeasureTool::snapPoint( QPoint p )
{
QgsPointLocator::Match m = mCanvas->snappingUtils()->snapToMap( p );
return m.isValid() ? m.point() : mCanvas->getCoordinateTransform()->toMapCoordinates( p );
}

View File

@ -24,7 +24,7 @@ class QgsDistanceArea;
class QgsMapCanvas;
class QgsMeasureDialog;
class QgsRubberBand;
class QgsSnapIndicator;
class APP_EXPORT QgsMeasureTool : public QgsMapTool
@ -102,9 +102,7 @@ class APP_EXPORT QgsMeasureTool : public QgsMapTool
//! Destination CoordinateReferenceSystem used by the MapCanvas
QgsCoordinateReferenceSystem mDestinationCrs;
//! Returns the snapped (map) coordinate
//\param p (pixel) coordinate
QgsPointXY snapPoint( QPoint p );
std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
//! Removes the last vertex from mRubberBand
void undo();