Add willBeDeleted() signal to QgsMapLayer (#3998)

This allows pieces of code that depend on map layers to listen directly
to the layer's notification rather than having to listen to project's
layersWillBeRemoved signal (and cycle through the whole list)
This commit is contained in:
Martin Dobias 2017-01-16 16:51:44 +08:00 committed by GitHub
parent 6d23b0450c
commit b340d7bdb6
6 changed files with 27 additions and 0 deletions

View File

@ -743,6 +743,14 @@ class QgsMapLayer : QObject
*/
void dependenciesChanged();
/**
* Emitted in the destructor when the layer is about to be deleted,
* but it is still in a perfectly valid state: the last chance for
* other pieces of code for some cleanup if they use the layer.
* @note added in QGIS 3.0
*/
void willBeDeleted();
protected:
/** Set the extent */
virtual void setExtent( const QgsRectangle &rect );

View File

@ -778,6 +778,14 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
void dependenciesChanged();
/**
* Emitted in the destructor when the layer is about to be deleted,
* but it is still in a perfectly valid state: the last chance for
* other pieces of code for some cleanup if they use the layer.
* @note added in QGIS 3.0
*/
void willBeDeleted();
protected:
//! Set the extent
virtual void setExtent( const QgsRectangle &rect );

View File

@ -24,6 +24,13 @@ QgsPluginLayer::QgsPluginLayer( const QString& layerType, const QString& layerNa
setLegend( QgsMapLayerLegend::defaultPluginLegend( this ) );
}
QgsPluginLayer::~QgsPluginLayer()
{
// TODO: shall we move the responsibility of emitting the signal to plugin
// layer implementations before they start doing their part of cleanup...?
emit willBeDeleted();
}
QString QgsPluginLayer::pluginLayerType()
{
return mPluginLayerType;

View File

@ -34,6 +34,7 @@ class CORE_EXPORT QgsPluginLayer : public QgsMapLayer
public:
QgsPluginLayer( const QString& layerType, const QString& layerName = QString() );
~QgsPluginLayer();
//! Return plugin layer type (the same as used in QgsPluginLayerRegistry)
QString pluginLayerType();

View File

@ -172,6 +172,7 @@ QgsVectorLayer::QgsVectorLayer( const QString& vectorLayerPath,
QgsVectorLayer::~QgsVectorLayer()
{
emit willBeDeleted();
mValid = false;

View File

@ -170,6 +170,8 @@ QgsRasterLayer::QgsRasterLayer( const QString & uri,
QgsRasterLayer::~QgsRasterLayer()
{
emit willBeDeleted();
mValid = false;
// Note: provider and other interfaces are owned and deleted by pipe
}