24 #include "models/qgsprocessingmodelalgorithm.h" 28 #include <QHBoxLayout> 46 return mModelChildAlgorithmId;
72 , mParameterDefinition( parameter )
100 QHBoxLayout *hLayout =
new QHBoxLayout();
101 hLayout->setMargin( 0 );
102 hLayout->setContentsMargins( 0, 0, 0, 0 );
103 hLayout->addWidget( mWidget, 1 );
105 hLayout->addWidget( mPropertyButton );
107 mPropertyButton->registerEnabledWidget( mWidget,
false );
108 mPropertyButton->registerExpressionContextGenerator(
this );
110 wrappedWidget =
new QWidget();
111 wrappedWidget->setLayout( hLayout );
140 return mParameterDefinition;
145 if ( mPropertyButton && value.canConvert<
QgsProperty >() )
147 mPropertyButton->setToProperty( value.value<
QgsProperty >() );
151 if ( mPropertyButton )
160 if ( mPropertyButton && mPropertyButton->isActive() )
161 return mPropertyButton->toProperty();
181 QString description = mParameterDefinition->
description();
183 description = QObject::tr(
"%1 [optional]" ).arg( description );
184 std::unique_ptr< QLabel > label = qgis::make_unique< QLabel >( description );
185 label->setToolTip( mParameterDefinition->
toolTip() );
186 return label.release();
194 if ( mPropertyButton )
195 return mPropertyButton->vectorLayer();
212 setDynamicParentLayerParameter( wrapper );
235 setDynamicParentLayerParameter( wrapper );
241 if ( mPropertyButton )
245 std::unique_ptr< QgsProcessingContext > tmpContext;
251 tmpContext = qgis::make_unique< QgsProcessingContext >();
252 context = tmpContext.get();
258 mPropertyButton->setVectorLayer(
nullptr );
264 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
267 mDynamicLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
268 layer = mDynamicLayer.get();
275 mPropertyButton->setVectorLayer( layer );
281 std::unique_ptr< QgsProcessingModelerParameterWidget > widget = qgis::make_unique< QgsProcessingModelerParameterWidget >( model, childId, parameter, context );
282 widget->
populateSources( compatibleParameterTypes(), compatibleOutputTypes(), compatibleDataTypes() );
283 widget->setExpressionHelpText( modelerExpressionFormatString() );
284 return widget.release();
301 std::unique_ptr< QgsProcessingContext > tmpContext;
302 if ( processingContextGenerator )
307 tmpContext = qgis::make_unique< QgsProcessingContext >();
308 context = tmpContext.get();
313 if ( widgetContext.
model() )
326 QStringList highlightedVariables = childScope->
variableNames();
327 QStringList highlightedFunctions = childScope->functionNames();
328 highlightedVariables += algorithmScope->variableNames();
329 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.
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.
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...
Base class for the definition of processing parameters.
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.
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.