QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
128 QUuid id() const { return mId; }
129
135 bool isValid() const { return !mId.isNull(); }
136
138 QString iconPath() const { return mIcon; }
139
141 QIcon icon() const { return QIcon( mIcon ); }
142
150 QString command() const { return mCommand; }
151
157 QString notificationMessage() const { return mNotificationMessage; }
158
160 Qgis::AttributeActionType type() const { return mType; }
161
163 bool capture() const { return mCaptureOutput; }
164
165
167 bool isEnabledOnlyWhenEditable() const { return mIsEnabledOnlyWhenEditable; }
168
174 void setEnabledOnlyWhenEditable( bool enable ) { mIsEnabledOnlyWhenEditable = enable; };
175
176
178 bool runable() const;
179
185 void run( QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext ) const;
186
192 void run( const QgsExpressionContext &expressionContext ) const;
193
202 QSet<QString> actionScopes() const;
203
211 void setActionScopes( const QSet<QString> &actionScopes );
212
219 void readXml( const QDomNode &actionNode );
220
227 void writeXml( QDomNode &actionsNode ) const;
228
234 void setExpressionContextScope( const QgsExpressionContextScope &scope );
235
241 QgsExpressionContextScope expressionContextScope() const;
242
248 QString html( ) const;
249
254 void setCommand( const QString &newCommand );
255
256 private:
257
258 void handleFormSubmitAction( const QString &expandedAction ) const;
260 QString mDescription;
261 QString mShortTitle;
262 QString mIcon;
263 QString mCommand;
264 bool mCaptureOutput = false;
265 QSet<QString> mActionScopes;
266 QString mNotificationMessage;
267 QUuid mId;
268 QgsExpressionContextScope mExpressionContextScope;
269 bool mIsEnabledOnlyWhenEditable = false;
270};
271
273
274#endif // QGSACTION_H
AttributeActionType
Map layer action flags.
Definition qgis.h:3248
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:174
QString notificationMessage() const
Returns the notification message that triggers the action.
Definition qgsaction.h:157
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:160
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:141
QString iconPath() const
The path to the icon.
Definition qgsaction.h:138
bool isValid() const
Returns true if this action was a default constructed one.
Definition qgsaction.h:135
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:150
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:167
bool capture() const
Whether to capture output for display when this action is run.
Definition qgsaction.h:163
QUuid id() const
Returns a unique id for this action.
Definition qgsaction.h:128
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)