Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Use snap indicator for measure angle tool
- Loading branch information
Showing
with
11 additions
and
11 deletions.
-
+8
−9
src/app/qgsmaptoolmeasureangle.cpp
-
+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(); |
|
|