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-
137138void 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
148156void 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