[QGIS Commit] r8477 - in trunk/qgis: python/core src/app src/core src/gui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed May 21 01:59:05 EDT 2008


Author: mhugent
Date: 2008-05-21 01:59:04 -0400 (Wed, 21 May 2008)
New Revision: 8477

Modified:
   trunk/qgis/python/core/qgssnapper.sip
   trunk/qgis/src/app/qgsmaptoolmovevertex.cpp
   trunk/qgis/src/app/qgsmaptoolmovevertex.h
   trunk/qgis/src/core/qgssnapper.cpp
   trunk/qgis/src/core/qgssnapper.h
   trunk/qgis/src/gui/qgsmapcanvassnapper.cpp
   trunk/qgis/src/gui/qgsmapcanvassnapper.h
Log:
Fix for bug #1096 Snapping to currently moved vertex should be suppressed

Modified: trunk/qgis/python/core/qgssnapper.sip
===================================================================
--- trunk/qgis/python/core/qgssnapper.sip	2008-05-20 22:09:40 UTC (rev 8476)
+++ trunk/qgis/python/core/qgssnapper.sip	2008-05-21 05:59:04 UTC (rev 8477)
@@ -63,7 +63,7 @@
    @param startPoint the start point for snapping (in pixel coordinates)
   @param snappingResult the list where the results are inserted (everything in map coordinate system)
   @return 0 in case of success*/
-  int snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult);
+  int snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult, const QList<QgsPoint>& excludeList);
 
   //setters
   void setLayersToSnap(const QList<QgsVectorLayer*>& layerList);

Modified: trunk/qgis/src/app/qgsmaptoolmovevertex.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoolmovevertex.cpp	2008-05-20 22:09:40 UTC (rev 8476)
+++ trunk/qgis/src/app/qgsmaptoolmovevertex.cpp	2008-05-21 05:59:04 UTC (rev 8477)
@@ -34,6 +34,11 @@
 
 void QgsMapToolMoveVertex::canvasMoveEvent(QMouseEvent * e)
 {
+  if(mRecentSnappingResults.size() < 1)
+    {
+      return ; //snapping not necessary
+    }
+
   //list of rubber bands, snapping results and point index to move
   //must have equal size
   int rbSize = mRubberBands.size();
@@ -51,7 +56,8 @@
   QList<QgsRubberBand*>::iterator rb_it = mRubberBands.begin();
 
   QList<QgsSnappingResult> snapResults;
-  if(mSnapper.snapToBackgroundLayers(e->pos(), snapResults) != 0)
+  
+  if(mSnapper.snapToBackgroundLayers(e->pos(), snapResults, mExcludePoint) != 0)
   {
     return; //error, bail out
   }
@@ -119,7 +125,10 @@
       mRubberBands.push_back(rb);
     }
 
-  //create rubber band list for snapping results
+  if(mRecentSnappingResults.size() > 0)
+    {
+      mExcludePoint.push_back(mRecentSnappingResults.first().snappedVertex);
+    }
 }
 
 void QgsMapToolMoveVertex::canvasReleaseEvent(QMouseEvent * e)
@@ -138,7 +147,7 @@
       QgsPoint snappedPointLayerCoord;
       QList<QgsSnappingResult> snapResults;
 
-      if(mSnapper.snapToBackgroundLayers(e->pos(), snapResults) != 0)
+      if(mSnapper.snapToBackgroundLayers(e->pos(), snapResults, mExcludePoint) != 0)
       {
 	  //error
       }
@@ -171,6 +180,7 @@
 
   mRecentSnappingResults.clear();
   mRubberBandMovingPoints.clear();
+  mExcludePoint.clear();
 
   mCanvas->refresh();
 }

Modified: trunk/qgis/src/app/qgsmaptoolmovevertex.h
===================================================================
--- trunk/qgis/src/app/qgsmaptoolmovevertex.h	2008-05-20 22:09:40 UTC (rev 8476)
+++ trunk/qgis/src/app/qgsmaptoolmovevertex.h	2008-05-21 05:59:04 UTC (rev 8477)
@@ -46,6 +46,9 @@
   that no point should be moved*/
   QList<int> mRubberBandMovingPoints;
 
+  /**The position of the vertex to move (in map coordinates) to exclude later from snapping*/
+  QList<QgsPoint> mExcludePoint;
+
   /**Deletes the rubber band pointers
    and clears mRubberBands*/
   void removeRubberBands();

Modified: trunk/qgis/src/core/qgssnapper.cpp
===================================================================
--- trunk/qgis/src/core/qgssnapper.cpp	2008-05-20 22:09:40 UTC (rev 8476)
+++ trunk/qgis/src/core/qgssnapper.cpp	2008-05-21 05:59:04 UTC (rev 8477)
@@ -39,7 +39,7 @@
   
 }
 
-int QgsSnapper::snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult)
+int QgsSnapper::snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult, const QList<QgsPoint>& excludePoints)
 {
   snappingResult.clear();
 
@@ -84,6 +84,9 @@
 	  snappingResultList.insert(sqrt(newResult.snappedVertex.sqrDist(mapCoordPoint)), newResult);
 	}
     }
+
+  //excluded specific points from result
+  cleanResultList(snappingResultList, excludePoints);
   
   //evaluate results according to snap mode
   QMultiMap<double, QgsSnappingResult>::iterator evalIt =  snappingResultList.begin();
@@ -137,3 +140,30 @@
 {
   mSnapMode = snapMode;
 }
+
+void QgsSnapper::cleanResultList(QMultiMap<double, QgsSnappingResult>& list, const QList<QgsPoint>& excludeList) const
+{
+  QgsPoint currentResultPoint;
+  QgsSnappingResult currentSnappingResult;
+  QList<double> keysToRemove;
+
+  QMultiMap<double, QgsSnappingResult>::iterator result_it = list.begin();
+  for(; result_it != list.end(); ++result_it)
+    {
+      currentSnappingResult = result_it.value();
+      if(currentSnappingResult.snappedVertexNr != -1)
+	{
+	  currentResultPoint = currentSnappingResult.snappedVertex;
+	  if(excludeList.contains(currentResultPoint))
+	    {
+	      keysToRemove.push_back(result_it.key());
+	    }
+	}
+    }
+
+  QList<double>::const_iterator remove_it = keysToRemove.constBegin();
+  for(; remove_it != keysToRemove.constEnd(); ++remove_it)
+    {
+      list.remove(*remove_it);
+    }
+}

Modified: trunk/qgis/src/core/qgssnapper.h
===================================================================
--- trunk/qgis/src/core/qgssnapper.h	2008-05-20 22:09:40 UTC (rev 8476)
+++ trunk/qgis/src/core/qgssnapper.h	2008-05-21 05:59:04 UTC (rev 8477)
@@ -81,8 +81,9 @@
   /**Does the snapping operation
    @param startPoint the start point for snapping (in pixel coordinates)
   @param snappingResult the list where the results are inserted (everything in map coordinate system)
+  @param excludePoints a list with (map coordinate) points that should be excluded in the snapping result. Useful e.g. for vertex moves where a vertex should not be snapped to its original position
   @return 0 in case of success*/
-  int snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult);
+  int snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult, const QList<QgsPoint>& excludePoints = QList<QgsPoint>());
 
   //setters
   void setLayersToSnap(const QList<QgsVectorLayer*>& layerList);
@@ -93,6 +94,10 @@
  private:
   /**Don't use the default constructor*/
   QgsSnapper();
+  
+  /**Removes the snapping results that contains points in exclude list*/
+  void cleanResultList(QMultiMap<double, QgsSnappingResult>& list, const QList<QgsPoint>& excludeList) const;
+
   /**The maprender object contains information about the output coordinate system
    of the map and about the relationship between pixel space and map space*/
   QgsMapRender* mMapRender;

Modified: trunk/qgis/src/gui/qgsmapcanvassnapper.cpp
===================================================================
--- trunk/qgis/src/gui/qgsmapcanvassnapper.cpp	2008-05-20 22:09:40 UTC (rev 8476)
+++ trunk/qgis/src/gui/qgsmapcanvassnapper.cpp	2008-05-21 05:59:04 UTC (rev 8477)
@@ -58,7 +58,7 @@
     }
 }
 
-int QgsMapCanvasSnapper::snapToCurrentLayer(const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SNAP_TO snap_to, double snappingTol)
+int QgsMapCanvasSnapper::snapToCurrentLayer(const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SNAP_TO snap_to, double snappingTol, const QList<QgsPoint>& excludePoints)
 {
   results.clear();
   
@@ -112,7 +112,7 @@
       mSnapper->setTolerances(toleranceList);
       mSnapper->setSnapToList(snapToList);
 
-      if(mSnapper->snapPoint(p, results) != 0)
+      if(mSnapper->snapPoint(p, results, excludePoints) != 0)
 	{
 	  return 4;
 	}
@@ -125,7 +125,7 @@
     }
 }
 
-int QgsMapCanvasSnapper::snapToBackgroundLayers(const QPoint& p, QList<QgsSnappingResult>& results)
+int QgsMapCanvasSnapper::snapToBackgroundLayers(const QPoint& p, QList<QgsSnappingResult>& results, const QList<QgsPoint>& excludePoints)
 {
   results.clear();
 
@@ -252,7 +252,7 @@
       mSnapper->setTolerances(toleranceDoubleList);
       mSnapper->setSnapToList(snapTo);
 
-      if(mSnapper->snapPoint(p, results) != 0)
+      if(mSnapper->snapPoint(p, results, excludePoints) != 0)
 	{
 	  return 4;
 	}

Modified: trunk/qgis/src/gui/qgsmapcanvassnapper.h
===================================================================
--- trunk/qgis/src/gui/qgsmapcanvassnapper.h	2008-05-20 22:09:40 UTC (rev 8476)
+++ trunk/qgis/src/gui/qgsmapcanvassnapper.h	2008-05-21 05:59:04 UTC (rev 8477)
@@ -48,16 +48,18 @@
      @param p start point of the snap (in pixel coordinates)
      @param results list to which the results are appended
      @param snap_to snap to vertex or to segment
-     @param snappingTol snapping tolerance. -1 means that the search radius for vertex edits is taken*/
-  int snapToCurrentLayer(const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SNAP_TO snap_to, double snappingTol = -1);
+     @param snappingTol snapping tolerance. -1 means that the search radius for vertex edits is taken
+     @param excludePoints a list with (map coordinate) points that should be excluded in the snapping result. Useful e.g. for vertex moves where a vertex should not be snapped to its original position*/
+  int snapToCurrentLayer(const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SNAP_TO snap_to, double snappingTol = -1, const QList<QgsPoint>& excludePoints = QList<QgsPoint>());
   /**Snaps to the background layers. This method is usefull to align the features of the 
      edited layers to those of other layers (as described in the project properties). 
      Uses snap mode QgsSnapper::ONE_RESULT. Therefore, only the
      closest result is returned.
      @param p start point of the snap (in pixel coordinates)
      @param result snapped point
+     @param excludePoints a list with (map coordinate) points that should be excluded in the snapping result. Useful e.g. for vertex moves where a vertex should not be snapped to its original position
      @return 0 in case of success*/
-  int snapToBackgroundLayers(const QPoint& p, QList<QgsSnappingResult>& results);
+  int snapToBackgroundLayers(const QPoint& p, QList<QgsSnappingResult>& results, const QList<QgsPoint>& excludePoints = QList<QgsPoint>());
 
   void setMapCanvas(QgsMapCanvas* canvas);
 



More information about the QGIS-commit mailing list