From db07f2f90c4872a5e42bebf13d40f37bcde41922 Mon Sep 17 00:00:00 2001 From: Radim Blazek Date: Tue, 13 Aug 2013 11:52:09 +0200 Subject: [PATCH] correctly delete last digitized point, fixes #8462 --- src/app/qgsmaptoolcapture.cpp | 22 +++++++++++++++++++--- src/gui/qgsrubberband.cpp | 6 ++++++ src/gui/qgsrubberband.h | 7 +++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/app/qgsmaptoolcapture.cpp b/src/app/qgsmaptoolcapture.cpp index 4061ac2e68d2..5a8227fe4e9a 100644 --- a/src/app/qgsmaptoolcapture.cpp +++ b/src/app/qgsmaptoolcapture.cpp @@ -209,8 +209,9 @@ int QgsMapToolCapture::addVertex( const QPoint &p ) { mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line , true ); } - else{ - mTempRubberBand->reset(CapturePolygon ? true : false); + else + { + mTempRubberBand->reset( mCaptureMode == CapturePolygon ? true : false ); } if ( mCaptureMode == CaptureLine ) { @@ -234,6 +235,7 @@ void QgsMapToolCapture::undo() if ( mRubberBand ) { int rubberBandSize = mRubberBand->numberOfVertices(); + int tempRubberBandSize = mTempRubberBand->numberOfVertices(); int captureListSize = mCaptureList.size(); if ( rubberBandSize < 1 || captureListSize < 1 ) @@ -241,7 +243,21 @@ void QgsMapToolCapture::undo() return; } - mRubberBand->removePoint( -2 ); // remove the one before the last one + mRubberBand->removePoint( -1 ); + + if ( mRubberBand->numberOfVertices() > 0 ) + { + if ( mTempRubberBand->numberOfVertices() > 1 ) + { + const QgsPoint *point = mRubberBand->getPoint( 0, mRubberBand->numberOfVertices() - 1 ); + mTempRubberBand->movePoint( mTempRubberBand->numberOfVertices() - 2, *point ); + } + } + else + { + mTempRubberBand->reset( mCaptureMode == CapturePolygon ? true : false ); + } + mCaptureList.removeLast(); validateGeometry(); diff --git a/src/gui/qgsrubberband.cpp b/src/gui/qgsrubberband.cpp index 339e5e72d1ec..e74e06500dd4 100644 --- a/src/gui/qgsrubberband.cpp +++ b/src/gui/qgsrubberband.cpp @@ -536,6 +536,12 @@ int QgsRubberBand::size() const return mPoints.size(); } +int QgsRubberBand::partSize( int geometryIndex ) const +{ + if ( geometryIndex < 0 || geometryIndex >= mPoints.size() ) return 0; + return mPoints[geometryIndex].size(); +} + int QgsRubberBand::numberOfVertices() const { int count = 0; diff --git a/src/gui/qgsrubberband.h b/src/gui/qgsrubberband.h index 32ed4ef47f09..79a0f72c4c59 100644 --- a/src/gui/qgsrubberband.h +++ b/src/gui/qgsrubberband.h @@ -163,6 +163,13 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem */ void movePoint( int index, const QgsPoint& p, int geometryIndex = 0 ); + /** + * Returns number of vertices in feature part + * @param geometryIndex The index of the feature part (in case of multipart geometries) + * @return number of vertices + */ + int partSize( int geometryIndex ) const; + /** * Sets this rubber band to the geometry of an existing feature. * This is useful for feature highlighting.