34#include "moc_qgsprocessingwidgetwrapper.cpp"
43 , mParameterDefinition( parameter )
68 if ( mParameterDefinition->isDynamic() )
70 QHBoxLayout *hLayout =
new QHBoxLayout();
71 hLayout->setContentsMargins( 0, 0, 0, 0 );
72 hLayout->addWidget( mWidget, 1 );
74 hLayout->addWidget( mPropertyButton );
75 mPropertyButton->init( 0,
QgsProperty(), mParameterDefinition->dynamicPropertyDefinition() );
76 mPropertyButton->registerEnabledWidget( mWidget,
false );
77 mPropertyButton->registerExpressionContextGenerator(
this );
86 setWidgetValue( mParameterDefinition->defaultValueForGui(), context );
113 return mParameterDefinition;
118 if ( mPropertyButton && value.userType() == qMetaTypeId<QgsProperty>() )
120 mPropertyButton->setToProperty( value.value<
QgsProperty>() );
124 if ( mPropertyButton )
133 if ( mPropertyButton && mPropertyButton->isActive() )
134 return mPropertyButton->toProperty();
141 return QVariantMap();
164 QString description = mParameterDefinition->description();
166 description = QObject::tr(
"%1 [optional]" ).arg( description );
167 auto label = std::make_unique<QLabel>( description );
168 label->setToolTip( mParameterDefinition->toolTip() );
169 label->setWordWrap(
true );
170 return label.release();
178 if ( mPropertyButton )
179 return mPropertyButton->vectorLayer();
194 if ( wrapper->parameterDefinition()->name() ==
parameterDefinition()->dynamicLayerParameterName() )
196 setDynamicParentLayerParameter( wrapper );
219 if ( mParameterDefinition && !mParameterDefinition->additionalExpressionContextVariables().isEmpty() )
221 auto paramScope = std::make_unique<QgsExpressionContextScope>();
222 const QStringList additional = mParameterDefinition->additionalExpressionContextVariables();
223 for (
const QString &var : additional )
225 paramScope->setVariable( var, QVariant() );
231 highlighted.append( additional );
244 setDynamicParentLayerParameter( wrapper );
250 if ( mPropertyButton )
253 QgsProcessingContext *context =
nullptr;
254 std::unique_ptr<QgsProcessingContext> tmpContext;
260 tmpContext = std::make_unique<QgsProcessingContext>();
261 context = tmpContext.get();
265 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
268 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
275 mPropertyButton->setVectorLayer(
nullptr );
281 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
284 mDynamicLayer.reset( qobject_cast<QgsVectorLayer *>( ownedLayer.release() ) );
285 layer = mDynamicLayer.get();
292 mPropertyButton->setVectorLayer( layer );
300 auto widget = std::make_unique<QgsProcessingModelerParameterWidget>( model, childId, parameter, context );
309 return widget.release();
323 return QStringList();
331 return QStringList();
364 std::unique_ptr<QgsProcessingContext> tmpContext;
365 if ( processingContextGenerator )
370 tmpContext = std::make_unique<QgsProcessingContext>();
371 context = tmpContext.get();
376 if (
auto *lModel = widgetContext.
model() )
389 QStringList highlightedVariables = childScope->
variableNames();
390 QStringList highlightedFunctions = childScope->functionNames();
391 highlightedVariables += algorithmScope->variableNames();
392 highlightedVariables += lModel->variables().keys();
393 highlightedFunctions += algorithmScope->functionNames();
394 c.setHighlightedVariables( highlightedVariables );
395 c.setHighlightedFunctions( highlightedFunctions );
416 if ( mValue == value )
ProcessingMode
Types of modes which Processing widgets can be created for.
@ Batch
Batch processing mode.
@ Standard
Standard (single-run) algorithm mode.
ProcessingModelChildParameterSource
Processing model child parameter sources.
@ ModelOutput
Parameter value is linked to an output parameter for the model.
@ StaticValue
Parameter value is a static value.
@ Optional
Parameter is optional.
static QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers,...
Single scope for storing variables and functions for use within a QgsExpressionContext.
QStringList variableNames() const
Returns a list of variable names contained within the scope.
static QgsExpressionContextScope * processingModelAlgorithmScope(const QgsProcessingModelAlgorithm *model, const QVariantMap ¶meters, QgsProcessingContext &context)
Creates a new scope which contains variables and functions relating to a processing model algorithm,...
static QgsExpressionContextScope * processingAlgorithmScope(const QgsProcessingAlgorithm *algorithm, const QVariantMap ¶meters, QgsProcessingContext &context)
Creates a new scope which contains variables and functions relating to a processing algorithm,...
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QStringList highlightedVariables() const
Returns the current list of variables highlighted within the context.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user.
Abstract base class for processing algorithms.
An interface for objects which can create Processing contexts.
virtual QgsProcessingContext * processingContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return a Proc...
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsMapLayer * takeResultLayer(const QString &id)
Takes the result map layer with matching id from the context and transfers ownership of it back to th...
Base class for all parameter definitions which represent file or layer destinations,...
QgsProperty source
Source definition.
Base class for the definition of processing parameters.
virtual bool isDestination() const
Returns true if this parameter represents a file or layer destination, e.g.
Makes metadata of processing parameters available.
virtual QStringList acceptedOutputTypes() const =0
Returns a list of compatible Processing output types for inputs for this parameter type.
virtual QList< int > acceptedDataTypes(const QgsProcessingParameterDefinition *parameter) const
Returns a list of compatible Processing data types for inputs for this parameter type for the specifi...
virtual QStringList acceptedParameterTypes() const =0
Returns a list of compatible Processing parameter types for inputs for this parameter type.
Contains settings which reflect the context in which a Processing parameter widget is shown.
QgsProcessingModelAlgorithm * model() const
Returns the model which the parameter widget is associated with.
QString modelChildAlgorithmId() const
Returns the child algorithm ID within the model which the parameter widget is associated with.
An interface for objects which can create sets of parameter values for processing algorithms.
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
QgsProcessingParameterType * parameterType(const QString &id) const
Returns the parameter type registered for id.
A store for object properties.
Represents a vector layer which manages a vector based dataset.
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
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 c