QGIS API Documentation  3.6.0-Noosa (5873452)
qgsprocessingfeedback.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprocessingfeedback.cpp
3  -------------------------
4  begin : June 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgsprocessingfeedback.h"
19 
21  : mChildSteps( childAlgorithmCount )
22  , mFeedback( feedback )
23 {
24  connect( mFeedback, &QgsFeedback::canceled, this, &QgsFeedback::cancel, Qt::DirectConnection );
25  connect( this, &QgsFeedback::progressChanged, this, &QgsProcessingMultiStepFeedback::updateOverallProgress );
26 }
27 
29 {
30  mCurrentStep = step;
31  mFeedback->setProgress( 100.0 * static_cast< double >( mCurrentStep ) / mChildSteps );
32 }
33 
35 {
36  mFeedback->setProgressText( text );
37 }
38 
39 void QgsProcessingMultiStepFeedback::reportError( const QString &error, bool fatalError )
40 {
41  mFeedback->reportError( error, fatalError );
42 }
43 
44 void QgsProcessingMultiStepFeedback::pushInfo( const QString &info )
45 {
46  mFeedback->pushInfo( info );
47 }
48 
50 {
51  mFeedback->pushCommandInfo( info );
52 }
53 
55 {
56  mFeedback->pushDebugInfo( info );
57 }
58 
60 {
61  mFeedback->pushConsoleInfo( info );
62 }
63 
64 void QgsProcessingMultiStepFeedback::updateOverallProgress( double progress )
65 {
66  double baseProgress = 100.0 * static_cast< double >( mCurrentStep ) / mChildSteps;
67  double currentAlgorithmProgress = progress / mChildSteps;
68  mFeedback->setProgress( baseProgress + currentAlgorithmProgress );
69 }
70 
71 
Base class for providing feedback from a processing algorithm.
void cancel()
Tells the internal routines that the current operation should be canceled. This should be run by the ...
Definition: qgsfeedback.h:85
double progress() const
Returns the current progress reported by the feedback object.
Definition: qgsfeedback.h:80
void reportError(const QString &error, bool fatalError) override
Reports that the algorithm encountered an error while executing.
void pushConsoleInfo(const QString &info) override
Pushes a console feedback message from the algorithm.
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition: qgsfeedback.h:63
void pushDebugInfo(const QString &info) override
Pushes an informational message containing debugging helpers from the algorithm.
void canceled()
Internal routines can connect to this signal if they use event loop.
void setCurrentStep(int step)
Sets the step which is being executed.
virtual void setProgressText(const QString &text)
Sets a progress report text string.
void setProgressText(const QString &text) override
Sets a progress report text string.
void pushCommandInfo(const QString &info) override
Pushes an informational message containing a command from the algorithm.
void progressChanged(double progress)
Emitted when the feedback object reports a progress change.
QgsProcessingMultiStepFeedback(int steps, QgsProcessingFeedback *feedback)
Constructor for QgsProcessingMultiStepFeedback, for a process with the specified number of steps...
virtual void pushDebugInfo(const QString &info)
Pushes an informational message containing debugging helpers from the algorithm.
virtual void pushConsoleInfo(const QString &info)
Pushes a console feedback message from the algorithm.
virtual void pushCommandInfo(const QString &info)
Pushes an informational message containing a command from the algorithm.
void pushInfo(const QString &info) override
Pushes a general informational message from the algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.