Skip to content
Permalink
Browse files

Use QPointer for storing layer pointers in expression scope

  • Loading branch information
m-kuhn committed Nov 9, 2016
1 parent 6cf47be commit c282e2621008f49644c89acc1a4f72a48da1493b
Showing with 3 additions and 2 deletions.
  1. +2 −1 src/core/qgsexpression.cpp
  2. +1 −1 src/core/qgsexpressioncontext.cpp
@@ -331,7 +331,8 @@ static QgsExpression::Node* getNode( const QVariant& value, QgsExpression* paren

QgsVectorLayer* getVectorLayer( const QVariant& value, QgsExpression* )
{
QgsVectorLayer* vl = value.value<QgsVectorLayer*>();
QgsMapLayer* ml = value.value< QPointer<QgsMapLayer> >().data();
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( ml );
if ( !vl )
{
QString layerString = value.toString();
@@ -691,7 +691,7 @@ QgsExpressionContextScope* QgsExpressionContextUtils::layerScope( const QgsMapLa

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

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

0 comments on commit c282e26

Please sign in to comment.
You can’t perform that action at this time.