QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 
29 #ifdef HAVE_PDAL
30 #include <pdal/pdal.hpp>
31 #endif
32 
34  : mLogFeedback( logFeedback )
35 {
36 
37 }
38 
40 {
41 }
42 
43 void QgsProcessingFeedback::reportError( const QString &error, bool )
44 {
45  if ( mLogFeedback )
46  QgsMessageLog::logMessage( error, tr( "Processing" ), Qgis::Critical );
47 
48  mHtmlLog.append( QStringLiteral( "<span style=\"color:red\">%1</span><br/>" ).arg( error.toHtmlEscaped() ).replace( '\n', QLatin1String( "<br>" ) ) );
49  mTextLog.append( error + '\n' );
50 }
51 
52 void QgsProcessingFeedback::pushWarning( const QString &warning )
53 {
54  if ( mLogFeedback )
55  QgsMessageLog::logMessage( warning, tr( "Processing" ), Qgis::Warning );
56 
57  mHtmlLog.append( QStringLiteral( "<span style=\"color:#b85a20;\">%1</span><br/>" ).arg( warning.toHtmlEscaped() ).replace( '\n', QLatin1String( "<br>" ) ) + QStringLiteral( "<br/>" ) );
58  mTextLog.append( warning + '\n' );
59 }
60 
61 void QgsProcessingFeedback::pushInfo( const QString &info )
62 {
63  if ( mLogFeedback )
64  QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::Info );
65 
66  mHtmlLog.append( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) + QStringLiteral( "<br/>" ) );
67  mTextLog.append( info + '\n' );
68 }
69 
70 void QgsProcessingFeedback::pushCommandInfo( const QString &info )
71 {
72  if ( mLogFeedback )
73  QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::Info );
74 
75  mHtmlLog.append( QStringLiteral( "<code>%1</code><br/>" ).arg( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) ) );
76  mTextLog.append( info + '\n' );
77 }
78 
79 void QgsProcessingFeedback::pushDebugInfo( const QString &info )
80 {
81  if ( mLogFeedback )
82  QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::Info );
83 
84  mHtmlLog.append( QStringLiteral( "<span style=\"color:#777\">%1</span><br/>" ).arg( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) ) );
85  mTextLog.append( info + '\n' );
86 }
87 
88 void QgsProcessingFeedback::pushConsoleInfo( const QString &info )
89 {
90  if ( mLogFeedback )
91  QgsMessageLog::logMessage( info, tr( "Processing" ), Qgis::Info );
92 
93  mHtmlLog.append( QStringLiteral( "<code style=\"color:#777\">%1</code><br/>" ).arg( info.toHtmlEscaped().replace( '\n', QLatin1String( "<br>" ) ) ) );
94  mTextLog.append( info + '\n' );
95 }
96 
98 {
99  pushDebugInfo( tr( "QGIS version: %1" ).arg( Qgis::version() ) );
100  if ( QString( Qgis::devVersion() ) != QLatin1String( "exported" ) )
101  {
102  pushDebugInfo( tr( "QGIS code revision: %1" ).arg( Qgis::devVersion() ) );
103  }
104  pushDebugInfo( tr( "Qt version: %1" ).arg( qVersion() ) );
105  pushDebugInfo( tr( "GDAL version: %1" ).arg( GDALVersionInfo( "RELEASE_NAME" ) ) );
106  pushDebugInfo( tr( "GEOS version: %1" ).arg( GEOSversion() ) );
107 
108 #if PROJ_VERSION_MAJOR > 4
109  PJ_INFO info = proj_info();
110  pushDebugInfo( tr( "PROJ version: %1" ).arg( info.release ) );
111 #else
112  pushDebugInfo( tr( "PROJ version: %1" ).arg( PJ_VERSION ) );
113 #endif
114 
115 #ifdef HAVE_PDAL
116 #if PDAL_VERSION_MAJOR_INT > 1 || (PDAL_VERSION_MAJOR_INT == 1 && PDAL_VERSION_MINOR_INT >= 7)
117  pushDebugInfo( tr( "PDAL version: %1" ).arg( QString::fromStdString( pdal::Config::fullVersionString() ) ) );
118 #else
119  pushDebugInfo( tr( "PDAL version: %1" ).arg( QString::fromStdString( pdal::GetFullVersionString() ) ) );
120 #endif
121 #endif
122 
123  if ( provider && !provider->versionInfo().isEmpty() )
124  {
125  pushDebugInfo( tr( "%1 version: %2" ).arg( provider->name(), provider->versionInfo() ) );
126  }
127 }
128 
130 {
131  return mHtmlLog;
132 }
133 
135 {
136  return mTextLog;
137 }
138 
139 
141  : mChildSteps( childAlgorithmCount )
142  , mFeedback( feedback )
143 {
144  connect( mFeedback, &QgsFeedback::canceled, this, &QgsFeedback::cancel, Qt::DirectConnection );
145  connect( this, &QgsFeedback::progressChanged, this, &QgsProcessingMultiStepFeedback::updateOverallProgress );
146 }
147 
149 {
150  mCurrentStep = step;
151  mFeedback->setProgress( 100.0 * static_cast< double >( mCurrentStep ) / mChildSteps );
152 }
153 
155 {
156  mFeedback->setProgressText( text );
157 }
158 
159 void QgsProcessingMultiStepFeedback::reportError( const QString &error, bool fatalError )
160 {
161  mFeedback->reportError( error, fatalError );
162 }
163 
164 void QgsProcessingMultiStepFeedback::pushWarning( const QString &warning )
165 {
166  mFeedback->pushWarning( warning );
167 }
168 
169 void QgsProcessingMultiStepFeedback::pushInfo( const QString &info )
170 {
171  mFeedback->pushInfo( info );
172 }
173 
175 {
176  mFeedback->pushCommandInfo( info );
177 }
178 
180 {
181  mFeedback->pushDebugInfo( info );
182 }
183 
185 {
186  mFeedback->pushConsoleInfo( info );
187 }
188 
190 {
191  return mFeedback->htmlLog();
192 }
193 
195 {
196  return mFeedback->textLog();
197 }
198 
199 void QgsProcessingMultiStepFeedback::updateOverallProgress( double progress )
200 {
201  double baseProgress = 100.0 * static_cast< double >( mCurrentStep ) / mChildSteps;
202  double currentAlgorithmProgress = progress / mChildSteps;
203  mFeedback->setProgress( baseProgress + currentAlgorithmProgress );
204 }
205 
static QString version()
Version string.
Definition: qgis.cpp:276
@ Warning
Definition: qgis.h:91
@ Critical
Definition: qgis.h:92
@ Info
Definition: qgis.h:90
static QString devVersion()
The development version.
Definition: qgis.cpp:293
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.
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
double progress() const
Returns the current progress reported by the feedback object.
Definition: qgsfeedback.h:80
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).
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.