Skip to content
Permalink
Browse files

Add eval to QgsPythonRunner.

  • Loading branch information
NathanW2 committed Mar 30, 2013
1 parent 67b9c48 commit 0229ea931f45a5090550826b8317f46495c11ac3
Showing with 33 additions and 0 deletions.
  1. +5 −0 python/core/qgspythonrunner.sip
  2. +10 −0 src/app/qgisapp.cpp
  3. +13 −0 src/core/qgspythonrunner.cpp
  4. +5 −0 src/core/qgspythonrunner.h
@@ -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;
};
@@ -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;
};
@@ -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;
@@ -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;
};

0 comments on commit 0229ea9

Please sign in to comment.
You can’t perform that action at this time.