24 changes: 22 additions & 2 deletions resources/context_help/QgsVectorLayerProperties-en_US
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,31 @@ The <label>Metadata</label> tab contains information about the layer, including
<h4>Actions</h4>
</a>
QGIS provides the ability to perform an action based on the attributes of a feature. This can be used to perform any number of actions, for example, running a program with arguments built from the attributes of a feature or passing parameters to a web reporting tool. <br/>
Actions are useful when you frequently want to run an external application or view a web page based on one or more values in your vector layer. An example is performing a search based on an attribute value.<p>
Actions are useful when you frequently want to run an external application or view a web page based on one or more values in your vector layer.<p>

The new implementation of actions uses the QGIS expression engine to do evaluations. Each expression is evaluated and replaced by its result at runtime.<p>
An expression must be enclosed between <code>[%</code> and <code>%]</code> - the GUI has some buttons which do that for you automatically.
The <label>Insert expression...</label> button launches the <label>Expression builder</label> which allows to write an expression easily, the <label>Insert field</label> button inserts into the action a placeholder like <code>[% "fieldname" %]</code> where fieldname is the name of the field selected in the field dropdown list.<p>

See the User Guide for further information.

<h5>Using Actions</h5>
Actions can be invoked from the <label>Identify Results</label> dialog.
Actions can be invoked from the <label>Identify Results</label> dialog or using the <label>Run feature action</label> tool on the toolbar.<p>

Each action adds a little set of custom expressions to the default set available in the <label>Expression builder</label>.<br/>
While running actions from the <label>Identify Results</label> dialog the custom expression <code>$currfield</code> will be replaced with the value of the selected field in the dialog, using the <label>Run feature action</label> tool the following custom expressions are available (instead of $currfield):
<ul>
<li><code>$clickx</code> returns the x coordinate of the click position on the canvas</li>
<li><code>$clicky</code> returns the y coordinate of the click position on the canvas</li>
<li><code>$layerid</code> returns the ID of the selected layer in the legend</li>
</ul>

Note: the <label>Run feature action</label> tool executes the actions on all the matching features, where as <label>Identify Results</label> allows you to select which specific feature to run action on.<p>


<h5>Action Examples</h5>
You can add some example actions by clicking on the <label>Add default actions</label> button.


<a name="diagram">
<h4>Diagram Overlay</h4>
Expand Down
14 changes: 14 additions & 0 deletions src/app/qgsattributeactiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ QgsAttributeActionDialog::QgsAttributeActionDialog( QgsAttributeAction* actions,
connect( moveUpButton, SIGNAL( clicked() ), this, SLOT( moveUp() ) );
connect( moveDownButton, SIGNAL( clicked() ), this, SLOT( moveDown() ) );
connect( removeButton, SIGNAL( clicked() ), this, SLOT( remove() ) );
connect( addDefaultActionsButton, SIGNAL( clicked() ), this, SLOT( addDefaultActions() ) );

connect( browseButton, SIGNAL( clicked() ), this, SLOT( browse() ) );
connect( insertButton, SIGNAL( clicked() ), this, SLOT( insert() ) );
connect( updateButton, SIGNAL( clicked() ), this, SLOT( update() ) );
Expand Down Expand Up @@ -319,6 +321,18 @@ void QgsAttributeActionDialog::apply()
}
}

void QgsAttributeActionDialog::addDefaultActions()
{
int pos = 0;
insertRow( pos++, QgsAction::Generic, tr( "Echo attribute's value" ), "echo \"[% \"MY_FIELD\" %]\"", true );
insertRow( pos++, QgsAction::Generic, tr( "Run an application" ), "ogr2ogr -f \"ESRI Shapefile\" \"[% \"OUTPUT_PATH\" %]\" \"[% \"INPUT_FILE\" %]\"", true );
insertRow( pos++, QgsAction::GenericPython, tr( "Get feature id" ), "QtGui.QMessageBox.information(None, \"Feature id\", \"feature id is [% $id %]\")", false );
insertRow( pos++, QgsAction::GenericPython, tr( "Selected field's value (Identify features tool)" ), "QtGui.QMessageBox.information(None, \"Current field's value\", \"[% $currentfield %]\")", false );
insertRow( pos++, QgsAction::GenericPython, tr( "Clicked coordinates (Run feature actions tool)" ), "QtGui.QMessageBox.information(None, \"Clicked coords\", \"layer: [% $layerid %]\\ncoords: ([% $clickx %],[% $clickx %])\")", false );
insertRow( pos++, QgsAction::OpenUrl, tr( "Open file" ), "[% \"PATH\" %]", false );
insertRow( pos++, QgsAction::OpenUrl, tr( "Search on web based on attribute's value" ), "http://www.google.it/?q=[% \"ATTRIBUTE\" %]", false );
}

void QgsAttributeActionDialog::itemSelectionChanged()
{
QList<QTableWidgetItem *> selection = attributeActionTable->selectedItems();
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsattributeactiondialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class QgsAttributeActionDialog: public QWidget, private Ui::QgsAttributeActionDi
void insertExpression();
void apply();
void update();
void addDefaultActions();
void itemSelectionChanged();

private slots:
Expand Down
10 changes: 9 additions & 1 deletion src/core/qgsattributeaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,15 @@ void QgsAttributeAction::doAction( int index, QgsFeature &feat,

void QgsAttributeAction::runAction( const QgsAction &action, void ( *executePython )( const QString & ) )
{
if ( action.type() == QgsAction::GenericPython )
if ( action.type() == QgsAction::OpenUrl )
{
QFileInfo finfo( action.action() );
if ( finfo.exists() && finfo.isFile() )
QDesktopServices::openUrl( QUrl::fromLocalFile( action.action() ) );
else
QDesktopServices::openUrl( QUrl( action.action(), QUrl::TolerantMode ) );
}
else if ( action.type() == QgsAction::GenericPython )
{
if ( executePython )
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsattributeaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CORE_EXPORT QgsAction
Mac,
Windows,
Unix,
OpenUrl,
};

QgsAction( ActionType type, QString name, QString action, bool capture ) :
Expand All @@ -69,6 +70,7 @@ class CORE_EXPORT QgsAction
{
return mType == Generic ||
mType == GenericPython ||
mType == OpenUrl ||
#if defined(Q_OS_WIN)
mType == Windows
#elif defined(Q_OS_MAC)
Expand Down
14 changes: 13 additions & 1 deletion src/ui/qgsattributeactiondialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<string>Action list</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0" colspan="4">
<item row="0" column="0" colspan="5">
<widget class="QTableWidget" name="attributeActionTable">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
Expand Down Expand Up @@ -98,6 +98,13 @@
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="addDefaultActionsButton">
<property name="text">
<string>Add default actions</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -152,6 +159,11 @@
<string>Unix</string>
</property>
</item>
<item>
<property name="text">
<string>Open</string>
</property>
</item>
</widget>
</item>
<item>
Expand Down