20#include <gdal_version.h>
28#include "moc_qgsprocessingfeedback.cpp"
31#include <pdal/pdal.hpp>
35#include <SFCGAL/capi/sfcgal_c.h>
39 : mLogFeedback( logFeedback )
46 mHtmlLog.append( text.toHtmlEscaped().replace(
'\n', QLatin1String(
"<br>" ) ) + QStringLiteral(
"<br/>" ) );
47 mTextLog.append( text +
'\n' );
50void QgsProcessingFeedback::log(
const QString &htmlMessage,
const QString &textMessage )
52 constexpr int MESSAGE_COUNT_LIMIT = 10000;
54 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
56 ++mMessageLoggedCount;
57 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
59 mHtmlLog.append( QStringLiteral(
"<span style=\"color:red\">%1</span><br/>" ).arg( tr(
"Message log truncated" ) ) );
60 mTextLog.append( tr(
"Message log truncated" ) +
'\n' );
64 mHtmlLog.append( htmlMessage );
65 mTextLog.append( textMessage );
75 log( QStringLiteral(
"<span style=\"color:red\">%1</span><br/>" ).arg( error.toHtmlEscaped() ).replace(
'\n', QLatin1String(
"<br>" ) ),
84 log( QStringLiteral(
"<span style=\"color:#b85a20;\">%1</span><br/>" ).arg( warning.toHtmlEscaped() ).replace(
'\n', QLatin1String(
"<br>" ) ) + QStringLiteral(
"<br/>" ),
93 mHtmlLog.append( info.toHtmlEscaped().replace(
'\n', QLatin1String(
"<br>" ) ) + QStringLiteral(
"<br/>" ) );
94 mTextLog.append( info +
'\n' );
102 mHtmlLog.append( html + QStringLiteral(
"<br/>" ) );
103 mTextLog.append( text +
'\n' );
111 log( QStringLiteral(
"<code>%1</code><br/>" ).arg( info.toHtmlEscaped().replace(
'\n', QLatin1String(
"<br>" ) ) ),
120 log( QStringLiteral(
"<span style=\"color:#777\">%1</span><br/>" ).arg( info.toHtmlEscaped().replace(
'\n', QLatin1String(
"<br>" ) ) ),
129 log( QStringLiteral(
"<code style=\"color:#777\">%1</code><br/>" ).arg( info.toHtmlEscaped().replace(
'\n', QLatin1String(
"<br>" ) ) ),
141 pushDebugInfo( tr(
"Python version: %1" ).arg( PYTHON_VERSION ) );
142 pushDebugInfo( tr(
"GDAL version: %1" ).arg( GDALVersionInfo(
"RELEASE_NAME" ) ) );
143 pushDebugInfo( tr(
"GEOS version: %1" ).arg( GEOSversion() ) );
145 const PJ_INFO info = proj_info();
146 pushDebugInfo( tr(
"PROJ version: %1" ).arg( info.release ) );
149#if PDAL_VERSION_MAJOR_INT > 1 || (PDAL_VERSION_MAJOR_INT == 1 && PDAL_VERSION_MINOR_INT >= 7)
150 pushDebugInfo( tr(
"PDAL version: %1" ).arg( QString::fromStdString( pdal::Config::fullVersionString() ) ) );
152 pushDebugInfo( tr(
"PDAL version: %1" ).arg( QString::fromStdString( pdal::GetFullVersionString() ) ) );
157 pushDebugInfo( tr(
"SFCGAL version: %1" ).arg( sfcgal_version() ) );
162 if ( provider && !provider->
versionInfo().isEmpty() )
170 if ( results.empty() )
175 const QList< const QgsProcessingOutputDefinition * > outputs =
algorithm->outputDefinitions();
178 const QString outputName = output->name();
179 if ( outputName == QLatin1String(
"CHILD_RESULTS" ) || outputName == QLatin1String(
"CHILD_INPUTS" ) )
182 if ( !results.contains( outputName ) )
186 const QString textValue = output->valueAsString( results.value( output->name() ), context, ok );
187 const QString formattedValue = output->valueAsFormattedString( results.value( output->name() ), context, ok );
190 pushFormattedMessage( QStringLiteral(
"<code> %1: %2</code>" ).arg( output->name(), formattedValue ),
191 QStringLiteral(
" %1: %2" ).arg( output->name(), textValue ) );
208 : mChildSteps( childAlgorithmCount )
209 , mFeedback( feedback )
223 mFeedback->setProgress( 100.0 *
static_cast< double >( mCurrentStep ) / mChildSteps );
229 mFeedback->setProgressText( text );
235 mFeedback->reportError( error, fatalError );
241 mFeedback->pushWarning( warning );
247 mFeedback->pushInfo( info );
253 mFeedback->pushCommandInfo( info );
259 mFeedback->pushDebugInfo( info );
265 mFeedback->pushConsoleInfo( info );
271 mFeedback->pushFormattedMessage( html, text );
277 return mFeedback->htmlLog();
284 return mFeedback->textLog();
288void QgsProcessingMultiStepFeedback::updateOverallProgress(
double progress )
290 const double baseProgress = 100.0 *
static_cast< double >( mCurrentStep ) / mChildSteps;
291 const double currentAlgorithmProgress =
progress / mChildSteps;
293 mFeedback->
setProgress( baseProgress + currentAlgorithmProgress );
static QString version()
Version string.
@ Warning
Warning message.
@ Critical
Critical/error message.
@ Info
Information message.
static QString devVersion()
The development version.
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 ...
void setProgress(double progress)
Sets the current progress for the feedback object.
double progress() const
Returns the current progress reported by the feedback object.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
Abstract base class for processing algorithms.
Contains information about the context in which a processing algorithm is executed.
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.
void pushFormattedResults(const QgsProcessingAlgorithm *algorithm, QgsProcessingContext &context, const QVariantMap &results)
Pushes a summary of the execution results to the log.
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 pushFormattedMessage(const QString &html, const QString &text)
Pushes a pre-formatted message 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 pushFormattedMessage(const QString &html, const QString &text) override
Pushes a pre-formatted message 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...
Base class for the definition of processing outputs.
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.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call