Skip to content

Commit

Permalink
add QgsAttributeAction::doAction to python bindings
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14010 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Aug 4, 2010
1 parent 9127249 commit d86ffa2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
5 changes: 2 additions & 3 deletions python/core/qgsattributeaction.sip
Expand Up @@ -49,13 +49,12 @@ class QgsAttributeAction
// dialog box.
void addAction( QgsAction::ActionType type, QString name, QString action, bool capture = false );

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

//! Removes all actions
void clearActions();
Expand Down
7 changes: 1 addition & 6 deletions src/app/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -497,11 +497,6 @@ void QgsAttributeTableModel::incomingChangeLayout()
emit layoutAboutToBeChanged();
}

static void _runPythonString( const QString &expr )
{
QgisApp::instance()->runPythonString( expr );
}

void QgsAttributeTableModel::executeAction( int action, const QModelIndex &idx ) const
{
QList< QPair<QString, QString> > attributes;
Expand All @@ -514,5 +509,5 @@ void QgsAttributeTableModel::executeAction( int action, const QModelIndex &idx )
);
}

mLayer->actions()->doAction( action, attributes, fieldIdx( idx.column() ), _runPythonString );
mLayer->actions()->doAction( action, attributes, fieldIdx( idx.column() ) );
}
7 changes: 7 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -159,6 +159,7 @@
#include "qgscredentialdialog.h"
#include "qgstilescalewidget.h"
#include "qgsquerybuilder.h"
#include "qgsattributeaction.h"

#ifdef HAVE_QWT
#include "qgsgpsinformationwidget.h"
Expand Down Expand Up @@ -4939,6 +4940,11 @@ void QgisApp::showPluginManager()
}
}

static void _runPythonString( const QString &expr )
{
QgisApp::instance()->runPythonString( expr );
}

void QgisApp::loadPythonSupport()
{
QString pythonlibName( "qgispython" );
Expand Down Expand Up @@ -4983,6 +4989,7 @@ void QgisApp::loadPythonSupport()
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
QgsPluginRegistry::instance()->setPythonUtils( mPythonUtils );
QgsAttributeAction::setPythonExecute( _runPythonString );

mActionShowPythonDialog = new QAction( tr( "Python Console" ), this );
QgsShortcutsManager::instance()->registerAction( mActionShowPythonDialog );
Expand Down
7 changes: 1 addition & 6 deletions src/app/qgsidentifyresults.cpp
Expand Up @@ -44,11 +44,6 @@

#include "qgslogger.h"

static void _runPythonString( const QString &expr )
{
QgisApp::instance()->runPythonString( expr );
}

QgsFeatureAction::QgsFeatureAction( const QString &name, QgsIdentifyResults *results, QgsVectorLayer *vl, int action, QTreeWidgetItem *featItem )
: QAction( name, results )
, mLayer( vl )
Expand All @@ -60,7 +55,7 @@ QgsFeatureAction::QgsFeatureAction( const QString &name, QgsIdentifyResults *res

void QgsFeatureAction::execute()
{
mLayer->actions()->doAction( mAction, mAttributes, mIdx, _runPythonString );
mLayer->actions()->doAction( mAction, mAttributes, mIdx );
}

class QgsIdentifyResultsDock : public QDockWidget
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsattributeaction.cpp
Expand Up @@ -68,6 +68,10 @@ void QgsAttributeAction::doAction( int index, const QList< QPair<QString, QStrin
{
executePython( expandedAction );
}
else if ( smPythonExecute )
{
smPythonExecute( expandedAction );
}
}
else
{
Expand Down Expand Up @@ -151,3 +155,9 @@ bool QgsAttributeAction::readXML( const QDomNode& layer_node )
return true;
}

void ( *QgsAttributeAction::smPythonExecute )( const QString & ) = 0;

void QgsAttributeAction::setPythonExecute( void ( *runPython )( const QString & ) )
{
smPythonExecute = runPython;
}
5 changes: 5 additions & 0 deletions src/core/qgsattributeaction.h
Expand Up @@ -32,6 +32,7 @@

class QDomNode;
class QDomDocument;
class QgsPythonUtils;

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

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

static void setPythonExecute( void ( * )( const QString & ) );

private:
QList<QgsAction> mActions;
static void ( *smPythonExecute )( const QString & );
};

#endif

0 comments on commit d86ffa2

Please sign in to comment.