Skip to content
Permalink
Browse files

Use snap indicator for measure angle tool

Fixes #14954
  • Loading branch information
nyalldawson committed Jan 19, 2018
1 parent 5d264d9 commit 5ee4b565fddb6942c26df01e209254cfff1a0a61
Showing with 11 additions and 11 deletions.
  1. +8 −9 src/app/qgsmaptoolmeasureangle.cpp
  2. +3 −2 src/app/qgsmaptoolmeasureangle.h
@@ -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" );

@@ -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 )
{
@@ -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 );
}
@@ -125,6 +128,8 @@ void QgsMapToolMeasureAngle::activate()

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

stopMeasuring();
QgsMapTool::deactivate();
}
@@ -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 )
@@ -23,6 +23,7 @@

class QgsDisplayAngle;
class QgsRubberBand;
class QgsSnapIndicator;

//! Map tool to measure angle between two segments
class APP_EXPORT QgsMapToolMeasureAngle: public QgsMapTool
@@ -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();

0 comments on commit 5ee4b56

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