Skip to content

Commit 721e94d

Browse files
committed
[processing] Fix newlines are stripped from Python traces in log
(cherry-picked from 26bdd92)
1 parent d225753 commit 721e94d

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

python/gui/processing/qgsprocessingalgorithmdialogbase.sip.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ Hides the short help panel.
215215
%Docstring
216216
Sets the current ``task`` running in the dialog. The task will automatically be started
217217
by the dialog. Ownership of ``task`` is transferred to the dialog.
218+
%End
219+
220+
static QString formatStringForLog( const QString &string );
221+
%Docstring
222+
Formats an input ``string`` for display in the log tab.
223+
224+
.. versionadded:: 3.0.1
218225
%End
219226

220227
protected slots:

src/gui/processing/qgsprocessingalgorithmdialogbase.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,21 +333,21 @@ void QgsProcessingAlgorithmDialogBase::pushInfo( const QString &info )
333333

334334
void QgsProcessingAlgorithmDialogBase::pushCommandInfo( const QString &command )
335335
{
336-
txtLog->append( QStringLiteral( "<code>%1<code>" ).arg( command.toHtmlEscaped() ) );
336+
txtLog->append( QStringLiteral( "<code>%1<code>" ).arg( formatStringForLog( command.toHtmlEscaped() ) ) );
337337
scrollToBottomOfLog();
338338
processEvents();
339339
}
340340

341341
void QgsProcessingAlgorithmDialogBase::pushDebugInfo( const QString &message )
342342
{
343-
txtLog->append( QStringLiteral( "<span style=\"color:blue\">%1</span>" ).arg( message.toHtmlEscaped() ) );
343+
txtLog->append( QStringLiteral( "<span style=\"color:blue\">%1</span>" ).arg( formatStringForLog( message.toHtmlEscaped() ) ) );
344344
scrollToBottomOfLog();
345345
processEvents();
346346
}
347347

348348
void QgsProcessingAlgorithmDialogBase::pushConsoleInfo( const QString &info )
349349
{
350-
txtLog->append( QStringLiteral( "<code><span style=\"color:blue\">%1</darkgray></code>" ).arg( info.toHtmlEscaped() ) );
350+
txtLog->append( QStringLiteral( "<code><span style=\"color:blue\">%1</darkgray></code>" ).arg( formatStringForLog( info.toHtmlEscaped() ) ) );
351351
scrollToBottomOfLog();
352352
processEvents();
353353
}
@@ -474,14 +474,21 @@ void QgsProcessingAlgorithmDialogBase::setCurrentTask( QgsProcessingAlgRunnerTas
474474
QgsApplication::taskManager()->addTask( mAlgorithmTask );
475475
}
476476

477+
QString QgsProcessingAlgorithmDialogBase::formatStringForLog( const QString &string )
478+
{
479+
QString s = string;
480+
s.replace( '\n', QStringLiteral( "<br>" ) );
481+
return s;
482+
}
483+
477484
void QgsProcessingAlgorithmDialogBase::setInfo( const QString &message, bool isError, bool escapeHtml )
478485
{
479486
if ( isError )
480-
txtLog->append( QStringLiteral( "<span style=\"color:red\">%1</span>" ).arg( message ) );
487+
txtLog->append( QStringLiteral( "<span style=\"color:red\">%1</span>" ).arg( formatStringForLog( message ) ) );
481488
else if ( escapeHtml )
482-
txtLog->append( message.toHtmlEscaped() );
489+
txtLog->append( formatStringForLog( message.toHtmlEscaped() ) );
483490
else
484-
txtLog->append( message );
491+
txtLog->append( formatStringForLog( message ) );
485492
scrollToBottomOfLog();
486493
processEvents();
487494
}

src/gui/processing/qgsprocessingalgorithmdialogbase.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,13 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
260260
*/
261261
void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
262262

263+
/**
264+
* Formats an input \a string for display in the log tab.
265+
*
266+
* \since QGIS 3.0.1
267+
*/
268+
static QString formatStringForLog( const QString &string );
269+
263270
protected slots:
264271

265272
/**

0 commit comments

Comments
 (0)