QGIS API Documentation 3.27.0-Master (f261cc1f8b)
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#include <QUuid>
32
33#include "qgsaction.h"
34#include "qgsfeature.h"
35
36class QDomNode;
37class QDomDocument;
38class QgsPythonUtils;
39class QgsVectorLayer;
42
52class CORE_EXPORT QgsActionManager: public QObject
53{
54 Q_OBJECT
55
56 public:
59 : mLayer( layer )
60 {}
61
69 QUuid addAction( QgsAction::ActionType type, const QString &name, const QString &command, bool capture = false );
70
78 QUuid addAction( QgsAction::ActionType type, const QString &name, const QString &command, const QString &icon, bool capture = false );
79
83 void addAction( const QgsAction &action );
84
90 void removeAction( QUuid actionId );
91
102 void doAction( QUuid actionId, const QgsFeature &feature, int defaultValueIndex = 0, const QgsExpressionContextScope &scope = QgsExpressionContextScope() ) SIP_PYNAME( doActionFeature );
103
111 void doAction( QUuid actionId, const QgsFeature &feature, const QgsExpressionContext &context );
112
114 void clearActions();
115
122 QList<QgsAction> actions( const QString &actionScope = QString() ) const;
123
125 QgsVectorLayer *layer() const { return mLayer; }
126
128 bool writeXml( QDomNode &layer_node ) const;
129
131 bool readXml( const QDomNode &layer_node );
132
138 QgsAction action( QUuid id ) const;
139
146 void setDefaultAction( const QString &actionScope, QUuid actionId );
147
154 QgsAction defaultAction( const QString &actionScope );
155
156 private:
157 QList<QgsAction> mActions;
158 QgsVectorLayer *mLayer = nullptr;
159 static void ( *smPythonExecute )( const QString & );
160
161 void runAction( const QgsAction &action );
162
163 QMap<QString, QUuid> mDefaultActions;
164
165 bool mOnNotifyConnected = false;
166
167 QgsExpressionContext createExpressionContext() const;
168
169 private slots:
170 void onNotifyRunActions( const QString &message );
171};
172
173#endif
Storage and management of actions associated with a layer.
QgsActionManager(QgsVectorLayer *layer)
Constructor.
Utility class that encapsulates an action based on vector attributes.
Definition: qgsaction.h:35
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Represents a vector layer which manages a vector based data sets.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81