QGIS API Documentation 4.1.0-Master (60fea48833c)
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 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
75 const QString &description,
76 const QString &action,
77 const QString &icon,
78 bool capture,
79 const QString &shortTitle = QString(),
80 const QSet<QString> &actionScopes = QSet<QString>(),
81 const QString &notificationMessage = QString(),
82 bool enabledOnlyWhenEditable SIP_PYARGREMOVE = false
83 )
84 : mType( type )
85 , mDescription( description )
86 , mShortTitle( shortTitle )
87 , mIcon( icon )
88 , mCommand( action )
89 , mCaptureOutput( capture )
90 , mActionScopes( actionScopes )
91 , mNotificationMessage( notificationMessage )
92 , mId( QUuid::createUuid() )
93 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
94 {}
95
111 const QUuid &id,
113 const QString &description,
114 const QString &action,
115 const QString &icon,
116 bool capture,
117 const QString &shortTitle = QString(),
118 const QSet<QString> &actionScopes = QSet<QString>(),
119 const QString &notificationMessage = QString(),
120 bool enabledOnlyWhenEditable SIP_PYARGREMOVE = false
121 )
122 : mType( type )
123 , mDescription( description )
124 , mShortTitle( shortTitle )
125 , mIcon( icon )
126 , mCommand( action )
127 , mCaptureOutput( capture )
128 , mActionScopes( actionScopes )
129 , mNotificationMessage( notificationMessage )
130 , mId( id )
131 , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
132 {}
133
134
136 QString name() const { return mDescription; }
137
139 QString shortTitle() const { return mShortTitle; }
140
145 QUuid id() const { return mId; }
146
151 bool isValid() const { return !mId.isNull(); }
152
154 QString iconPath() const { return mIcon; }
155
157 QIcon icon() const { return QIcon( mIcon ); }
158
165 QString command() const { return mCommand; }
166
171 QString notificationMessage() const { return mNotificationMessage; }
172
174 Qgis::AttributeActionType type() const { return mType; }
175
177 bool capture() const { return mCaptureOutput; }
178
179
181 bool isEnabledOnlyWhenEditable() const { return mIsEnabledOnlyWhenEditable; }
182
188 void setEnabledOnlyWhenEditable( bool enable ) { mIsEnabledOnlyWhenEditable = enable; };
189
190
192 bool runable() const;
193
198 void run( QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext ) const;
199
204 void run( const QgsExpressionContext &expressionContext ) const;
205
213 QSet<QString> actionScopes() const;
214
221 void setActionScopes( const QSet<QString> &actionScopes );
222
229 void readXml( const QDomNode &actionNode, const QgsReadWriteContext &context = QgsReadWriteContext() );
230
236 void writeXml( QDomNode &actionsNode ) const;
237
242 void setExpressionContextScope( const QgsExpressionContextScope &scope );
243
248 QgsExpressionContextScope expressionContextScope() const;
249
255 QString html() const;
256
261 void setCommand( const QString &newCommand );
262
263 private:
264 void handleFormSubmitAction( const QString &expandedAction ) const;
266 QString mDescription;
267 QString mShortTitle;
268 QString mIcon;
269 QString mCommand;
270 bool mCaptureOutput = false;
271 QSet<QString> mActionScopes;
272 QString mNotificationMessage;
273 QUuid mId;
274 QgsExpressionContextScope mExpressionContextScope;
275 bool mIsEnabledOnlyWhenEditable = false;
276};
277
279
280#endif // QGSACTION_H
AttributeActionType
Attribute action types.
Definition qgis.h:4832
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:188
QString notificationMessage() const
Returns the notification message that triggers the action.
Definition qgsaction.h:171
QString name() const
The name of the action. This may be a longer description.
Definition qgsaction.h:136
QSet< QString > actionScopes() const
The action scopes define where an action will be available.
Qgis::AttributeActionType type() const
The action type.
Definition qgsaction.h:174
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:110
QgsAction()=default
QIcon icon() const
The icon.
Definition qgsaction.h:157
QString iconPath() const
The path to the icon.
Definition qgsaction.h:154
bool isValid() const
Returns true if this action was a default constructed one.
Definition qgsaction.h:151
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:165
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:139
bool isEnabledOnlyWhenEditable() const
Returns whether only enabled in editable mode.
Definition qgsaction.h:181
bool capture() const
Whether to capture output for display when this action is run.
Definition qgsaction.h:177
QUuid id() const
Returns a unique id for this action.
Definition qgsaction.h:145
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:60
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:158
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)