19 #include <QDesktopServices> 36 #elif defined(Q_OS_MAC) 58 QgsDebugMsg( QStringLiteral(
"Invalid action cannot be run" ) );
70 QFileInfo finfo( expandedAction );
71 if ( finfo.exists() && finfo.isFile() )
72 QDesktopServices::openUrl( QUrl::fromLocalFile( expandedAction ) );
74 QDesktopServices::openUrl( QUrl( expandedAction, QUrl::TolerantMode ) );
101 QDomElement actionElement = actionNode.toElement();
102 QDomNodeList actionScopeNodes = actionElement.elementsByTagName( QStringLiteral(
"actionScope" ) );
104 if ( actionScopeNodes.isEmpty() )
107 << QStringLiteral(
"Canvas" )
108 << QStringLiteral(
"Field" )
109 << QStringLiteral(
"Feature" );
113 for (
int j = 0; j < actionScopeNodes.length(); ++j )
115 QDomElement actionScopeElem = actionScopeNodes.item( j ).toElement();
116 mActionScopes << actionScopeElem.attribute( QStringLiteral(
"id" ) );
120 mType =
static_cast< QgsAction::ActionType >( actionElement.attributeNode( QStringLiteral(
"type" ) ).value().toInt() );
121 mDescription = actionElement.attributeNode( QStringLiteral(
"name" ) ).value();
122 mCommand = actionElement.attributeNode( QStringLiteral(
"action" ) ).value();
123 mIcon = actionElement.attributeNode( QStringLiteral(
"icon" ) ).value();
124 mCaptureOutput = actionElement.attributeNode( QStringLiteral(
"capture" ) ).value().toInt() != 0;
125 mShortTitle = actionElement.attributeNode( QStringLiteral(
"shortTitle" ) ).value();
126 mNotificationMessage = actionElement.attributeNode( QStringLiteral(
"notificationMessage" ) ).value();
127 mIsEnabledOnlyWhenEditable = actionElement.attributeNode( QStringLiteral(
"isEnabledOnlyWhenEditable" ) ).value().toInt() != 0;
128 mId = QUuid( actionElement.attributeNode( QStringLiteral(
"id" ) ).value() );
130 mId = QUuid::createUuid();
135 QDomElement actionSetting = actionsNode.ownerDocument().createElement( QStringLiteral(
"actionsetting" ) );
136 actionSetting.setAttribute( QStringLiteral(
"type" ), mType );
137 actionSetting.setAttribute( QStringLiteral(
"name" ), mDescription );
138 actionSetting.setAttribute( QStringLiteral(
"shortTitle" ), mShortTitle );
139 actionSetting.setAttribute( QStringLiteral(
"icon" ), mIcon );
140 actionSetting.setAttribute( QStringLiteral(
"action" ), mCommand );
141 actionSetting.setAttribute( QStringLiteral(
"capture" ), mCaptureOutput );
142 actionSetting.setAttribute( QStringLiteral(
"notificationMessage" ), mNotificationMessage );
143 actionSetting.setAttribute( QStringLiteral(
"isEnabledOnlyWhenEditable" ), mIsEnabledOnlyWhenEditable );
144 actionSetting.setAttribute( QStringLiteral(
"id" ), mId.toString() );
146 Q_FOREACH (
const QString &scope, mActionScopes )
148 QDomElement actionScopeElem = actionsNode.ownerDocument().createElement( QStringLiteral(
"actionScope" ) );
149 actionScopeElem.setAttribute( QStringLiteral(
"id" ), scope );
150 actionSetting.appendChild( actionScopeElem );
153 actionsNode.appendChild( actionSetting );
158 mExpressionContextScope = scope;
163 return mExpressionContextScope;
QSet< QString > actionScopes() const
The action scopes define where an action will be available.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void run(QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext) const
Run this action.
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.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsExpressionContextScope expressionContextScope() const
Returns an expression context scope used for running the action.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void writeXml(QDomNode &actionsNode) const
Appends an XML definition for this action as a new child node to actionsNode.
static bool run(const QString &command, const QString &messageOnError=QString())
Execute a Python statement.
bool runable() const
Checks if the action is runable on the current platform.
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.
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...