void QgsAttributeAction::runAction( const QgsAction &action, void ( *executePython )( const QString & ) ) { if ( action.type() == QgsAction::OpenUrl ) { QFileInfo finfo( action.action() ); if ( finfo.exists() && finfo.isFile() ) QDesktopServices::openUrl( QUrl::fromLocalFile( action.action() ) ); else QDesktopServices::openUrl( QUrl( action.action(), QUrl::TolerantMode ) ); } else if ( action.type() == QgsAction::GenericPython ) { if ( executePython ) { // deprecated executePython( action.action() ); } else if ( smPythonExecute ) { // deprecated smPythonExecute( action.action() ); } else { // TODO: capture output from QgsPythonRunner (like QgsRunProcess does) QgsPythonRunner::run( action.action() ); } } else { // The QgsRunProcess instance created by this static function // deletes itself when no longer needed. QgsRunProcess::create( action.action(), action.capture() ); } }
void QgsAttributeAction::doAction( int index, const QgsAttributeMap &attributes, int defaultValueIndex, void ( *executePython )( const QString & ) ) { if ( index < 0 || index >= size() ) return; const QgsAction &action = at( index ); if ( !action.runable() ) return; // A couple of extra options for running the action may be // useful. For example, // - run the action inside a terminal (on unix) // - capture the stdout from the process and display in a dialog // box // // The capture stdout one is partially implemented. It just needs // the UI and the code in this function to select on the // action.capture() return value. // The QgsRunProcess instance created by this static function // deletes itself when no longer needed. QString expandedAction = expandAction( action.action(), attributes, defaultValueIndex ); if ( action.type() == QgsAction::GenericPython ) { if ( executePython ) { executePython( expandedAction ); } else if ( smPythonExecute ) { smPythonExecute( expandedAction ); } } else { QgsRunProcess::create( expandedAction, action.capture() ); } }