Skip to content

Commit db07f2f

Browse files
committedAug 13, 2013
correctly delete last digitized point, fixes #8462
1 parent 441a46b commit db07f2f

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed
 

‎src/app/qgsmaptoolcapture.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ int QgsMapToolCapture::addVertex( const QPoint &p )
209209
{
210210
mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line , true );
211211
}
212-
else{
213-
mTempRubberBand->reset(CapturePolygon ? true : false);
212+
else
213+
{
214+
mTempRubberBand->reset( mCaptureMode == CapturePolygon ? true : false );
214215
}
215216
if ( mCaptureMode == CaptureLine )
216217
{
@@ -234,14 +235,29 @@ void QgsMapToolCapture::undo()
234235
if ( mRubberBand )
235236
{
236237
int rubberBandSize = mRubberBand->numberOfVertices();
238+
int tempRubberBandSize = mTempRubberBand->numberOfVertices();
237239
int captureListSize = mCaptureList.size();
238240

239241
if ( rubberBandSize < 1 || captureListSize < 1 )
240242
{
241243
return;
242244
}
243245

244-
mRubberBand->removePoint( -2 ); // remove the one before the last one
246+
mRubberBand->removePoint( -1 );
247+
248+
if ( mRubberBand->numberOfVertices() > 0 )
249+
{
250+
if ( mTempRubberBand->numberOfVertices() > 1 )
251+
{
252+
const QgsPoint *point = mRubberBand->getPoint( 0, mRubberBand->numberOfVertices() - 1 );
253+
mTempRubberBand->movePoint( mTempRubberBand->numberOfVertices() - 2, *point );
254+
}
255+
}
256+
else
257+
{
258+
mTempRubberBand->reset( mCaptureMode == CapturePolygon ? true : false );
259+
}
260+
245261
mCaptureList.removeLast();
246262

247263
validateGeometry();

‎src/gui/qgsrubberband.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,12 @@ int QgsRubberBand::size() const
536536
return mPoints.size();
537537
}
538538

539+
int QgsRubberBand::partSize( int geometryIndex ) const
540+
{
541+
if ( geometryIndex < 0 || geometryIndex >= mPoints.size() ) return 0;
542+
return mPoints[geometryIndex].size();
543+
}
544+
539545
int QgsRubberBand::numberOfVertices() const
540546
{
541547
int count = 0;

‎src/gui/qgsrubberband.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
163163
*/
164164
void movePoint( int index, const QgsPoint& p, int geometryIndex = 0 );
165165

166+
/**
167+
* Returns number of vertices in feature part
168+
* @param geometryIndex The index of the feature part (in case of multipart geometries)
169+
* @return number of vertices
170+
*/
171+
int partSize( int geometryIndex ) const;
172+
166173
/**
167174
* Sets this rubber band to the geometry of an existing feature.
168175
* This is useful for feature highlighting.

0 commit comments

Comments
 (0)
Please sign in to comment.