QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Public Member Functions | Static Public Member Functions | List of all members
QgsActionManager Class Reference

Storage and management of actions associated with a layer. More...

#include <qgsactionmanager.h>

Public Member Functions

 QgsActionManager (QgsVectorLayer *layer)
 Constructor. More...
 
void addAction (QgsAction::ActionType type, const QString &name, const QString &action, bool capture=false)
 Add an action with the given name and action details. More...
 
void addAction (QgsAction::ActionType type, const QString &name, const QString &action, const QString &icon, bool capture=false)
 Add an action with the given name and action details. More...
 
void addAction (const QgsAction &action)
 Add a new action to this list. More...
 
const QgsActionat (int idx) const
 Get the action at the specified index. More...
 
void clearActions ()
 Removes all actions. More...
 
int defaultAction () const
 Returns the index of the default action, or -1 if no default action is available. More...
 
void doAction (int index, const QgsFeature &feat, int defaultValueIndex=0, const QgsExpressionContextScope &scope=QgsExpressionContextScope())
 Does the given action. More...
 
void doAction (int index, const QgsFeature &feature, const QgsExpressionContext &context, const QMap< QString, QVariant > *substitutionMap=nullptr)
 Does the action using the expression engine to replace any embedded expressions in the action definition. More...
 
Q_DECL_DEPRECATED void doAction (int index, const QgsFeature &feat, const QMap< QString, QVariant > *substitutionMap)
 Does the action using the expression builder to expand it and getting values from the passed feature attribute map. More...
 
Q_DECL_DEPRECATED QString expandAction (QString action, const QgsAttributeMap &attributes, uint defaultValueIndex)
 Expands the given action, replacing all 's with the value as given. More...
 
Q_DECL_DEPRECATED QString expandAction (const QString &action, QgsFeature &feat, const QMap< QString, QVariant > *substitutionMap=nullptr)
 Expands the given action using the expression builder This function currently replaces each expression between [% and %] placeholders in the action with the result of its evaluation on the feature passed as argument. More...
 
QgsVectorLayerlayer () const
 Return the layer. More...
 
QList< QgsActionlistActions () const
 Return a list of all actions. More...
 
QgsAction operator[] (int idx) const
 Get the action at the specified index. More...
 
bool readXML (const QDomNode &layer_node)
 Reads the actions in in XML format. More...
 
void removeAction (int index)
 Remove an action at given index. More...
 
void setDefaultAction (int actionNumber)
 Set the index of the default action. More...
 
int size () const
 Get the number of actions managed by this. More...
 
bool writeXML (QDomNode &layer_node, QDomDocument &doc) const
 Writes the actions out in XML format. More...
 

Static Public Member Functions

static Q_DECL_DEPRECATED void setPythonExecute (void(*)(const QString &))
 

Detailed Description

Storage and management of actions associated with a layer.

Actions can trigger custom code or applications to be executed based on attributes of a given feature.

Definition at line 48 of file qgsactionmanager.h.

Constructor & Destructor Documentation

◆ QgsActionManager()

QgsActionManager::QgsActionManager ( QgsVectorLayer layer)
inline

Constructor.

Definition at line 52 of file qgsactionmanager.h.

Member Function Documentation

◆ addAction() [1/3]

void QgsActionManager::addAction ( QgsAction::ActionType  type,
const QString name,
const QString action,
bool  capture = false 
)

Add an action with the given name and action details.

Will happily have duplicate names and actions. If capture is true, when running the action using doAction(), any stdout from the process will be captured and displayed in a dialog box.

Definition at line 43 of file qgsactionmanager.cpp.

◆ addAction() [2/3]

void QgsActionManager::addAction ( QgsAction::ActionType  type,
const QString name,
const QString action,
const QString icon,
bool  capture = false 
)

Add an action with the given name and action details.

Will happily have duplicate names and actions. If capture is true, when running the action using doAction(), any stdout from the process will be captured and displayed in a dialog box.

Definition at line 48 of file qgsactionmanager.cpp.

◆ addAction() [3/3]

void QgsActionManager::addAction ( const QgsAction action)

Add a new action to this list.

Definition at line 53 of file qgsactionmanager.cpp.

◆ at()

const QgsAction& QgsActionManager::at ( int  idx) const
inline

Get the action at the specified index.

Definition at line 165 of file qgsactionmanager.h.

◆ clearActions()

void QgsActionManager::clearActions ( )

Removes all actions.

Definition at line 118 of file qgsactionmanager.cpp.

◆ defaultAction()

int QgsActionManager::defaultAction ( ) const
inline

Returns the index of the default action, or -1 if no default action is available.

See also
setDefaultAction()

Definition at line 181 of file qgsactionmanager.h.

◆ doAction() [1/3]

void QgsActionManager::doAction ( int  index,
const QgsFeature feat,
int  defaultValueIndex = 0,
const QgsExpressionContextScope scope = QgsExpressionContextScope() 
)

Does the given action.

Parameters
indexIndex of the action
featFeature to run action for
defaultValueIndexIndex of the field to be used if the action has a $currfield placeholder.
scopeExpression context scope to add during expression evaluation
Note
available in python bindings as doActionFeature

Definition at line 66 of file qgsactionmanager.cpp.

◆ doAction() [2/3]

void QgsActionManager::doAction ( int  index,
const QgsFeature feature,
const QgsExpressionContext context,
const QMap< QString, QVariant > *  substitutionMap = nullptr 
)

Does the action using the expression engine to replace any embedded expressions in the action definition.

Parameters
indexaction index
featurefeature to run action for
contextexpression context to evalute expressions under
substitutionMapdeprecated - kept for compatibility with projects, will be removed for 3.0

Definition at line 75 of file qgsactionmanager.cpp.

◆ doAction() [3/3]

void QgsActionManager::doAction ( int  index,
const QgsFeature feat,
const QMap< QString, QVariant > *  substitutionMap 
)

Does the action using the expression builder to expand it and getting values from the passed feature attribute map.

substitutionMap is used to pass custom substitutions, to replace each key in the map with the associated value

Note
available in python bindings as doActionFeatureWithSubstitution
Deprecated:
use QgsExpressionContext variant instead

Definition at line 98 of file qgsactionmanager.cpp.

◆ expandAction() [1/2]

QString QgsActionManager::expandAction ( QString  action,
const QgsAttributeMap attributes,
uint  defaultValueIndex 
)

Expands the given action, replacing all 's with the value as given.

Deprecated:
use QgsExpression::replaceExpressionText() instead

Definition at line 175 of file qgsactionmanager.cpp.

◆ expandAction() [2/2]

QString QgsActionManager::expandAction ( const QString action,
QgsFeature feat,
const QMap< QString, QVariant > *  substitutionMap = nullptr 
)

Expands the given action using the expression builder This function currently replaces each expression between [% and %] placeholders in the action with the result of its evaluation on the feature passed as argument.

Additional substitutions can be passed through the substitutionMap parameter

Deprecated:
use QgsExpression::replaceExpressionText() instead

Definition at line 233 of file qgsactionmanager.cpp.

◆ layer()

QgsVectorLayer* QgsActionManager::layer ( ) const
inline

Return the layer.

Definition at line 129 of file qgsactionmanager.h.

◆ listActions()

QList< QgsAction > QgsActionManager::listActions ( ) const

Return a list of all actions.

Definition at line 123 of file qgsactionmanager.cpp.

◆ operator[]()

QgsAction QgsActionManager::operator[] ( int  idx) const
inline

Get the action at the specified index.

Definition at line 170 of file qgsactionmanager.h.

◆ readXML()

bool QgsActionManager::readXML ( const QDomNode layer_node)

Reads the actions in in XML format.

Definition at line 315 of file qgsactionmanager.cpp.

◆ removeAction()

void QgsActionManager::removeAction ( int  index)

Remove an action at given index.

Definition at line 58 of file qgsactionmanager.cpp.

◆ setDefaultAction()

void QgsActionManager::setDefaultAction ( int  actionNumber)
inline

Set the index of the default action.

Parameters
actionNumberindex of action which should be made the default for the layer
See also
defaultAction()

Definition at line 188 of file qgsactionmanager.h.

◆ setPythonExecute()

void QgsActionManager::setPythonExecute ( void(*)(const QString &)  runPython)
static
Deprecated:
Initialize QgsPythonRunner instead
Note
not available in Python bindings

Definition at line 346 of file qgsactionmanager.cpp.

◆ size()

int QgsActionManager::size ( ) const
inline

Get the number of actions managed by this.

Definition at line 160 of file qgsactionmanager.h.

◆ writeXML()

bool QgsActionManager::writeXML ( QDomNode layer_node,
QDomDocument doc 
) const

Writes the actions out in XML format.

Definition at line 293 of file qgsactionmanager.cpp.


The documentation for this class was generated from the following files: