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() )
89 runAction( newAction );
92 void QgsAttributeAction::runAction(
const QgsAction &action,
void ( *executePython )(
const QString & ) )
97 if ( finfo.exists() && finfo.isFile() )
107 executePython( action.
action() );
109 else if ( smPythonExecute )
112 smPythonExecute( action.
action() );
129 uint clickedOnValue )
147 if ( attributes.
contains( clickedOnValue ) )
148 expanded_action = action.
replace(
"%%", attributes[clickedOnValue].toString() );
150 expanded_action = action;
154 for (
int i = 0; i < 4; i++ )
156 for ( QgsAttributeMap::const_iterator it = attributes.
begin(); it != attributes.
end(); ++it )
158 int attrIdx = it.key();
159 if ( attrIdx < 0 || attrIdx >= fields.
count() )
165 case 0: to_replace =
"[%" + fields[attrIdx].name() +
"]";
break;
167 case 2: to_replace =
"%" + fields[attrIdx].name();
break;
171 expanded_action = expanded_action.
replace( to_replace, it.value().toString() );
175 return expanded_action;
190 while ( index < action.
size() )
194 int pos = rx.
indexIn( action, index );
204 if ( substitutionMap && substitutionMap->
contains( to_replace ) )
206 expr_action += action.
mid( start, pos - start ) + substitutionMap->
value( to_replace ).toString();
214 expr_action += action.
mid( start, index - start );
222 expr_action += action.
mid( start, index - start );
227 expr_action += action.
mid( start, pos - start ) + result.
toString();
230 expr_action += action.
mid( index );
239 for (
int i = 0; i < mActions.
size(); i++ )
242 actionSetting.
setAttribute(
"type", mActions[i].type() );
243 actionSetting.
setAttribute(
"name", mActions[i].name() );
245 actionSetting.
setAttribute(
"action", mActions[i].action() );
246 actionSetting.
setAttribute(
"capture", mActions[i].capture() );
263 for (
unsigned int i = 0; i < actionsettings.
length(); ++i )
276 void ( *QgsAttributeAction::smPythonExecute )(
const QString & ) = 0;
280 smPythonExecute = runPython;
Class for parsing and evaluation of expressions (formerly called "search strings").
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
void addAction(QgsAction::ActionType type, QString name, QString action, bool capture=false)
Add an action with the given name and action details.
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
QDomNode appendChild(const QDomNode &newChild)
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
Container of fields for a vector layer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QDomNodeList childNodes() const
QString iconPath(QString iconFile)
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.
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
static bool run(QString command, QString messageOnError=QString())
execute a python statement
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.
int count() const
Return number of items.
QString expandAction(QString action, const QgsAttributeMap &attributes, uint defaultValueIndex)
QString action() const
The action.
static void setPythonExecute(void(*)(const QString &))
QDomNode namedItem(const QString &name) const
ActionType type() const
The action type.
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
void doAction(int index, const QgsFeature &feat, int defaultValueIndex=0)
bool runable() const
Whether the action is runable on the current platform.
iterator insert(const Key &key, const T &value)
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
static QgsRunProcess * create(const QString &action, bool capture)
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
static QString replaceExpressionText(const QString &action, const QgsFeature *feat, QgsVectorLayer *layer, const QMap< QString, QVariant > *substitutionMap=0, const QgsDistanceArea *distanceArea=0)
This function currently replaces each expression between [% and %] in the string with the result of i...