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 const auto constMActionScopes = mActionScopes;
148 for (
const QString &scope : constMActionScopes )
150 QDomElement actionScopeElem = actionsNode.ownerDocument().createElement( QStringLiteral(
"actionScope" ) );
151 actionScopeElem.setAttribute( QStringLiteral(
"id" ), scope );
152 actionSetting.appendChild( actionScopeElem );
155 actionsNode.appendChild( actionSetting );
160 mExpressionContextScope = scope;
165 return mExpressionContextScope;
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.
void run(QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext) const
Run this action.
bool runable() const
Checks if the action is runable on the current platform.
bool isValid() const
Returns true if this action was a default constructed one.
void setExpressionContextScope(const QgsExpressionContextScope &scope)
Sets an expression context scope to use for running the action.
void writeXml(QDomNode &actionsNode) const
Appends an XML definition for this action as a new child node to actionsNode.
QgsExpressionContextScope expressionContextScope() const
Returns an expression context scope used for running the action.
void setActionScopes(const QSet< QString > &actionScopes)
The action scopes define where an action will be available.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
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...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
static bool run(const QString &command, const QString &messageOnError=QString())
Execute a Python statement.
static QgsRunProcess * create(const QString &action, bool capture)
Represents a vector layer which manages a vector based data sets.