Skip to content

Commit

Permalink
[processing] Fix newlines are stripped from Python traces in log
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 19, 2018
1 parent 0ef6e1b commit 26bdd92
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
7 changes: 7 additions & 0 deletions python/gui/processing/qgsprocessingalgorithmdialogbase.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 13 additions & 6 deletions src/gui/processing/qgsprocessingalgorithmdialogbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
7 changes: 7 additions & 0 deletions src/gui/processing/qgsprocessingalgorithmdialogbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

/**
Expand Down

0 comments on commit 26bdd92

Please sign in to comment.