QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
7  email : [email protected]
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 
25 #include "qgsexpressioncontext.h"
26 #include <memory>
27 
29 
34 class CORE_EXPORT QgsAction
35 {
36  public:
38  {
41  Mac,
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
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsAction::notificationMessage
QString notificationMessage() const
Returns the notification message that triggers the action.
Definition: qgsaction.h:166
QgsAction::Generic
@ Generic
Definition: qgsaction.h:39
QgsAction::name
QString name() const
The name of the action. This may be a longer description.
Definition: qgsaction.h:127
QgsAction::OpenUrl
@ OpenUrl
Definition: qgsaction.h:44
QgsAction::shortTitle
QString shortTitle() const
The short title is used to label user interface elements like buttons.
Definition: qgsaction.h:130
QgsAction::QgsAction
QgsAction(ActionType type, const QString &description, const QString &command, bool capture=false, bool enabledOnlyWhenEditable=false)
Create a new QgsAction.
Definition: qgsaction.h:63
QgsAction::isEnabledOnlyWhenEditable
bool isEnabledOnlyWhenEditable() const
Returns whether only enabled in editable mode.
Definition: qgsaction.h:176
QgsAction::QgsAction
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
QgsAction::iconPath
QString iconPath() const
The path to the icon.
Definition: qgsaction.h:147
SIP_PYARGREMOVE
#define SIP_PYARGREMOVE
Definition: qgis_sip.h:151
QgsAction::isValid
bool isValid() const
Returns true if this action was a default constructed one.
Definition: qgsaction.h:144
QgsAction::Windows
@ Windows
Definition: qgsaction.h:42
QgsAction::Mac
@ Mac
Definition: qgsaction.h:41
qgsexpressioncontext.h
QgsAction::type
ActionType type() const
The action type.
Definition: qgsaction.h:169
QgsAction::QgsAction
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::GenericPython
@ GenericPython
Definition: qgsaction.h:40
QgsAction::Unix
@ Unix
Definition: qgsaction.h:43
QgsAction::icon
QIcon icon() const
The icon.
Definition: qgsaction.h:150
QgsAction::SubmitUrlMultipart
@ SubmitUrlMultipart
POST data to an URL using "multipart/form-data".
Definition: qgsaction.h:46
QgsAction::ActionType
ActionType
Definition: qgsaction.h:37
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:113
QgsAction
Utility class that encapsulates an action based on vector attributes.
Definition: qgsaction.h:34
QgsAction::capture
bool capture() const
Whether to capture output for display when this action is run.
Definition: qgsaction.h:172
QgsAction::setEnabledOnlyWhenEditable
void setEnabledOnlyWhenEditable(bool enable)
Set whether the action is only enabled in editable mode.
Definition: qgsaction.h:183
QgsAction::id
QUuid id() const
Returns a unique id for this action.
Definition: qgsaction.h:137
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsAction::command
QString command() const
Returns the command that is executed by this action.
Definition: qgsaction.h:159
QgsAction::SubmitUrlEncoded
@ SubmitUrlEncoded
POST data to an URL, using "application/x-www-form-urlencoded" or "application/json" if the body is v...
Definition: qgsaction.h:45