24 #include "models/qgsprocessingmodelalgorithm.h" 28 #include <QHBoxLayout> 66 return mModelChildAlgorithmId;
92 , mParameterDefinition( parameter )
120 QHBoxLayout *hLayout =
new QHBoxLayout();
121 hLayout->setMargin( 0 );
122 hLayout->setContentsMargins( 0, 0, 0, 0 );
123 hLayout->addWidget( mWidget, 1 );
125 hLayout->addWidget( mPropertyButton );
127 mPropertyButton->registerEnabledWidget( mWidget,
false );
128 mPropertyButton->registerExpressionContextGenerator(
this );
130 wrappedWidget =
new QWidget();
131 wrappedWidget->setLayout( hLayout );
160 return mParameterDefinition;
165 if ( mPropertyButton && value.canConvert<
QgsProperty >() )
167 mPropertyButton->setToProperty( value.value<
QgsProperty >() );
171 if ( mPropertyButton )
180 if ( mPropertyButton && mPropertyButton->isActive() )
181 return mPropertyButton->toProperty();
201 QString description = mParameterDefinition->
description();
203 description = QObject::tr(
"%1 [optional]" ).arg( description );
204 std::unique_ptr< QLabel > label = qgis::make_unique< QLabel >( description );
205 label->setToolTip( mParameterDefinition->
toolTip() );
206 return label.release();
214 if ( mPropertyButton )
215 return mPropertyButton->vectorLayer();
232 setDynamicParentLayerParameter( wrapper );
251 std::unique_ptr< QgsExpressionContextScope > paramScope = qgis::make_unique< QgsExpressionContextScope >();
253 for (
const QString &var : additional )
255 paramScope->setVariable( var, QVariant() );
261 highlighted.append( additional );
276 setDynamicParentLayerParameter( wrapper );
282 if ( mPropertyButton )
286 std::unique_ptr< QgsProcessingContext > tmpContext;
292 tmpContext = qgis::make_unique< QgsProcessingContext >();
293 context = tmpContext.get();
299 mPropertyButton->setVectorLayer(
nullptr );
305 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
308 mDynamicLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
309 layer = mDynamicLayer.get();
316 mPropertyButton->setVectorLayer( layer );
322 std::unique_ptr< QgsProcessingModelerParameterWidget > widget = qgis::make_unique< QgsProcessingModelerParameterWidget >( model, childId, parameter, context );
323 widget->
populateSources( compatibleParameterTypes(), compatibleOutputTypes(), compatibleDataTypes() );
324 widget->setExpressionHelpText( modelerExpressionFormatString() );
325 return widget.release();
349 std::unique_ptr< QgsProcessingContext > tmpContext;
350 if ( processingContextGenerator )
355 tmpContext = qgis::make_unique< QgsProcessingContext >();
356 context = tmpContext.get();
361 if ( widgetContext.
model() )
374 QStringList highlightedVariables = childScope->
variableNames();
375 QStringList highlightedFunctions = childScope->functionNames();
376 highlightedVariables += algorithmScope->variableNames();
377 highlightedVariables += widgetContext.
model()->variables().keys();
378 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.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
WidgetType
Types of dialogs which Processing widgets can be created for.
QStringList variableNames() const
Returns a list of variable names contained within the scope.
A bar for displaying non-blocking messages to the user.
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.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
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.