mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Ensure member QObjects for QgsMapLayer (and subclasses) are correctly
parented to their owner QgsMapLayer. This ensures that if the layer is moved to a different thread with QObject::moveToThread(), then those children are also considered by QObject::moveToThread() and correctly also moved to the new target thread. This fixes broken connections (and likely other issues) caused when moving layers between threads (such as is done when a background processing algorithm completes). Fixes #18005
This commit is contained in:
parent
dbe45b8d5e
commit
0607f79f47
@ -1909,7 +1909,10 @@ void QgsMapLayer::setLegend( QgsMapLayerLegend *legend )
|
||||
mLegend = legend;
|
||||
|
||||
if ( mLegend )
|
||||
{
|
||||
mLegend->setParent( this );
|
||||
connect( mLegend, &QgsMapLayerLegend::itemsChanged, this, &QgsMapLayer::legendChanged );
|
||||
}
|
||||
|
||||
emit legendChanged();
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ class QgsMapLayer;
|
||||
#include <QObject>
|
||||
|
||||
#include "qgis_core.h"
|
||||
#include "qgis_sip.h"
|
||||
|
||||
class QDomElement;
|
||||
|
||||
@ -96,8 +97,12 @@ class CORE_EXPORT QgsMapLayerStyleManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//! Construct a style manager associated with a map layer (must not be null)
|
||||
QgsMapLayerStyleManager( QgsMapLayer *layer );
|
||||
|
||||
/**
|
||||
* Construct a style manager associated with a map layer (must not be null).
|
||||
* The style manager will be parented to \a layer.
|
||||
*/
|
||||
QgsMapLayerStyleManager( QgsMapLayer *layer SIP_TRANSFERTHIS );
|
||||
|
||||
//! Get pointer to the associated map layer
|
||||
QgsMapLayer *layer() const { return mLayer; }
|
||||
|
@ -147,6 +147,7 @@ QgsVectorLayer::QgsVectorLayer( const QString &vectorLayerPath,
|
||||
mConditionalStyles = new QgsConditionalLayerStyles();
|
||||
|
||||
mJoinBuffer = new QgsVectorLayerJoinBuffer( this );
|
||||
mJoinBuffer->setParent( this );
|
||||
connect( mJoinBuffer, &QgsVectorLayerJoinBuffer::joinedFieldsChanged, this, &QgsVectorLayer::onJoinedFieldsChanged );
|
||||
|
||||
mExpressionFieldBuffer = new QgsExpressionFieldBuffer();
|
||||
@ -1553,6 +1554,7 @@ bool QgsVectorLayer::setDataProvider( QString const &provider )
|
||||
return false;
|
||||
}
|
||||
|
||||
mDataProvider->setParent( this );
|
||||
connect( mDataProvider, &QgsVectorDataProvider::raiseError, this, &QgsVectorLayer::raiseError );
|
||||
|
||||
QgsDebugMsgLevel( QStringLiteral( "Instantiated the data provider plugin" ), 2 );
|
||||
@ -4405,6 +4407,7 @@ void QgsVectorLayer::setAuxiliaryLayer( QgsAuxiliaryLayer *alayer )
|
||||
}
|
||||
|
||||
mAuxiliaryLayer.reset( alayer );
|
||||
mAuxiliaryLayer->setParent( this );
|
||||
updateFields();
|
||||
}
|
||||
|
||||
|
@ -614,6 +614,7 @@ void QgsRasterLayer::setDataProvider( QString const &provider )
|
||||
return;
|
||||
}
|
||||
QgsDebugMsgLevel( "Data provider created", 4 );
|
||||
mDataProvider->setParent( this );
|
||||
|
||||
// Set data provider into pipe even if not valid so that it is deleted with pipe (with layer)
|
||||
mPipe.set( mDataProvider );
|
||||
|
Loading…
x
Reference in New Issue
Block a user