Skip to content
Permalink
Browse files
add QgsAttributeAction::doAction to python bindings
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14010 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Aug 4, 2010
1 parent 99752a8 commit 22ce134137003377d53855e4726b3bf74e873d11
@@ -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();
@@ -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;
@@ -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() ) );
}
@@ -159,6 +159,7 @@
#include "qgscredentialdialog.h"
#include "qgstilescalewidget.h"
#include "qgsquerybuilder.h"
#include "qgsattributeaction.h"

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

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

void QgisApp::loadPythonSupport()
{
QString pythonlibName( "qgispython" );
@@ -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 );
@@ -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 )
@@ -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
@@ -68,6 +68,10 @@ void QgsAttributeAction::doAction( int index, const QList< QPair<QString, QStrin
{
executePython( expandedAction );
}
else if ( smPythonExecute )
{
smPythonExecute( expandedAction );
}
}
else
{
@@ -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;
}
@@ -32,6 +32,7 @@

class QDomNode;
class QDomDocument;
class QgsPythonUtils;

/** \ingroup core
* Utility class that encapsulates an action based on vector attributes.
@@ -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 );

@@ -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 22ce134

Please sign in to comment.