34#include "moc_qgsprocessingwidgetwrapper.cpp"
62 mBrowserModel =
model;
82 return mModelChildAlgorithmId;
118 , mParameterDefinition( parameter )
144 if ( mParameterDefinition->isDynamic() )
146 QHBoxLayout *hLayout =
new QHBoxLayout();
147 hLayout->setContentsMargins( 0, 0, 0, 0 );
148 hLayout->addWidget( mWidget, 1 );
150 hLayout->addWidget( mPropertyButton );
151 mPropertyButton->init( 0,
QgsProperty(), mParameterDefinition->dynamicPropertyDefinition() );
152 mPropertyButton->registerEnabledWidget( mWidget,
false );
153 mPropertyButton->registerExpressionContextGenerator(
this );
162 setWidgetValue( mParameterDefinition->defaultValueForGui(), context );
189 return mParameterDefinition;
194 if ( mPropertyButton && value.userType() == qMetaTypeId<QgsProperty>() )
196 mPropertyButton->setToProperty( value.value<
QgsProperty>() );
200 if ( mPropertyButton )
209 if ( mPropertyButton && mPropertyButton->isActive() )
210 return mPropertyButton->toProperty();
217 return QVariantMap();
240 QString description = mParameterDefinition->description();
242 description = QObject::tr(
"%1 [optional]" ).arg( description );
243 auto label = std::make_unique<QLabel>( description );
244 label->setToolTip( mParameterDefinition->toolTip() );
245 label->setWordWrap(
true );
246 return label.release();
254 if ( mPropertyButton )
255 return mPropertyButton->vectorLayer();
270 if ( wrapper->parameterDefinition()->name() ==
parameterDefinition()->dynamicLayerParameterName() )
272 setDynamicParentLayerParameter( wrapper );
294 if ( mParameterDefinition && !mParameterDefinition->additionalExpressionContextVariables().isEmpty() )
296 auto paramScope = std::make_unique<QgsExpressionContextScope>();
297 const QStringList additional = mParameterDefinition->additionalExpressionContextVariables();
298 for (
const QString &var : additional )
300 paramScope->setVariable( var, QVariant() );
306 highlighted.append( additional );
320 setDynamicParentLayerParameter( wrapper );
326 if ( mPropertyButton )
329 QgsProcessingContext *context =
nullptr;
330 std::unique_ptr<QgsProcessingContext> tmpContext;
336 tmpContext = std::make_unique<QgsProcessingContext>();
337 context = tmpContext.get();
341 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
344 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
351 mPropertyButton->setVectorLayer(
nullptr );
357 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
360 mDynamicLayer.reset( qobject_cast<QgsVectorLayer *>( ownedLayer.release() ) );
361 layer = mDynamicLayer.get();
368 mPropertyButton->setVectorLayer( layer );
374 auto widget = std::make_unique<QgsProcessingModelerParameterWidget>( model, childId, parameter, context );
383 return widget.release();
395 return QStringList();
403 return QStringList();
434 std::unique_ptr<QgsProcessingContext> tmpContext;
435 if ( processingContextGenerator )
440 tmpContext = std::make_unique<QgsProcessingContext>();
441 context = tmpContext.get();
446 if (
auto *lModel = widgetContext.
model() )
459 QStringList highlightedVariables = childScope->
variableNames();
460 QStringList highlightedFunctions = childScope->functionNames();
461 highlightedVariables += algorithmScope->variableNames();
462 highlightedVariables += lModel->variables().keys();
463 highlightedFunctions += algorithmScope->functionNames();
464 c.setHighlightedVariables( highlightedVariables );
465 c.setHighlightedFunctions( highlightedFunctions );
487 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,...
A model for showing available data sources and other items in a structured tree.
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.
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
A bar for displaying non-blocking messages to the user.
Abstract base class for processing algorithms.
An interface for objects which can create Processing contexts.
virtual QgsProcessingContext * processingContext()=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.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsProject * project() const
Returns the project associated with the widget.
QgsBrowserGuiModel * browserModel() const
Returns the browser model associated with the widget.
void setActiveLayer(QgsMapLayer *layer)
Sets the current active layer.
void setModelChildAlgorithmId(const QString &id)
Sets the child algorithm id within the model which the parameter widget is associated with.
void setProject(QgsProject *project)
Sets the project associated with the widget.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
void setBrowserModel(QgsBrowserGuiModel *model)
Sets the browser model associated with the widget.
QgsProcessingModelAlgorithm * model() const
Returns the model which the parameter widget is associated with.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
QgsMapLayer * activeLayer() const
Returns the current active layer.
void setModel(QgsProcessingModelAlgorithm *model)
Sets 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.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
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