20
20
#include " qgsmaprenderer.h"
21
21
#include " qgsmaptopixel.h"
22
22
#include " qgsrubberband.h"
23
+ #include " qgsvectorlayer.h"
24
+ #include " qgstolerance.h"
23
25
24
26
#include " qgsmeasuredialog.h"
25
27
#include " qgsmeasuretool.h"
@@ -133,12 +135,18 @@ void QgsMeasureTool::canvasPressEvent( QMouseEvent * e )
133
135
}
134
136
}
135
137
136
-
137
138
void QgsMeasureTool::canvasMoveEvent ( QMouseEvent * e )
138
139
{
139
140
if ( !mRightMouseClicked )
140
141
{
142
+ QgsVectorLayer *vl = dynamic_cast <QgsVectorLayer *>( mCanvas ->currentLayer () );
141
143
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
+
142
150
mRubberBand ->movePoint ( point );
143
151
mDialog ->mouseMove ( point );
144
152
}
@@ -147,7 +155,13 @@ void QgsMeasureTool::canvasMoveEvent( QMouseEvent * e )
147
155
148
156
void QgsMeasureTool::canvasReleaseEvent ( QMouseEvent * e )
149
157
{
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
+ }
151
165
152
166
if ( e->button () == Qt::RightButton && ( e->buttons () & Qt::LeftButton ) == 0 ) // restart
153
167
{
0 commit comments