Skip to content

Commit c282e26

Browse files
committed
Use QPointer for storing layer pointers in expression scope
1 parent 6cf47be commit c282e26

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/core/qgsexpression.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ static QgsExpression::Node* getNode( const QVariant& value, QgsExpression* paren
331331

332332
QgsVectorLayer* getVectorLayer( const QVariant& value, QgsExpression* )
333333
{
334-
QgsVectorLayer* vl = value.value<QgsVectorLayer*>();
334+
QgsMapLayer* ml = value.value< QPointer<QgsMapLayer> >().data();
335+
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( ml );
335336
if ( !vl )
336337
{
337338
QString layerString = value.toString();

src/core/qgsexpressioncontext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ QgsExpressionContextScope* QgsExpressionContextUtils::layerScope( const QgsMapLa
691691

692692
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layer_name" ), layer->name(), true ) );
693693
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layer_id" ), layer->id(), true ) );
694-
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layer" ), QVariant::fromValue<QgsMapLayer*>( const_cast<QgsMapLayer*>( layer ) ), true ) );
694+
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layer" ), QVariant::fromValue<QPointer<QgsMapLayer> >( QPointer<QgsMapLayer>( const_cast<QgsMapLayer*>( layer ) ) ), true ) );
695695

696696
const QgsVectorLayer* vLayer = dynamic_cast< const QgsVectorLayer* >( layer );
697697
if ( vLayer )

0 commit comments

Comments
 (0)