From fee6a6afb6077fde166253232d478ecef7c0d8b0 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sun, 22 Oct 2023 10:38:18 +0700 Subject: [PATCH] Use a better logic when building a rubber band model from a polygon geometry --- src/core/rubberbandmodel.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/rubberbandmodel.cpp b/src/core/rubberbandmodel.cpp index 450e2f6f21..69306df2a6 100644 --- a/src/core/rubberbandmodel.cpp +++ b/src/core/rubberbandmodel.cpp @@ -333,17 +333,21 @@ void RubberbandModel::setDataFromGeometry( QgsGeometry geometry, const QgsCoordi while ( abstractGeom->nextVertex( vertexId, pt ) ) { if ( vertexId.part > 1 || vertexId.ring > 0 ) + { break; + } - // skip first vertex on polygon, as it's duplicate of the last one - if ( geometry.type() == Qgis::GeometryType::Polygon && vertexId.vertex == 0 ) + // skip last vertex on polygon, as it's duplicate of the last one + if ( geometry.type() == Qgis::GeometryType::Polygon && vertexId.vertex == abstractGeom->vertexCount() ) + { continue; + } mPointList << pt; } // insert the last point twice so the resutling rubberband's current coordinate property being modified (by e.g. // the GNSS position) will not replace the last vertex from the passed geometry - mPointList << pt; + mPointList << mPointList.last(); mCurrentCoordinateIndex = mPointList.size() - 1;