34#include "moc_qgsprocessingwidgetwrapper.cpp"
62 mBrowserModel =
model;
82 return mModelChildAlgorithmId;
102 mProcessingContextGenerator = generator;
107 return mProcessingContextGenerator;
117 mModelDialog = dialog;
138 , mParameterDefinition( parameter )
164 if ( mParameterDefinition->isDynamic() )
166 QHBoxLayout *hLayout =
new QHBoxLayout();
167 hLayout->setContentsMargins( 0, 0, 0, 0 );
168 hLayout->addWidget( mWidget, 1 );
170 hLayout->addWidget( mPropertyButton );
171 mPropertyButton->init( 0,
QgsProperty(), mParameterDefinition->dynamicPropertyDefinition() );
172 mPropertyButton->registerEnabledWidget( mWidget,
false );
173 mPropertyButton->registerExpressionContextGenerator(
this );
182 setWidgetValue( mParameterDefinition->defaultValueForGui(), context );
209 return mParameterDefinition;
214 if ( mPropertyButton && value.userType() == qMetaTypeId<QgsProperty>() )
216 mPropertyButton->setToProperty( value.value<
QgsProperty>() );
220 if ( mPropertyButton )
229 if ( mPropertyButton && mPropertyButton->isActive() )
230 return mPropertyButton->toProperty();
237 return QVariantMap();
260 QString description = mParameterDefinition->description();
262 description = QObject::tr(
"%1 [optional]" ).arg( description );
263 auto label = std::make_unique<QLabel>( description );
264 label->setToolTip( mParameterDefinition->toolTip() );
265 label->setWordWrap(
true );
266 return label.release();
274 if ( mPropertyButton )
275 return mPropertyButton->vectorLayer();
290 if ( wrapper->parameterDefinition()->name() ==
parameterDefinition()->dynamicLayerParameterName() )
292 setDynamicParentLayerParameter( wrapper );
314 if ( mParameterDefinition && !mParameterDefinition->additionalExpressionContextVariables().isEmpty() )
316 auto paramScope = std::make_unique<QgsExpressionContextScope>();
317 const QStringList additional = mParameterDefinition->additionalExpressionContextVariables();
318 for (
const QString &var : additional )
320 paramScope->setVariable( var, QVariant() );
326 highlighted.append( additional );
340 setDynamicParentLayerParameter( wrapper );
346 if ( mPropertyButton )
349 QgsProcessingContext *context =
nullptr;
350 std::unique_ptr<QgsProcessingContext> tmpContext;
356 tmpContext = std::make_unique<QgsProcessingContext>();
357 context = tmpContext.get();
361 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
364 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
371 mPropertyButton->setVectorLayer(
nullptr );
377 std::unique_ptr<QgsMapLayer> ownedLayer( context->
takeResultLayer( layer->
id() ) );
380 mDynamicLayer.reset( qobject_cast<QgsVectorLayer *>( ownedLayer.release() ) );
381 layer = mDynamicLayer.get();
388 mPropertyButton->setVectorLayer( layer );
394 auto widget = std::make_unique<QgsProcessingModelerParameterWidget>( model, childId, parameter, context );
403 return widget.release();
415 return QStringList();
423 return QStringList();
454 std::unique_ptr<QgsProcessingContext> tmpContext;
455 if ( processingContextGenerator )
460 tmpContext = std::make_unique<QgsProcessingContext>();
461 context = tmpContext.get();
466 if (
auto *lModel = widgetContext.
model() )
479 QStringList highlightedVariables = childScope->
variableNames();
480 QStringList highlightedFunctions = childScope->functionNames();
481 highlightedVariables += algorithmScope->variableNames();
482 highlightedVariables += lModel->variables().keys();
483 highlightedFunctions += algorithmScope->functionNames();
484 c.setHighlightedVariables( highlightedVariables );
485 c.setHighlightedFunctions( highlightedFunctions );
507 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.
QgsModelDesignerDialog * modelDesignerDialog() const
Returns the associated model designer dialog, if applicable.
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 setModelDesignerDialog(QgsModelDesignerDialog *dialog)
Sets the associated model designer dialog, if applicable.
void setModel(QgsProcessingModelAlgorithm *model)
Sets the model which the parameter widget is associated with.
QgsProcessingContextGenerator * processingContextGenerator()
Returns the Processing context generator class that will be used to retrieve a Processing context for...
void registerProcessingContextGenerator(QgsProcessingContextGenerator *generator)
Registers a Processing context generator class that will be used to retrieve a Processing context for...
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