Skip to content

Commit

Permalink
correctly delete last digitized point, fixes #8462
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Aug 13, 2013
1 parent 441a46b commit db07f2f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/app/qgsmaptoolcapture.cpp
Expand Up @@ -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 )
{
Expand All @@ -234,14 +235,29 @@ void QgsMapToolCapture::undo()
if ( mRubberBand )
{
int rubberBandSize = mRubberBand->numberOfVertices();
int tempRubberBandSize = mTempRubberBand->numberOfVertices();
int captureListSize = mCaptureList.size();

if ( rubberBandSize < 1 || captureListSize < 1 )
{
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();
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsrubberband.cpp
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsrubberband.h
Expand Up @@ -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.
Expand Down

0 comments on commit db07f2f

Please sign in to comment.