Skip to content
Permalink
Browse files

[api] Add a public method to clear the rubber band for the

QgsMapToolExtent

Otherwise plugins have no way to remove this from the canvas
  • Loading branch information
nyalldawson committed Mar 29, 2021
1 parent d68cd29 commit 34735aa9ef9fad310054eb024753a208a4dde37e
Showing with 20 additions and 4 deletions.
  1. +7 −0 python/gui/auto_generated/qgsmaptoolextent.sip.in
  2. +6 −4 src/gui/qgsmaptoolextent.cpp
  3. +7 −0 src/gui/qgsmaptoolextent.h
@@ -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:
@@ -34,8 +34,7 @@ void QgsMapToolExtent::activate()

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

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

@@ -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 )
@@ -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 );
@@ -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

0 comments on commit 34735aa

Please sign in to comment.