[processing] Fix newlines are stripped from Python traces in log

This commit is contained in:
Nyall Dawson 2018-03-19 09:21:35 +10:00
parent 0ef6e1b666
commit 26bdd920f4
3 changed files with 27 additions and 6 deletions

View File

@ -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:

View File

@ -333,21 +333,21 @@ void QgsProcessingAlgorithmDialogBase::pushInfo( const QString &info )
void QgsProcessingAlgorithmDialogBase::pushCommandInfo( const QString &command )
{
txtLog->append( QStringLiteral( "<code>%1<code>" ).arg( command.toHtmlEscaped() ) );
txtLog->append( QStringLiteral( "<code>%1<code>" ).arg( formatStringForLog( command.toHtmlEscaped() ) ) );
scrollToBottomOfLog();
processEvents();
}
void QgsProcessingAlgorithmDialogBase::pushDebugInfo( const QString &message )
{
txtLog->append( QStringLiteral( "<span style=\"color:blue\">%1</span>" ).arg( message.toHtmlEscaped() ) );
txtLog->append( QStringLiteral( "<span style=\"color:blue\">%1</span>" ).arg( formatStringForLog( message.toHtmlEscaped() ) ) );
scrollToBottomOfLog();
processEvents();
}
void QgsProcessingAlgorithmDialogBase::pushConsoleInfo( const QString &info )
{
txtLog->append( QStringLiteral( "<code><span style=\"color:blue\">%1</darkgray></code>" ).arg( info.toHtmlEscaped() ) );
txtLog->append( QStringLiteral( "<code><span style=\"color:blue\">%1</darkgray></code>" ).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( "<br>" ) );
return s;
}
void QgsProcessingAlgorithmDialogBase::setInfo( const QString &message, bool isError, bool escapeHtml )
{
if ( isError )
txtLog->append( QStringLiteral( "<span style=\"color:red\">%1</span>" ).arg( message ) );
txtLog->append( QStringLiteral( "<span style=\"color:red\">%1</span>" ).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();
}

View File

@ -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:
/**