mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-11-04 00:04:25 -05:00 
			
		
		
		
	Add eval to QgsPythonRunner.
This commit is contained in:
		
							parent
							
								
									67b9c48891
								
							
						
					
					
						commit
						0229ea931f
					
				@ -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;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user