22
22
#include " processing/qgsprocessingprovider.h"
23
23
#include < QToolButton>
24
24
#include < QDesktopServices>
25
+ #include < QScrollBar>
25
26
26
27
// /@cond NOT_STABLE
27
28
@@ -271,27 +272,35 @@ void QgsProcessingAlgorithmDialogBase::reportError( const QString &error )
271
272
{
272
273
setInfo ( error, true );
273
274
resetGui ();
274
- mTabWidget ->setCurrentIndex ( 1 );
275
+ showLog ();
276
+ processEvents ();
275
277
}
276
278
277
279
void QgsProcessingAlgorithmDialogBase::pushInfo ( const QString &info )
278
280
{
279
281
setInfo ( info );
282
+ processEvents ();
280
283
}
281
284
282
285
void QgsProcessingAlgorithmDialogBase::pushCommandInfo ( const QString &command )
283
286
{
284
287
txtLog->append ( QStringLiteral ( " <code>%1<code>" ).arg ( command.toHtmlEscaped () ) );
288
+ scrollToBottomOfLog ();
289
+ processEvents ();
285
290
}
286
291
287
292
void QgsProcessingAlgorithmDialogBase::pushDebugInfo ( const QString &message )
288
293
{
289
294
txtLog->append ( QStringLiteral ( " <span style=\" color:blue\" >%1</span>" ).arg ( message.toHtmlEscaped () ) );
295
+ scrollToBottomOfLog ();
296
+ processEvents ();
290
297
}
291
298
292
299
void QgsProcessingAlgorithmDialogBase::pushConsoleInfo ( const QString &info )
293
300
{
294
301
txtLog->append ( QStringLiteral ( " <code><span style=\" color:blue\" >%1</darkgray></code>" ).arg ( info.toHtmlEscaped () ) );
302
+ scrollToBottomOfLog ();
303
+ processEvents ();
295
304
}
296
305
297
306
void QgsProcessingAlgorithmDialogBase::setPercentage ( double percent )
@@ -300,12 +309,15 @@ void QgsProcessingAlgorithmDialogBase::setPercentage( double percent )
300
309
if ( progressBar->maximum () == 0 )
301
310
progressBar->setMaximum ( 100 );
302
311
progressBar->setValue ( percent );
312
+ processEvents ();
303
313
}
304
314
305
315
void QgsProcessingAlgorithmDialogBase::setProgressText ( const QString &text )
306
316
{
307
317
lblProgress->setText ( text );
308
318
setInfo ( text, false );
319
+ scrollToBottomOfLog ();
320
+ processEvents ();
309
321
}
310
322
311
323
QString QgsProcessingAlgorithmDialogBase::formatHelp ( QgsProcessingAlgorithm *algorithm )
@@ -325,6 +337,28 @@ QString QgsProcessingAlgorithmDialogBase::formatHelp( QgsProcessingAlgorithm *al
325
337
return QString ();
326
338
}
327
339
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
+
328
362
void QgsProcessingAlgorithmDialogBase::resetGui ()
329
363
{
330
364
lblProgress->clear ();
@@ -352,6 +386,8 @@ void QgsProcessingAlgorithmDialogBase::setInfo( const QString &message, bool isE
352
386
txtLog->append ( message.toHtmlEscaped () );
353
387
else
354
388
txtLog->append ( message );
389
+ scrollToBottomOfLog ();
390
+ processEvents ();
355
391
}
356
392
357
393
// /@endcond
0 commit comments