34 #include <QStringList> 35 #include <QDomElement> 37 #include <QDesktopServices> 45 mActions <<
QgsAction( type, name, action, capture );
50 mActions <<
QgsAction( type, name, action, icon, capture );
55 if ( index >= 0 && index < mActions.
size() )
64 if ( defaultValueIndex >= 0 )
68 substitutionMap.
insert(
"$currfield", defaultValue );
71 doAction( index, feat, &substitutionMap );
76 if ( index < 0 || index >=
size() )
91 runAction( newAction );
94 void QgsAttributeAction::runAction(
const QgsAction &action,
void ( *executePython )(
const QString & ) )
99 if ( finfo.exists() && finfo.isFile() )
109 executePython( action.
action() );
111 else if ( smPythonExecute )
114 smPythonExecute( action.
action() );
142 uint clickedOnValue )
160 if ( attributes.
contains( clickedOnValue ) )
161 expanded_action = action.
replace(
"%%", attributes[clickedOnValue].toString() );
163 expanded_action = action;
167 for (
int i = 0; i < 4; i++ )
169 for ( QgsAttributeMap::const_iterator it = attributes.
begin(); it != attributes.
end(); ++it )
171 int attrIdx = it.key();
172 if ( attrIdx < 0 || attrIdx >= fields.
count() )
179 to_replace =
"[%" + fields[attrIdx].name() +
']';
185 to_replace =
'%' + fields[attrIdx].name();
192 expanded_action = expanded_action.
replace( to_replace, it.value().toString() );
196 return expanded_action;
211 while ( index < action.
size() )
215 int pos = rx.
indexIn( action, index );
225 if ( substitutionMap && substitutionMap->
contains( to_replace ) )
227 expr_action += action.
mid( start, pos - start ) + substitutionMap->
value( to_replace ).toString();
235 expr_action += action.
midRef( start, index - start );
246 expr_action += action.
midRef( start, index - start );
251 expr_action += action.
mid( start, pos - start ) + result.
toString();
254 expr_action += action.
midRef( index );
263 for (
int i = 0; i < mActions.
size(); i++ )
266 actionSetting.
setAttribute(
"type", mActions[i].type() );
267 actionSetting.
setAttribute(
"name", mActions[i].name() );
269 actionSetting.
setAttribute(
"action", mActions[i].action() );
270 actionSetting.
setAttribute(
"capture", mActions[i].capture() );
287 for (
int i = 0; i < actionsettings.
size(); ++i )
300 void ( *QgsAttributeAction::smPythonExecute )(
const QString & ) =
nullptr;
304 smPythonExecute = runPython;
void addAction(QgsAction::ActionType type, const QString &name, const QString &action, bool capture=false)
Add an action with the given name and action details.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
QString cap(int nth) const
QDomNode item(int index) const
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
bool contains(const Key &key) const
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
QDomNode appendChild(const QDomNode &newChild)
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QgsFields fields() const
Returns the list of fields of this layer.
Container of fields for a vector layer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QString iconPath(const QString &iconFile)
QDomNodeList childNodes() const
bool capture() const
Whether to capture output for display when this action is run.
bool writeXML(QDomNode &layer_node, QDomDocument &doc) const
Writes the actions out in XML format.
QDomElement toElement() const
int matchedLength() const
int indexIn(const QString &str, int offset, CaretMode caretMode) const
QString name() const
The name of the action.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
void setAttribute(const QString &name, const QString &value)
int toInt(bool *ok, int base) const
Utility class that encapsulates an action based on vector attributes.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
int count() const
Return number of items.
QString expandAction(QString action, const QgsAttributeMap &attributes, uint defaultValueIndex)
Expands the given action, replacing all 's with the value as given.
QString action() const
The action.
static Q_DECL_DEPRECATED void setPythonExecute(void(*)(const QString &))
QDomNode namedItem(const QString &name) const
ActionType type() const
The action type.
QStringRef midRef(int position, int n) const
QString & replace(int position, int n, QChar after)
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QString mid(int position, int n) const
static bool run(const QString &command, const QString &messageOnError=QString())
Execute a python statement.
void doAction(int index, const QgsFeature &feat, int defaultValueIndex=0)
Does the given values.
static Q_DECL_DEPRECATED QString replaceExpressionText(const QString &action, const QgsFeature *feat, QgsVectorLayer *layer, const QMap< QString, QVariant > *substitutionMap=nullptr, const QgsDistanceArea *distanceArea=nullptr)
This function currently replaces each expression between [% and %] in the string with the result of i...
bool runable() const
Whether the action is runable on the current platform.
iterator insert(const Key &key, const T &value)
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
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.
QDomElement createElement(const QString &tagName)
bool openUrl(const QUrl &url)
QString parserErrorString() const
Returns parser error.
QDomAttr attributeNode(const QString &name)
QString evalErrorString() const
Returns evaluation error.
bool readXML(const QDomNode &layer_node)
Reads the actions in in XML format.
void removeAction(int index)
Remove an action at given index.
QUrl fromLocalFile(const QString &localFile)
const T value(const Key &key) const