QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsactionmanager.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsactionmanager.h
3 
4  These classes store and control the managment and execution of actions
5  associated with a particular Qgis layer. Actions are defined to be
6  external programs that are run with user-specified inputs that can
7  depend on the contents of layer attributes.
8 
9  -------------------
10  begin : Oct 24 2004
11  copyright : (C) 2004 by Gavin Macaulay
12  email : gavin at macaulay dot co dot nz
13  ***************************************************************************/
14 
15 /***************************************************************************
16  * *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or *
20  * (at your option) any later version. *
21  * *
22  ***************************************************************************/
23 
24 #ifndef QGSACTIONMANAGER_H
25 #define QGSACTIONMANAGER_H
26 
27 #include <QString>
28 #include <QIcon>
29 
30 #include "qgsaction.h"
31 #include "qgsfeature.h"
32 #include "qgsexpressioncontext.h"
33 
34 class QDomNode;
35 class QDomDocument;
36 class QgsPythonUtils;
37 class QgsVectorLayer;
38 
39 
48 class CORE_EXPORT QgsActionManager
49 {
50  public:
53  : mLayer( layer )
54  , mDefaultAction( -1 )
55  {}
56 
63  void addAction( QgsAction::ActionType type, const QString& name, const QString& action, bool capture = false );
64 
71  void addAction( QgsAction::ActionType type, const QString& name, const QString& action, const QString& icon, bool capture = false );
72 
76  void addAction( const QgsAction& action );
77 
79  void removeAction( int index );
80 
91  void doAction( int index,
92  const QgsFeature &feat,
93  int defaultValueIndex = 0,
95 
103  // TODO QGIS 3.0 remove substition map - force use of expression variables
104  void doAction( int index,
105  const QgsFeature& feature,
106  const QgsExpressionContext& context,
107  const QMap<QString, QVariant> *substitutionMap = nullptr );
108 
116  Q_DECL_DEPRECATED void doAction( int index,
117  const QgsFeature &feat,
118  const QMap<QString, QVariant> *substitutionMap );
119 
121  void clearActions();
122 
126  QList<QgsAction> listActions() const;
127 
129  QgsVectorLayer* layer() const { return mLayer; }
130 
135  Q_DECL_DEPRECATED QString expandAction( QString action, const QgsAttributeMap &attributes, uint defaultValueIndex );
136 
146  Q_DECL_DEPRECATED QString expandAction( const QString& action,
147  QgsFeature &feat,
148  const QMap<QString, QVariant> *substitutionMap = nullptr );
149 
150 
152  bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;
153 
155  bool readXML( const QDomNode& layer_node );
156 
160  int size() const { return mActions.size(); }
161 
165  const QgsAction& at( int idx ) const { return mActions.at( idx ); }
166 
170  QgsAction operator[]( int idx ) const { return mActions[idx]; }
171 
175  Q_DECL_DEPRECATED static void setPythonExecute( void ( * )( const QString & ) );
176 
181  int defaultAction() const { return mDefaultAction < 0 || mDefaultAction >= size() ? -1 : mDefaultAction; }
182 
188  void setDefaultAction( int actionNumber ) { mDefaultAction = actionNumber ; }
189 
190  private:
191  QList<QgsAction> mActions;
192  QgsVectorLayer *mLayer;
193  static void ( *smPythonExecute )( const QString & );
194 
195  void runAction( const QgsAction &action,
196  void ( *executePython )( const QString & ) = nullptr );
197 
198  int mDefaultAction;
199 
200  QgsExpressionContext createExpressionContext() const;
201 };
202 
203 #endif
static unsigned index
QgsVectorLayer * layer() const
Return the layer.
int defaultAction() const
Returns the index of the default action, or -1 if no default action is available. ...
void setDefaultAction(int actionNumber)
Set the index of the default action.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
const QgsAction & at(int idx) const
Get the action at the specified index.
QgsActionManager(QgsVectorLayer *layer)
Constructor.
Utility class that encapsulates an action based on vector attributes.
Definition: qgsaction.h:25
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Storage and management of actions associated with a layer.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QgsAction operator[](int idx) const
Get the action at the specified index.
Represents a vector layer which manages a vector based data sets.
int size() const
Get the number of actions managed by this.