QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsactionmanager.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsactionmanager.h
3 
4  These classes store and control the management 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 "qgis_core.h"
28 #include <QString>
29 #include <QIcon>
30 #include <QObject>
31 
32 #include "qgsaction.h"
33 #include "qgsfeature.h"
34 
35 class QDomNode;
36 class QDomDocument;
37 class QgsPythonUtils;
38 class QgsVectorLayer;
41 
51 class CORE_EXPORT QgsActionManager: public QObject
52 {
53  Q_OBJECT
54 
55  public:
58  : mLayer( layer )
59  {}
60 
68  QUuid addAction( QgsAction::ActionType type, const QString &name, const QString &command, bool capture = false );
69 
77  QUuid addAction( QgsAction::ActionType type, const QString &name, const QString &command, const QString &icon, bool capture = false );
78 
82  void addAction( const QgsAction &action );
83 
89  void removeAction( QUuid actionId );
90 
101  void doAction( QUuid actionId, const QgsFeature &feature, int defaultValueIndex = 0, const QgsExpressionContextScope &scope = QgsExpressionContextScope() ) SIP_PYNAME( doActionFeature );
102 
110  void doAction( QUuid actionId, const QgsFeature &feature, const QgsExpressionContext &context );
111 
113  void clearActions();
114 
121  QList<QgsAction> actions( const QString &actionScope = QString() ) const;
122 
124  QgsVectorLayer *layer() const { return mLayer; }
125 
127  bool writeXml( QDomNode &layer_node ) const;
128 
130  bool readXml( const QDomNode &layer_node );
131 
137  QgsAction action( QUuid id );
138 
145  void setDefaultAction( const QString &actionScope, QUuid actionId );
146 
153  QgsAction defaultAction( const QString &actionScope );
154 
155  private:
156  QList<QgsAction> mActions;
157  QgsVectorLayer *mLayer = nullptr;
158  static void ( *smPythonExecute )( const QString & );
159 
160  void runAction( const QgsAction &action );
161 
162  QMap<QString, QUuid> mDefaultActions;
163 
164  bool mOnNotifyConnected = false;
165 
166  QgsExpressionContext createExpressionContext() const;
167 
168  private slots:
169  void onNotifyRunActions( const QString &message );
170 };
171 
172 #endif
QgsVectorLayer * layer() const
Returns the layer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
QgsActionManager(QgsVectorLayer *layer)
Constructor.
Utility class that encapsulates an action based on vector attributes.
Definition: qgsaction.h:35
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.
Represents a vector layer which manages a vector based data sets.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81