Skip to content

Commit

Permalink
[api] Add a public method to clear the rubber band for the
Browse files Browse the repository at this point in the history
QgsMapToolExtent

Otherwise plugins have no way to remove this from the canvas
  • Loading branch information
nyalldawson committed Mar 29, 2021
1 parent d68cd29 commit 34735aa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgsmaptoolextent.sip.in
Expand Up @@ -57,6 +57,13 @@ If the aspect ratio isn't fixed, the width and height will be set to zero.
QgsRectangle extent() const;
%Docstring
Returns the current extent drawn onto the canvas.
%End

void clearRubberBand();
%Docstring
Removes the tool's rubber band from the canvas.

.. versionadded:: 3.20
%End

signals:
Expand Down
10 changes: 6 additions & 4 deletions src/gui/qgsmaptoolextent.cpp
Expand Up @@ -34,8 +34,7 @@ void QgsMapToolExtent::activate()

void QgsMapToolExtent::deactivate()
{
mRubberBand->reset( QgsWkbTypes::PolygonGeometry );

clearRubberBand();
QgsMapTool::deactivate();
}

Expand Down Expand Up @@ -95,6 +94,11 @@ QgsRectangle QgsMapToolExtent::extent() const
}
}

void QgsMapToolExtent::clearRubberBand()
{
mRubberBand->reset( QgsWkbTypes::PolygonGeometry );
}

void QgsMapToolExtent::calculateEndPoint( QgsPointXY &point )
{
if ( mRatio.width() > 0 && mRatio.height() > 0 )
Expand All @@ -112,8 +116,6 @@ void QgsMapToolExtent::drawExtent()
if ( qgsDoubleNear( mStartPoint.x(), mEndPoint.x() ) && qgsDoubleNear( mStartPoint.y(), mEndPoint.y() ) )
return;

mRubberBand->reset( QgsWkbTypes::PolygonGeometry );

QgsRectangle rect( mStartPoint, mEndPoint );

mRubberBand->reset( QgsWkbTypes::PolygonGeometry );
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsmaptoolextent.h
Expand Up @@ -64,6 +64,13 @@ class GUI_EXPORT QgsMapToolExtent : public QgsMapTool
*/
QgsRectangle extent() const;

/**
* Removes the tool's rubber band from the canvas.
*
* \since QGIS 3.20
*/
void clearRubberBand();

signals:

//! signal emitted on extent change
Expand Down

0 comments on commit 34735aa

Please sign in to comment.