From 26bdd920f4892bc97ecdfcf757496b10cf1ddaea Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 19 Mar 2018 09:21:35 +1000 Subject: [PATCH] [processing] Fix newlines are stripped from Python traces in log --- .../qgsprocessingalgorithmdialogbase.sip.in | 7 +++++++ .../qgsprocessingalgorithmdialogbase.cpp | 19 +++++++++++++------ .../qgsprocessingalgorithmdialogbase.h | 7 +++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/python/gui/processing/qgsprocessingalgorithmdialogbase.sip.in b/python/gui/processing/qgsprocessingalgorithmdialogbase.sip.in index 9d47630e3b6..f0796fe7952 100644 --- a/python/gui/processing/qgsprocessingalgorithmdialogbase.sip.in +++ b/python/gui/processing/qgsprocessingalgorithmdialogbase.sip.in @@ -215,6 +215,13 @@ Hides the short help panel. %Docstring Sets the current ``task`` running in the dialog. The task will automatically be started by the dialog. Ownership of ``task`` is transferred to the dialog. +%End + + static QString formatStringForLog( const QString &string ); +%Docstring +Formats an input ``string`` for display in the log tab. + +.. versionadded:: 3.0.1 %End protected slots: diff --git a/src/gui/processing/qgsprocessingalgorithmdialogbase.cpp b/src/gui/processing/qgsprocessingalgorithmdialogbase.cpp index ee494c5339e..3b81aa98c64 100644 --- a/src/gui/processing/qgsprocessingalgorithmdialogbase.cpp +++ b/src/gui/processing/qgsprocessingalgorithmdialogbase.cpp @@ -333,21 +333,21 @@ void QgsProcessingAlgorithmDialogBase::pushInfo( const QString &info ) void QgsProcessingAlgorithmDialogBase::pushCommandInfo( const QString &command ) { - txtLog->append( QStringLiteral( "%1" ).arg( command.toHtmlEscaped() ) ); + txtLog->append( QStringLiteral( "%1" ).arg( formatStringForLog( command.toHtmlEscaped() ) ) ); scrollToBottomOfLog(); processEvents(); } void QgsProcessingAlgorithmDialogBase::pushDebugInfo( const QString &message ) { - txtLog->append( QStringLiteral( "%1" ).arg( message.toHtmlEscaped() ) ); + txtLog->append( QStringLiteral( "%1" ).arg( formatStringForLog( message.toHtmlEscaped() ) ) ); scrollToBottomOfLog(); processEvents(); } void QgsProcessingAlgorithmDialogBase::pushConsoleInfo( const QString &info ) { - txtLog->append( QStringLiteral( "%1" ).arg( info.toHtmlEscaped() ) ); + txtLog->append( QStringLiteral( "%1" ).arg( formatStringForLog( info.toHtmlEscaped() ) ) ); scrollToBottomOfLog(); processEvents(); } @@ -474,14 +474,21 @@ void QgsProcessingAlgorithmDialogBase::setCurrentTask( QgsProcessingAlgRunnerTas QgsApplication::taskManager()->addTask( mAlgorithmTask ); } +QString QgsProcessingAlgorithmDialogBase::formatStringForLog( const QString &string ) +{ + QString s = string; + s.replace( '\n', QStringLiteral( "
" ) ); + return s; +} + void QgsProcessingAlgorithmDialogBase::setInfo( const QString &message, bool isError, bool escapeHtml ) { if ( isError ) - txtLog->append( QStringLiteral( "%1" ).arg( message ) ); + txtLog->append( QStringLiteral( "%1" ).arg( formatStringForLog( message ) ) ); else if ( escapeHtml ) - txtLog->append( message.toHtmlEscaped() ); + txtLog->append( formatStringForLog( message.toHtmlEscaped() ) ); else - txtLog->append( message ); + txtLog->append( formatStringForLog( message ) ); scrollToBottomOfLog(); processEvents(); } diff --git a/src/gui/processing/qgsprocessingalgorithmdialogbase.h b/src/gui/processing/qgsprocessingalgorithmdialogbase.h index 97c503500b2..765d9cd345b 100644 --- a/src/gui/processing/qgsprocessingalgorithmdialogbase.h +++ b/src/gui/processing/qgsprocessingalgorithmdialogbase.h @@ -260,6 +260,13 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui:: */ void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER ); + /** + * Formats an input \a string for display in the log tab. + * + * \since QGIS 3.0.1 + */ + static QString formatStringForLog( const QString &string ); + protected slots: /**