Skip to content

Commit 3f6c58c

Browse files
author
jef
committedAug 22, 2009
[FEATURE] add snapping to current layer in measure dialog (apply #1863)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11480 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed
 

‎src/app/qgsmeasuretool.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "qgsmaprenderer.h"
2121
#include "qgsmaptopixel.h"
2222
#include "qgsrubberband.h"
23+
#include "qgsvectorlayer.h"
24+
#include "qgstolerance.h"
2325

2426
#include "qgsmeasuredialog.h"
2527
#include "qgsmeasuretool.h"
@@ -133,12 +135,18 @@ void QgsMeasureTool::canvasPressEvent( QMouseEvent * e )
133135
}
134136
}
135137

136-
137138
void QgsMeasureTool::canvasMoveEvent( QMouseEvent * e )
138139
{
139140
if ( !mRightMouseClicked )
140141
{
142+
QgsVectorLayer *vl = dynamic_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
141143
QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( e->pos().x(), e->pos().y() );
144+
145+
if ( vl )
146+
{
147+
vl->snapPoint( point, QgsTolerance::defaultTolerance( vl, mCanvas->mapRenderer() ) );
148+
}
149+
142150
mRubberBand->movePoint( point );
143151
mDialog->mouseMove( point );
144152
}
@@ -147,7 +155,13 @@ void QgsMeasureTool::canvasMoveEvent( QMouseEvent * e )
147155

148156
void QgsMeasureTool::canvasReleaseEvent( QMouseEvent * e )
149157
{
150-
QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
158+
QgsVectorLayer *vl = dynamic_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
159+
QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( e->pos().x(), e->pos().y() );
160+
161+
if ( vl )
162+
{
163+
vl->snapPoint( point, QgsTolerance::defaultTolerance( vl, mCanvas->mapRenderer() ) );
164+
}
151165

152166
if ( e->button() == Qt::RightButton && ( e->buttons() & Qt::LeftButton ) == 0 ) // restart
153167
{

0 commit comments

Comments
 (0)
Please sign in to comment.