QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 <QObject>
22 #include <QWidget>
23 #include <QPointer>
24 #include <memory>
25 #include "qgis_gui.h"
26 #include "qgis_sip.h"
27 #include "qgsprocessinggui.h"
28 #include "qgsvectorlayer.h"
29 
33 class QgsProcessingModelAlgorithm;
34 class QLabel;
36 class QgsVectorLayer;
37 class QgsProcessingModelAlgorithm;
38 class QgsMapCanvas;
41 class QgsMessageBar;
42 class QgsBrowserGuiModel;
43 
53 {
54  public:
55 
64 
65  virtual ~QgsProcessingContextGenerator() = default;
66 };
67 
77 {
78  public:
79 
84  virtual QVariantMap createProcessingParameters() = 0;
85 
86  virtual ~QgsProcessingParametersGenerator() = default;
87 };
88 
89 
100 {
101  public:
102 
107 
113  void setMapCanvas( QgsMapCanvas *canvas );
114 
119  QgsMapCanvas *mapCanvas() const;
120 
127  void setMessageBar( QgsMessageBar *bar );
128 
135  QgsMessageBar *messageBar() const;
136 
142  void setBrowserModel( QgsBrowserGuiModel *model );
143 
149  QgsBrowserGuiModel *browserModel() const;
150 
157  void setProject( QgsProject *project );
158 
163  QgsProject *project() const;
164 
171  QgsProcessingModelAlgorithm *model() const;
172 
179  void setModel( QgsProcessingModelAlgorithm *model );
180 
187  QString modelChildAlgorithmId() const;
188 
195  void setModelChildAlgorithmId( const QString &id );
196 
203  QgsMapLayer *activeLayer() const;
204 
211  void setActiveLayer( QgsMapLayer *layer );
212 
213  private:
214 
215  QgsProcessingModelAlgorithm *mModel = nullptr;
216 
217  QString mModelChildAlgorithmId;
218 
219  QgsMapCanvas *mMapCanvas = nullptr;
220 
221  QgsMessageBar *mMessageBar = nullptr;
222 
223  QgsProject *mProject = nullptr;
224 
225  QgsBrowserGuiModel *mBrowserModel = nullptr;
226 
227  QgsMapLayer *mActiveLayer = nullptr;
228 
229 };
230 
231 #ifndef SIP_RUN
232 class GUI_EXPORT QgsProcessingGuiUtils
234 {
235  public:
236 
237  static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr,
239  const QgsProcessingAlgorithm *algorithm = nullptr,
240  const QgsVectorLayer *linkedLayer = nullptr );
241 
242 
243 };
245 #endif
246 
267 {
268  Q_OBJECT
269 
270  public:
271 
278 
282  QgsProcessingGui::WidgetType type() const;
283 
293  virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
294 
302  const QgsProcessingParameterWidgetContext &widgetContext() const;
303 
314  QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
315 
328  QLabel *createWrappedLabel() SIP_FACTORY;
329 
334  QWidget *wrappedWidget();
335 
340  QLabel *wrappedLabel();
341 
345  const QgsProcessingParameterDefinition *parameterDefinition() const;
346 
347  // TODO QGIS 4.0 -- remove
348 #ifdef SIP_RUN
349  % Property( name = param, get = parameterDefinition )
350 #endif
351 
360  void setParameterValue( const QVariant &value, QgsProcessingContext &context );
361 
367  QVariant parameterValue() const;
368 
372  virtual QVariantMap customProperties() const;
373 
378  void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
379 
387  void registerProcessingParametersGenerator( QgsProcessingParametersGenerator *generator );
388 
393  virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
394 
402  virtual int stretch() const;
403 
405 
411  virtual void setDialog( QDialog *dialog );
412 
413  signals:
414 
415  // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
416  // yet can easily be retrieved by checking the sender()
417 
422 
423  protected:
424 
432  virtual QWidget *createWidget() = 0 SIP_FACTORY;
433 
444  virtual QLabel *createLabel() SIP_FACTORY;
445 
454  virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
455 
461  virtual QVariant widgetValue() const = 0;
462 
472  virtual const QgsVectorLayer *linkedVectorLayer() const;
473 
474  protected:
475 
476  QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
477  QgsProcessingParametersGenerator *mParametersGenerator = nullptr;
479 
480  private slots:
481 
482  void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
483 
484  private:
485 
486  QgsProcessingGui::WidgetType mType = QgsProcessingGui::Standard;
487  const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
488 
489  void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
490 
491  QPointer< QWidget > mWidget;
492  QPointer< QgsPropertyOverrideButton > mPropertyButton;
493  QPointer< QLabel > mLabel;
494  std::unique_ptr< QgsVectorLayer > mDynamicLayer;
495 
496  friend class TestProcessingGui;
497 
498 };
499 
500 
515 {
516 
517  public:
518 
520 
524  virtual QString parameterType() const = 0;
525 
535 
551  virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
552  const QString &childId,
553  const QgsProcessingParameterDefinition *parameter,
554  QgsProcessingContext &context );
555 
580  virtual QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
581  QgsProcessingContext &context,
582  const QgsProcessingParameterWidgetContext &widgetContext,
583  const QgsProcessingParameterDefinition *definition = nullptr,
584  const QgsProcessingAlgorithm *algorithm = nullptr ) SIP_FACTORY;
585 
586  protected:
587 
602  virtual QStringList compatibleParameterTypes() const = 0;
603 
618  virtual QStringList compatibleOutputTypes() const = 0;
619 
634  virtual QList< int > compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
635 
645  virtual QString modelerExpressionFormatString() const;
646 
647 };
648 
662 {
663  public:
664 
671  QObject *parent SIP_TRANSFERTHIS = nullptr );
672 
673  void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
674  QVariant widgetValue() const override;
675 
676  const QgsVectorLayer *linkedVectorLayer() const override;
677 
681  void setLinkedVectorLayer( const QgsVectorLayer *layer );
682 
683  protected:
684  QWidget *createWidget() override;
685  QLabel *createLabel() override;
686 
687  private:
688 
689  QVariant mValue;
690  QPointer < const QgsVectorLayer > mLayer;
691 
692 };
693 
694 #endif // QGSPROCESSINGWIDGETWRAPPER_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsProcessingParameterWidgetContext
Contains settings which reflect the context in which a Processing parameter widget is shown,...
Definition: qgsprocessingwidgetwrapper.h:100
QgsAbstractProcessingParameterWidgetWrapper::createWidget
virtual QWidget * createWidget()=0
Creates a new widget which allows customization of the parameter's value.
QgsProcessingParameterWidgetFactoryInterface::~QgsProcessingParameterWidgetFactoryInterface
virtual ~QgsProcessingParameterWidgetFactoryInterface()=default
algorithm
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
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:85
QgsProcessingParameterDefinition
Base class for the definition of processing parameters.
Definition: qgsprocessingparameters.h:331
QgsAbstractProcessingParameterWidgetWrapper
A widget wrapper for Processing parameter value widgets.
Definition: qgsprocessingwidgetwrapper.h:267
QgsProcessingParametersGenerator::createProcessingParameters
virtual QVariantMap createProcessingParameters()=0
This method needs to be reimplemented in all classes which implement this interface and return a algo...
QgsProcessingParameterWidgetFactoryInterface::createWidgetWrapper
virtual QgsAbstractProcessingParameterWidgetWrapper * createWidgetWrapper(const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type)=0
Creates a new widget wrapper for the specified parameter definition.
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
QgsProcessingHiddenWidgetWrapper
An widget wrapper for hidden widgets.
Definition: qgsprocessingwidgetwrapper.h:662
QgsProcessingGui::Standard
@ Standard
Standard algorithm dialog.
Definition: qgsprocessinggui.h:40
QgsPropertyOverrideButton
A button for controlling property overrides which may apply to a widget.
Definition: qgspropertyoverridebutton.h:51
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
QgsProcessingParameterWidgetFactoryInterface::parameterType
virtual QString parameterType() const =0
Returns the type string for the parameter type the factory is associated with.
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition: qgsprocessingcontext.h:44
qgsprocessinggui.h
qgis_sip.h
QgsMessageBar
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
QgsProcessingParameterWidgetContext::QgsProcessingParameterWidgetContext
QgsProcessingParameterWidgetContext()=default
Constructor for QgsProcessingParameterWidgetContext.
QgsProcessingModelerParameterWidget
A widget for customising the value of Processing algorithm parameter inside a Processing model.
Definition: qgsprocessingmodelerparameterwidget.h:62
QgsExpressionContextGenerator::createExpressionContext
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsProcessingParametersGenerator
An interface for objects which can create sets of parameter values for processing algorithms.
Definition: qgsprocessingwidgetwrapper.h:77
QgsAbstractProcessingParameterWidgetWrapper::widgetValueHasChanged
void widgetValueHasChanged(QgsAbstractProcessingParameterWidgetWrapper *wrapper)
Emitted whenever the parameter value (as defined by the wrapped widget) is changed.
QgsProcessingAbstractParameterDefinitionWidget
Abstract base class for widgets which allow users to specify the properties of a Processing parameter...
Definition: qgsprocessingparameterdefinitionwidget.h:44
qgsvectorlayer.h
QgsProcessingGui::WidgetType
WidgetType
Types of dialogs which Processing widgets can be created for.
Definition: qgsprocessinggui.h:39
QgsProcessingParameterWidgetFactoryInterface
An interface for Processing widget wrapper factories.
Definition: qgsprocessingwidgetwrapper.h:515
QgsProcessingAlgorithm
Abstract base class for processing algorithms.
Definition: qgsprocessingalgorithm.h:52
QgsProcessingGui
Contains general functions and values related to Processing GUI components.
Definition: qgsprocessinggui.h:33
QgsProcessingContextGenerator::~QgsProcessingContextGenerator
virtual ~QgsProcessingContextGenerator()=default
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsProcessingContextGenerator::processingContext
virtual QgsProcessingContext * processingContext()=0
This method needs to be reimplemented in all classes which implement this interface and return a Proc...
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:37
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsBrowserGuiModel
A model for showing available data sources and other items in a structured tree.
Definition: qgsbrowserguimodel.h:38
QgsProcessingContextGenerator
An interface for objects which can create Processing contexts.
Definition: qgsprocessingwidgetwrapper.h:53
QgsProcessingParametersGenerator::~QgsProcessingParametersGenerator
virtual ~QgsProcessingParametersGenerator()=default