Skip to content

Commit

Permalink
Fix a crash when destroying an extent widget while the "draw on canvas"
Browse files Browse the repository at this point in the history
option is still active
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Aug 26, 2021
1 parent ab00739 commit f253f6d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions python/gui/auto_generated/qgsextentwidget.sip.in
Expand Up @@ -52,6 +52,8 @@ When using the widget, make sure to call :py:func:`~setOriginalExtent`, :py:func
Constructor for QgsExtentWidget.
%End

~QgsExtentWidget();

void setOriginalExtent( const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs );
%Docstring
Sets the original extent and coordinate reference system for the widget. This should be called as part of initialization.
Expand Down
23 changes: 18 additions & 5 deletions src/gui/qgsextentwidget.cpp
Expand Up @@ -89,6 +89,17 @@ QgsExtentWidget::QgsExtentWidget( QWidget *parent, WidgetStyle style )
setAcceptDrops( true );
}

QgsExtentWidget::~QgsExtentWidget()
{
if ( mMapToolExtent )
{
// disconnect from deactivated signal -- this will be called when the map tool is being destroyed,
// and we don't want to act on that anymore (the mapToolDeactivated slot tries to show the widget again, but
// that's being destroyed!)
disconnect( mMapToolExtent.get(), &QgsMapToolExtent::deactivated, this, &QgsExtentWidget::mapToolDeactivated );
}
}

void QgsExtentWidget::setOriginalExtent( const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs )
{
mOriginalExtent = originalExtent;
Expand Down Expand Up @@ -393,11 +404,7 @@ void QgsExtentWidget::setOutputExtentFromDrawOnCanvas()
{
mMapToolExtent.reset( new QgsMapToolExtent( mCanvas ) );
connect( mMapToolExtent.get(), &QgsMapToolExtent::extentChanged, this, &QgsExtentWidget::extentDrawn );
connect( mMapToolExtent.get(), &QgsMapTool::deactivated, this, [ = ]
{
emit toggleDialogVisibility( true );
mMapToolPrevious = nullptr;
} );
connect( mMapToolExtent.get(), &QgsMapTool::deactivated, this, &QgsExtentWidget::mapToolDeactivated );
}
mMapToolExtent->setRatio( mRatio );
mCanvas->setMapTool( mMapToolExtent.get() );
Expand All @@ -414,6 +421,12 @@ void QgsExtentWidget::extentDrawn( const QgsRectangle &extent )
mMapToolPrevious = nullptr;
}

void QgsExtentWidget::mapToolDeactivated()
{
emit toggleDialogVisibility( true );
mMapToolPrevious = nullptr;
}

QgsRectangle QgsExtentWidget::outputExtent() const
{
return QgsRectangle( QgsDoubleValidator::toDouble( mXMinLineEdit->text() ), QgsDoubleValidator::toDouble( mYMinLineEdit->text() ),
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsextentwidget.h
Expand Up @@ -75,6 +75,8 @@ class GUI_EXPORT QgsExtentWidget : public QWidget, private Ui::QgsExtentGroupBox
*/
explicit QgsExtentWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, WidgetStyle style = CondensedStyle );

~QgsExtentWidget() override;

/**
* Sets the original extent and coordinate reference system for the widget. This should be called as part of initialization.
* \see originalExtent()
Expand Down Expand Up @@ -244,6 +246,7 @@ class GUI_EXPORT QgsExtentWidget : public QWidget, private Ui::QgsExtentGroupBox
void layerMenuAboutToShow();

void extentDrawn( const QgsRectangle &extent );
void mapToolDeactivated();

private:
void setOutputExtent( const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, QgsExtentWidget::ExtentState state );
Expand Down

0 comments on commit f253f6d

Please sign in to comment.