QGIS API Documentation  3.17.0-Master (df2c9ff931)
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 
63  virtual QgsProcessingContext *processingContext() = 0;
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 
421  void widgetValueHasChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
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 
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 
533  virtual QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter,
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
Base class for all map layer types.
Definition: qgsmaplayer.h:84
A widget wrapper for Processing parameter value widgets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
Abstract base class for widgets which allow users to specify the properties of a Processing parameter...
WidgetType
Types of dialogs which Processing widgets can be created for.
An interface for Processing widget wrapper factories.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:60
A widget for customising the value of Processing algorithm parameter inside a Processing model...
virtual QLabel * createLabel()
Creates a new label to accompany widgets created by the wrapper.
A model for showing available data sources and other items in a structured tree.
Abstract base class for processing algorithms.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:85
virtual const QgsVectorLayer * linkedVectorLayer() const
Returns the optional vector layer associated with this widget wrapper, or nullptr if no vector layer ...
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
A button for controlling property overrides which may apply to a widget.
An interface for objects which can create Processing contexts.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
virtual void setWidgetValue(const QVariant &value, QgsProcessingContext &context)=0
Sets the current value for the parameter to show in the widget.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:98
#define SIP_FACTORY
Definition: qgis_sip.h:76
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
QgsProcessingParameterWidgetContext mWidgetContext
Abstract interface for generating an expression context.
virtual QVariant widgetValue() const =0
Returns the current value of the parameter.
Contains settings which reflect the context in which a Processing parameter widget is shown...
Base class for the definition of processing parameters.
virtual QWidget * createWidget()=0
Creates a new widget which allows customization of the parameter&#39;s value.
An widget wrapper for hidden widgets.
Represents a vector layer which manages a vector based data sets.
An interface for objects which can create sets of parameter values for processing algorithms...
Contains information about the context in which a processing algorithm is executed.
Standard algorithm dialog.