Skip to content

Commit

Permalink
[processing] Fix algorithm progress bar resets to 0 when an algorithm
Browse files Browse the repository at this point in the history
reports a non-fatal error

Fixes the "flashy" progress bar when an algorithm encounters a lot
of errors.

(cherry-picked from 654a4a4)
  • Loading branch information
nyalldawson committed Mar 15, 2018
1 parent 2700f77 commit 47a90e9
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 21 deletions.
9 changes: 5 additions & 4 deletions python/core/processing/qgsprocessingfeedback.sip.in
Expand Up @@ -35,10 +35,11 @@ setProgress() to provide detailed progress reports, such as "Transformed
.. seealso:: :py:func:`setProgress`
%End

virtual void reportError( const QString &error );
virtual void reportError( const QString &error, bool fatalError = false );
%Docstring
Reports that the algorithm encountered an error which prevented it
from successfully executing.
Reports that the algorithm encountered an ``error`` while executing.

If ``fatalError`` is true then the error prevented the algorithm from executing.
%End

virtual void pushInfo( const QString &info );
Expand Down Expand Up @@ -127,7 +128,7 @@ to scale the current progress to account for progress through the overall proces

virtual void setProgressText( const QString &text );

virtual void reportError( const QString &error );
virtual void reportError( const QString &error, bool fatalError );

virtual void pushInfo( const QString &info );

Expand Down
Expand Up @@ -100,9 +100,11 @@ Returns the parameter values for the algorithm to run in the dialog.
virtual void accept();


void reportError( const QString &error );
void reportError( const QString &error, bool fatalError );
%Docstring
Reports an ``error`` string to the dialog's log.

If ``fatalError`` is true, the error prevented the algorithm from executing.
%End

void pushInfo( const QString &info );
Expand Down
Expand Up @@ -67,7 +67,7 @@ def __init__(self, dialog):
QgsProcessingFeedback.__init__(self)
self.dialog = dialog

def reportError(self, msg):
def reportError(self, msg, fatal_error):
self.dialog.error(msg)


Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/MessageBarProgress.py
Expand Up @@ -48,7 +48,7 @@ def __init__(self, algname=None):
iface.messageBar().pushWidget(self.progressMessageBar,
Qgis.Info)

def reportError(self, msg):
def reportError(self, msg, fatal_error):
self.msg.append(msg)

def close(self):
Expand Down
4 changes: 2 additions & 2 deletions src/core/processing/qgsprocessingfeedback.cpp
Expand Up @@ -36,9 +36,9 @@ void QgsProcessingMultiStepFeedback::setProgressText( const QString &text )
mFeedback->setProgressText( text );
}

void QgsProcessingMultiStepFeedback::reportError( const QString &error )
void QgsProcessingMultiStepFeedback::reportError( const QString &error, bool fatalError )
{
mFeedback->reportError( error );
mFeedback->reportError( error, fatalError );
}

void QgsProcessingMultiStepFeedback::pushInfo( const QString &info )
Expand Down
9 changes: 5 additions & 4 deletions src/core/processing/qgsprocessingfeedback.h
Expand Up @@ -47,10 +47,11 @@ class CORE_EXPORT QgsProcessingFeedback : public QgsFeedback
virtual void setProgressText( const QString &text ) { Q_UNUSED( text ); }

/**
* Reports that the algorithm encountered an error which prevented it
* from successfully executing.
* Reports that the algorithm encountered an \a error while executing.
*
* If \a fatalError is true then the error prevented the algorithm from executing.
*/
virtual void reportError( const QString &error ) { QgsMessageLog::logMessage( error ); }
virtual void reportError( const QString &error, bool fatalError = false ) { Q_UNUSED( fatalError ); QgsMessageLog::logMessage( error ); }

/**
* Pushes a general informational message from the algorithm. This can
Expand Down Expand Up @@ -125,7 +126,7 @@ class CORE_EXPORT QgsProcessingMultiStepFeedback : public QgsProcessingFeedback
void setCurrentStep( int step );

void setProgressText( const QString &text ) override;
void reportError( const QString &error ) override;
void reportError( const QString &error, bool fatalError ) override;
void pushInfo( const QString &info ) override;
void pushCommandInfo( const QString &info ) override;
void pushDebugInfo( const QString &info ) override;
Expand Down
11 changes: 6 additions & 5 deletions src/gui/processing/qgsprocessingalgorithmdialogbase.cpp
Expand Up @@ -38,9 +38,9 @@ void QgsProcessingAlgorithmDialogFeedback::setProgressText( const QString &text
emit progressTextChanged( text );
}

void QgsProcessingAlgorithmDialogFeedback::reportError( const QString &error )
void QgsProcessingAlgorithmDialogFeedback::reportError( const QString &error, bool fatalError )
{
emit errorReported( error );
emit errorReported( error, fatalError );
}

void QgsProcessingAlgorithmDialogFeedback::pushInfo( const QString &info )
Expand Down Expand Up @@ -316,10 +316,11 @@ void QgsProcessingAlgorithmDialogBase::closeClicked()
close();
}

void QgsProcessingAlgorithmDialogBase::reportError( const QString &error )
void QgsProcessingAlgorithmDialogBase::reportError( const QString &error, bool fatalError )
{
setInfo( error, true );
resetGui();
if ( fatalError )
resetGui();
showLog();
processEvents();
}
Expand Down Expand Up @@ -476,7 +477,7 @@ void QgsProcessingAlgorithmDialogBase::setCurrentTask( QgsProcessingAlgRunnerTas
void QgsProcessingAlgorithmDialogBase::setInfo( const QString &message, bool isError, bool escapeHtml )
{
if ( isError )
txtLog->append( QStringLiteral( "<span style=\"color:red\">%1</span><br />" ).arg( message ) );
txtLog->append( QStringLiteral( "<span style=\"color:red\">%1</span>" ).arg( message ) );
else if ( escapeHtml )
txtLog->append( message.toHtmlEscaped() );
else
Expand Down
8 changes: 5 additions & 3 deletions src/gui/processing/qgsprocessingalgorithmdialogbase.h
Expand Up @@ -54,7 +54,7 @@ class QgsProcessingAlgorithmDialogFeedback : public QgsProcessingFeedback
signals:

void progressTextChanged( const QString &text );
void errorReported( const QString &text );
void errorReported( const QString &text, bool fatalError );
void infoPushed( const QString &text );
void commandInfoPushed( const QString &text );
void debugInfoPushed( const QString &text );
Expand All @@ -63,7 +63,7 @@ class QgsProcessingAlgorithmDialogFeedback : public QgsProcessingFeedback
public slots:

void setProgressText( const QString &text ) override;
void reportError( const QString &error ) override;
void reportError( const QString &error, bool fatalError ) override;
void pushInfo( const QString &info ) override;
void pushCommandInfo( const QString &info ) override;
void pushDebugInfo( const QString &info ) override;
Expand Down Expand Up @@ -150,8 +150,10 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::

/**
* Reports an \a error string to the dialog's log.
*
* If \a fatalError is true, the error prevented the algorithm from executing.
*/
void reportError( const QString &error );
void reportError( const QString &error, bool fatalError );

/**
* Pushes an information string to the dialog's log.
Expand Down

0 comments on commit 47a90e9

Please sign in to comment.