Skip to content

Commit d25a9c4

Browse files
author
jef
committedJan 7, 2010
move QgsMapToolFeature::avoidIntersections to QgsGeometry
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12700 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5a1d9a9 commit d25a9c4

File tree

6 files changed

+69
-58
lines changed

6 files changed

+69
-58
lines changed
 

‎python/core/qgsgeometry.sip

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,5 +314,14 @@ not disjoint with existing polygons of the feature*/
314314
@return true in case of success and false else*/
315315
bool convertToMultiType();
316316

317+
/** Modifies geometry to avoid intersections with the layers specified in project properties
318+
* @return 0 in case of success,
319+
* 1 if geometry is not of polygon type,
320+
* 2 if avoid intersection would change the geometry type,
321+
* 3 other error during intersection removal
322+
* @note added in 1.5
323+
*/
324+
int avoidIntersections();
325+
317326
}; // class QgsGeometry
318327

‎src/app/gps/qgsgpsinformationwidget.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "qgsapplication.h"
3131
#include "qgslogger.h"
3232
#include "qgsattributedialog.h"
33+
#include "qgsgeometry.h"
3334

3435
//for avoid intersections static method
3536
#include "qgsmaptooladdfeature.h"
@@ -449,9 +450,6 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
449450
mGPSTextEdit->append( "hdop: " + QString::number( info.hdop ) );
450451
mGPSTextEdit->append( "vdop: " + QString::number( info.vdop ) );
451452

452-
453-
454-
455453
// Avoid refreshing / panning if we havent moved
456454
if ( mLastGpsPosition != myNewCenter )
457455
{
@@ -768,7 +766,7 @@ void QgsGPSInformationWidget::on_mBtnCloseFeature_clicked( )
768766
memcpy( &wkb[position], &y, sizeof( double ) );
769767
f->setGeometryAndOwnership( &wkb[0], size );
770768

771-
int avoidIntersectionsReturn = QgsMapToolAddFeature::avoidIntersections( f->geometry() );
769+
int avoidIntersectionsReturn = f->geometry()->avoidIntersections();
772770
if ( avoidIntersectionsReturn == 1 )
773771
{
774772
//not a polygon type. Impossible to get there

‎src/app/qgsmaptooladdfeature.cpp

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
443443
}
444444
f->setGeometryAndOwnership( &wkb[0], size );
445445

446-
int avoidIntersectionsReturn = avoidIntersections( f->geometry() );
446+
int avoidIntersectionsReturn = f->geometry()->avoidIntersections();
447447
if ( avoidIntersectionsReturn == 1 )
448448
{
449449
//not a polygon type. Impossible to get there
@@ -519,47 +519,3 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
519519
}
520520
}
521521
}
522-
523-
int QgsMapToolAddFeature::avoidIntersections( QgsGeometry* g )
524-
{
525-
int returnValue = 0;
526-
527-
//check if g has polygon type
528-
if ( !g || g->type() != QGis::Polygon )
529-
{
530-
return 1;
531-
}
532-
533-
QGis::WkbType geomTypeBeforeModification = g->wkbType();
534-
535-
//read avoid intersections list from project properties
536-
bool listReadOk;
537-
QStringList avoidIntersectionsList = QgsProject::instance()->readListEntry( "Digitizing", "/AvoidIntersectionsList", &listReadOk );
538-
if ( !listReadOk )
539-
{
540-
return true; //no intersections stored in project does not mean error
541-
}
542-
543-
//go through list, convert each layer to vector layer and call QgsVectorLayer::removePolygonIntersections for each
544-
QgsVectorLayer* currentLayer = 0;
545-
QStringList::const_iterator aIt = avoidIntersectionsList.constBegin();
546-
for ( ; aIt != avoidIntersectionsList.constEnd(); ++aIt )
547-
{
548-
currentLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( *aIt ) );
549-
if ( currentLayer )
550-
{
551-
if ( currentLayer->removePolygonIntersections( g ) != 0 )
552-
{
553-
returnValue = 3;
554-
}
555-
}
556-
}
557-
558-
//make sure the geometry still has the same type (e.g. no change from polygon to multipolygon)
559-
if ( g->wkbType() != geomTypeBeforeModification )
560-
{
561-
return 2;
562-
}
563-
564-
return returnValue;
565-
}

‎src/app/qgsmaptooladdfeature.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@ class QgsMapToolAddFeature: public QgsMapToolCapture
2121
{
2222
Q_OBJECT
2323
public:
24-
QgsMapToolAddFeature( QgsMapCanvas* canvas, enum CaptureMode tool );
24+
QgsMapToolAddFeature( QgsMapCanvas* canvas, CaptureMode mode );
2525
virtual ~QgsMapToolAddFeature();
2626
void canvasReleaseEvent( QMouseEvent * e );
27-
28-
/**Modifies geometry to avoid intersections with the layers specified in project properties
29-
@return 0 in case of success,
30-
@return 1 if geometry is not of polygon type,
31-
@return 2 if avoid intersection would change the geometry type, \
32-
3 other error during intersection removal
33-
@note Consider moving this into analysis lib since it is now used by QgsGpsInformation too. */
34-
static int avoidIntersections( QgsGeometry* g );
3527
};

‎src/core/qgsgeometry.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ email : morb at ozemail dot com dot au
2727
#include "qgsrectangle.h"
2828
#include "qgslogger.h"
2929

30+
#include "qgsmaplayerregistry.h"
31+
#include "qgsvectorlayer.h"
32+
#include "qgsproject.h"
33+
3034
#define DEFAULT_QUADRANT_SEGMENTS 8
3135

3236
#define CATCH_GEOS(r) \
@@ -6210,3 +6214,47 @@ bool QgsGeometry::deletePart( int partNum )
62106214

62116215
return TRUE;
62126216
}
6217+
6218+
int QgsGeometry::avoidIntersections()
6219+
{
6220+
int returnValue = 0;
6221+
6222+
//check if g has polygon type
6223+
if ( type() != QGis::Polygon )
6224+
{
6225+
return 1;
6226+
}
6227+
6228+
QGis::WkbType geomTypeBeforeModification = wkbType();
6229+
6230+
//read avoid intersections list from project properties
6231+
bool listReadOk;
6232+
QStringList avoidIntersectionsList = QgsProject::instance()->readListEntry( "Digitizing", "/AvoidIntersectionsList", &listReadOk );
6233+
if ( !listReadOk )
6234+
{
6235+
return true; //no intersections stored in project does not mean error
6236+
}
6237+
6238+
//go through list, convert each layer to vector layer and call QgsVectorLayer::removePolygonIntersections for each
6239+
QgsVectorLayer* currentLayer = 0;
6240+
QStringList::const_iterator aIt = avoidIntersectionsList.constBegin();
6241+
for ( ; aIt != avoidIntersectionsList.constEnd(); ++aIt )
6242+
{
6243+
currentLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( *aIt ) );
6244+
if ( currentLayer )
6245+
{
6246+
if ( currentLayer->removePolygonIntersections( this ) != 0 )
6247+
{
6248+
returnValue = 3;
6249+
}
6250+
}
6251+
}
6252+
6253+
//make sure the geometry still has the same type (e.g. no change from polygon to multipolygon)
6254+
if ( wkbType() != geomTypeBeforeModification )
6255+
{
6256+
return 2;
6257+
}
6258+
6259+
return returnValue;
6260+
}

‎src/core/qgsgeometry.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,14 @@ class CORE_EXPORT QgsGeometry
353353
@return true in case of success and false else*/
354354
bool convertToMultiType();
355355

356+
/** Modifies geometry to avoid intersections with the layers specified in project properties
357+
* @return 0 in case of success,
358+
* 1 if geometry is not of polygon type,
359+
* 2 if avoid intersection would change the geometry type,
360+
* 3 other error during intersection removal
361+
* @note added in 1.5
362+
*/
363+
int avoidIntersections();
356364

357365
private:
358366
// Private variables

0 commit comments

Comments
 (0)