QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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
43 QgsAction() = default;
44
54 QgsAction( Qgis::AttributeActionType type, const QString &description, const QString &command, bool capture = false, bool enabledOnlyWhenEditable SIP_PYARGREMOVE = false )
55 : mType( type )
56 , mDescription( description )
57 , mCommand( command )
58 , mCaptureOutput( capture )
59 , mId( QUuid::createUuid() )
60 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
61 {}
62
76 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 )
77 : mType( type )
78 , mDescription( description )
79 , mShortTitle( shortTitle )
80 , mIcon( icon )
81 , mCommand( action )
82 , mCaptureOutput( capture )
83 , mActionScopes( actionScopes )
84 , mNotificationMessage( notificationMessage )
85 , mId( QUuid::createUuid() )
86 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
87 {}
88
103 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 )
104 : mType( type )
105 , mDescription( description )
106 , mShortTitle( shortTitle )
107 , mIcon( icon )
108 , mCommand( action )
109 , mCaptureOutput( capture )
110 , mActionScopes( actionScopes )
111 , mNotificationMessage( notificationMessage )
112 , mId( id )
113 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
114 {}
115
116
118 QString name() const { return mDescription; }
119
121 QString shortTitle() const { return mShortTitle; }
122
127 QUuid id() const { return mId; }
128
133 bool isValid() const { return !mId.isNull(); }
134
136 QString iconPath() const { return mIcon; }
137
139 QIcon icon() const { return QIcon( mIcon ); }
140
147 QString command() const { return mCommand; }
148
153 QString notificationMessage() const { return mNotificationMessage; }
154
156 Qgis::AttributeActionType type() const { return mType; }
157
159 bool capture() const { return mCaptureOutput; }
160
161
163 bool isEnabledOnlyWhenEditable() const { return mIsEnabledOnlyWhenEditable; }
164
170 void setEnabledOnlyWhenEditable( bool enable ) { mIsEnabledOnlyWhenEditable = enable; };
171
172
174 bool runable() const;
175
180 void run( QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext ) const;
181
186 void run( const QgsExpressionContext &expressionContext ) const;
187
195 QSet<QString> actionScopes() const;
196
203 void setActionScopes( const QSet<QString> &actionScopes );
204
210 void readXml( const QDomNode &actionNode );
211
217 void writeXml( QDomNode &actionsNode ) const;
218
223 void setExpressionContextScope( const QgsExpressionContextScope &scope );
224
229 QgsExpressionContextScope expressionContextScope() const;
230
236 QString html( ) const;
237
242 void setCommand( const QString &newCommand );
243
244 private:
245
246 void handleFormSubmitAction( const QString &expandedAction ) const;
248 QString mDescription;
249 QString mShortTitle;
250 QString mIcon;
251 QString mCommand;
252 bool mCaptureOutput = false;
253 QSet<QString> mActionScopes;
254 QString mNotificationMessage;
255 QUuid mId;
256 QgsExpressionContextScope mExpressionContextScope;
257 bool mIsEnabledOnlyWhenEditable = false;
258};
259
261
262#endif // QGSACTION_H
AttributeActionType
Map layer action flags.
Definition qgis.h:3814
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:170
QString notificationMessage() const
Returns the notification message that triggers the action.
Definition qgsaction.h:153
QString name() const
The name of the action. This may be a longer description.
Definition qgsaction.h:118
Qgis::AttributeActionType type() const
The action type.
Definition qgsaction.h:156
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:103
QgsAction()=default
Default constructor.
QIcon icon() const
The icon.
Definition qgsaction.h:139
QString iconPath() const
The path to the icon.
Definition qgsaction.h:136
bool isValid() const
Returns true if this action was a default constructed one.
Definition qgsaction.h:133
QgsAction(Qgis::AttributeActionType type, const QString &description, const QString &command, bool capture=false, bool enabledOnlyWhenEditable=false)
Create a new QgsAction.
Definition qgsaction.h:54
QString command() const
Returns the command that is executed by this action.
Definition qgsaction.h:147
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:76
QString shortTitle() const
The short title is used to label user interface elements like buttons.
Definition qgsaction.h:121
bool isEnabledOnlyWhenEditable() const
Returns whether only enabled in editable mode.
Definition qgsaction.h:163
bool capture() const
Whether to capture output for display when this action is run.
Definition qgsaction.h:159
QUuid id() const
Returns a unique id for this action.
Definition qgsaction.h:127
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:151
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)