[QGIS Commit] r11480 - trunk/qgis/src/app

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Aug 22 06:20:31 EDT 2009


Author: jef
Date: 2009-08-22 06:20:31 -0400 (Sat, 22 Aug 2009)
New Revision: 11480

Modified:
   trunk/qgis/src/app/qgsmeasuretool.cpp
Log:
[FEATURE] add snapping to current layer in measure dialog (apply #1863)

Modified: trunk/qgis/src/app/qgsmeasuretool.cpp
===================================================================
--- trunk/qgis/src/app/qgsmeasuretool.cpp	2009-08-22 10:20:18 UTC (rev 11479)
+++ trunk/qgis/src/app/qgsmeasuretool.cpp	2009-08-22 10:20:31 UTC (rev 11480)
@@ -20,6 +20,8 @@
 #include "qgsmaprenderer.h"
 #include "qgsmaptopixel.h"
 #include "qgsrubberband.h"
+#include "qgsvectorlayer.h"
+#include "qgstolerance.h"
 
 #include "qgsmeasuredialog.h"
 #include "qgsmeasuretool.h"
@@ -133,12 +135,18 @@
   }
 }
 
-
 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() ) );
+    }
+
     mRubberBand->movePoint( point );
     mDialog->mouseMove( point );
   }
@@ -147,8 +155,14 @@
 
 void QgsMeasureTool::canvasReleaseEvent( QMouseEvent * e )
 {
-  QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
+  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() ) );
+  }
+
   if ( e->button() == Qt::RightButton && ( e->buttons() & Qt::LeftButton ) == 0 ) // restart
   {
     if ( mRightMouseClicked )



More information about the QGIS-commit mailing list