24 #include "models/qgsprocessingmodelalgorithm.h" 26 #include <QHBoxLayout> 44 return mModelChildAlgorithmId;
70 , mParameterDefinition( parameter )
98 QHBoxLayout *hLayout =
new QHBoxLayout();
99 hLayout->setMargin( 0 );
100 hLayout->setContentsMargins( 0, 0, 0, 0 );
101 hLayout->addWidget( mWidget, 1 );
103 hLayout->addWidget( mPropertyButton );
105 mPropertyButton->registerEnabledWidget( mWidget,
false );
106 mPropertyButton->registerExpressionContextGenerator(
this );
108 wrappedWidget =
new QWidget();
109 wrappedWidget->setLayout( hLayout );
138 return mParameterDefinition;
143 if ( mPropertyButton && value.canConvert<
QgsProperty >() )
145 mPropertyButton->setToProperty( value.value<
QgsProperty >() );
149 if ( mPropertyButton )
158 if ( mPropertyButton && mPropertyButton->isActive() )
159 return mPropertyButton->toProperty();
179 QString description = mParameterDefinition->
description();
181 description = QObject::tr(
"%1 [optional]" ).arg( description );
182 std::unique_ptr< QLabel > label = qgis::make_unique< QLabel >( description );
183 label->setToolTip( mParameterDefinition->
toolTip() );
184 return label.release();
192 if ( mPropertyButton )
193 return mPropertyButton->vectorLayer();
210 setDynamicParentLayerParameter( wrapper );
228 std::unique_ptr< QgsProcessingContext > tmpContext;
234 tmpContext = qgis::make_unique< QgsProcessingContext >();
235 context = tmpContext.get();
251 QStringList highlightedVariables = childScope->
variableNames();
252 QStringList highlightedFunctions = childScope->functionNames();
253 highlightedVariables += algorithmScope->variableNames();
254 highlightedFunctions += algorithmScope->functionNames();
274 setDynamicParentLayerParameter( wrapper );
280 if ( mPropertyButton )
284 std::unique_ptr< QgsProcessingContext > tmpContext;
290 tmpContext = qgis::make_unique< QgsProcessingContext >();
291 context = tmpContext.get();
297 mPropertyButton->setVectorLayer(
nullptr );
303 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
306 mDynamicLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
307 layer = mDynamicLayer.get();
314 mPropertyButton->setVectorLayer( layer );
320 std::unique_ptr< QgsProcessingModelerParameterWidget > widget = qgis::make_unique< QgsProcessingModelerParameterWidget >( model, childId, parameter, context );
321 widget->
populateSources( compatibleParameterTypes(), compatibleOutputTypes(), compatibleDataTypes() );
322 widget->setExpressionHelpText( modelerExpressionFormatString() );
323 return widget.release();
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...
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.
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.
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
bool isDynamic() const
Returns true if the parameter supports is dynamic, and can support data-defined values (i...
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.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
QgsProcessingAlgorithm * algorithm() const
Returns a pointer to the algorithm which owns this parameter.
QString description() const
Returns the description for the parameter.
Single scope for storing variables and functions for use within a QgsExpressionContext.
A store for object properties.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsProcessingModelAlgorithm * model() const
Returns the model which the parameter widget is associated with.
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...
QgsPropertyDefinition dynamicPropertyDefinition() const
Returns the property definition for dynamic 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
Base class for the definition of processing parameters.
virtual QString toolTip() const
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user...
QVariant defaultValue() const
Returns the default value for the parameter.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
QgsMapCanvas * mapCanvas() const
Returns the map canvas 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 dynamicLayerParameterName() const
Returns the name of the parameter for a layer linked to a dynamic parameter, or an empty string if th...
QStringList variableNames() const
Returns a list of variable names contained within the scope.
QString modelChildAlgorithmId() const
Returns the child algorithm ID within the model which the parameter widget is associated with...
Standard algorithm dialog.