QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
52 {
53  public:
54 
63 
64  virtual ~QgsProcessingContextGenerator() = default;
65 };
66 
76 {
77  public:
78 
83  virtual QVariantMap createProcessingParameters() = 0;
84 
85  virtual ~QgsProcessingParametersGenerator() = default;
86 };
87 
88 
99 {
100  public:
101 
106 
112  void setMapCanvas( QgsMapCanvas *canvas );
113 
118  QgsMapCanvas *mapCanvas() const;
119 
126  void setMessageBar( QgsMessageBar *bar );
127 
134  QgsMessageBar *messageBar() const;
135 
141  void setBrowserModel( QgsBrowserGuiModel *model );
142 
148  QgsBrowserGuiModel *browserModel() const;
149 
156  void setProject( QgsProject *project );
157 
162  QgsProject *project() const;
163 
170  QgsProcessingModelAlgorithm *model() const;
171 
178  void setModel( QgsProcessingModelAlgorithm *model );
179 
186  QString modelChildAlgorithmId() const;
187 
194  void setModelChildAlgorithmId( const QString &id );
195 
202  QgsMapLayer *activeLayer() const;
203 
210  void setActiveLayer( QgsMapLayer *layer );
211 
212  private:
213 
214  QgsProcessingModelAlgorithm *mModel = nullptr;
215 
216  QString mModelChildAlgorithmId;
217 
218  QgsMapCanvas *mMapCanvas = nullptr;
219 
220  QgsMessageBar *mMessageBar = nullptr;
221 
222  QgsProject *mProject = nullptr;
223 
224  QgsBrowserGuiModel *mBrowserModel = nullptr;
225 
226  QgsMapLayer *mActiveLayer = nullptr;
227 
228 };
229 
230 #ifndef SIP_RUN
232 class GUI_EXPORT QgsProcessingGuiUtils
233 {
234  public:
235 
236  static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr,
238  const QgsProcessingAlgorithm *algorithm = nullptr,
239  const QgsVectorLayer *linkedLayer = nullptr );
240 
241 
242 };
244 #endif
245 
266 {
267  Q_OBJECT
268 
269  public:
270 
277 
281  QgsProcessingGui::WidgetType type() const;
282 
292  virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
293 
301  const QgsProcessingParameterWidgetContext &widgetContext() const;
302 
313  QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
314 
327  QLabel *createWrappedLabel() SIP_FACTORY;
328 
333  QWidget *wrappedWidget();
334 
339  QLabel *wrappedLabel();
340 
344  const QgsProcessingParameterDefinition *parameterDefinition() const;
345 
346  // TODO QGIS 4.0 -- remove
347 #ifdef SIP_RUN
348  % Property( name = param, get = parameterDefinition )
349 #endif
350 
359  void setParameterValue( const QVariant &value, QgsProcessingContext &context );
360 
366  QVariant parameterValue() const;
367 
371  virtual QVariantMap customProperties() const;
372 
379  virtual void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
380 
388  void registerProcessingParametersGenerator( QgsProcessingParametersGenerator *generator );
389 
394  virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
395 
403  virtual int stretch() const;
404 
405  QgsExpressionContext createExpressionContext() const override;
406 
412  virtual void setDialog( QDialog *dialog );
413 
414  signals:
415 
416  // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
417  // yet can easily be retrieved by checking the sender()
418 
423 
424  protected:
425 
433  virtual QWidget *createWidget() = 0 SIP_FACTORY;
434 
445  virtual QLabel *createLabel() SIP_FACTORY;
446 
455  virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
456 
462  virtual QVariant widgetValue() const = 0;
463 
473  virtual const QgsVectorLayer *linkedVectorLayer() const;
474 
475  protected:
476 
477  QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
478  QgsProcessingParametersGenerator *mParametersGenerator = nullptr;
480 
481  private slots:
482 
483  void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
484 
485  private:
486 
487  QgsProcessingGui::WidgetType mType = QgsProcessingGui::Standard;
488  const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
489 
490  void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
491 
492  QPointer< QWidget > mWidget;
493  QPointer< QgsPropertyOverrideButton > mPropertyButton;
494  QPointer< QLabel > mLabel;
495  std::unique_ptr< QgsVectorLayer > mDynamicLayer;
496 
497  friend class TestProcessingGui;
498 
499 };
500 
501 
516 {
517 
518  public:
519 
521 
525  virtual QString parameterType() const = 0;
526 
536 
552  virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
553  const QString &childId,
554  const QgsProcessingParameterDefinition *parameter,
555  QgsProcessingContext &context );
556 
581  virtual QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
582  QgsProcessingContext &context,
583  const QgsProcessingParameterWidgetContext &widgetContext,
584  const QgsProcessingParameterDefinition *definition = nullptr,
585  const QgsProcessingAlgorithm *algorithm = nullptr ) SIP_FACTORY;
586 
587  protected:
588 
603  virtual QStringList compatibleParameterTypes() const = 0;
604 
619  virtual QStringList compatibleOutputTypes() const = 0;
620 
635  virtual QList< int > compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
636 
646  virtual QString modelerExpressionFormatString() const;
647 
648 };
649 
663 {
664  public:
665 
672  QObject *parent SIP_TRANSFERTHIS = nullptr );
673 
674  void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
675  QVariant widgetValue() const override;
676 
677  const QgsVectorLayer *linkedVectorLayer() const override;
678 
682  void setLinkedVectorLayer( const QgsVectorLayer *layer );
683 
684  protected:
685  QWidget *createWidget() override;
686  QLabel *createLabel() override;
687 
688  private:
689 
690  QVariant mValue;
691  QPointer < const QgsVectorLayer > mLayer;
692 
693 };
694 
695 #endif // QGSPROCESSINGWIDGETWRAPPER_H
A widget wrapper for Processing parameter value widgets.
virtual QWidget * createWidget()=0
Creates a new widget which allows customization of the parameter's value.
void widgetValueHasChanged(QgsAbstractProcessingParameterWidgetWrapper *wrapper)
Emitted whenever the parameter value (as defined by the wrapped widget) is changed.
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.
Definition: qgsmapcanvas.h:86
Base class for all map layer types.
Definition: qgsmaplayer.h:70
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
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.
Contains general functions and values related to Processing GUI components.
WidgetType
Types of dialogs which Processing widgets can be created for.
@ Standard
Standard algorithm dialog.
An widget wrapper for hidden widgets.
A widget for customising the value of Processing algorithm parameter 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,...
QgsProcessingParameterWidgetContext()=default
Constructor for QgsProcessingParameterWidgetContext.
An interface for Processing widget wrapper factories.
virtual QgsAbstractProcessingParameterWidgetWrapper * createWidgetWrapper(const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type)=0
Creates a new widget wrapper for the specified parameter definition.
virtual ~QgsProcessingParameterWidgetFactoryInterface()=default
virtual QString parameterType() const =0
Returns the type string for the parameter type the factory is associated with.
An interface for objects which can create sets of parameter values for processing algorithms.
virtual QVariantMap createProcessingParameters()=0
This method needs to be reimplemented in all classes which implement this interface and return a algo...
virtual ~QgsProcessingParametersGenerator()=default
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:99
A button for controlling property overrides which may apply to a widget.
Represents a vector layer which manages a vector based data sets.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
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_FACTORY
Definition: qgis_sip.h:76