QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsaction.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsaction.h - QgsAction
3
4 ---------------------
5 begin : 18.4.2016
6 copyright : (C) 2016 by Matthias Kuhn
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSACTION_H
17#define QGSACTION_H
18
19#include "qgis_core.h"
20#include <QSet>
21#include <QString>
22#include <QIcon>
23#include <QUuid>
24
26#include <memory>
27
29
34class CORE_EXPORT QgsAction
35{
36 public:
38 {
47 };
48
52 QgsAction() = default;
53
63 QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false, bool enabledOnlyWhenEditable SIP_PYARGREMOVE = false )
64 : mType( type )
65 , mDescription( description )
66 , mCommand( command )
67 , mCaptureOutput( capture )
68 , mId( QUuid::createUuid() )
69 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
70 {}
71
85 QgsAction( ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString(), bool enabledOnlyWhenEditable SIP_PYARGREMOVE = false )
86 : mType( type )
87 , mDescription( description )
88 , mShortTitle( shortTitle )
89 , mIcon( icon )
90 , mCommand( action )
91 , mCaptureOutput( capture )
92 , mActionScopes( actionScopes )
93 , mNotificationMessage( notificationMessage )
94 , mId( QUuid::createUuid() )
95 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
96 {}
97
112 QgsAction( const QUuid &id, ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString(), bool enabledOnlyWhenEditable SIP_PYARGREMOVE = false )
113 : mType( type )
114 , mDescription( description )
115 , mShortTitle( shortTitle )
116 , mIcon( icon )
117 , mCommand( action )
118 , mCaptureOutput( capture )
119 , mActionScopes( actionScopes )
120 , mNotificationMessage( notificationMessage )
121 , mId( id )
122 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
123 {}
124
125
127 QString name() const { return mDescription; }
128
130 QString shortTitle() const { return mShortTitle; }
131
137 QUuid id() const { return mId; }
138
144 bool isValid() const { return !mId.isNull(); }
145
147 QString iconPath() const { return mIcon; }
148
150 QIcon icon() const { return QIcon( mIcon ); }
151
159 QString command() const { return mCommand; }
160
166 QString notificationMessage() const { return mNotificationMessage; }
167
169 ActionType type() const { return mType; }
170
172 bool capture() const { return mCaptureOutput; }
173
174
176 bool isEnabledOnlyWhenEditable() const { return mIsEnabledOnlyWhenEditable; }
177
183 void setEnabledOnlyWhenEditable( bool enable ) { mIsEnabledOnlyWhenEditable = enable; };
184
185
187 bool runable() const;
188
194 void run( QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext ) const;
195
201 void run( const QgsExpressionContext &expressionContext ) const;
202
211 QSet<QString> actionScopes() const;
212
220 void setActionScopes( const QSet<QString> &actionScopes );
221
228 void readXml( const QDomNode &actionNode );
229
236 void writeXml( QDomNode &actionsNode ) const;
237
243 void setExpressionContextScope( const QgsExpressionContextScope &scope );
244
250 QgsExpressionContextScope expressionContextScope() const;
251
257 QString html( ) const;
258
263 void setCommand( const QString &newCommand );
264
265 private:
266
267 void handleFormSubmitAction( const QString &expandedAction ) const;
268 ActionType mType = Generic;
269 QString mDescription;
270 QString mShortTitle;
271 QString mIcon;
272 QString mCommand;
273 bool mCaptureOutput = false;
274 QSet<QString> mActionScopes;
275 QString mNotificationMessage;
276 QUuid mId;
277 QgsExpressionContextScope mExpressionContextScope;
278 bool mIsEnabledOnlyWhenEditable = false;
279};
280
282
283#endif // QGSACTION_H
Utility class that encapsulates an action based on vector attributes.
Definition: qgsaction.h:35
QgsAction(ActionType type, const QString &description, const QString &command, bool capture=false, bool enabledOnlyWhenEditable=false)
Create a new QgsAction.
Definition: qgsaction.h:63
void setEnabledOnlyWhenEditable(bool enable)
Set whether the action is only enabled in editable mode.
Definition: qgsaction.h:183
QString notificationMessage() const
Returns the notification message that triggers the action.
Definition: qgsaction.h:166
QString name() const
The name of the action. This may be a longer description.
Definition: qgsaction.h:127
QgsAction()=default
Default constructor.
QIcon icon() const
The icon.
Definition: qgsaction.h:150
QString iconPath() const
The path to the icon.
Definition: qgsaction.h:147
bool isValid() const
Returns true if this action was a default constructed one.
Definition: qgsaction.h:144
ActionType type() const
The action type.
Definition: qgsaction.h:169
QString command() const
Returns the command that is executed by this action.
Definition: qgsaction.h:159
QString shortTitle() const
The short title is used to label user interface elements like buttons.
Definition: qgsaction.h:130
bool isEnabledOnlyWhenEditable() const
Returns whether only enabled in editable mode.
Definition: qgsaction.h:176
bool capture() const
Whether to capture output for display when this action is run.
Definition: qgsaction.h:172
QUuid id() const
Returns a unique id for this action.
Definition: qgsaction.h:137
QgsAction(const QUuid &id, ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle=QString(), const QSet< QString > &actionScopes=QSet< QString >(), const QString &notificationMessage=QString(), bool enabledOnlyWhenEditable=false)
Create a new QgsAction.
Definition: qgsaction.h:112
QgsAction(ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle=QString(), const QSet< QString > &actionScopes=QSet< QString >(), const QString &notificationMessage=QString(), bool enabledOnlyWhenEditable=false)
Create a new QgsAction.
Definition: qgsaction.h:85
@ GenericPython
Definition: qgsaction.h:40
@ SubmitUrlEncoded
POST data to an URL, using "application/x-www-form-urlencoded" or "application/json" if the body is v...
Definition: qgsaction.h:45
@ SubmitUrlMultipart
POST data to an URL using "multipart/form-data".
Definition: qgsaction.h:46
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_PYARGREMOVE
Definition: qgis_sip.h:151
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)