QGIS API Documentation 3.99.0-Master (a8882ad4560)
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 <memory>
20
21#include "qgis.h"
22#include "qgis_core.h"
24#include "qgsreadwritecontext.h"
25
26#include <QIcon>
27#include <QSet>
28#include <QString>
29#include <QUuid>
30
32
37class CORE_EXPORT QgsAction
38{
39 public:
40
41 QgsAction() = default;
42
52 QgsAction( Qgis::AttributeActionType type, const QString &description, const QString &command, bool capture = false, bool enabledOnlyWhenEditable SIP_PYARGREMOVE = false )
53 : mType( type )
54 , mDescription( description )
55 , mCommand( command )
56 , mCaptureOutput( capture )
57 , mId( QUuid::createUuid() )
58 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
59 {}
60
74 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 )
75 : mType( type )
76 , mDescription( description )
77 , mShortTitle( shortTitle )
78 , mIcon( icon )
79 , mCommand( action )
80 , mCaptureOutput( capture )
81 , mActionScopes( actionScopes )
82 , mNotificationMessage( notificationMessage )
83 , mId( QUuid::createUuid() )
84 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
85 {}
86
101 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 )
102 : mType( type )
103 , mDescription( description )
104 , mShortTitle( shortTitle )
105 , mIcon( icon )
106 , mCommand( action )
107 , mCaptureOutput( capture )
108 , mActionScopes( actionScopes )
109 , mNotificationMessage( notificationMessage )
110 , mId( id )
111 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
112 {}
113
114
116 QString name() const { return mDescription; }
117
119 QString shortTitle() const { return mShortTitle; }
120
125 QUuid id() const { return mId; }
126
131 bool isValid() const { return !mId.isNull(); }
132
134 QString iconPath() const { return mIcon; }
135
137 QIcon icon() const { return QIcon( mIcon ); }
138
145 QString command() const { return mCommand; }
146
151 QString notificationMessage() const { return mNotificationMessage; }
152
154 Qgis::AttributeActionType type() const { return mType; }
155
157 bool capture() const { return mCaptureOutput; }
158
159
161 bool isEnabledOnlyWhenEditable() const { return mIsEnabledOnlyWhenEditable; }
162
168 void setEnabledOnlyWhenEditable( bool enable ) { mIsEnabledOnlyWhenEditable = enable; };
169
170
172 bool runable() const;
173
178 void run( QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext ) const;
179
184 void run( const QgsExpressionContext &expressionContext ) const;
185
193 QSet<QString> actionScopes() const;
194
201 void setActionScopes( const QSet<QString> &actionScopes );
202
209 void readXml( const QDomNode &actionNode, const QgsReadWriteContext &context = QgsReadWriteContext() );
210
216 void writeXml( QDomNode &actionsNode ) const;
217
222 void setExpressionContextScope( const QgsExpressionContextScope &scope );
223
228 QgsExpressionContextScope expressionContextScope() const;
229
235 QString html( ) const;
236
241 void setCommand( const QString &newCommand );
242
243 private:
244
245 void handleFormSubmitAction( const QString &expandedAction ) const;
247 QString mDescription;
248 QString mShortTitle;
249 QString mIcon;
250 QString mCommand;
251 bool mCaptureOutput = false;
252 QSet<QString> mActionScopes;
253 QString mNotificationMessage;
254 QUuid mId;
255 QgsExpressionContextScope mExpressionContextScope;
256 bool mIsEnabledOnlyWhenEditable = false;
257};
258
260
261#endif // QGSACTION_H
AttributeActionType
Attribute action types.
Definition qgis.h:4735
Utility class that encapsulates an action based on vector attributes.
Definition qgsaction.h:38
void setEnabledOnlyWhenEditable(bool enable)
Set whether the action is only enabled in editable mode.
Definition qgsaction.h:168
QString notificationMessage() const
Returns the notification message that triggers the action.
Definition qgsaction.h:151
QString name() const
The name of the action. This may be a longer description.
Definition qgsaction.h:116
QSet< QString > actionScopes() const
The action scopes define where an action will be available.
Qgis::AttributeActionType type() const
The action type.
Definition qgsaction.h:154
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:101
QgsAction()=default
QIcon icon() const
The icon.
Definition qgsaction.h:137
QString iconPath() const
The path to the icon.
Definition qgsaction.h:134
bool isValid() const
Returns true if this action was a default constructed one.
Definition qgsaction.h:131
QgsAction(Qgis::AttributeActionType type, const QString &description, const QString &command, bool capture=false, bool enabledOnlyWhenEditable=false)
Create a new QgsAction.
Definition qgsaction.h:52
QString command() const
Returns the command that is executed by this action.
Definition qgsaction.h:145
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:74
QString shortTitle() const
The short title is used to label user interface elements like buttons.
Definition qgsaction.h:119
bool isEnabledOnlyWhenEditable() const
Returns whether only enabled in editable mode.
Definition qgsaction.h:161
bool capture() const
Whether to capture output for display when this action is run.
Definition qgsaction.h:157
QUuid id() const
Returns a unique id for this action.
Definition qgsaction.h:125
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
A container for the context for various read/write operations on objects.
Represents a vector layer which manages a vector based dataset.
#define SIP_PYARGREMOVE
Definition qgis_sip.h:159
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)