QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 #include <proj.h>
24 
25 #ifdef HAVE_PDAL
26 #include <pdal/pdal.hpp>
27 #endif
28 
30  : mLogFeedback( logFeedback )
31 {
32 
33 }
34 
36 {
37 }
38 
39 void QgsProcessingFeedback::reportError( const QString &error, bool )
40 {
41  if ( mLogFeedback )
42  QgsMessageLog::logMessage( error, tr( "Processing" ), Qgis::MessageLevel::Critical );
43 
44  mHtmlLog.append( QStringLiteral( "<span style=\"color:red\">%1</span><br/>" ).arg( error.toHtmlEscaped() ).replace( '\n', QLatin1String( "<br>" ) ) );
45  mTextLog.append( error + '\n' );
46 }
47 
48 void QgsProcessingFeedback::pushWarning( const QString &warning )
49 {
50  if ( mLogFeedback )
51  QgsMessageLog::logMessage( warning, tr( "Processing" ), Qgis::MessageLevel::Warning );
52 
53  mHtmlLog.append( QStringLiteral( "<span style=\"color:#b85a20;\">%1</span><br/>" ).arg( warning.toHtmlEscaped() ).replace( '\n', QLatin1String( "<br>" ) ) + QStringLiteral( "<br/>" ) );
54  mTextLog.append( warning + '\n' );
55 }
56 
57 void QgsProcessingFeedback::pushInfo( const QString &info )
58 {
59  if ( mLogFeedback )
60  QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::MessageLevel::Info );
61 
62  mHtmlLog.append( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) + QStringLiteral( "<br/>" ) );
63  mTextLog.append( info + '\n' );
64 }
65 
66 void QgsProcessingFeedback::pushCommandInfo( const QString &info )
67 {
68  if ( mLogFeedback )
69  QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::MessageLevel::Info );
70 
71  mHtmlLog.append( QStringLiteral( "<code>%1</code><br/>" ).arg( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) ) );
72  mTextLog.append( info + '\n' );
73 }
74 
75 void QgsProcessingFeedback::pushDebugInfo( const QString &info )
76 {
77  if ( mLogFeedback )
78  QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::MessageLevel::Info );
79 
80  mHtmlLog.append( QStringLiteral( "<span style=\"color:#777\">%1</span><br/>" ).arg( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) ) );
81  mTextLog.append( info + '\n' );
82 }
83 
84 void QgsProcessingFeedback::pushConsoleInfo( const QString &info )
85 {
86  if ( mLogFeedback )
87  QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::MessageLevel::Info );
88 
89  mHtmlLog.append( QStringLiteral( "<code style=\"color:#777\">%1</code><br/>" ).arg( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) ) );
90  mTextLog.append( info + '\n' );
91 }
92 
94 {
95  pushDebugInfo( tr( "QGIS version: %1" ).arg( Qgis::version() ) );
96  if ( QString( Qgis::devVersion() ) != QLatin1String( "exported" ) )
97  {
98  pushDebugInfo( tr( "QGIS code revision: %1" ).arg( Qgis::devVersion() ) );
99  }
100  pushDebugInfo( tr( "Qt version: %1" ).arg( qVersion() ) );
101  pushDebugInfo( tr( "Python version: %1" ).arg( PYTHON_VERSION ) );
102  pushDebugInfo( tr( "GDAL version: %1" ).arg( GDALVersionInfo( "RELEASE_NAME" ) ) );
103  pushDebugInfo( tr( "GEOS version: %1" ).arg( GEOSversion() ) );
104 
105  PJ_INFO info = proj_info();
106  pushDebugInfo( tr( "PROJ version: %1" ).arg( info.release ) );
107 
108 #ifdef HAVE_PDAL
109 #if PDAL_VERSION_MAJOR_INT > 1 || (PDAL_VERSION_MAJOR_INT == 1 && PDAL_VERSION_MINOR_INT >= 7)
110  pushDebugInfo( tr( "PDAL version: %1" ).arg( QString::fromStdString( pdal::Config::fullVersionString() ) ) );
111 #else
112  pushDebugInfo( tr( "PDAL version: %1" ).arg( QString::fromStdString( pdal::GetFullVersionString() ) ) );
113 #endif
114 #endif
115 
116  if ( provider && !provider->versionInfo().isEmpty() )
117  {
118  pushDebugInfo( tr( "%1 version: %2" ).arg( provider->name(), provider->versionInfo() ) );
119  }
120 }
121 
123 {
124  return mHtmlLog;
125 }
126 
128 {
129  return mTextLog;
130 }
131 
132 
134  : mChildSteps( childAlgorithmCount )
135  , mFeedback( feedback )
136 {
137  connect( mFeedback, &QgsFeedback::canceled, this, &QgsFeedback::cancel, Qt::DirectConnection );
138  connect( this, &QgsFeedback::progressChanged, this, &QgsProcessingMultiStepFeedback::updateOverallProgress );
139 }
140 
142 {
143  mCurrentStep = step;
144  mFeedback->setProgress( 100.0 * static_cast< double >( mCurrentStep ) / mChildSteps );
145 }
146 
148 {
149  mFeedback->setProgressText( text );
150 }
151 
152 void QgsProcessingMultiStepFeedback::reportError( const QString &error, bool fatalError )
153 {
154  mFeedback->reportError( error, fatalError );
155 }
156 
157 void QgsProcessingMultiStepFeedback::pushWarning( const QString &warning )
158 {
159  mFeedback->pushWarning( warning );
160 }
161 
162 void QgsProcessingMultiStepFeedback::pushInfo( const QString &info )
163 {
164  mFeedback->pushInfo( info );
165 }
166 
168 {
169  mFeedback->pushCommandInfo( info );
170 }
171 
173 {
174  mFeedback->pushDebugInfo( info );
175 }
176 
178 {
179  mFeedback->pushConsoleInfo( info );
180 }
181 
183 {
184  return mFeedback->htmlLog();
185 }
186 
188 {
189  return mFeedback->textLog();
190 }
191 
192 void QgsProcessingMultiStepFeedback::updateOverallProgress( double progress )
193 {
194  double baseProgress = 100.0 * static_cast< double >( mCurrentStep ) / mChildSteps;
195  double currentAlgorithmProgress = progress / mChildSteps;
196  mFeedback->setProgress( baseProgress + currentAlgorithmProgress );
197 }
198 
static QString version()
Version string.
Definition: qgis.cpp:285
static QString devVersion()
The development version.
Definition: qgis.cpp:302
void progressChanged(double progress)
Emitted when the feedback object reports a progress change.
void canceled()
Internal routines can connect to this signal if they use event loop.
double progress() const SIP_HOLDGIL
Returns the current progress reported by the feedback object.
Definition: qgsfeedback.h:80
void cancel()
Tells the internal routines that the current operation should be canceled. This should be run by the ...
Definition: qgsfeedback.h:85
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition: qgsfeedback.h:63
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Base class for providing feedback from a processing algorithm.
virtual void pushCommandInfo(const QString &info)
Pushes an informational message containing a command from the algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
virtual void pushWarning(const QString &warning)
Pushes a warning informational message from the algorithm.
void pushVersionInfo(const QgsProcessingProvider *provider=nullptr)
Pushes a summary of the QGIS (and underlying library) version information to the log.
virtual QString textLog() const
Returns the plain text contents of the log, which contains all messages pushed to the feedback object...
QgsProcessingFeedback(bool logFeedback=true)
Constructor for QgsProcessingFeedback.
virtual QString htmlLog() const
Returns the HTML formatted contents of the log, which contains all messages pushed to the feedback ob...
virtual void pushDebugInfo(const QString &info)
Pushes an informational message containing debugging helpers from the algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
virtual void pushConsoleInfo(const QString &info)
Pushes a console feedback message from the algorithm.
virtual void setProgressText(const QString &text)
Sets a progress report text string.
QgsProcessingMultiStepFeedback(int steps, QgsProcessingFeedback *feedback)
Constructor for QgsProcessingMultiStepFeedback, for a process with the specified number of steps.
void pushDebugInfo(const QString &info) override
Pushes an informational message containing debugging helpers from the algorithm.
void pushConsoleInfo(const QString &info) override
Pushes a console feedback message from the algorithm.
void pushInfo(const QString &info) override
Pushes a general informational message from the algorithm.
void pushWarning(const QString &warning) override
Pushes a warning informational message from the algorithm.
void setProgressText(const QString &text) override
Sets a progress report text string.
void setCurrentStep(int step)
Sets the step which is being executed.
void reportError(const QString &error, bool fatalError=false) override
Reports that the algorithm encountered an error while executing.
QString textLog() const override
Returns the plain text contents of the log, which contains all messages pushed to the feedback object...
void pushCommandInfo(const QString &info) override
Pushes an informational message containing a command from the algorithm.
QString htmlLog() const override
Returns the HTML formatted contents of the log, which contains all messages pushed to the feedback ob...
Abstract base class for processing providers.
virtual QString versionInfo() const
Returns a version information string for the provider, or an empty string if this is not applicable (...
virtual QString name() const =0
Returns the provider name, which is used to describe the provider within the GUI.