QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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 "qgis.h"
22
23#include <QSet>
24#include <QString>
25#include <QIcon>
26#include <QUuid>
27
28#include <memory>
29
31
36class CORE_EXPORT QgsAction
37{
38 public:
39
40 QgsAction() = default;
41
51 QgsAction( Qgis::AttributeActionType type, const QString &description, const QString &command, bool capture = false, bool enabledOnlyWhenEditable SIP_PYARGREMOVE = false )
52 : mType( type )
53 , mDescription( description )
54 , mCommand( command )
55 , mCaptureOutput( capture )
56 , mId( QUuid::createUuid() )
57 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
58 {}
59
73 QgsAction( Qgis::AttributeActionType 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 )
74 : mType( type )
75 , mDescription( description )
76 , mShortTitle( shortTitle )
77 , mIcon( icon )
78 , mCommand( action )
79 , mCaptureOutput( capture )
80 , mActionScopes( actionScopes )
81 , mNotificationMessage( notificationMessage )
82 , mId( QUuid::createUuid() )
83 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
84 {}
85
100 QgsAction( const QUuid &id, Qgis::AttributeActionType 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 )
101 : mType( type )
102 , mDescription( description )
103 , mShortTitle( shortTitle )
104 , mIcon( icon )
105 , mCommand( action )
106 , mCaptureOutput( capture )
107 , mActionScopes( actionScopes )
108 , mNotificationMessage( notificationMessage )
109 , mId( id )
110 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
111 {}
112
113
115 QString name() const { return mDescription; }
116
118 QString shortTitle() const { return mShortTitle; }
119
124 QUuid id() const { return mId; }
125
130 bool isValid() const { return !mId.isNull(); }
131
133 QString iconPath() const { return mIcon; }
134
136 QIcon icon() const { return QIcon( mIcon ); }
137
144 QString command() const { return mCommand; }
145
150 QString notificationMessage() const { return mNotificationMessage; }
151
153 Qgis::AttributeActionType type() const { return mType; }
154
156 bool capture() const { return mCaptureOutput; }
157
158
160 bool isEnabledOnlyWhenEditable() const { return mIsEnabledOnlyWhenEditable; }
161
167 void setEnabledOnlyWhenEditable( bool enable ) { mIsEnabledOnlyWhenEditable = enable; };
168
169
171 bool runable() const;
172
177 void run( QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext ) const;
178
183 void run( const QgsExpressionContext &expressionContext ) const;
184
192 QSet<QString> actionScopes() const;
193
200 void setActionScopes( const QSet<QString> &actionScopes );
201
207 void readXml( const QDomNode &actionNode );
208
214 void writeXml( QDomNode &actionsNode ) const;
215
220 void setExpressionContextScope( const QgsExpressionContextScope &scope );
221
226 QgsExpressionContextScope expressionContextScope() const;
227
233 QString html( ) const;
234
239 void setCommand( const QString &newCommand );
240
241 private:
242
243 void handleFormSubmitAction( const QString &expandedAction ) const;
245 QString mDescription;
246 QString mShortTitle;
247 QString mIcon;
248 QString mCommand;
249 bool mCaptureOutput = false;
250 QSet<QString> mActionScopes;
251 QString mNotificationMessage;
252 QUuid mId;
253 QgsExpressionContextScope mExpressionContextScope;
254 bool mIsEnabledOnlyWhenEditable = false;
255};
256
258
259#endif // QGSACTION_H
AttributeActionType
Attribute action types.
Definition qgis.h:4331
Utility class that encapsulates an action based on vector attributes.
Definition qgsaction.h:37
void setEnabledOnlyWhenEditable(bool enable)
Set whether the action is only enabled in editable mode.
Definition qgsaction.h:167
QString notificationMessage() const
Returns the notification message that triggers the action.
Definition qgsaction.h:150
QString name() const
The name of the action. This may be a longer description.
Definition qgsaction.h:115
Qgis::AttributeActionType type() const
The action type.
Definition qgsaction.h:153
QgsAction(const QUuid &id, Qgis::AttributeActionType 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:100
QgsAction()=default
QIcon icon() const
The icon.
Definition qgsaction.h:136
QString iconPath() const
The path to the icon.
Definition qgsaction.h:133
bool isValid() const
Returns true if this action was a default constructed one.
Definition qgsaction.h:130
QgsAction(Qgis::AttributeActionType type, const QString &description, const QString &command, bool capture=false, bool enabledOnlyWhenEditable=false)
Create a new QgsAction.
Definition qgsaction.h:51
QString command() const
Returns the command that is executed by this action.
Definition qgsaction.h:144
QgsAction(Qgis::AttributeActionType 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:73
QString shortTitle() const
The short title is used to label user interface elements like buttons.
Definition qgsaction.h:118
bool isEnabledOnlyWhenEditable() const
Returns whether only enabled in editable mode.
Definition qgsaction.h:160
bool capture() const
Whether to capture output for display when this action is run.
Definition qgsaction.h:156
QUuid id() const
Returns a unique id for this action.
Definition qgsaction.h:124
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:58
Represents a vector layer which manages a vector based data sets.
#define SIP_PYARGREMOVE
Definition qgis_sip.h:151
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)