Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #544 from rduivenvoorde/rubberband#7628
fix #7628
  • Loading branch information
m-kuhn committed Apr 19, 2013
2 parents 31cecdb + 7fff92a commit bfef00a
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
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
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
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
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 bfef00a

Please sign in to comment.