24 #include "models/qgsprocessingmodelalgorithm.h" 28 #include <QHBoxLayout> 56 return mModelChildAlgorithmId;
82 , mParameterDefinition( parameter )
110 QHBoxLayout *hLayout =
new QHBoxLayout();
111 hLayout->setMargin( 0 );
112 hLayout->setContentsMargins( 0, 0, 0, 0 );
113 hLayout->addWidget( mWidget, 1 );
115 hLayout->addWidget( mPropertyButton );
117 mPropertyButton->registerEnabledWidget( mWidget,
false );
118 mPropertyButton->registerExpressionContextGenerator(
this );
120 wrappedWidget =
new QWidget();
121 wrappedWidget->setLayout( hLayout );
150 return mParameterDefinition;
155 if ( mPropertyButton && value.canConvert<
QgsProperty >() )
157 mPropertyButton->setToProperty( value.value<
QgsProperty >() );
161 if ( mPropertyButton )
170 if ( mPropertyButton && mPropertyButton->isActive() )
171 return mPropertyButton->toProperty();
191 QString description = mParameterDefinition->
description();
193 description = QObject::tr(
"%1 [optional]" ).arg( description );
194 std::unique_ptr< QLabel > label = qgis::make_unique< QLabel >( description );
195 label->setToolTip( mParameterDefinition->
toolTip() );
196 return label.release();
204 if ( mPropertyButton )
205 return mPropertyButton->vectorLayer();
222 setDynamicParentLayerParameter( wrapper );
241 std::unique_ptr< QgsExpressionContextScope > paramScope = qgis::make_unique< QgsExpressionContextScope >();
243 for (
const QString &var : additional )
245 paramScope->setVariable( var, QVariant() );
251 highlighted.append( additional );
266 setDynamicParentLayerParameter( wrapper );
272 if ( mPropertyButton )
276 std::unique_ptr< QgsProcessingContext > tmpContext;
282 tmpContext = qgis::make_unique< QgsProcessingContext >();
283 context = tmpContext.get();
289 mPropertyButton->setVectorLayer(
nullptr );
295 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
298 mDynamicLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
299 layer = mDynamicLayer.get();
306 mPropertyButton->setVectorLayer( layer );
312 std::unique_ptr< QgsProcessingModelerParameterWidget > widget = qgis::make_unique< QgsProcessingModelerParameterWidget >( model, childId, parameter, context );
313 widget->
populateSources( compatibleParameterTypes(), compatibleOutputTypes(), compatibleDataTypes() );
314 widget->setExpressionHelpText( modelerExpressionFormatString() );
315 return widget.release();
332 std::unique_ptr< QgsProcessingContext > tmpContext;
333 if ( processingContextGenerator )
338 tmpContext = qgis::make_unique< QgsProcessingContext >();
339 context = tmpContext.get();
344 if ( widgetContext.
model() )
357 QStringList highlightedVariables = childScope->
variableNames();
358 QStringList highlightedFunctions = childScope->functionNames();
359 highlightedVariables += algorithmScope->variableNames();
360 highlightedVariables += widgetContext.
model()->variables().keys();
361 highlightedFunctions += algorithmScope->functionNames();
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...
QgsPropertyDefinition dynamicPropertyDefinition() const
Returns the property definition for dynamic properties.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
void setModel(QgsProcessingModelAlgorithm *model)
Sets the model which the parameter widget is associated with.
WidgetType
Types of dialogs which Processing widgets can be created for.
QStringList variableNames() const
Returns a list of variable names contained within the scope.
QgsMapLayer * takeResultLayer(const QString &id)
Takes the result map layer with matching id from the context and transfers ownership of it back to th...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
Abstract base class for processing algorithms.
Map canvas is a class for displaying all GIS data types on a canvas.
void setHighlightedFunctions(const QStringList &names)
Sets the list of function names intended to be highlighted to the user.
QString modelChildAlgorithmId() const
Returns the child algorithm ID within the model which the parameter widget is associated with...
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
virtual QString toolTip() const
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
QVariant defaultValue() const
Returns the default value for the parameter.
An interface for objects which can create Processing contexts.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
QgsProcessingAlgorithm * algorithm() const
Returns a pointer to the algorithm which owns this parameter.
Reads and writes project states.
QgsProject * project() const
Returns the project associated with the widget.
Single scope for storing variables and functions for use within a QgsExpressionContext.
A store for object properties.
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
QString dynamicLayerParameterName() const
Returns the name of the parameter for a layer linked to a dynamic parameter, or an empty string if th...
QgsExpressionContext & expressionContext()
Returns the expression context.
QStringList highlightedVariables() const
Returns the current list of variables highlighted within the context.
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...
QgsProcessingModelAlgorithm * model() const
Returns the model which the parameter widget is associated with.
bool isDynamic() const
Returns true if the parameter supports is dynamic, and can support data-defined values (i...
virtual QgsProcessingContext * processingContext()=0
This method needs to be reimplemented in all classes which implement this interface and return a Proc...
Contains settings which reflect the context in which a Processing parameter widget is shown...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Base class for the definition of processing parameters.
QStringList additionalExpressionContextVariables() const
Returns a list of additional expression context variables which are available for use when evaluating...
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user...
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
void setProject(QgsProject *project)
Sets the project associated with the widget.
Represents a vector layer which manages a vector based data sets.
Contains information about the context in which a processing algorithm is executed.
void setModelChildAlgorithmId(const QString &id)
Sets the child algorithm id within the model which the parameter widget is associated with...
QString description() const
Returns the description for the parameter.
Standard algorithm dialog.