21#include <gdal_version.h>
31#include "moc_qgsprocessingfeedback.cpp"
33using namespace Qt::StringLiterals;
36#include <pdal/pdal.hpp>
40#include <SFCGAL/capi/sfcgal_c.h>
43#ifdef WITH_GEOGRAPHICLIB
44#include <GeographicLib/Constants.hpp>
48 : mLogFeedback( logFeedback )
53 mHtmlLog.append( text.toHtmlEscaped().replace(
'\n',
"<br>"_L1 ) + u
"<br/>"_s );
54 mTextLog.append( text +
'\n' );
59void QgsProcessingFeedback::log(
const QString &htmlMessage,
const QString &textMessage )
61 constexpr int MESSAGE_COUNT_LIMIT = 10000;
63 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
65 ++mMessageLoggedCount;
66 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
68 mHtmlLog.append( u
"<span style=\"color:red\">%1</span><br/>"_s.arg( tr(
"Message log truncated" ) ) );
69 mTextLog.append( tr(
"Message log truncated" ) +
'\n' );
73 mHtmlLog.append( htmlMessage );
74 mTextLog.append( textMessage );
83 log( u
"<span style=\"color:red\">%1</span><br/>"_s.arg( error.toHtmlEscaped() ).replace(
'\n',
"<br>"_L1 ), error +
'\n' );
93 log( u
"<span style=\"color:#b85a20;\">%1</span><br/>"_s.arg( warning.toHtmlEscaped() ).replace(
'\n',
"<br>"_L1 ) + u
"<br/>"_s, warning +
'\n' );
103 mHtmlLog.append( info.toHtmlEscaped().replace(
'\n',
"<br>"_L1 ) + u
"<br/>"_s );
104 mTextLog.append( info +
'\n' );
114 mHtmlLog.append( html + u
"<br/>"_s );
115 mTextLog.append( text +
'\n' );
125 log( u
"<code>%1</code><br/>"_s.arg( info.toHtmlEscaped().replace(
'\n',
"<br>"_L1 ) ), info +
'\n' );
135 log( u
"<span style=\"color:#777\">%1</span><br/>"_s.arg( info.toHtmlEscaped().replace(
'\n',
"<br>"_L1 ) ), info +
'\n' );
145 log( u
"<code style=\"color:#777\">%1</code><br/>"_s.arg( info.toHtmlEscaped().replace(
'\n',
"<br>"_L1 ) ), info +
'\n' );
158 pushDebugInfo( tr(
"Python version: %1" ).arg( PYTHON_VERSION ) );
159 pushDebugInfo( tr(
"GDAL version: %1" ).arg( GDALVersionInfo(
"RELEASE_NAME" ) ) );
160 pushDebugInfo( tr(
"GEOS version: %1" ).arg( GEOSversion() ) );
162 const PJ_INFO info = proj_info();
163 pushDebugInfo( tr(
"PROJ version: %1" ).arg( info.release ) );
166#if PDAL_VERSION_MAJOR_INT > 1 || ( PDAL_VERSION_MAJOR_INT == 1 && PDAL_VERSION_MINOR_INT >= 7 )
167 pushDebugInfo( tr(
"PDAL version: %1" ).arg( QString::fromStdString( pdal::Config::fullVersionString() ) ) );
169 pushDebugInfo( tr(
"PDAL version: %1" ).arg( QString::fromStdString( pdal::GetFullVersionString() ) ) );
174 pushDebugInfo( tr(
"SFCGAL version: %1" ).arg( sfcgal_version() ) );
179#ifdef WITH_GEOGRAPHICLIB
180 pushDebugInfo( tr(
"GeographicLib version: %1.%2.%3" ).arg( GEOGRAPHICLIB_VERSION_MAJOR ).arg( GEOGRAPHICLIB_VERSION_MINOR ).arg( GEOGRAPHICLIB_VERSION_PATCH ) );
185 if ( provider && !provider->
versionInfo().isEmpty() )
193 if ( results.empty() )
198 const QList< const QgsProcessingOutputDefinition * > outputs =
algorithm->outputDefinitions();
201 const QString outputName = output->name();
202 if ( outputName ==
"CHILD_RESULTS"_L1 || outputName ==
"CHILD_INPUTS"_L1 )
205 if ( !results.contains( outputName ) )
209 const QString textValue = output->valueAsString( results.value( output->name() ), context, ok );
210 const QString formattedValue = output->valueAsFormattedString( results.value( output->name() ), context, ok );
213 pushFormattedMessage( u
"<code> %1: %2</code>"_s.arg( output->name(), formattedValue ), u
" %1: %2"_s.arg( output->name(), textValue ) );
235 long long countAtLastSignal = 0;
236 long long previousCount = 0;
237 auto it = mSinkFeatureCounts.find( output );
238 if ( it == mSinkFeatureCounts.end() )
240 it = mSinkFeatureCounts.insert( output, SinkStats() );
244 countAtLastSignal = it.value().countAtLastSignal;
245 previousCount = it.value().featureCount;
248 const long long newCount = previousCount + 1;
249 it.value().featureCount = newCount;
250 if ( newCount - countAtLastSignal >= 100 )
253 it.value().countAtLastSignal = newCount;
259 long long previousCount = 0;
260 auto it = mSinkFeatureCounts.find( output );
261 if ( it == mSinkFeatureCounts.end() )
263 it = mSinkFeatureCounts.insert( output, SinkStats() );
267 previousCount = it.value().featureCount;
271 it.value().countAtLastSignal = previousCount;
276 mSinkFeatureCounts.clear();
280 : mChildSteps( childAlgorithmCount )
281 , mFeedback( feedback )
290 const double equalWeight = mChildSteps > 0 ? 1.0 / mChildSteps : 0.0;
291 for (
int i = 0; i < mChildSteps; ++i )
293 mStepWeights << equalWeight;
302 mCurrentStepBaseProgress = 0.0;
303 for (
int i = 0; i < mCurrentStep && i < mStepWeights.count(); ++i )
305 mCurrentStepBaseProgress += mStepWeights.at( i ) * 100.0;
310 mFeedback->setProgress( mCurrentStepBaseProgress );
315 if ( weights.size() != mChildSteps )
320 const double totalWeight = std::reduce( weights.begin(), weights.end() );
322 mStepWeights.clear();
323 if ( totalWeight > 0.0 )
325 for (
double w : weights )
327 mStepWeights << ( w / totalWeight );
333 const double equalWeight = mChildSteps > 0 ? 1.0 / mChildSteps : 0.0;
334 for (
int i = 0; i < mChildSteps; ++i )
336 mStepWeights << equalWeight;
344 mFeedback->setProgressText( text );
350 mFeedback->reportError( error, fatalError );
356 mFeedback->pushWarning( warning );
362 mFeedback->pushInfo( info );
368 mFeedback->pushCommandInfo( info );
374 mFeedback->pushDebugInfo( info );
380 mFeedback->pushConsoleInfo( info );
386 mFeedback->pushFormattedMessage( html, text );
392 return mFeedback->htmlLog();
399 return mFeedback->textLog();
403void QgsProcessingMultiStepFeedback::updateOverallProgress(
double progress )
408 const double currentStepWeight = mStepWeights.value( mCurrentStep, 0 );
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(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
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.
void featureAddedToSink(const QString &output)
Reports that a feature was added to the the sink associated with the specified algorithm output.
virtual void pushCommandInfo(const QString &info)
Pushes an informational message containing a command from the algorithm.
void warningPushed(const QString &text)
Emitted when an warning is pushed.
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 infoPushed(const QString &text)
Emitted when information text is pushed.
void errorReported(const QString &text, bool fatalError)
Emitted when an error is reported.
void progressTextChanged(const QString &text)
Emitted when the progress text is changed.
void debugInfoPushed(const QString &text)
Emitted when debug information text is pushed.
void sinkFeatureCountChanged(const QString &output, long long featureCount)
Emitted when the count of features pushed to a sink has changed.
void featureSinkFinalized(const QString &output)
Reports that a feature sink has been finalized.
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...
void sourceLoaded(const QString ¶meterName, long long featureCount)
Emitted when a feature source was retrieved for the specified algorithm input parameter.
virtual void pushDebugInfo(const QString &info)
Pushes an informational message containing debugging helpers from the algorithm.
void reportSourceLoaded(const QString ¶meterName, long long featureCount)
Reports that a feature source was retrieved for the specified algorithm input parameter.
void formattedMessagePushed(const QString &html)
Emitted when a formatted html message is pushed.
virtual void pushFormattedMessage(const QString &html, const QString &text)
Pushes a pre-formatted message from the algorithm.
void resetFeatureSinkCounts()
Resets all stored feature sink counts.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
void commandInfoPushed(const QString &text)
Emitted when command information text is pushed.
void consoleInfoPushed(const QString &text)
Emitted when console information text is pushed.
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 setStepWeights(const QList< double > &weights)
Sets the relative weights for each step.
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