Skip to content

Commit

Permalink
Show a snap indicator for measure tool
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 20, 2018
1 parent 045a17f commit 5d264d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
18 changes: 8 additions & 10 deletions src/app/qgsmeasuretool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -98,6 +100,8 @@ void QgsMeasureTool::activate()

void QgsMeasureTool::deactivate()
{
mSnapIndicator->setMatch( QgsPointLocator::Match() );

mDialog->hide();
QgsMapTool::deactivate();
}
Expand Down Expand Up @@ -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 );
}
Expand All @@ -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
{
Expand Down Expand Up @@ -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 );
}
6 changes: 2 additions & 4 deletions src/app/qgsmeasuretool.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class QgsDistanceArea;
class QgsMapCanvas;
class QgsMeasureDialog;
class QgsRubberBand;

class QgsSnapIndicator;


class APP_EXPORT QgsMeasureTool : public QgsMapTool
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 5d264d9

Please sign in to comment.