Skip to content

Commit 22ce134

Browse files
author
jef
committed
add QgsAttributeAction::doAction to python bindings
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14010 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 99752a8 commit 22ce134

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

python/core/qgsattributeaction.sip

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,12 @@ class QgsAttributeAction
4949
// dialog box.
5050
void addAction( QgsAction::ActionType type, QString name, QString action, bool capture = false );
5151

52-
/*
5352
//! Does the action using the given values. defaultValueIndex is an
5453
// index into values which indicates which value in the values vector
5554
// is to be used if the action has a default placeholder.
55+
// @note added to python API in 1.6 (without executePython parameter)
5656
void doAction( int index, const QList< QPair<QString, QString> > &values,
57-
int defaultValueIndex = 0, void *executePython = 0 );
58-
*/
57+
int defaultValueIndex = 0 );
5958

6059
//! Removes all actions
6160
void clearActions();

src/app/attributetable/qgsattributetablemodel.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -497,11 +497,6 @@ void QgsAttributeTableModel::incomingChangeLayout()
497497
emit layoutAboutToBeChanged();
498498
}
499499

500-
static void _runPythonString( const QString &expr )
501-
{
502-
QgisApp::instance()->runPythonString( expr );
503-
}
504-
505500
void QgsAttributeTableModel::executeAction( int action, const QModelIndex &idx ) const
506501
{
507502
QList< QPair<QString, QString> > attributes;
@@ -514,5 +509,5 @@ void QgsAttributeTableModel::executeAction( int action, const QModelIndex &idx )
514509
);
515510
}
516511

517-
mLayer->actions()->doAction( action, attributes, fieldIdx( idx.column() ), _runPythonString );
512+
mLayer->actions()->doAction( action, attributes, fieldIdx( idx.column() ) );
518513
}

src/app/qgisapp.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
#include "qgscredentialdialog.h"
160160
#include "qgstilescalewidget.h"
161161
#include "qgsquerybuilder.h"
162+
#include "qgsattributeaction.h"
162163

163164
#ifdef HAVE_QWT
164165
#include "qgsgpsinformationwidget.h"
@@ -4939,6 +4940,11 @@ void QgisApp::showPluginManager()
49394940
}
49404941
}
49414942

4943+
static void _runPythonString( const QString &expr )
4944+
{
4945+
QgisApp::instance()->runPythonString( expr );
4946+
}
4947+
49424948
void QgisApp::loadPythonSupport()
49434949
{
49444950
QString pythonlibName( "qgispython" );
@@ -4983,6 +4989,7 @@ void QgisApp::loadPythonSupport()
49834989
if ( mPythonUtils && mPythonUtils->isEnabled() )
49844990
{
49854991
QgsPluginRegistry::instance()->setPythonUtils( mPythonUtils );
4992+
QgsAttributeAction::setPythonExecute( _runPythonString );
49864993

49874994
mActionShowPythonDialog = new QAction( tr( "Python Console" ), this );
49884995
QgsShortcutsManager::instance()->registerAction( mActionShowPythonDialog );

src/app/qgsidentifyresults.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@
4444

4545
#include "qgslogger.h"
4646

47-
static void _runPythonString( const QString &expr )
48-
{
49-
QgisApp::instance()->runPythonString( expr );
50-
}
51-
5247
QgsFeatureAction::QgsFeatureAction( const QString &name, QgsIdentifyResults *results, QgsVectorLayer *vl, int action, QTreeWidgetItem *featItem )
5348
: QAction( name, results )
5449
, mLayer( vl )
@@ -60,7 +55,7 @@ QgsFeatureAction::QgsFeatureAction( const QString &name, QgsIdentifyResults *res
6055

6156
void QgsFeatureAction::execute()
6257
{
63-
mLayer->actions()->doAction( mAction, mAttributes, mIdx, _runPythonString );
58+
mLayer->actions()->doAction( mAction, mAttributes, mIdx );
6459
}
6560

6661
class QgsIdentifyResultsDock : public QDockWidget

src/core/qgsattributeaction.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ void QgsAttributeAction::doAction( int index, const QList< QPair<QString, QStrin
6868
{
6969
executePython( expandedAction );
7070
}
71+
else if ( smPythonExecute )
72+
{
73+
smPythonExecute( expandedAction );
74+
}
7175
}
7276
else
7377
{
@@ -151,3 +155,9 @@ bool QgsAttributeAction::readXML( const QDomNode& layer_node )
151155
return true;
152156
}
153157

158+
void ( *QgsAttributeAction::smPythonExecute )( const QString & ) = 0;
159+
160+
void QgsAttributeAction::setPythonExecute( void ( *runPython )( const QString & ) )
161+
{
162+
smPythonExecute = runPython;
163+
}

src/core/qgsattributeaction.h

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
class QDomNode;
3434
class QDomDocument;
35+
class QgsPythonUtils;
3536

3637
/** \ingroup core
3738
* Utility class that encapsulates an action based on vector attributes.
@@ -109,6 +110,7 @@ class CORE_EXPORT QgsAttributeAction
109110
//! Does the action using the given values. defaultValueIndex is an
110111
// index into values which indicates which value in the values vector
111112
// is to be used if the action has a default placeholder.
113+
// @note parameter executePython deprecated (and missing in python binding)
112114
void doAction( int index, const QList< QPair<QString, QString> > &values,
113115
int defaultValueIndex = 0, void ( *executePython )( const QString & ) = 0 );
114116

@@ -130,8 +132,11 @@ class CORE_EXPORT QgsAttributeAction
130132
QgsAction &at( int idx ) { return mActions[idx]; }
131133
QgsAction &operator[]( int idx ) { return mActions[idx]; }
132134

135+
static void setPythonExecute( void ( * )( const QString & ) );
136+
133137
private:
134138
QList<QgsAction> mActions;
139+
static void ( *smPythonExecute )( const QString & );
135140
};
136141

137142
#endif

0 commit comments

Comments
 (0)