QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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,
45  };
46 
50  QgsAction() = default;
51 
61  QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false, bool enabledOnlyWhenEditable SIP_PYARGREMOVE = false )
62  : mType( type )
63  , mDescription( description )
64  , mCommand( command )
65  , mCaptureOutput( capture )
66  , mId( QUuid::createUuid() )
67  , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
68  {}
69 
83  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 )
84  : mType( type )
85  , mDescription( description )
86  , mShortTitle( shortTitle )
87  , mIcon( icon )
88  , mCommand( action )
89  , mCaptureOutput( capture )
90  , mActionScopes( actionScopes )
91  , mNotificationMessage( notificationMessage )
92  , mId( QUuid::createUuid() )
93  , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
94  {}
95 
110  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 )
111  : mType( type )
112  , mDescription( description )
113  , mShortTitle( shortTitle )
114  , mIcon( icon )
115  , mCommand( action )
116  , mCaptureOutput( capture )
117  , mActionScopes( actionScopes )
118  , mNotificationMessage( notificationMessage )
119  , mId( id )
120  , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
121  {}
122 
123 
125  QString name() const { return mDescription; }
126 
128  QString shortTitle() const { return mShortTitle; }
129 
135  QUuid id() const { return mId; }
136 
142  bool isValid() const { return !mId.isNull(); }
143 
145  QString iconPath() const { return mIcon; }
146 
148  QIcon icon() const { return QIcon( mIcon ); }
149 
157  QString command() const { return mCommand; }
158 
164  QString notificationMessage() const { return mNotificationMessage; }
165 
167  ActionType type() const { return mType; }
168 
170  bool capture() const { return mCaptureOutput; }
171 
172 
174  bool isEnabledOnlyWhenEditable() const { return mIsEnabledOnlyWhenEditable; }
175 
181  void setEnabledOnlyWhenEditable( bool enable ) { mIsEnabledOnlyWhenEditable = enable; };
182 
183 
185  bool runable() const;
186 
192  void run( QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext ) const;
193 
199  void run( const QgsExpressionContext &expressionContext ) const;
200 
209  QSet<QString> actionScopes() const;
210 
218  void setActionScopes( const QSet<QString> &actionScopes );
219 
226  void readXml( const QDomNode &actionNode );
227 
234  void writeXml( QDomNode &actionsNode ) const;
235 
241  void setExpressionContextScope( const QgsExpressionContextScope &scope );
242 
248  QgsExpressionContextScope expressionContextScope() const;
249 
255  QString html( ) const;
256 
257  private:
258  ActionType mType = Generic;
259  QString mDescription;
260  QString mShortTitle;
261  QString mIcon;
262  QString mCommand;
263  bool mCaptureOutput = false;
264  QSet<QString> mActionScopes;
265  QString mNotificationMessage;
266  QUuid mId;
267  QgsExpressionContextScope mExpressionContextScope;
268  bool mIsEnabledOnlyWhenEditable = false;
269 };
270 
272 
273 #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:61
void setEnabledOnlyWhenEditable(bool enable)
Set whether the action is only enabled in editable mode.
Definition: qgsaction.h:181
QString notificationMessage() const
Returns the notification message that triggers the action.
Definition: qgsaction.h:164
QString name() const
The name of the action. This may be a longer description.
Definition: qgsaction.h:125
QgsAction()=default
Default constructor.
QIcon icon() const
The icon.
Definition: qgsaction.h:148
QString iconPath() const
The path to the icon.
Definition: qgsaction.h:145
bool isValid() const
Returns true if this action was a default constructed one.
Definition: qgsaction.h:142
ActionType type() const
The action type.
Definition: qgsaction.h:167
QString command() const
Returns the command that is executed by this action.
Definition: qgsaction.h:157
QString shortTitle() const
The short title is used to label user interface elements like buttons.
Definition: qgsaction.h:128
bool isEnabledOnlyWhenEditable() const
Returns whether only enabled in editable mode.
Definition: qgsaction.h:174
bool capture() const
Whether to capture output for display when this action is run.
Definition: qgsaction.h:170
QUuid id() const
Returns a unique id for this action.
Definition: qgsaction.h:135
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:110
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:83
@ GenericPython
Definition: qgsaction.h:40
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:146
Q_DECLARE_METATYPE(QgsMeshTimeSettings)