mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-08 00:05:09 -04:00
add QgsAttributeAction::doAction to python bindings
git-svn-id: http://svn.osgeo.org/qgis/trunk@14010 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
9127249182
commit
d86ffa2571
@ -49,13 +49,12 @@ class QgsAttributeAction
|
|||||||
// dialog box.
|
// dialog box.
|
||||||
void addAction( QgsAction::ActionType type, QString name, QString action, bool capture = false );
|
void addAction( QgsAction::ActionType type, QString name, QString action, bool capture = false );
|
||||||
|
|
||||||
/*
|
|
||||||
//! Does the action using the given values. defaultValueIndex is an
|
//! Does the action using the given values. defaultValueIndex is an
|
||||||
// index into values which indicates which value in the values vector
|
// index into values which indicates which value in the values vector
|
||||||
// is to be used if the action has a default placeholder.
|
// 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,
|
void doAction( int index, const QList< QPair<QString, QString> > &values,
|
||||||
int defaultValueIndex = 0, void *executePython = 0 );
|
int defaultValueIndex = 0 );
|
||||||
*/
|
|
||||||
|
|
||||||
//! Removes all actions
|
//! Removes all actions
|
||||||
void clearActions();
|
void clearActions();
|
||||||
|
@ -497,11 +497,6 @@ void QgsAttributeTableModel::incomingChangeLayout()
|
|||||||
emit layoutAboutToBeChanged();
|
emit layoutAboutToBeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _runPythonString( const QString &expr )
|
|
||||||
{
|
|
||||||
QgisApp::instance()->runPythonString( expr );
|
|
||||||
}
|
|
||||||
|
|
||||||
void QgsAttributeTableModel::executeAction( int action, const QModelIndex &idx ) const
|
void QgsAttributeTableModel::executeAction( int action, const QModelIndex &idx ) const
|
||||||
{
|
{
|
||||||
QList< QPair<QString, QString> > attributes;
|
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 "qgscredentialdialog.h"
|
||||||
#include "qgstilescalewidget.h"
|
#include "qgstilescalewidget.h"
|
||||||
#include "qgsquerybuilder.h"
|
#include "qgsquerybuilder.h"
|
||||||
|
#include "qgsattributeaction.h"
|
||||||
|
|
||||||
#ifdef HAVE_QWT
|
#ifdef HAVE_QWT
|
||||||
#include "qgsgpsinformationwidget.h"
|
#include "qgsgpsinformationwidget.h"
|
||||||
@ -4939,6 +4940,11 @@ void QgisApp::showPluginManager()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _runPythonString( const QString &expr )
|
||||||
|
{
|
||||||
|
QgisApp::instance()->runPythonString( expr );
|
||||||
|
}
|
||||||
|
|
||||||
void QgisApp::loadPythonSupport()
|
void QgisApp::loadPythonSupport()
|
||||||
{
|
{
|
||||||
QString pythonlibName( "qgispython" );
|
QString pythonlibName( "qgispython" );
|
||||||
@ -4983,6 +4989,7 @@ void QgisApp::loadPythonSupport()
|
|||||||
if ( mPythonUtils && mPythonUtils->isEnabled() )
|
if ( mPythonUtils && mPythonUtils->isEnabled() )
|
||||||
{
|
{
|
||||||
QgsPluginRegistry::instance()->setPythonUtils( mPythonUtils );
|
QgsPluginRegistry::instance()->setPythonUtils( mPythonUtils );
|
||||||
|
QgsAttributeAction::setPythonExecute( _runPythonString );
|
||||||
|
|
||||||
mActionShowPythonDialog = new QAction( tr( "Python Console" ), this );
|
mActionShowPythonDialog = new QAction( tr( "Python Console" ), this );
|
||||||
QgsShortcutsManager::instance()->registerAction( mActionShowPythonDialog );
|
QgsShortcutsManager::instance()->registerAction( mActionShowPythonDialog );
|
||||||
|
@ -44,11 +44,6 @@
|
|||||||
|
|
||||||
#include "qgslogger.h"
|
#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 )
|
QgsFeatureAction::QgsFeatureAction( const QString &name, QgsIdentifyResults *results, QgsVectorLayer *vl, int action, QTreeWidgetItem *featItem )
|
||||||
: QAction( name, results )
|
: QAction( name, results )
|
||||||
, mLayer( vl )
|
, mLayer( vl )
|
||||||
@ -60,7 +55,7 @@ QgsFeatureAction::QgsFeatureAction( const QString &name, QgsIdentifyResults *res
|
|||||||
|
|
||||||
void QgsFeatureAction::execute()
|
void QgsFeatureAction::execute()
|
||||||
{
|
{
|
||||||
mLayer->actions()->doAction( mAction, mAttributes, mIdx, _runPythonString );
|
mLayer->actions()->doAction( mAction, mAttributes, mIdx );
|
||||||
}
|
}
|
||||||
|
|
||||||
class QgsIdentifyResultsDock : public QDockWidget
|
class QgsIdentifyResultsDock : public QDockWidget
|
||||||
|
@ -68,6 +68,10 @@ void QgsAttributeAction::doAction( int index, const QList< QPair<QString, QStrin
|
|||||||
{
|
{
|
||||||
executePython( expandedAction );
|
executePython( expandedAction );
|
||||||
}
|
}
|
||||||
|
else if ( smPythonExecute )
|
||||||
|
{
|
||||||
|
smPythonExecute( expandedAction );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -151,3 +155,9 @@ bool QgsAttributeAction::readXML( const QDomNode& layer_node )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ( *QgsAttributeAction::smPythonExecute )( const QString & ) = 0;
|
||||||
|
|
||||||
|
void QgsAttributeAction::setPythonExecute( void ( *runPython )( const QString & ) )
|
||||||
|
{
|
||||||
|
smPythonExecute = runPython;
|
||||||
|
}
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
class QDomNode;
|
class QDomNode;
|
||||||
class QDomDocument;
|
class QDomDocument;
|
||||||
|
class QgsPythonUtils;
|
||||||
|
|
||||||
/** \ingroup core
|
/** \ingroup core
|
||||||
* Utility class that encapsulates an action based on vector attributes.
|
* 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
|
//! Does the action using the given values. defaultValueIndex is an
|
||||||
// index into values which indicates which value in the values vector
|
// index into values which indicates which value in the values vector
|
||||||
// is to be used if the action has a default placeholder.
|
// 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,
|
void doAction( int index, const QList< QPair<QString, QString> > &values,
|
||||||
int defaultValueIndex = 0, void ( *executePython )( const QString & ) = 0 );
|
int defaultValueIndex = 0, void ( *executePython )( const QString & ) = 0 );
|
||||||
|
|
||||||
@ -130,8 +132,11 @@ class CORE_EXPORT QgsAttributeAction
|
|||||||
QgsAction &at( int idx ) { return mActions[idx]; }
|
QgsAction &at( int idx ) { return mActions[idx]; }
|
||||||
QgsAction &operator[]( int idx ) { return mActions[idx]; }
|
QgsAction &operator[]( int idx ) { return mActions[idx]; }
|
||||||
|
|
||||||
|
static void setPythonExecute( void ( * )( const QString & ) );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QgsAction> mActions;
|
QList<QgsAction> mActions;
|
||||||
|
static void ( *smPythonExecute )( const QString & );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user