19 #include <QDesktopServices> 37 #elif defined(Q_OS_MAC) 59 QgsDebugMsg( QStringLiteral(
"Invalid action cannot be run" ) );
71 QFileInfo finfo( expandedAction );
72 if ( finfo.exists() && finfo.isFile() )
73 QDesktopServices::openUrl( QUrl::fromLocalFile( expandedAction ) );
75 QDesktopServices::openUrl( QUrl( expandedAction, QUrl::TolerantMode ) );
102 QDomElement actionElement = actionNode.toElement();
103 QDomNodeList actionScopeNodes = actionElement.elementsByTagName( QStringLiteral(
"actionScope" ) );
105 if ( actionScopeNodes.isEmpty() )
108 << QStringLiteral(
"Canvas" )
109 << QStringLiteral(
"Field" )
110 << QStringLiteral(
"Feature" );
114 for (
int j = 0; j < actionScopeNodes.length(); ++j )
116 QDomElement actionScopeElem = actionScopeNodes.item( j ).toElement();
117 mActionScopes << actionScopeElem.attribute( QStringLiteral(
"id" ) );
121 mType =
static_cast< QgsAction::ActionType >( actionElement.attributeNode( QStringLiteral(
"type" ) ).value().toInt() );
122 mDescription = actionElement.attributeNode( QStringLiteral(
"name" ) ).value();
123 mCommand = actionElement.attributeNode( QStringLiteral(
"action" ) ).value();
124 mIcon = actionElement.attributeNode( QStringLiteral(
"icon" ) ).value();
125 mCaptureOutput = actionElement.attributeNode( QStringLiteral(
"capture" ) ).value().toInt() != 0;
126 mShortTitle = actionElement.attributeNode( QStringLiteral(
"shortTitle" ) ).value();
127 mNotificationMessage = actionElement.attributeNode( QStringLiteral(
"notificationMessage" ) ).value();
128 mIsEnabledOnlyWhenEditable = actionElement.attributeNode( QStringLiteral(
"isEnabledOnlyWhenEditable" ) ).value().toInt() != 0;
129 mId = QUuid( actionElement.attributeNode( QStringLiteral(
"id" ) ).value() );
131 mId = QUuid::createUuid();
136 QDomElement actionSetting = actionsNode.ownerDocument().createElement( QStringLiteral(
"actionsetting" ) );
137 actionSetting.setAttribute( QStringLiteral(
"type" ), mType );
138 actionSetting.setAttribute( QStringLiteral(
"name" ), mDescription );
139 actionSetting.setAttribute( QStringLiteral(
"shortTitle" ), mShortTitle );
140 actionSetting.setAttribute( QStringLiteral(
"icon" ), mIcon );
141 actionSetting.setAttribute( QStringLiteral(
"action" ), mCommand );
142 actionSetting.setAttribute( QStringLiteral(
"capture" ), mCaptureOutput );
143 actionSetting.setAttribute( QStringLiteral(
"notificationMessage" ), mNotificationMessage );
144 actionSetting.setAttribute( QStringLiteral(
"isEnabledOnlyWhenEditable" ), mIsEnabledOnlyWhenEditable );
145 actionSetting.setAttribute( QStringLiteral(
"id" ), mId.toString() );
147 Q_FOREACH (
const QString &scope, mActionScopes )
149 QDomElement actionScopeElem = actionsNode.ownerDocument().createElement( QStringLiteral(
"actionScope" ) );
150 actionScopeElem.setAttribute( QStringLiteral(
"id" ), scope );
151 actionSetting.appendChild( actionScopeElem );
154 actionsNode.appendChild( actionSetting );
159 mExpressionContextScope = scope;
164 return mExpressionContextScope;
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QSet< QString > actionScopes() const
The action scopes define where an action will be available.
void readXml(const QDomNode &actionNode)
Reads an XML definition from actionNode into this object.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool isValid() const
Returns true if this action was a default constructed one.
void run(QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext) const
Run this action.
void writeXml(QDomNode &actionsNode) const
Appends an XML definition for this action as a new child node to actionsNode.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool runable() const
Checks if the action is runable on the current platform.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static bool run(const QString &command, const QString &messageOnError=QString())
Execute a Python statement.
static QgsRunProcess * create(const QString &action, bool capture)
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
QgsExpressionContextScope expressionContextScope() const
Returns an expression context scope used for running the action.
void setExpressionContextScope(const QgsExpressionContextScope &scope)
Sets an expression context scope to use for running the action.
Represents a vector layer which manages a vector based data sets.
void setActionScopes(const QSet< QString > &actionScopes)
The action scopes define where an action will be available.
static QString replaceExpressionText(const QString &action, const QgsExpressionContext *context, const QgsDistanceArea *distanceArea=nullptr)
This function replaces each expression between [% and %] in the string with the result of its evaluat...