QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 #include "qgsgeos.h"
20 #include "qgsprocessingprovider.h"
21 #include <ogr_api.h>
22 #include <gdal_version.h>
23 #if PROJ_VERSION_MAJOR > 4
24 #include <proj.h>
25 #else
26 #include <proj_api.h>
27 #endif
28 
30 {
31 }
32 
33 void QgsProcessingFeedback::reportError( const QString &error, bool )
34 {
35  QgsMessageLog::logMessage( error, tr( "Processing" ), Qgis::Critical );
36 }
37 
38 void QgsProcessingFeedback::pushInfo( const QString &info )
39 {
40  QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::Info );
41 }
42 
43 void QgsProcessingFeedback::pushCommandInfo( const QString &info )
44 {
45  QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::Info );
46 }
47 
48 void QgsProcessingFeedback::pushDebugInfo( const QString &info )
49 {
50  QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::Info );
51 }
52 
53 void QgsProcessingFeedback::pushConsoleInfo( const QString &info )
54 {
55  QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::Info );
56 }
57 
59 {
60  pushDebugInfo( tr( "QGIS version: %1" ).arg( Qgis::QGIS_VERSION ) );
61  if ( QString( Qgis::QGIS_DEV_VERSION ) != QLatin1String( "exported" ) )
62  {
63  pushDebugInfo( tr( "QGIS code revision: %1" ).arg( Qgis::QGIS_DEV_VERSION ) );
64  }
65  pushDebugInfo( tr( "Qt version: %1" ).arg( qVersion() ) );
66  pushDebugInfo( tr( "GDAL version: %1" ).arg( GDALVersionInfo( "RELEASE_NAME" ) ) );
67  pushDebugInfo( tr( "GEOS version: %1" ).arg( GEOSversion() ) );
68 
69 #if PROJ_VERSION_MAJOR > 4
70  PJ_INFO info = proj_info();
71  pushDebugInfo( tr( "PROJ version: %1" ).arg( info.release ) );
72 #else
73  pushDebugInfo( tr( "PROJ version: %1" ).arg( PJ_VERSION ) );
74 #endif
75  if ( provider && !provider->versionInfo().isEmpty() )
76  {
77  pushDebugInfo( tr( "%1 version: %2" ).arg( provider->name(), provider->versionInfo() ) );
78  }
79 }
80 
81 
83  : mChildSteps( childAlgorithmCount )
84  , mFeedback( feedback )
85 {
86  connect( mFeedback, &QgsFeedback::canceled, this, &QgsFeedback::cancel, Qt::DirectConnection );
87  connect( this, &QgsFeedback::progressChanged, this, &QgsProcessingMultiStepFeedback::updateOverallProgress );
88 }
89 
91 {
92  mCurrentStep = step;
93  mFeedback->setProgress( 100.0 * static_cast< double >( mCurrentStep ) / mChildSteps );
94 }
95 
97 {
98  mFeedback->setProgressText( text );
99 }
100 
101 void QgsProcessingMultiStepFeedback::reportError( const QString &error, bool fatalError )
102 {
103  mFeedback->reportError( error, fatalError );
104 }
105 
106 void QgsProcessingMultiStepFeedback::pushInfo( const QString &info )
107 {
108  mFeedback->pushInfo( info );
109 }
110 
112 {
113  mFeedback->pushCommandInfo( info );
114 }
115 
117 {
118  mFeedback->pushDebugInfo( info );
119 }
120 
122 {
123  mFeedback->pushConsoleInfo( info );
124 }
125 
126 void QgsProcessingMultiStepFeedback::updateOverallProgress( double progress )
127 {
128  double baseProgress = 100.0 * static_cast< double >( mCurrentStep ) / mChildSteps;
129  double currentAlgorithmProgress = progress / mChildSteps;
130  mFeedback->setProgress( baseProgress + currentAlgorithmProgress );
131 }
132 
virtual void pushConsoleInfo(const QString &info)
Pushes a console feedback message from the algorithm.
static const QString QGIS_VERSION
Version string.
Definition: qgis.h:51
Base class for providing feedback from a processing algorithm.
static const char * QGIS_DEV_VERSION
The development version.
Definition: qgis.h:57
virtual QString name() const =0
Returns the provider name, which is used to describe the provider within the GUI. ...
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
virtual void pushCommandInfo(const QString &info)
Pushes an informational message containing a command from the algorithm.
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 QString versionInfo() const
Returns a version information string for the provider, or an empty string if this is not applicable (...
Abstract base class for processing providers.
void setProgressText(const QString &text) override
Sets a progress report text string.
virtual void setProgressText(const QString &text)
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.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
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.
void pushVersionInfo(const QgsProcessingProvider *provider=nullptr)
Pushes a summary of the QGIS (and underlying library) version information to the log.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
void pushInfo(const QString &info) override
Pushes a general informational message from the algorithm.