[QGIS Commit] r12700 - in trunk/qgis: python/core src/app src/app/gps src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Jan 7 15:30:25 EST 2010


Author: jef
Date: 2010-01-07 15:30:25 -0500 (Thu, 07 Jan 2010)
New Revision: 12700

Modified:
   trunk/qgis/python/core/qgsgeometry.sip
   trunk/qgis/src/app/gps/qgsgpsinformationwidget.cpp
   trunk/qgis/src/app/qgsmaptooladdfeature.cpp
   trunk/qgis/src/app/qgsmaptooladdfeature.h
   trunk/qgis/src/core/qgsgeometry.cpp
   trunk/qgis/src/core/qgsgeometry.h
Log:
move QgsMapToolFeature::avoidIntersections to QgsGeometry

Modified: trunk/qgis/python/core/qgsgeometry.sip
===================================================================
--- trunk/qgis/python/core/qgsgeometry.sip	2010-01-07 20:24:06 UTC (rev 12699)
+++ trunk/qgis/python/core/qgsgeometry.sip	2010-01-07 20:30:25 UTC (rev 12700)
@@ -314,5 +314,14 @@
     @return true in case of success and false else*/
     bool convertToMultiType();
 
+    /** Modifies geometry to avoid intersections with the layers specified in project properties
+     *  @return 0 in case of success,
+     *          1 if geometry is not of polygon type,
+     *          2 if avoid intersection would change the geometry type,
+     *          3 other error during intersection removal
+     *  @note added in 1.5
+     */
+    int avoidIntersections();
+
 }; // class QgsGeometry
 

Modified: trunk/qgis/src/app/gps/qgsgpsinformationwidget.cpp
===================================================================
--- trunk/qgis/src/app/gps/qgsgpsinformationwidget.cpp	2010-01-07 20:24:06 UTC (rev 12699)
+++ trunk/qgis/src/app/gps/qgsgpsinformationwidget.cpp	2010-01-07 20:30:25 UTC (rev 12700)
@@ -30,6 +30,7 @@
 #include "qgsapplication.h"
 #include "qgslogger.h"
 #include "qgsattributedialog.h"
+#include "qgsgeometry.h"
 
 //for avoid intersections static method
 #include "qgsmaptooladdfeature.h"
@@ -449,9 +450,6 @@
   mGPSTextEdit->append( "hdop: " + QString::number( info.hdop ) );
   mGPSTextEdit->append( "vdop: " + QString::number( info.vdop ) );
 
-
-
-
   // Avoid refreshing / panning if we havent moved
   if ( mLastGpsPosition != myNewCenter )
   {
@@ -768,7 +766,7 @@
       memcpy( &wkb[position], &y, sizeof( double ) );
       f->setGeometryAndOwnership( &wkb[0], size );
 
-      int avoidIntersectionsReturn = QgsMapToolAddFeature::avoidIntersections( f->geometry() );
+      int avoidIntersectionsReturn = f->geometry()->avoidIntersections();
       if ( avoidIntersectionsReturn == 1 )
       {
         //not a polygon type. Impossible to get there

Modified: trunk/qgis/src/app/qgsmaptooladdfeature.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptooladdfeature.cpp	2010-01-07 20:24:06 UTC (rev 12699)
+++ trunk/qgis/src/app/qgsmaptooladdfeature.cpp	2010-01-07 20:30:25 UTC (rev 12700)
@@ -443,7 +443,7 @@
         }
         f->setGeometryAndOwnership( &wkb[0], size );
 
-        int avoidIntersectionsReturn = avoidIntersections( f->geometry() );
+        int avoidIntersectionsReturn = f->geometry()->avoidIntersections();
         if ( avoidIntersectionsReturn == 1 )
         {
           //not a polygon type. Impossible to get there
@@ -519,47 +519,3 @@
     }
   }
 }
-
-int QgsMapToolAddFeature::avoidIntersections( QgsGeometry* g )
-{
-  int returnValue = 0;
-
-  //check if g has polygon type
-  if ( !g || g->type() != QGis::Polygon )
-  {
-    return 1;
-  }
-
-  QGis::WkbType geomTypeBeforeModification = g->wkbType();
-
-  //read avoid intersections list from project properties
-  bool listReadOk;
-  QStringList avoidIntersectionsList = QgsProject::instance()->readListEntry( "Digitizing", "/AvoidIntersectionsList", &listReadOk );
-  if ( !listReadOk )
-  {
-    return true; //no intersections stored in project does not mean error
-  }
-
-  //go through list, convert each layer to vector layer and call QgsVectorLayer::removePolygonIntersections for each
-  QgsVectorLayer* currentLayer = 0;
-  QStringList::const_iterator aIt = avoidIntersectionsList.constBegin();
-  for ( ; aIt != avoidIntersectionsList.constEnd(); ++aIt )
-  {
-    currentLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( *aIt ) );
-    if ( currentLayer )
-    {
-      if ( currentLayer->removePolygonIntersections( g ) != 0 )
-      {
-        returnValue = 3;
-      }
-    }
-  }
-
-  //make sure the geometry still has the same type (e.g. no change from polygon to multipolygon)
-  if ( g->wkbType() != geomTypeBeforeModification )
-  {
-    return 2;
-  }
-
-  return returnValue;
-}

Modified: trunk/qgis/src/app/qgsmaptooladdfeature.h
===================================================================
--- trunk/qgis/src/app/qgsmaptooladdfeature.h	2010-01-07 20:24:06 UTC (rev 12699)
+++ trunk/qgis/src/app/qgsmaptooladdfeature.h	2010-01-07 20:30:25 UTC (rev 12700)
@@ -21,15 +21,7 @@
 {
     Q_OBJECT
   public:
-    QgsMapToolAddFeature( QgsMapCanvas* canvas, enum CaptureMode tool );
+    QgsMapToolAddFeature( QgsMapCanvas* canvas, CaptureMode mode );
     virtual ~QgsMapToolAddFeature();
     void canvasReleaseEvent( QMouseEvent * e );
-    
-    /**Modifies geometry to avoid intersections with the layers specified in project properties
-    @return 0 in case of success, 
-    @return 1 if geometry is not of polygon type, 
-    @return 2 if avoid intersection would change the geometry type, \
-    3 other error during intersection removal
-    @note Consider moving this into analysis lib since it is now used by QgsGpsInformation too. */
-    static int avoidIntersections( QgsGeometry* g );
 };

Modified: trunk/qgis/src/core/qgsgeometry.cpp
===================================================================
--- trunk/qgis/src/core/qgsgeometry.cpp	2010-01-07 20:24:06 UTC (rev 12699)
+++ trunk/qgis/src/core/qgsgeometry.cpp	2010-01-07 20:30:25 UTC (rev 12700)
@@ -27,6 +27,10 @@
 #include "qgsrectangle.h"
 #include "qgslogger.h"
 
+#include "qgsmaplayerregistry.h"
+#include "qgsvectorlayer.h"
+#include "qgsproject.h"
+
 #define DEFAULT_QUADRANT_SEGMENTS 8
 
 #define CATCH_GEOS(r) \
@@ -6210,3 +6214,47 @@
 
   return TRUE;
 }
+
+int QgsGeometry::avoidIntersections()
+{
+  int returnValue = 0;
+
+  //check if g has polygon type
+  if ( type() != QGis::Polygon )
+  {
+    return 1;
+  }
+
+  QGis::WkbType geomTypeBeforeModification = wkbType();
+
+  //read avoid intersections list from project properties
+  bool listReadOk;
+  QStringList avoidIntersectionsList = QgsProject::instance()->readListEntry( "Digitizing", "/AvoidIntersectionsList", &listReadOk );
+  if ( !listReadOk )
+  {
+    return true; //no intersections stored in project does not mean error
+  }
+
+  //go through list, convert each layer to vector layer and call QgsVectorLayer::removePolygonIntersections for each
+  QgsVectorLayer* currentLayer = 0;
+  QStringList::const_iterator aIt = avoidIntersectionsList.constBegin();
+  for ( ; aIt != avoidIntersectionsList.constEnd(); ++aIt )
+  {
+    currentLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( *aIt ) );
+    if ( currentLayer )
+    {
+      if ( currentLayer->removePolygonIntersections( this ) != 0 )
+      {
+        returnValue = 3;
+      }
+    }
+  }
+
+  //make sure the geometry still has the same type (e.g. no change from polygon to multipolygon)
+  if ( wkbType() != geomTypeBeforeModification )
+  {
+    return 2;
+  }
+
+  return returnValue;
+}

Modified: trunk/qgis/src/core/qgsgeometry.h
===================================================================
--- trunk/qgis/src/core/qgsgeometry.h	2010-01-07 20:24:06 UTC (rev 12699)
+++ trunk/qgis/src/core/qgsgeometry.h	2010-01-07 20:30:25 UTC (rev 12700)
@@ -353,6 +353,14 @@
     @return true in case of success and false else*/
     bool convertToMultiType();
 
+    /** Modifies geometry to avoid intersections with the layers specified in project properties
+     *  @return 0 in case of success,
+     *          1 if geometry is not of polygon type,
+     *          2 if avoid intersection would change the geometry type,
+     *          3 other error during intersection removal
+     *  @note added in 1.5
+     */
+    int avoidIntersections();
 
   private:
     // Private variables



More information about the QGIS-commit mailing list