Skip to content

Commit

Permalink
[Backport]: Avoid intersection for QgsMapToolAddPart. Fixes ticket #4624
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Feb 18, 2012
1 parent a9a9b93 commit a1ac714
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/app/qgsmaptooladdpart.cpp
Expand Up @@ -125,6 +125,22 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
{
//close polygon
closePolygon();
//avoid intersections
QgsGeometry* geom = QgsGeometry::fromPolygon( QgsPolygon() << points().toVector() );
if ( geom )
{
geom->avoidIntersections();
QgsPolygon poly = geom->asPolygon();
if ( poly.size() < 1 )
{
stopCapturing();
delete geom;
vlayer->destroyEditCommand();
return;
}
setPoints( geom->asPolygon()[0].toList() );
delete geom;
}
}

vlayer->beginEditCommand( tr( "Part added" ) );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsmaptoolcapture.h
Expand Up @@ -91,6 +91,7 @@ class QgsMapToolCapture : public QgsMapToolEdit
QList<QgsPoint>::iterator begin() { return mCaptureList.begin(); }
QList<QgsPoint>::iterator end() { return mCaptureList.end(); }
const QList<QgsPoint> &points() { return mCaptureList; }
void setPoints( const QList<QgsPoint>& pointList ) { mCaptureList = pointList; }
void closePolygon();

private:
Expand Down

0 comments on commit a1ac714

Please sign in to comment.