mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
Show a snap indicator for measure tool
This commit is contained in:
parent
045a17f798
commit
5d264d94c6
@ -27,6 +27,7 @@
|
||||
#include "qgsmessagelog.h"
|
||||
#include "qgssettings.h"
|
||||
#include "qgsproject.h"
|
||||
#include "qgssnapindicator.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QMouseEvent>
|
||||
@ -34,6 +35,7 @@
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user