Skip to content

Commit

Permalink
fix for #7628 undo does not work ok
Browse files Browse the repository at this point in the history
adding a removePoint method, which can also take a negative index to start
removing vertices from the end.
actual fix for #7628 was to not remove the last node, but the one before that.
  • Loading branch information
rduivenvoorde committed Apr 18, 2013
1 parent 3b88054 commit 7fff92a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
7 changes: 7 additions & 0 deletions python/gui/qgsrubberband.sip
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class QgsRubberBand: QgsMapCanvasItem
//! geometryIndex is the index of the feature part (in case of multipart geometries)
void addPoint( const QgsPoint & p, bool update = true, int geometryIndex = 0 );

/**Remove a vertex from the rubberband and (optionally) update canvas.
@param index The index of the vertex/point to remove, negative indexes start at end
@param doUpdate Should the map canvas be updated immediately?
@param geometryIndex The index of the feature part (in case of multipart geometries)
*/
void removePoint( int index = 0, bool doUpdate = true, int geometryIndex = 0 );

//!Removes the last point. Most useful in connection with undo operations
void removeLastPoint( int geometryIndex = 0 );

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void QgsMapToolCapture::undo()
return;
}

mRubberBand->removeLastPoint();
mRubberBand->removePoint(-2); // remove the one before the last one
mCaptureList.removeLast();

validateGeometry();
Expand Down
24 changes: 20 additions & 4 deletions src/gui/qgsrubberband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,36 @@ void QgsRubberBand::addPoint( const QgsPoint & p, bool doUpdate /* = true */, in
}
}

void QgsRubberBand::removeLastPoint( int geometryIndex )

void QgsRubberBand::removePoint( int index, bool doUpdate/* = true*/, int geometryIndex/* = 0*/ )
{

if ( mPoints.size() < geometryIndex + 1 )
{
return;
}


if ( mPoints[geometryIndex].size() > 0 )
{
mPoints[geometryIndex].pop_back();
// negative index removes from end, eg -1 removes last one
if ( index < 0 )
{
index = mPoints[geometryIndex].size() + index;
}
mPoints[geometryIndex].removeAt(index);
}

updateRect();
update();
if ( doUpdate )
{
updateRect();
update();
}
}

void QgsRubberBand::removeLastPoint( int geometryIndex )
{
removePoint(-1, true, geometryIndex);
}

/*!
Expand Down
8 changes: 8 additions & 0 deletions src/gui/qgsrubberband.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
*/
void addPoint( const QgsPoint & p, bool doUpdate = true, int geometryIndex = 0 );

/**
* Remove a vertex from the rubberband and (optionally) update canvas.
* @param index The index of the vertex/point to remove, negative indexes start at end
* @param doUpdate Should the map canvas be updated immediately?
* @param geometryIndex The index of the feature part (in case of multipart geometries)
*/
void removePoint( int index = 0, bool doUpdate = true, int geometryIndex = 0 );

/**
* Removes the last point. Most useful in connection with undo operations
*/
Expand Down

0 comments on commit 7fff92a

Please sign in to comment.