Skip to content

Commit

Permalink
Use QPointer for storing layer pointers in expression scope
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 9, 2016
1 parent 6cf47be commit c282e26
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/core/qgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsexpressioncontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down

0 comments on commit c282e26

Please sign in to comment.