@@ -81,7 +81,9 @@ void QgsAttributeAction::doAction( int index, const QgsFeature &feat, const QMap
81
81
return ;
82
82
83
83
// search for expressions while expanding actions
84
- QString expandedAction = QgsExpression::replaceExpressionText ( action.action (), &feat, mLayer , substitutionMap );
84
+ QgsExpressionContext context = createExpressionContext ();
85
+ context.setFeature ( feat );
86
+ QString expandedAction = QgsExpression::replaceExpressionText ( action.action (), &context, substitutionMap );
85
87
if ( expandedAction.isEmpty () )
86
88
return ;
87
89
@@ -125,6 +127,17 @@ void QgsAttributeAction::runAction( const QgsAction &action, void ( *executePyth
125
127
}
126
128
}
127
129
130
+ QgsExpressionContext QgsAttributeAction::createExpressionContext () const
131
+ {
132
+ QgsExpressionContext context;
133
+ context << QgsExpressionContextUtils::globalScope ()
134
+ << QgsExpressionContextUtils::projectScope ();
135
+ if ( mLayer )
136
+ context << QgsExpressionContextUtils::layerScope ( mLayer );
137
+
138
+ return context;
139
+ }
140
+
128
141
QString QgsAttributeAction::expandAction ( QString action, const QgsAttributeMap &attributes,
129
142
uint clickedOnValue )
130
143
{
@@ -215,7 +228,10 @@ QString QgsAttributeAction::expandAction( QString action, QgsFeature &feat, cons
215
228
continue ;
216
229
}
217
230
218
- QVariant result = exp.evaluate ( &feat, mLayer ->fields () );
231
+ QgsExpressionContext context = createExpressionContext ();
232
+ context.setFeature ( feat );
233
+
234
+ QVariant result = exp.evaluate ( &context );
219
235
if ( exp.hasEvalError () )
220
236
{
221
237
QgsDebugMsg ( " Expression parser eval error: " + exp.evalErrorString () );
0 commit comments