20#include <gdal_version.h>
30#include "moc_qgsprocessingfeedback.cpp"
32using namespace Qt::StringLiterals;
35#include <pdal/pdal.hpp>
39#include <SFCGAL/capi/sfcgal_c.h>
42#ifdef WITH_GEOGRAPHICLIB
43#include <GeographicLib/Constants.hpp>
47 : mLogFeedback( logFeedback )
52 mHtmlLog.append( text.toHtmlEscaped().replace(
'\n',
"<br>"_L1 ) + u
"<br/>"_s );
53 mTextLog.append( text +
'\n' );
58void QgsProcessingFeedback::log(
const QString &htmlMessage,
const QString &textMessage )
60 constexpr int MESSAGE_COUNT_LIMIT = 10000;
62 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
64 ++mMessageLoggedCount;
65 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
67 mHtmlLog.append( u
"<span style=\"color:red\">%1</span><br/>"_s.arg( tr(
"Message log truncated" ) ) );
68 mTextLog.append( tr(
"Message log truncated" ) +
'\n' );
72 mHtmlLog.append( htmlMessage );
73 mTextLog.append( textMessage );
82 log( u
"<span style=\"color:red\">%1</span><br/>"_s.arg( error.toHtmlEscaped() ).replace(
'\n',
"<br>"_L1 ), error +
'\n' );
92 log( u
"<span style=\"color:#b85a20;\">%1</span><br/>"_s.arg( warning.toHtmlEscaped() ).replace(
'\n',
"<br>"_L1 ) + u
"<br/>"_s, warning +
'\n' );
102 mHtmlLog.append( info.toHtmlEscaped().replace(
'\n',
"<br>"_L1 ) + u
"<br/>"_s );
103 mTextLog.append( info +
'\n' );
113 mHtmlLog.append( html + u
"<br/>"_s );
114 mTextLog.append( text +
'\n' );
124 log( u
"<code>%1</code><br/>"_s.arg( info.toHtmlEscaped().replace(
'\n',
"<br>"_L1 ) ), info +
'\n' );
134 log( u
"<span style=\"color:#777\">%1</span><br/>"_s.arg( info.toHtmlEscaped().replace(
'\n',
"<br>"_L1 ) ), info +
'\n' );
144 log( u
"<code style=\"color:#777\">%1</code><br/>"_s.arg( info.toHtmlEscaped().replace(
'\n',
"<br>"_L1 ) ), info +
'\n' );
157 pushDebugInfo( tr(
"Python version: %1" ).arg( PYTHON_VERSION ) );
158 pushDebugInfo( tr(
"GDAL version: %1" ).arg( GDALVersionInfo(
"RELEASE_NAME" ) ) );
159 pushDebugInfo( tr(
"GEOS version: %1" ).arg( GEOSversion() ) );
161 const PJ_INFO info = proj_info();
162 pushDebugInfo( tr(
"PROJ version: %1" ).arg( info.release ) );
165#if PDAL_VERSION_MAJOR_INT > 1 || ( PDAL_VERSION_MAJOR_INT == 1 && PDAL_VERSION_MINOR_INT >= 7 )
166 pushDebugInfo( tr(
"PDAL version: %1" ).arg( QString::fromStdString( pdal::Config::fullVersionString() ) ) );
168 pushDebugInfo( tr(
"PDAL version: %1" ).arg( QString::fromStdString( pdal::GetFullVersionString() ) ) );
173 pushDebugInfo( tr(
"SFCGAL version: %1" ).arg( sfcgal_version() ) );
178#ifdef WITH_GEOGRAPHICLIB
179 pushDebugInfo( tr(
"GeographicLib version: %1.%2.%3" ).arg( GEOGRAPHICLIB_VERSION_MAJOR ).arg( GEOGRAPHICLIB_VERSION_MINOR ).arg( GEOGRAPHICLIB_VERSION_PATCH ) );
184 if ( provider && !provider->
versionInfo().isEmpty() )
192 if ( results.empty() )
197 const QList< const QgsProcessingOutputDefinition * > outputs =
algorithm->outputDefinitions();
200 const QString outputName = output->name();
201 if ( outputName ==
"CHILD_RESULTS"_L1 || outputName ==
"CHILD_INPUTS"_L1 )
204 if ( !results.contains( outputName ) )
208 const QString textValue = output->valueAsString( results.value( output->name() ), context, ok );
209 const QString formattedValue = output->valueAsFormattedString( results.value( output->name() ), context, ok );
212 pushFormattedMessage( u
"<code> %1: %2</code>"_s.arg( output->name(), formattedValue ), u
" %1: %2"_s.arg( output->name(), textValue ) );
234 long long countAtLastSignal = 0;
235 long long previousCount = 0;
236 auto it = mSinkFeatureCounts.find( output );
237 if ( it == mSinkFeatureCounts.end() )
239 it = mSinkFeatureCounts.insert( output, SinkStats() );
243 countAtLastSignal = it.value().countAtLastSignal;
244 previousCount = it.value().featureCount;
247 const long long newCount = previousCount + 1;
248 it.value().featureCount = newCount;
249 if ( newCount - countAtLastSignal >= 100 )
252 it.value().countAtLastSignal = newCount;
258 long long previousCount = 0;
259 auto it = mSinkFeatureCounts.find( output );
260 if ( it == mSinkFeatureCounts.end() )
262 it = mSinkFeatureCounts.insert( output, SinkStats() );
266 previousCount = it.value().featureCount;
270 it.value().countAtLastSignal = previousCount;
275 mSinkFeatureCounts.clear();
279 : mChildSteps( childAlgorithmCount )
280 , mFeedback( feedback )
289 const double equalWeight = mChildSteps > 0 ? 1.0 / mChildSteps : 0.0;
290 for (
int i = 0; i < mChildSteps; ++i )
292 mStepWeights << equalWeight;
301 mCurrentStepBaseProgress = 0.0;
302 for (
int i = 0; i < mCurrentStep && i < mStepWeights.count(); ++i )
304 mCurrentStepBaseProgress += mStepWeights.at( i ) * 100.0;
309 mFeedback->setProgress( mCurrentStepBaseProgress );
314 if ( weights.size() != mChildSteps )
319 const double totalWeight = std::reduce( weights.begin(), weights.end() );
321 mStepWeights.clear();
322 if ( totalWeight > 0.0 )
324 for (
double w : weights )
326 mStepWeights << ( w / totalWeight );
332 const double equalWeight = mChildSteps > 0 ? 1.0 / mChildSteps : 0.0;
333 for (
int i = 0; i < mChildSteps; ++i )
335 mStepWeights << equalWeight;
343 mFeedback->setProgressText( text );
349 mFeedback->reportError( error, fatalError );
355 mFeedback->pushWarning( warning );
361 mFeedback->pushInfo( info );
367 mFeedback->pushCommandInfo( info );
373 mFeedback->pushDebugInfo( info );
379 mFeedback->pushConsoleInfo( info );
385 mFeedback->pushFormattedMessage( html, text );
391 return mFeedback->htmlLog();
398 return mFeedback->textLog();
402void QgsProcessingMultiStepFeedback::updateOverallProgress(
double progress )
407 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