mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Port attribute actions to expression contexts
This commit is contained in:
parent
3b6f5915e7
commit
f82c641a3d
@ -81,7 +81,9 @@ void QgsAttributeAction::doAction( int index, const QgsFeature &feat, const QMap
|
||||
return;
|
||||
|
||||
// search for expressions while expanding actions
|
||||
QString expandedAction = QgsExpression::replaceExpressionText( action.action(), &feat, mLayer, substitutionMap );
|
||||
QgsExpressionContext context = createExpressionContext();
|
||||
context.setFeature( feat );
|
||||
QString expandedAction = QgsExpression::replaceExpressionText( action.action(), &context, substitutionMap );
|
||||
if ( expandedAction.isEmpty() )
|
||||
return;
|
||||
|
||||
@ -125,6 +127,17 @@ void QgsAttributeAction::runAction( const QgsAction &action, void ( *executePyth
|
||||
}
|
||||
}
|
||||
|
||||
QgsExpressionContext QgsAttributeAction::createExpressionContext() const
|
||||
{
|
||||
QgsExpressionContext context;
|
||||
context << QgsExpressionContextUtils::globalScope()
|
||||
<< QgsExpressionContextUtils::projectScope();
|
||||
if ( mLayer )
|
||||
context << QgsExpressionContextUtils::layerScope( mLayer );
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
QString QgsAttributeAction::expandAction( QString action, const QgsAttributeMap &attributes,
|
||||
uint clickedOnValue )
|
||||
{
|
||||
@ -215,7 +228,10 @@ QString QgsAttributeAction::expandAction( QString action, QgsFeature &feat, cons
|
||||
continue;
|
||||
}
|
||||
|
||||
QVariant result = exp.evaluate( &feat, mLayer->fields() );
|
||||
QgsExpressionContext context = createExpressionContext();
|
||||
context.setFeature( feat );
|
||||
|
||||
QVariant result = exp.evaluate( &context );
|
||||
if ( exp.hasEvalError() )
|
||||
{
|
||||
QgsDebugMsg( "Expression parser eval error: " + exp.evalErrorString() );
|
||||
|
@ -27,7 +27,8 @@
|
||||
#include <QString>
|
||||
#include <QIcon>
|
||||
|
||||
#include <qgsfeature.h>
|
||||
#include "qgsfeature.h"
|
||||
#include "qgsexpressioncontext.h"
|
||||
|
||||
class QDomNode;
|
||||
class QDomDocument;
|
||||
@ -202,6 +203,8 @@ class CORE_EXPORT QgsAttributeAction
|
||||
void ( *executePython )( const QString & ) = 0 );
|
||||
|
||||
int mDefaultAction;
|
||||
|
||||
QgsExpressionContext createExpressionContext() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user