34 #include <QStringList> 35 #include <QDomElement> 37 #include <QDesktopServices> 45 mActions <<
QgsAction( type, name, action, capture );
50 mActions <<
QgsAction( type, name, action, icon, capture );
60 if ( index >= 0 && index < mActions.
size() )
71 context << actionScope;
77 if ( index < 0 || index >=
size() )
95 runAction( newAction );
100 if ( index < 0 || index >=
size() )
111 if ( expandedAction.
isEmpty() )
115 runAction( newAction );
128 void QgsActionManager::runAction(
const QgsAction &action,
void ( *executePython )(
const QString & ) )
133 if ( finfo.exists() && finfo.isFile() )
143 executePython( action.
action() );
145 else if ( smPythonExecute )
148 smPythonExecute( action.
action() );
176 uint clickedOnValue )
194 if ( attributes.
contains( clickedOnValue ) )
195 expanded_action = action.
replace(
"%%", attributes[clickedOnValue].toString() );
197 expanded_action = action;
201 for (
int i = 0; i < 4; i++ )
203 for ( QgsAttributeMap::const_iterator it = attributes.
begin(); it != attributes.
end(); ++it )
205 int attrIdx = it.key();
206 if ( attrIdx < 0 || attrIdx >= fields.
count() )
213 to_replace =
"[%" + fields[attrIdx].name() +
']';
219 to_replace =
'%' + fields[attrIdx].name();
226 expanded_action = expanded_action.
replace( to_replace, it.value().toString() );
230 return expanded_action;
245 while ( index < action.
size() )
249 int pos = rx.
indexIn( action, index );
259 if ( substitutionMap && substitutionMap->
contains( to_replace ) )
261 expr_action += action.
mid( start, pos - start ) + substitutionMap->
value( to_replace ).toString();
269 expr_action += action.
midRef( start, index - start );
280 expr_action += action.
midRef( start, index - start );
285 expr_action += action.
mid( start, pos - start ) + result.
toString();
288 expr_action += action.
midRef( index );
298 Q_FOREACH (
const QgsAction& action, mActions )
326 for (
int i = 0; i < actionsettings.
size(); ++i )
344 void ( *QgsActionManager::smPythonExecute )(
const QString & ) =
nullptr;
348 smPythonExecute = runPython;
QList< QgsAction > listActions() const
Return a list of all actions.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
QString iconPath() const
The path to the icon.
Single variable definition for use within a QgsExpressionContextScope.
QString cap(int nth) const
QDomNode item(int index) const
bool contains(const Key &key) const
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
bool contains(const QString &name) const
bool capture() const
Whether to capture output for display when this action is run.
QDomNode appendChild(const QDomNode &newChild)
void addAction(QgsAction::ActionType type, const QString &name, const QString &action, bool capture=false)
Add an action with the given name and action details.
ActionType type() const
The action type.
QString attribute(const QString &name, const QString &defValue) const
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
bool readXML(const QDomNode &layer_node)
Reads the actions in in XML format.
QString evalErrorString() const
Returns evaluation error.
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 shortTitle() const
The short title is used to label user interface elements like buttons.
QDomNodeList childNodes() const
int count() const
Return number of items.
QString parserErrorString() const
Returns parser error.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
const QgsAction & at(int idx) const
Get the action at the specified index.
QgsFields fields() const
Returns the list of fields of this layer.
QDomElement toElement() const
int matchedLength() const
int indexIn(const QString &str, int offset, CaretMode caretMode) const
void append(const T &value)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
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...
void clearActions()
Removes all actions.
bool runable() const
Checks if the action is runable on the current platform.
void removeAction(int index)
Remove an action at given index.
QString name() const
The name of the action. This may be a longer description.
bool writeXML(QDomNode &layer_node, QDomDocument &doc) const
Writes the actions out in XML format.
bool showInAttributeTable() const
Whether this action should be shown on the attribute table.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static Q_DECL_DEPRECATED void setPythonExecute(void(*)(const QString &))
QDomNode namedItem(const QString &name) const
QStringRef midRef(int position, int n) const
QString & replace(int position, int n, QChar after)
QString mid(int position, int n) const
Q_DECL_DEPRECATED QString expandAction(QString action, const QgsAttributeMap &attributes, uint defaultValueIndex)
Expands the given action, replacing all 's with the value as given.
static bool run(const QString &command, const QString &messageOnError=QString())
Execute a python statement.
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...
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
QString action() const
The action.
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)
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
int size() const
Get the number of actions managed by this.
QDomAttr attributeNode(const QString &name)
void doAction(int index, const QgsFeature &feat, int defaultValueIndex=0, const QgsExpressionContextScope &scope=QgsExpressionContextScope())
Does the given action.
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
QUrl fromLocalFile(const QString &localFile)
const T value(const Key &key) const
QDomNamedNodeMap attributes() const