Skip to content
Permalink
Browse files
Use snapping settings of digitizing module also for measuring
git-svn-id: http://svn.osgeo.org/qgis/trunk@11734 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Sep 29, 2009
1 parent bc05a2c commit aa3442ef0e65378e7ffe6f05fdbfbf526e030db8
Showing with 24 additions and 13 deletions.
  1. +17 −13 src/app/qgsmeasuretool.cpp
  2. +7 −0 src/app/qgsmeasuretool.h
@@ -44,6 +44,7 @@ QgsMeasureTool::QgsMeasureTool( QgsMapCanvas* canvas, bool measureArea )
mRightMouseClicked = false;

mDialog = new QgsMeasureDialog( this );
mSnapper.setMapCanvas( canvas );
}

QgsMeasureTool::~QgsMeasureTool()
@@ -130,7 +131,7 @@ void QgsMeasureTool::canvasPressEvent( QMouseEvent * e )
if ( mRightMouseClicked )
mDialog->restart();

QgsPoint idPoint = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
QgsPoint idPoint = snapPoint( e->pos() );
mDialog->mousePress( idPoint );
}
}
@@ -140,12 +141,7 @@ void QgsMeasureTool::canvasMoveEvent( QMouseEvent * e )
if ( !mRightMouseClicked )
{
QgsVectorLayer *vl = dynamic_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( e->pos().x(), e->pos().y() );

if ( vl )
{
vl->snapPoint( point, QgsTolerance::defaultTolerance( vl, mCanvas->mapRenderer() ) );
}
QgsPoint point = snapPoint( e->pos() );

mRubberBand->movePoint( point );
mDialog->mouseMove( point );
@@ -156,12 +152,7 @@ void QgsMeasureTool::canvasMoveEvent( QMouseEvent * e )
void QgsMeasureTool::canvasReleaseEvent( QMouseEvent * e )
{
QgsVectorLayer *vl = dynamic_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( e->pos().x(), e->pos().y() );

if ( vl )
{
vl->snapPoint( point, QgsTolerance::defaultTolerance( vl, mCanvas->mapRenderer() ) );
}
QgsPoint point = snapPoint( e->pos() );

if ( e->button() == Qt::RightButton && ( e->buttons() & Qt::LeftButton ) == 0 ) // restart
{
@@ -194,3 +185,16 @@ void QgsMeasureTool::addPoint( QgsPoint &point )
mRubberBand->addPoint( point );
mDialog->addPoint( point );
}

QgsPoint QgsMeasureTool::snapPoint( const QPoint& p )
{
QList<QgsSnappingResult> snappingResults;
if ( mSnapper.snapToBackgroundLayers( p, snappingResults ) != 0 || snappingResults.size() < 1 )
{
return mCanvas->getCoordinateTransform()->toMapCoordinates( p );
}
else
{
return snappingResults.constBegin()->snappedVertex;
}
}
@@ -19,6 +19,7 @@
#define QGSMEASURETOOL_H

#include "qgsmaptool.h"
#include "qgsmapcanvassnapper.h"

class QgsDistanceArea;
class QgsMapCanvas;
@@ -89,6 +90,12 @@ class QgsMeasureTool : public QgsMapTool
// project projection
bool mWrongProjectProjection;

QgsMapCanvasSnapper mSnapper;

//! Returns the snapped (map) coordinate
//@param p (pixel) coordinate
QgsPoint snapPoint( const QPoint& p );

};

#endif

0 comments on commit aa3442e

Please sign in to comment.