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

QgsMapToolExtent

Otherwise plugins have no way to remove this from the canvas
This commit is contained in:
Nyall Dawson 2021-03-29 10:38:41 +10:00
parent d68cd295db
commit 34735aa9ef
3 changed files with 20 additions and 4 deletions

View File

@ -57,6 +57,13 @@ If the aspect ratio isn't fixed, the width and height will be set to zero.
QgsRectangle extent() const; QgsRectangle extent() const;
%Docstring %Docstring
Returns the current extent drawn onto the canvas. 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 %End
signals: signals:

View File

@ -34,8 +34,7 @@ void QgsMapToolExtent::activate()
void QgsMapToolExtent::deactivate() void QgsMapToolExtent::deactivate()
{ {
mRubberBand->reset( QgsWkbTypes::PolygonGeometry ); clearRubberBand();
QgsMapTool::deactivate(); QgsMapTool::deactivate();
} }
@ -95,6 +94,11 @@ QgsRectangle QgsMapToolExtent::extent() const
} }
} }
void QgsMapToolExtent::clearRubberBand()
{
mRubberBand->reset( QgsWkbTypes::PolygonGeometry );
}
void QgsMapToolExtent::calculateEndPoint( QgsPointXY &point ) void QgsMapToolExtent::calculateEndPoint( QgsPointXY &point )
{ {
if ( mRatio.width() > 0 && mRatio.height() > 0 ) 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() ) ) if ( qgsDoubleNear( mStartPoint.x(), mEndPoint.x() ) && qgsDoubleNear( mStartPoint.y(), mEndPoint.y() ) )
return; return;
mRubberBand->reset( QgsWkbTypes::PolygonGeometry );
QgsRectangle rect( mStartPoint, mEndPoint ); QgsRectangle rect( mStartPoint, mEndPoint );
mRubberBand->reset( QgsWkbTypes::PolygonGeometry ); mRubberBand->reset( QgsWkbTypes::PolygonGeometry );

View File

@ -64,6 +64,13 @@ class GUI_EXPORT QgsMapToolExtent : public QgsMapTool
*/ */
QgsRectangle extent() const; QgsRectangle extent() const;
/**
* Removes the tool's rubber band from the canvas.
*
* \since QGIS 3.20
*/
void clearRubberBand();
signals: signals:
//! signal emitted on extent change //! signal emitted on extent change