34 #include <QStringList>
35 #include <QDomElement>
37 #include <QDesktopServices>
50 if ( index >= 0 && index <
mActions.size() )
58 QMap<QString, QVariant> substitutionMap;
59 if ( defaultValueIndex >= 0 )
61 QVariant defaultValue = feat.
attribute( defaultValueIndex );
62 if ( defaultValue.isValid() )
63 substitutionMap.insert(
"$currfield", defaultValue );
66 doAction( index, feat, &substitutionMap );
70 const QMap<QString, QVariant> *substitutionMap )
72 if ( index < 0 || index >=
size() )
81 if ( expandedAction.isEmpty() )
92 QFileInfo finfo( action.
action() );
93 if ( finfo.exists() && finfo.isFile() )
94 QDesktopServices::openUrl( QUrl::fromLocalFile( action.
action() ) );
96 QDesktopServices::openUrl( QUrl( action.
action(), QUrl::TolerantMode ) );
103 executePython( action.
action() );
125 uint clickedOnValue )
142 QString expanded_action;
143 if ( attributes.contains( clickedOnValue ) )
144 expanded_action = action.replace(
"%%", attributes[clickedOnValue].toString() );
146 expanded_action = action;
150 for (
int i = 0; i < 4; i++ )
152 for ( QgsAttributeMap::const_iterator it = attributes.begin(); it != attributes.end(); it++ )
154 int attrIdx = it.key();
155 if ( attrIdx < 0 || attrIdx >= fields.
count() )
161 case 0: to_replace =
"[%" + fields[attrIdx].name() +
"]";
break;
163 case 2: to_replace =
"%" + fields[attrIdx].name();
break;
167 expanded_action = expanded_action.replace( to_replace, it.value().toString() );
171 return expanded_action;
186 while ( index < action.size() )
188 QRegExp rx = QRegExp(
"\\[%([^\\]]+)%\\]" );
190 int pos = rx.indexIn( action, index );
195 index = pos + rx.matchedLength();
197 QString to_replace = rx.cap( 1 ).trimmed();
200 if ( substitutionMap && substitutionMap->contains( to_replace ) )
202 expr_action += action.mid( start, pos - start ) + substitutionMap->value( to_replace ).toString();
210 expr_action += action.mid( start, index - start );
218 expr_action += action.mid( start, index - start );
222 QgsDebugMsg(
"Expression result is: " + result.toString() );
223 expr_action += action.mid( start, pos - start ) + result.toString();
226 expr_action += action.mid( index );
233 QDomElement aActions = doc.createElement(
"attributeactions" );
235 for (
int i = 0; i <
mActions.size(); i++ )
237 QDomElement actionSetting = doc.createElement(
"actionsetting" );
238 actionSetting.setAttribute(
"type",
mActions[i].type() );
239 actionSetting.setAttribute(
"name",
mActions[i].name() );
240 actionSetting.setAttribute(
"action",
mActions[i].action() );
241 actionSetting.setAttribute(
"capture",
mActions[i].capture() );
242 aActions.appendChild( actionSetting );
244 layer_node.appendChild( aActions );
253 QDomNode aaNode = layer_node.namedItem(
"attributeactions" );
255 if ( !aaNode.isNull() )
257 QDomNodeList actionsettings = aaNode.childNodes();
258 for (
unsigned int i = 0; i < actionsettings.length(); ++i )
260 QDomElement setting = actionsettings.item( i ).toElement();
262 setting.attributeNode(
"name" ).value(),
263 setting.attributeNode(
"action" ).value(),
264 setting.attributeNode(
"capture" ).value().toInt() != 0 );