Skip to content

Commit 67a8902

Browse files
committedJan 9, 2018
[processing] When running non-background enabled algorithms, use
processEvents to allow progress updates and cancelation clicks
1 parent 40e47e0 commit 67a8902

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
 

‎src/gui/processing/qgsprocessingalgorithmdialogbase.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "processing/qgsprocessingprovider.h"
2323
#include <QToolButton>
2424
#include <QDesktopServices>
25+
#include <QScrollBar>
2526

2627
///@cond NOT_STABLE
2728

@@ -271,27 +272,35 @@ void QgsProcessingAlgorithmDialogBase::reportError( const QString &error )
271272
{
272273
setInfo( error, true );
273274
resetGui();
274-
mTabWidget->setCurrentIndex( 1 );
275+
showLog();
276+
processEvents();
275277
}
276278

277279
void QgsProcessingAlgorithmDialogBase::pushInfo( const QString &info )
278280
{
279281
setInfo( info );
282+
processEvents();
280283
}
281284

282285
void QgsProcessingAlgorithmDialogBase::pushCommandInfo( const QString &command )
283286
{
284287
txtLog->append( QStringLiteral( "<code>%1<code>" ).arg( command.toHtmlEscaped() ) );
288+
scrollToBottomOfLog();
289+
processEvents();
285290
}
286291

287292
void QgsProcessingAlgorithmDialogBase::pushDebugInfo( const QString &message )
288293
{
289294
txtLog->append( QStringLiteral( "<span style=\"color:blue\">%1</span>" ).arg( message.toHtmlEscaped() ) );
295+
scrollToBottomOfLog();
296+
processEvents();
290297
}
291298

292299
void QgsProcessingAlgorithmDialogBase::pushConsoleInfo( const QString &info )
293300
{
294301
txtLog->append( QStringLiteral( "<code><span style=\"color:blue\">%1</darkgray></code>" ).arg( info.toHtmlEscaped() ) );
302+
scrollToBottomOfLog();
303+
processEvents();
295304
}
296305

297306
void QgsProcessingAlgorithmDialogBase::setPercentage( double percent )
@@ -300,12 +309,15 @@ void QgsProcessingAlgorithmDialogBase::setPercentage( double percent )
300309
if ( progressBar->maximum() == 0 )
301310
progressBar->setMaximum( 100 );
302311
progressBar->setValue( percent );
312+
processEvents();
303313
}
304314

305315
void QgsProcessingAlgorithmDialogBase::setProgressText( const QString &text )
306316
{
307317
lblProgress->setText( text );
308318
setInfo( text, false );
319+
scrollToBottomOfLog();
320+
processEvents();
309321
}
310322

311323
QString QgsProcessingAlgorithmDialogBase::formatHelp( QgsProcessingAlgorithm *algorithm )
@@ -325,6 +337,28 @@ QString QgsProcessingAlgorithmDialogBase::formatHelp( QgsProcessingAlgorithm *al
325337
return QString();
326338
}
327339

340+
void QgsProcessingAlgorithmDialogBase::processEvents()
341+
{
342+
// So that we get a chance of hitting the Abort button
343+
#ifdef Q_OS_LINUX
344+
// For some reason on Windows hasPendingEvents() always return true,
345+
// but one iteration is actually enough on Windows to get good interactivity
346+
// whereas on Linux we must allow for far more iterations.
347+
// For safety limit the number of iterations
348+
int nIters = 0;
349+
while ( QCoreApplication::hasPendingEvents() && ++nIters < 100 )
350+
#endif
351+
{
352+
QCoreApplication::processEvents();
353+
}
354+
}
355+
356+
void QgsProcessingAlgorithmDialogBase::scrollToBottomOfLog()
357+
{
358+
QScrollBar *sb = txtLog->verticalScrollBar();
359+
sb->setValue( sb->maximum() );
360+
}
361+
328362
void QgsProcessingAlgorithmDialogBase::resetGui()
329363
{
330364
lblProgress->clear();
@@ -352,6 +386,8 @@ void QgsProcessingAlgorithmDialogBase::setInfo( const QString &message, bool isE
352386
txtLog->append( message.toHtmlEscaped() );
353387
else
354388
txtLog->append( message );
389+
scrollToBottomOfLog();
390+
processEvents();
355391
}
356392

357393
///@endcond

‎src/gui/processing/qgsprocessingalgorithmdialogbase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
271271
bool mHelpCollapsed = false;
272272

273273
QString formatHelp( QgsProcessingAlgorithm *algorithm );
274+
void processEvents();
275+
void scrollToBottomOfLog();
274276

275277
};
276278

0 commit comments

Comments
 (0)
Please sign in to comment.