Skip to content

Commit a1ac714

Browse files
committed
[Backport]: Avoid intersection for QgsMapToolAddPart. Fixes ticket #4624
1 parent a9a9b93 commit a1ac714

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/app/qgsmaptooladdpart.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
125125
{
126126
//close polygon
127127
closePolygon();
128+
//avoid intersections
129+
QgsGeometry* geom = QgsGeometry::fromPolygon( QgsPolygon() << points().toVector() );
130+
if ( geom )
131+
{
132+
geom->avoidIntersections();
133+
QgsPolygon poly = geom->asPolygon();
134+
if ( poly.size() < 1 )
135+
{
136+
stopCapturing();
137+
delete geom;
138+
vlayer->destroyEditCommand();
139+
return;
140+
}
141+
setPoints( geom->asPolygon()[0].toList() );
142+
delete geom;
143+
}
128144
}
129145

130146
vlayer->beginEditCommand( tr( "Part added" ) );

src/app/qgsmaptoolcapture.h

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class QgsMapToolCapture : public QgsMapToolEdit
9191
QList<QgsPoint>::iterator begin() { return mCaptureList.begin(); }
9292
QList<QgsPoint>::iterator end() { return mCaptureList.end(); }
9393
const QList<QgsPoint> &points() { return mCaptureList; }
94+
void setPoints( const QList<QgsPoint>& pointList ) { mCaptureList = pointList; }
9495
void closePolygon();
9596

9697
private:

0 commit comments

Comments
 (0)