Skip to content

Commit 062de6a

Browse files
committed
Add project/layer expression context scope only if it is available
Better to leave them out than adding dummy scopes
1 parent 63d1cfd commit 062de6a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/core/qgsexpressioncontext.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,14 @@ QgsExpressionContextScope* QgsExpressionContextUtils::layerScope( const QgsMapLa
686686
QList<QgsExpressionContextScope*> QgsExpressionContextUtils::globalProjectLayerScopes( const QgsMapLayer* layer )
687687
{
688688
QList<QgsExpressionContextScope*> scopes;
689-
scopes << globalScope()
690-
<< projectScope( QgsProject::instance() ) // TODO: use project associated with layer
691-
<< layerScope( layer );
689+
scopes << globalScope();
690+
691+
QgsProject* project = QgsProject::instance(); // TODO: use project associated with layer
692+
if ( project )
693+
scopes << projectScope( project );
694+
695+
if ( layer )
696+
scopes << layerScope( layer );
692697
return scopes;
693698
}
694699

src/gui/symbology-ng/qgssymbolwidgetcontext.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ QList<QgsExpressionContextScope *> QgsSymbolWidgetContext::globalProjectAtlasMap
9393
{
9494
scopes << QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
9595
}
96-
scopes << QgsExpressionContextUtils::layerScope( layer );
96+
if ( layer )
97+
scopes << QgsExpressionContextUtils::layerScope( layer );
9798
return scopes;
9899
}

0 commit comments

Comments
 (0)