Skip to content
Permalink
Browse files

Show a snap indicator for measure tool

  • Loading branch information
nyalldawson committed Jan 19, 2018
1 parent 045a17f commit 5d264d94c606bf3e3b09148b1e0b00175ad3268b
Showing with 10 additions and 14 deletions.
  1. +8 −10 src/app/qgsmeasuretool.cpp
  2. +2 −4 src/app/qgsmeasuretool.h
@@ -27,13 +27,15 @@
#include "qgsmessagelog.h"
#include "qgssettings.h"
#include "qgsproject.h"
#include "qgssnapindicator.h"

#include <QMessageBox>
#include <QMouseEvent>

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 );
}
@@ -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();

0 comments on commit 5d264d9

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