Skip to content

Commit 5dd88c9

Browse files
committed
Avoid crash in style dock when layer is removed
1 parent 46fb193 commit 5dd88c9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/app/qgsmapstylingwidget.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "qgsundowidget.h"
1818
#include "qgsrendererv2.h"
1919
#include "qgsrendererv2registry.h"
20+
#include "qgsmaplayerregistry.h"
2021

2122
QgsMapStylingWidget::QgsMapStylingWidget( QgsMapCanvas* canvas, QWidget *parent )
2223
: QWidget( parent )
@@ -29,6 +30,8 @@ QgsMapStylingWidget::QgsMapStylingWidget( QgsMapCanvas* canvas, QWidget *parent
2930
layout->setContentsMargins( 0, 0, 0, 0 );
3031
this->setLayout( layout );
3132

33+
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QgsMapLayer* ) ), this, SLOT( layerAboutToBeRemoved( QgsMapLayer* ) ) );
34+
3235
mAutoApplyTimer = new QTimer( this );
3336
mAutoApplyTimer->setSingleShot( true );
3437
connect( mAutoApplyTimer, SIGNAL( timeout() ), this, SLOT( apply() ) );
@@ -199,6 +202,16 @@ void QgsMapStylingWidget::updateCurrentWidgetLayer( int currentPage )
199202
mBlockAutoApply = false;
200203
}
201204

205+
void QgsMapStylingWidget::layerAboutToBeRemoved( QgsMapLayer* layer )
206+
{
207+
if ( layer == mCurrentLayer )
208+
{
209+
mAutoApplyTimer->stop();
210+
mStackedWidget->setCurrentIndex( mNotSupportedPage );
211+
mCurrentLayer = nullptr;
212+
}
213+
}
214+
202215

203216
QgsMapLayerStyleCommand::QgsMapLayerStyleCommand( QgsMapLayer *layer, const QDomNode &current, const QDomNode &last )
204217
: QUndoCommand()

src/app/qgsmapstylingwidget.h

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class APP_EXPORT QgsMapStylingWidget : public QWidget
4949

5050
private slots:
5151
void updateCurrentWidgetLayer( int currentPage );
52+
void layerAboutToBeRemoved( QgsMapLayer* layer );
5253

5354
private:
5455
int mNotSupportedPage;

0 commit comments

Comments
 (0)