Skip to content
Permalink
Browse files
Fix a crash when destroying an extent widget while the "draw on canvas"
option is still active
  • Loading branch information
nyalldawson committed Aug 26, 2021
1 parent b2287f5 commit 204af6f02f1cfe0e592ab452e866d5cf1f70985f
Showing with 23 additions and 5 deletions.
  1. +2 −0 python/gui/auto_generated/qgsextentwidget.sip.in
  2. +18 −5 src/gui/qgsextentwidget.cpp
  3. +3 −0 src/gui/qgsextentwidget.h
@@ -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.
@@ -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;
@@ -394,11 +405,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() );
@@ -415,6 +422,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() ),
@@ -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()
@@ -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 );

0 comments on commit 204af6f

Please sign in to comment.