QGIS API Documentation 3.99.0-Master (7d2ca374f2d)
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"
26#include "qgsprocessinggui.h"
27#include "qgsvectorlayer.h"
28
29#include <QObject>
30#include <QPointer>
31#include <QWidget>
32
36class QgsProcessingModelAlgorithm;
37class QLabel;
39class QgsVectorLayer;
40class QgsProcessingModelAlgorithm;
41class QgsMapCanvas;
44class QgsMessageBar;
46class QgsModelGraphicsScene;
47
56{
57 public:
66
67 virtual ~QgsProcessingContextGenerator() = default;
68};
69
79{
80 public:
86 enum class Flag : int SIP_ENUM_BASETYPE( IntFlag )
87 {
88 SkipDefaultValueParameters = 1 << 0,
89 SkipValidation = 1 << 1,
90 };
91 Q_DECLARE_FLAGS( Flags, Flag )
92
93
101
103};
104
106
107
119{
120 public:
122
128 void setMapCanvas( QgsMapCanvas *canvas );
129
134 QgsMapCanvas *mapCanvas() const;
135
142 void setMessageBar( QgsMessageBar *bar );
143
150 QgsMessageBar *messageBar() const;
151
158
165
173
178 QgsProject *project() const;
179
186 QgsProcessingModelAlgorithm *model() const;
187
194 void setModel( QgsProcessingModelAlgorithm *model );
195
202 QString modelChildAlgorithmId() const;
203
210 void setModelChildAlgorithmId( const QString &id );
211
218 QgsMapLayer *activeLayer() const;
219
226 void setActiveLayer( QgsMapLayer *layer );
227
239
248
257 QgsModelDesignerDialog *modelDesignerDialog() const;
258
267 void setModelDesignerDialog( QgsModelDesignerDialog *dialog );
268
269 private:
270 QgsProcessingModelAlgorithm *mModel = nullptr;
271
272 QString mModelChildAlgorithmId;
273
274 QgsMapCanvas *mMapCanvas = nullptr;
275
276 QgsMessageBar *mMessageBar = nullptr;
277
278 QgsProject *mProject = nullptr;
279
280 QgsBrowserGuiModel *mBrowserModel = nullptr;
281
282 QgsMapLayer *mActiveLayer = nullptr;
283
284 QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
285
286 QgsModelDesignerDialog *mModelDialog = nullptr;
287};
288
289#ifndef SIP_RUN
291class GUI_EXPORT QgsProcessingWidgetWrapperUtils
292{
293 public:
294 static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr, const QgsProcessingParameterWidgetContext &widgetContext = QgsProcessingParameterWidgetContext(), const QgsProcessingAlgorithm *algorithm = nullptr, const QgsVectorLayer *linkedLayer = nullptr );
295};
297#endif
298
319{
320 Q_OBJECT
321
322 public:
328
333
343 virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
344
353
365
379
384 QWidget *wrappedWidget();
385
390 QLabel *wrappedLabel();
391
396
397 // TODO QGIS 5.0 -- remove
398#ifdef SIP_RUN
399 % Property( name = param, get = parameterDefinition )
400#endif
401
410 void setParameterValue( const QVariant &value, QgsProcessingContext &context );
411
417 QVariant parameterValue() const;
418
422 virtual QVariantMap customProperties() const;
423
431
440
445 virtual void postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers );
446
454 virtual int stretch() const;
455
457
463 virtual void setDialog( QDialog *dialog );
464
465 signals:
466
467 // TODO QGIS 5.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
468 // yet can easily be retrieved by checking the sender()
469
474
475 protected:
483 virtual QWidget *createWidget() = 0 SIP_FACTORY;
484
495 virtual QLabel *createLabel() SIP_FACTORY;
496
505 virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
506
512 virtual QVariant widgetValue() const = 0;
513
523 virtual const QgsVectorLayer *linkedVectorLayer() const;
524
525 protected:
529
530 private slots:
531
532 void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
533
534 private:
535 Qgis::ProcessingMode mType = Qgis::ProcessingMode::Standard;
536 const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
537
538 void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
539
540 QPointer<QWidget> mWidget;
541 QPointer<QgsPropertyOverrideButton> mPropertyButton;
542 QPointer<QLabel> mLabel;
543 std::unique_ptr<QgsVectorLayer> mDynamicLayer;
544
545 friend class TestProcessingGui;
546};
547
548
563{
564 public:
566
570 virtual QString parameterType() const = 0;
571
580
596 virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context );
597
623 QgsProcessingContext &context,
624 const QgsProcessingParameterWidgetContext &widgetContext,
625 const QgsProcessingParameterDefinition *definition = nullptr,
626 const QgsProcessingAlgorithm *algorithm = nullptr
627 ) SIP_FACTORY;
628
629 protected:
644 virtual QStringList compatibleParameterTypes() const;
645
660 virtual QStringList compatibleOutputTypes() const;
661
676 virtual QList<int> compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
677
687 virtual QString modelerExpressionFormatString() const;
688
694 virtual Qgis::ProcessingModelChildParameterSource defaultModelSource( const QgsProcessingParameterDefinition *parameter ) const;
695};
696
710{
711 Q_OBJECT
712 public:
718
719 void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
720 QVariant widgetValue() const override;
721
722 const QgsVectorLayer *linkedVectorLayer() const override;
723
727 void setLinkedVectorLayer( const QgsVectorLayer *layer );
728
729 protected:
730 QWidget *createWidget() override;
731 QLabel *createLabel() override;
732
733 private:
734 QVariant mValue;
735 QPointer<const QgsVectorLayer> mLayer;
736};
737
738#endif // QGSPROCESSINGWIDGETWRAPPER_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
ProcessingMode
Types of modes which Processing widgets can be created for.
Definition qgis.h:3757
@ Standard
Standard (single-run) algorithm mode.
Definition qgis.h:3758
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:83
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.
QgsModelDesignerDialog * modelDesignerDialog() const
Returns the associated model designer dialog, if applicable.
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 setModelDesignerDialog(QgsModelDesignerDialog *dialog)
Sets the associated model designer dialog, if applicable.
void setModel(QgsProcessingModelAlgorithm *model)
Sets the model which the parameter widget is associated with.
QgsProcessingContextGenerator * processingContextGenerator()
Returns the Processing context generator class that will be used to retrieve a Processing context for...
void registerProcessingContextGenerator(QgsProcessingContextGenerator *generator)
Registers a Processing context generator class that will be used to retrieve a Processing context for...
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:113
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:52
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:274
#define SIP_FACTORY
Definition qgis_sip.h:83
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)