Skip to content

Commit

Permalink
Use snap indicator for measure angle tool
Browse files Browse the repository at this point in the history
Fixes #14954
  • Loading branch information
nyalldawson committed Jan 20, 2018
1 parent 5d264d9 commit 5ee4b56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
17 changes: 8 additions & 9 deletions src/app/qgsmaptoolmeasureangle.cpp
Expand Up @@ -23,13 +23,14 @@
#include "qgsrubberband.h"
#include "qgssnappingutils.h"
#include "qgssettings.h"
#include "qgssnapindicator.h"

#include <QMouseEvent>
#include <cmath>

QgsMapToolMeasureAngle::QgsMapToolMeasureAngle( QgsMapCanvas *canvas )
: QgsMapTool( canvas )

, mSnapIndicator( new QgsSnapIndicator( canvas ) )
{
mToolName = tr( "Measure angle" );

Expand All @@ -44,12 +45,14 @@ QgsMapToolMeasureAngle::~QgsMapToolMeasureAngle()

void QgsMapToolMeasureAngle::canvasMoveEvent( QgsMapMouseEvent *e )
{
QgsPointXY point = e->snapPoint();
mSnapIndicator->setMatch( e->mapPointMatch() );

if ( !mRubberBand || mAnglePoints.empty() || mAnglePoints.size() > 2 )
{
return;
}

QgsPointXY point = snapPoint( e->pos() );
mRubberBand->movePoint( point );
if ( mAnglePoints.size() == 2 )
{
Expand Down Expand Up @@ -103,7 +106,7 @@ void QgsMapToolMeasureAngle::canvasReleaseEvent( QgsMapMouseEvent *e )

if ( mAnglePoints.size() < 3 )
{
QgsPointXY newPoint = snapPoint( e->pos() );
QgsPointXY newPoint = e->snapPoint();
mAnglePoints.push_back( newPoint );
mRubberBand->addPoint( newPoint );
}
Expand All @@ -125,6 +128,8 @@ void QgsMapToolMeasureAngle::activate()

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

stopMeasuring();
QgsMapTool::deactivate();
}
Expand All @@ -142,12 +147,6 @@ void QgsMapToolMeasureAngle::createRubberBand()
mRubberBand->setWidth( 3 );
}

QgsPointXY QgsMapToolMeasureAngle::snapPoint( QPoint p )
{
QgsPointLocator::Match m = mCanvas->snappingUtils()->snapToMap( p );
return m.isValid() ? m.point() : mCanvas->getCoordinateTransform()->toMapCoordinates( p );
}

void QgsMapToolMeasureAngle::updateSettings()
{
if ( mAnglePoints.size() != 3 )
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgsmaptoolmeasureangle.h
Expand Up @@ -23,6 +23,7 @@

class QgsDisplayAngle;
class QgsRubberBand;
class QgsSnapIndicator;

//! Map tool to measure angle between two segments
class APP_EXPORT QgsMapToolMeasureAngle: public QgsMapTool
Expand Down Expand Up @@ -54,12 +55,12 @@ class APP_EXPORT QgsMapToolMeasureAngle: public QgsMapTool

//! Creates a new rubber band and deletes the old one
void createRubberBand();
//! Snaps point to background layers
QgsPointXY snapPoint( QPoint p );

//! Tool for measuring
QgsDistanceArea mDa;

std::unique_ptr<QgsSnapIndicator> mSnapIndicator;

public slots:
//! Recalculate angle if projection state changed
void updateSettings();
Expand Down

0 comments on commit 5ee4b56

Please sign in to comment.