QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 <QAction>
24 #include <QUuid>
25 
26 #include "qgsexpressioncontext.h"
27 #include <memory>
28 
30 
35 class CORE_EXPORT QgsAction
36 {
37  public:
39  {
42  Mac,
46  };
47 
51  QgsAction() = default;
52 
62 #ifndef SIP_RUN
63  QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false, bool enabledOnlyWhenEditable = false )
64  : mType( type )
65  , mDescription( description )
66  , mCommand( command )
67  , mCaptureOutput( capture )
68  , mId( QUuid::createUuid() )
69  , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
70  {}
71 #else
72  QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false )
73  : mType( type )
74  , mDescription( description )
75  , mCommand( command )
76  , mCaptureOutput( capture )
77  , mId( QUuid::createUuid() )
78  , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
79  {}
80 #endif
81 
95 #ifndef SIP_RUN
96  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 )
97  : mType( type )
98  , mDescription( description )
99  , mShortTitle( shortTitle )
100  , mIcon( icon )
101  , mCommand( action )
102  , mCaptureOutput( capture )
103  , mActionScopes( actionScopes )
104  , mNotificationMessage( notificationMessage )
105  , mId( QUuid::createUuid() )
106  , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
107  {}
108 #else
109  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() )
110  : mType( type )
111  , mDescription( description )
112  , mShortTitle( shortTitle )
113  , mIcon( icon )
114  , mCommand( action )
115  , mCaptureOutput( capture )
116  , mActionScopes( actionScopes )
117  , mNotificationMessage( notificationMessage )
118  , mId( QUuid::createUuid() )
119  , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
120  {}
121 #endif
122 
124  QString name() const { return mDescription; }
125 
127  QString shortTitle() const { return mShortTitle; }
128 
134  QUuid id() const { return mId; }
135 
141  bool isValid() const { return !mId.isNull(); }
142 
144  QString iconPath() const { return mIcon; }
145 
147  QIcon icon() const { return QIcon( mIcon ); }
148 
156  QString command() const { return mCommand; }
157 
163  QString notificationMessage() const { return mNotificationMessage; }
164 
166  ActionType type() const { return mType; }
167 
169  bool capture() const { return mCaptureOutput; }
170 
171 
173  bool isEnabledOnlyWhenEditable() const { return mIsEnabledOnlyWhenEditable; }
174 
175 
177  bool runable() const;
178 
184  void run( QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext ) const;
185 
191  void run( const QgsExpressionContext &expressionContext ) const;
192 
201  QSet<QString> actionScopes() const;
202 
210  void setActionScopes( const QSet<QString> &actionScopes );
211 
218  void readXml( const QDomNode &actionNode );
219 
226  void writeXml( QDomNode &actionsNode ) const;
227 
233  void setExpressionContextScope( const QgsExpressionContextScope &scope );
234 
240  QgsExpressionContextScope expressionContextScope() const;
241 
242  private:
243  ActionType mType = Generic;
244  QString mDescription;
245  QString mShortTitle;
246  QString mIcon;
247  QString mCommand;
248  bool mCaptureOutput = false;
249  QSet<QString> mActionScopes;
250  QString mNotificationMessage;
251  mutable std::shared_ptr<QAction> mAction;
252  QUuid mId;
253  QgsExpressionContextScope mExpressionContextScope;
254  bool mIsEnabledOnlyWhenEditable = false;
255 };
256 
258 
259 #endif // QGSACTION_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
QgsAction::notificationMessage
QString notificationMessage() const
Returns the notification message that triggers the action.
Definition: qgsaction.h:163
QgsAction::Generic
@ Generic
Definition: qgsaction.h:40
QgsAction::name
QString name() const
The name of the action. This may be a longer description.
Definition: qgsaction.h:124
QgsAction::OpenUrl
@ OpenUrl
Definition: qgsaction.h:45
QgsAction::shortTitle
QString shortTitle() const
The short title is used to label user interface elements like buttons.
Definition: qgsaction.h:127
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:173
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:96
QgsAction::iconPath
QString iconPath() const
The path to the icon.
Definition: qgsaction.h:144
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
QgsAction::isValid
bool isValid() const
Returns true if this action was a default constructed one.
Definition: qgsaction.h:141
QgsAction::Windows
@ Windows
Definition: qgsaction.h:43
QgsAction::Mac
@ Mac
Definition: qgsaction.h:42
qgsexpressioncontext.h
QgsAction::type
ActionType type() const
The action type.
Definition: qgsaction.h:166
QgsAction::GenericPython
@ GenericPython
Definition: qgsaction.h:41
QgsAction::Unix
@ Unix
Definition: qgsaction.h:44
QgsAction::icon
QIcon icon() const
The icon.
Definition: qgsaction.h:147
QgsAction::ActionType
ActionType
Definition: qgsaction.h:38
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:111
QgsAction
Definition: qgsaction.h:35
QgsAction::capture
bool capture() const
Whether to capture output for display when this action is run.
Definition: qgsaction.h:169
QgsAction::id
QUuid id() const
Returns a unique id for this action.
Definition: qgsaction.h:134
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsFeature
Definition: qgsfeature.h:55
QgsAction::command
QString command() const
Returns the command that is executed by this action.
Definition: qgsaction.h:156