QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 #ifndef SIP_RUN
62  QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false, bool enabledOnlyWhenEditable = false )
63  : mType( type )
64  , mDescription( description )
65  , mCommand( command )
66  , mCaptureOutput( capture )
67  , mId( QUuid::createUuid() )
68  , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
69  {}
70 #else
71  QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false )
72  : mType( type )
73  , mDescription( description )
74  , mCommand( command )
75  , mCaptureOutput( capture )
76  , mId( QUuid::createUuid() )
77  , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
78  {}
79 #endif
80 
94 #ifndef SIP_RUN
95  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 )
96  : mType( type )
97  , mDescription( description )
98  , mShortTitle( shortTitle )
99  , mIcon( icon )
100  , mCommand( action )
101  , mCaptureOutput( capture )
102  , mActionScopes( actionScopes )
103  , mNotificationMessage( notificationMessage )
104  , mId( QUuid::createUuid() )
105  , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
106  {}
107 #else
108  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() )
109  : mType( type )
110  , mDescription( description )
111  , mShortTitle( shortTitle )
112  , mIcon( icon )
113  , mCommand( action )
114  , mCaptureOutput( capture )
115  , mActionScopes( actionScopes )
116  , mNotificationMessage( notificationMessage )
117  , mId( QUuid::createUuid() )
118  , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
119  {}
120 #endif
121 
123  QString name() const { return mDescription; }
124 
126  QString shortTitle() const { return mShortTitle; }
127 
133  QUuid id() const { return mId; }
134 
140  bool isValid() const { return !mId.isNull(); }
141 
143  QString iconPath() const { return mIcon; }
144 
146  QIcon icon() const { return QIcon( mIcon ); }
147 
155  QString command() const { return mCommand; }
156 
162  QString notificationMessage() const { return mNotificationMessage; }
163 
165  ActionType type() const { return mType; }
166 
168  bool capture() const { return mCaptureOutput; }
169 
170 
172  bool isEnabledOnlyWhenEditable() const { return mIsEnabledOnlyWhenEditable; }
173 
179  void setEnabledOnlyWhenEditable( bool enable ) { mIsEnabledOnlyWhenEditable = enable; };
180 
181 
183  bool runable() const;
184 
190  void run( QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext ) const;
191 
197  void run( const QgsExpressionContext &expressionContext ) const;
198 
207  QSet<QString> actionScopes() const;
208 
216  void setActionScopes( const QSet<QString> &actionScopes );
217 
224  void readXml( const QDomNode &actionNode );
225 
232  void writeXml( QDomNode &actionsNode ) const;
233 
239  void setExpressionContextScope( const QgsExpressionContextScope &scope );
240 
246  QgsExpressionContextScope expressionContextScope() const;
247 
248  private:
249  ActionType mType = Generic;
250  QString mDescription;
251  QString mShortTitle;
252  QString mIcon;
253  QString mCommand;
254  bool mCaptureOutput = false;
255  QSet<QString> mActionScopes;
256  QString mNotificationMessage;
257  QUuid mId;
258  QgsExpressionContextScope mExpressionContextScope;
259  bool mIsEnabledOnlyWhenEditable = false;
260 };
261 
263 
264 #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:62
void setEnabledOnlyWhenEditable(bool enable)
Set whether the action is only enabled in editable mode.
Definition: qgsaction.h:179
QString notificationMessage() const
Returns the notification message that triggers the action.
Definition: qgsaction.h:162
QString name() const
The name of the action. This may be a longer description.
Definition: qgsaction.h:123
QgsAction()=default
Default constructor.
QIcon icon() const
The icon.
Definition: qgsaction.h:146
QString iconPath() const
The path to the icon.
Definition: qgsaction.h:143
bool isValid() const
Returns true if this action was a default constructed one.
Definition: qgsaction.h:140
ActionType type() const
The action type.
Definition: qgsaction.h:165
QString command() const
Returns the command that is executed by this action.
Definition: qgsaction.h:155
QString shortTitle() const
The short title is used to label user interface elements like buttons.
Definition: qgsaction.h:126
bool isEnabledOnlyWhenEditable() const
Returns whether only enabled in editable mode.
Definition: qgsaction.h:172
bool capture() const
Whether to capture output for display when this action is run.
Definition: qgsaction.h:168
QUuid id() const
Returns a unique id for this action.
Definition: qgsaction.h:133
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:95
@ 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.
Q_DECLARE_METATYPE(QgsMeshTimeSettings)