QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsprocessingwidgetwrapper.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingwidgetwrapper.h
3 ---------------------
4 begin : August 2018
5 copyright : (C) 2018 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSPROCESSINGWIDGETWRAPPER_H
19#define QGSPROCESSINGWIDGETWRAPPER_H
20
21#include <memory>
22
23#include "qgis_gui.h"
24#include "qgis_sip.h"
25#include "qgsprocessinggui.h"
26#include "qgsvectorlayer.h"
27
28#include <QObject>
29#include <QPointer>
30#include <QWidget>
31
35class QgsProcessingModelAlgorithm;
36class QLabel;
38class QgsVectorLayer;
39class QgsProcessingModelAlgorithm;
40class QgsMapCanvas;
43class QgsMessageBar;
45
54{
55 public:
64
65 virtual ~QgsProcessingContextGenerator() = default;
66};
67
77{
78 public:
84 enum class Flag : int SIP_ENUM_BASETYPE( IntFlag )
85 {
86 SkipDefaultValueParameters = 1 << 0,
87 SkipValidation = 1 << 1,
88 };
89 Q_DECLARE_FLAGS( Flags, Flag )
90
91
99
101};
102
104
105
117{
118 public:
120
126 void setMapCanvas( QgsMapCanvas *canvas );
127
132 QgsMapCanvas *mapCanvas() const;
133
140 void setMessageBar( QgsMessageBar *bar );
141
148 QgsMessageBar *messageBar() const;
149
156
163
171
176 QgsProject *project() const;
177
184 QgsProcessingModelAlgorithm *model() const;
185
192 void setModel( QgsProcessingModelAlgorithm *model );
193
200 QString modelChildAlgorithmId() const;
201
208 void setModelChildAlgorithmId( const QString &id );
209
216 QgsMapLayer *activeLayer() const;
217
224 void setActiveLayer( QgsMapLayer *layer );
225
226 private:
227 QgsProcessingModelAlgorithm *mModel = nullptr;
228
229 QString mModelChildAlgorithmId;
230
231 QgsMapCanvas *mMapCanvas = nullptr;
232
233 QgsMessageBar *mMessageBar = nullptr;
234
235 QgsProject *mProject = nullptr;
236
237 QgsBrowserGuiModel *mBrowserModel = nullptr;
238
239 QgsMapLayer *mActiveLayer = nullptr;
240};
241
242#ifndef SIP_RUN
244class GUI_EXPORT QgsProcessingWidgetWrapperUtils
245{
246 public:
247 static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr, const QgsProcessingParameterWidgetContext &widgetContext = QgsProcessingParameterWidgetContext(), const QgsProcessingAlgorithm *algorithm = nullptr, const QgsVectorLayer *linkedLayer = nullptr );
248};
250#endif
251
272{
273 Q_OBJECT
274
275 public:
281
286
296 virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
297
306
318
332
337 QWidget *wrappedWidget();
338
343 QLabel *wrappedLabel();
344
349
350 // TODO QGIS 4.0 -- remove
351#ifdef SIP_RUN
352 % Property( name = param, get = parameterDefinition )
353#endif
354
363 void setParameterValue( const QVariant &value, QgsProcessingContext &context );
364
370 QVariant parameterValue() const;
371
375 virtual QVariantMap customProperties() const;
376
384
393
398 virtual void postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers );
399
407 virtual int stretch() const;
408
410
416 virtual void setDialog( QDialog *dialog );
417
418 signals:
419
420 // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
421 // yet can easily be retrieved by checking the sender()
422
427
428 protected:
436 virtual QWidget *createWidget() = 0 SIP_FACTORY;
437
448 virtual QLabel *createLabel() SIP_FACTORY;
449
458 virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
459
465 virtual QVariant widgetValue() const = 0;
466
476 virtual const QgsVectorLayer *linkedVectorLayer() const;
477
478 protected:
482
483 private slots:
484
485 void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
486
487 private:
488 Qgis::ProcessingMode mType = Qgis::ProcessingMode::Standard;
489 const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
490
491 void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
492
493 QPointer<QWidget> mWidget;
494 QPointer<QgsPropertyOverrideButton> mPropertyButton;
495 QPointer<QLabel> mLabel;
496 std::unique_ptr<QgsVectorLayer> mDynamicLayer;
497
498 friend class TestProcessingGui;
499};
500
501
516{
517 public:
519
523 virtual QString parameterType() const = 0;
524
533
549 virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context );
550
576 QgsProcessingContext &context,
577 const QgsProcessingParameterWidgetContext &widgetContext,
578 const QgsProcessingParameterDefinition *definition = nullptr,
579 const QgsProcessingAlgorithm *algorithm = nullptr
580 ) SIP_FACTORY;
581
582 protected:
597 virtual QStringList compatibleParameterTypes() const;
598
613 virtual QStringList compatibleOutputTypes() const;
614
629 virtual QList<int> compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
630
640 virtual QString modelerExpressionFormatString() const;
641
647 virtual Qgis::ProcessingModelChildParameterSource defaultModelSource( const QgsProcessingParameterDefinition *parameter ) const;
648};
649
663{
664 Q_OBJECT
665 public:
671
672 void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
673 QVariant widgetValue() const override;
674
675 const QgsVectorLayer *linkedVectorLayer() const override;
676
680 void setLinkedVectorLayer( const QgsVectorLayer *layer );
681
682 protected:
683 QWidget *createWidget() override;
684 QLabel *createLabel() override;
685
686 private:
687 QVariant mValue;
688 QPointer<const QgsVectorLayer> mLayer;
689};
690
691#endif // QGSPROCESSINGWIDGETWRAPPER_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
ProcessingMode
Types of modes which Processing widgets can be created for.
Definition qgis.h:3671
@ Standard
Standard (single-run) algorithm mode.
Definition qgis.h:3672
A widget wrapper for Processing parameter value widgets.
QVariant parameterValue() const
Returns the current value of the parameter.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Qgis::ProcessingMode type() const
Returns the dialog type for which widgets and labels will be created by this wrapper.
virtual QVariantMap customProperties() const
Returns any custom properties set by the wrapper.
virtual void setWidgetValue(const QVariant &value, QgsProcessingContext &context)=0
Sets the current value for the parameter to show in the widget.
virtual QLabel * createLabel()
Creates a new label to accompany widgets created by the wrapper.
void registerProcessingParametersGenerator(QgsProcessingParametersGenerator *generator)
Registers a Processing parameters generator class that will be used to retrieve algorithm parameters ...
QgsProcessingParameterWidgetContext mWidgetContext
QgsProcessingParametersGenerator * mParametersGenerator
virtual void registerProcessingContextGenerator(QgsProcessingContextGenerator *generator)
Registers a Processing context generator class that will be used to retrieve a Processing context for...
const QgsProcessingParameterWidgetContext & widgetContext() const
Returns the context in which the Processing parameter widget is shown, e.g., the parent model algorit...
QLabel * createWrappedLabel()
Creates and returns a new label to accompany widgets created by the wrapper.
QWidget * createWrappedWidget(QgsProcessingContext &context)
Creates and return a new wrapped widget which allows customization of the parameter's value.
QgsProcessingContextGenerator * mProcessingContextGenerator
void widgetValueHasChanged(QgsAbstractProcessingParameterWidgetWrapper *wrapper)
Emitted whenever the parameter value (as defined by the wrapped widget) is changed.
virtual void postInitialize(const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers)
Called after all wrappers have been created within a particular dialog or context,...
virtual const QgsVectorLayer * linkedVectorLayer() const
Returns the optional vector layer associated with this widget wrapper, or nullptr if no vector layer ...
QWidget * wrappedWidget()
Returns the current wrapped widget, if any.
const QgsProcessingParameterDefinition * parameterDefinition() const
Returns the parameter definition associated with this wrapper.
QLabel * wrappedLabel()
Returns the current wrapped label, if any.
virtual QVariant widgetValue() const =0
Returns the current value of the parameter.
QgsAbstractProcessingParameterWidgetWrapper(const QgsProcessingParameterDefinition *parameter=nullptr, Qgis::ProcessingMode type=Qgis::ProcessingMode::Standard, QObject *parent=nullptr)
Constructor for QgsAbstractProcessingParameterWidgetWrapper, for the specified parameter definition a...
virtual QWidget * createWidget()=0
Creates a new widget which allows customization of the parameter's value.
virtual int stretch() const
Returns the Qt layout "stretch" factor to use when adding this widget to a layout.
virtual void setDialog(QDialog *dialog)
Sets the parent dialog in which the wrapper is shown.
virtual void setWidgetContext(const QgsProcessingParameterWidgetContext &context)
Sets the context in which the Processing parameter widget is shown, e.g., the parent model algorithm,...
void setParameterValue(const QVariant &value, QgsProcessingContext &context)
Sets the current value for the parameter.
A model for showing available data sources and other items in a structured tree.
Abstract interface for generating an expression context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:80
A bar for displaying non-blocking messages to the user.
Abstract base class for widgets which allow users to specify the properties of a Processing parameter...
Abstract base class for processing algorithms.
An interface for objects which can create Processing contexts.
virtual ~QgsProcessingContextGenerator()=default
virtual QgsProcessingContext * processingContext()=0
This method needs to be reimplemented in all classes which implement this interface and return a Proc...
Contains information about the context in which a processing algorithm is executed.
QgsProcessingHiddenWidgetWrapper(const QgsProcessingParameterDefinition *parameter=nullptr, Qgis::ProcessingMode type=Qgis::ProcessingMode::Standard, QObject *parent=nullptr)
Constructor for QgsProcessingHiddenWidgetWrapper, for the specified parameter definition and dialog t...
QVariant widgetValue() const override
Returns the current value of the parameter.
QWidget * createWidget() override
Creates a new widget which allows customization of the parameter's value.
void setWidgetValue(const QVariant &value, QgsProcessingContext &context) override
Sets the current value for the parameter to show in the widget.
void setLinkedVectorLayer(const QgsVectorLayer *layer)
Sets the vector layer linked to the wrapper.
QLabel * createLabel() override
Creates a new label to accompany widgets created by the wrapper.
const QgsVectorLayer * linkedVectorLayer() const override
Returns the optional vector layer associated with this widget wrapper, or nullptr if no vector layer ...
A widget for customising the value of Processing algorithm parameters inside a Processing model.
Base class for the definition of processing parameters.
Contains settings which reflect the context in which a Processing parameter widget is shown.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsProject * project() const
Returns the project associated with the widget.
QgsBrowserGuiModel * browserModel() const
Returns the browser model associated with the widget.
void setActiveLayer(QgsMapLayer *layer)
Sets the current active layer.
void setModelChildAlgorithmId(const QString &id)
Sets the child algorithm id within the model which the parameter widget is associated with.
void setProject(QgsProject *project)
Sets the project associated with the widget.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
void setBrowserModel(QgsBrowserGuiModel *model)
Sets the browser model associated with the widget.
QgsProcessingModelAlgorithm * model() const
Returns the model which the parameter widget is associated with.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
QgsMapLayer * activeLayer() const
Returns the current active layer.
void setModel(QgsProcessingModelAlgorithm *model)
Sets the model which the parameter widget is associated with.
QString modelChildAlgorithmId() const
Returns the child algorithm ID within the model which the parameter widget is associated with.
An interface for Processing widget wrapper factories.
virtual QStringList compatibleParameterTypes() const
Returns a list of compatible Processing parameter types for inputs for this parameter.
virtual QList< int > compatibleDataTypes(const QgsProcessingParameterDefinition *parameter) const
Returns a list of compatible Processing data types for inputs for this widget for the specified param...
virtual ~QgsProcessingParameterWidgetFactoryInterface()=default
virtual QString parameterType() const =0
Returns the type string for the parameter type the factory is associated with.
virtual QgsAbstractProcessingParameterWidgetWrapper * createWidgetWrapper(const QgsProcessingParameterDefinition *parameter, Qgis::ProcessingMode type)=0
Creates a new widget wrapper for the specified parameter definition.
virtual QgsProcessingAbstractParameterDefinitionWidget * createParameterDefinitionWidget(QgsProcessingContext &context, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingParameterDefinition *definition=nullptr, const QgsProcessingAlgorithm *algorithm=nullptr)
Creates a new parameter definition widget allowing for configuration of an instance of the parameter ...
virtual QgsProcessingModelerParameterWidget * createModelerWidgetWrapper(QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context)
Creates a new modeler parameter widget for the given parameter.
virtual QStringList compatibleOutputTypes() const
Returns a list of compatible Processing output types for inputs for this parameter.
virtual Qgis::ProcessingModelChildParameterSource defaultModelSource(const QgsProcessingParameterDefinition *parameter) const
Returns the default source type to use for the widget for the specified parameter.
virtual QString modelerExpressionFormatString() const
Returns the expected expression format string for expression results for the parameter within model c...
An interface for objects which can create sets of parameter values for processing algorithms.
Flag
Flags controlling parameter generation.
virtual QVariantMap createProcessingParameters(QgsProcessingParametersGenerator::Flags flags=QgsProcessingParametersGenerator::Flags())=0
This method needs to be reimplemented in all classes which implement this interface and return a algo...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:109
A button for controlling property overrides which may apply to a widget.
Represents a vector layer which manages a vector based dataset.
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
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:275
#define SIP_FACTORY
Definition qgis_sip.h:84
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)