QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
24 #include "models/qgsprocessingmodelalgorithm.h"
28 #include <QHBoxLayout>
56 mBrowserModel =
model;
76 return mModelChildAlgorithmId;
112 , mParameterDefinition( parameter )
140 QHBoxLayout *hLayout =
new QHBoxLayout();
141 hLayout->setMargin( 0 );
142 hLayout->setContentsMargins( 0, 0, 0, 0 );
143 hLayout->addWidget( mWidget, 1 );
145 hLayout->addWidget( mPropertyButton );
147 mPropertyButton->registerEnabledWidget( mWidget,
false );
148 mPropertyButton->registerExpressionContextGenerator(
this );
184 return mParameterDefinition;
189 if ( mPropertyButton && value.canConvert<
QgsProperty >() )
191 mPropertyButton->setToProperty( value.value<
QgsProperty >() );
195 if ( mPropertyButton )
204 if ( mPropertyButton && mPropertyButton->isActive() )
205 return mPropertyButton->toProperty();
212 return QVariantMap();
235 QString description = mParameterDefinition->
description();
237 description = QObject::tr(
"%1 [optional]" ).arg( description );
238 std::unique_ptr< QLabel > label = qgis::make_unique< QLabel >( description );
239 label->setToolTip( mParameterDefinition->
toolTip() );
240 return label.release();
248 if ( mPropertyButton )
249 return mPropertyButton->vectorLayer();
264 if ( wrapper->parameterDefinition()->name() ==
parameterDefinition()->dynamicLayerParameterName() )
266 setDynamicParentLayerParameter( wrapper );
290 std::unique_ptr< QgsExpressionContextScope > paramScope = qgis::make_unique< QgsExpressionContextScope >();
292 for (
const QString &var : additional )
294 paramScope->setVariable( var, QVariant() );
300 highlighted.append( additional );
315 setDynamicParentLayerParameter( wrapper );
321 if ( mPropertyButton )
325 std::unique_ptr< QgsProcessingContext > tmpContext;
331 tmpContext = qgis::make_unique< QgsProcessingContext >();
332 context = tmpContext.get();
338 mPropertyButton->setVectorLayer(
nullptr );
344 std::unique_ptr< QgsMapLayer > ownedLayer( context->
takeResultLayer( layer->
id() ) );
347 mDynamicLayer.reset( qobject_cast< QgsVectorLayer * >( ownedLayer.release() ) );
348 layer = mDynamicLayer.get();
355 mPropertyButton->setVectorLayer( layer );
361 std::unique_ptr< QgsProcessingModelerParameterWidget > widget = qgis::make_unique< QgsProcessingModelerParameterWidget >( model, childId, parameter, context );
364 return widget.release();
376 return QList< int >();
393 std::unique_ptr< QgsProcessingContext > tmpContext;
394 if ( processingContextGenerator )
399 tmpContext = qgis::make_unique< QgsProcessingContext >();
400 context = tmpContext.get();
405 if ( widgetContext.
model() )
418 QStringList highlightedVariables = childScope->
variableNames();
419 QStringList highlightedFunctions = childScope->functionNames();
420 highlightedVariables += algorithmScope->variableNames();
421 highlightedVariables += widgetContext.
model()->variables().keys();
422 highlightedFunctions += algorithmScope->functionNames();
423 c.setHighlightedVariables( highlightedVariables );
424 c.setHighlightedFunctions( highlightedFunctions );
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsMapLayer * activeLayer() const
Returns the current active layer.
A store for object properties.
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.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
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
QgsMapLayer * takeResultLayer(const QString &id)
Takes the result map layer with matching id from the context and transfers ownership of it back to th...
void setModel(QgsProcessingModelAlgorithm *model)
Sets the model which the parameter widget is associated with.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
QStringList additionalExpressionContextVariables() const
Returns a list of additional expression context variables which are available for use when evaluating...
bool isDynamic() const
Returns true if the parameter supports is dynamic, and can support data-defined values (i....
void setActiveLayer(QgsMapLayer *layer)
Sets the current active layer.
@ Standard
Standard algorithm dialog.
QStringList variableNames() const
Returns a list of variable names contained within the scope.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
QString modelChildAlgorithmId() const
Returns the child algorithm ID within the model which the parameter widget is associated with.
QgsProject * project() const
Returns the project associated with the widget.
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
virtual QString toolTip() const
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
QgsProcessingAlgorithm * algorithm() const
Returns a pointer to the algorithm which owns this parameter.
@ Batch
Batch processing dialog.
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 * processingModelAlgorithmScope(const QgsProcessingModelAlgorithm *model, const QVariantMap ¶meters, QgsProcessingContext &context)
Creates a new scope which contains variables and functions relating to a processing model algorithm,...
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
QStringList highlightedVariables() const
Returns the current list of variables highlighted within the context.
Single scope for storing variables and functions for use within a QgsExpressionContext....
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
WidgetType
Types of dialogs which Processing widgets can be created for.
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 c
void setProject(QgsProject *project)
Sets the project associated with the widget.
QgsExpressionContext & expressionContext()
Returns the expression context.
void setBrowserModel(QgsBrowserGuiModel *model)
Sets the browser model associated with the widget.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user.
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...
@ FlagOptional
Parameter is optional.
QgsBrowserGuiModel * browserModel() const
Returns the browser model associated with the widget.
QVariant defaultValue() const
Returns the default value for the parameter.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.