Skip to content

Commit 516fc7e

Browse files
committedMar 28, 2012
feature actions: new "Open" action type to open urls in the default web browser and files with a suitable application
1 parent 1786b96 commit 516fc7e

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed
 

‎src/app/qgsattributeactiondialog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ void QgsAttributeActionDialog::addDefaultActions()
329329
insertRow( pos++, QgsAction::GenericPython, tr( "Get feature id" ), "QtGui.QMessageBox.information(None, \"Feature id\", \"feature id is [% $id %]\")", false );
330330
insertRow( pos++, QgsAction::GenericPython, tr( "Selected field's value (Identify features tool)" ), "QtGui.QMessageBox.information(None, \"Current field's value\", \"[% $currentfield %]\")", false );
331331
insertRow( pos++, QgsAction::GenericPython, tr( "Clicked coordinates (Run feature actions tool)" ), "QtGui.QMessageBox.information(None, \"Clicked coords\", \"layer: [% $layerid %]\\ncoords: ([% $clickx %],[% $clickx %])\")", false );
332+
insertRow( pos++, QgsAction::OpenUrl, tr( "Open file" ), "[% \"PATH\" %]", false );
333+
insertRow( pos++, QgsAction::OpenUrl, tr( "Search on web based on attribute's value" ), "http://www.google.it/?q=[% \"ATTRIBUTE\" %]", false );
332334
}
333335

334336
void QgsAttributeActionDialog::itemSelectionChanged()

‎src/core/qgsattributeaction.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,15 @@ void QgsAttributeAction::doAction( int index, QgsFeature &feat,
106106

107107
void QgsAttributeAction::runAction( const QgsAction &action, void ( *executePython )( const QString & ) )
108108
{
109-
if ( action.type() == QgsAction::GenericPython )
109+
if ( action.type() == QgsAction::OpenUrl )
110+
{
111+
QFileInfo finfo( action.action() );
112+
if ( finfo.exists() && finfo.isFile() )
113+
QDesktopServices::openUrl( QUrl::fromLocalFile( action.action() ) );
114+
else
115+
QDesktopServices::openUrl( QUrl( action.action(), QUrl::TolerantMode ) );
116+
}
117+
else if ( action.type() == QgsAction::GenericPython )
110118
{
111119
if ( executePython )
112120
{

‎src/core/qgsattributeaction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CORE_EXPORT QgsAction
4747
Mac,
4848
Windows,
4949
Unix,
50+
OpenUrl,
5051
};
5152

5253
QgsAction( ActionType type, QString name, QString action, bool capture ) :
@@ -69,6 +70,7 @@ class CORE_EXPORT QgsAction
6970
{
7071
return mType == Generic ||
7172
mType == GenericPython ||
73+
mType == OpenUrl ||
7274
#if defined(Q_OS_WIN)
7375
mType == Windows
7476
#elif defined(Q_OS_MAC)

‎src/ui/qgsattributeactiondialogbase.ui

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@
159159
<string>Unix</string>
160160
</property>
161161
</item>
162+
<item>
163+
<property name="text">
164+
<string>Open</string>
165+
</property>
166+
</item>
162167
</widget>
163168
</item>
164169
<item>

0 commit comments

Comments
 (0)
Please sign in to comment.