Add eval to QgsPythonRunner.

This commit is contained in:
Nathan Woodrow 2013-03-31 07:36:57 +10:00
parent 67b9c48891
commit 0229ea931f
4 changed files with 33 additions and 0 deletions

View File

@ -12,6 +12,9 @@ class QgsPythonRunner
/** execute a python statement */
static bool run( QString command, QString messageOnError = QString() );
/** Eval a python statement */
static bool eval( QString command, QString& result);
/** assign an instance of python runner so that run() can be used.
This method should be called during app initialization.
Takes ownership of the object, deletes previous instance. */
@ -23,4 +26,6 @@ class QgsPythonRunner
virtual ~QgsPythonRunner();
virtual bool runCommand( QString command, QString messageOnError = QString() ) = 0;
virtual bool evalCommand( QString command, QString& result ) = 0;
};

View File

@ -6232,6 +6232,7 @@ class QgsPythonRunnerImpl : public QgsPythonRunner
{
public:
QgsPythonRunnerImpl( QgsPythonUtils* pythonUtils ) : mPythonUtils( pythonUtils ) {}
virtual bool runCommand( QString command, QString messageOnError = QString() )
{
if ( mPythonUtils && mPythonUtils->isEnabled() )
@ -6241,6 +6242,15 @@ class QgsPythonRunnerImpl : public QgsPythonRunner
return false;
}
virtual bool evalCommand( QString command, QString &result )
{
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
return mPythonUtils->evalString( command, result );
}
return false;
}
protected:
QgsPythonUtils* mPythonUtils;
};

View File

@ -38,6 +38,19 @@ bool QgsPythonRunner::run( QString command, QString messageOnError )
}
}
bool QgsPythonRunner::eval( QString command, QString& result )
{
if ( mInstance )
{
return mInstance->evalCommand( command, result );
}
else
{
QgsDebugMsg( "Unable to run Python command: runner not available!" );
return false;
}
}
void QgsPythonRunner::setInstance( QgsPythonRunner* runner )
{
delete mInstance;

View File

@ -37,6 +37,9 @@ class CORE_EXPORT QgsPythonRunner
/** execute a python statement */
static bool run( QString command, QString messageOnError = QString() );
/** Eval a python statement */
static bool eval( QString command, QString& result);
/** assign an instance of python runner so that run() can be used.
This method should be called during app initialization.
Takes ownership of the object, deletes previous instance. */
@ -49,6 +52,8 @@ class CORE_EXPORT QgsPythonRunner
virtual bool runCommand( QString command, QString messageOnError = QString() ) = 0;
virtual bool evalCommand( QString command, QString& result ) = 0;
static QgsPythonRunner* mInstance;
};