QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
377  void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
378 
386  void registerProcessingParametersGenerator( QgsProcessingParametersGenerator *generator );
387 
392  virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
393 
401  virtual int stretch() const;
402 
403  QgsExpressionContext createExpressionContext() const override;
404 
410  virtual void setDialog( QDialog *dialog );
411 
412  signals:
413 
414  // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
415  // yet can easily be retrieved by checking the sender()
416 
421 
422  protected:
423 
431  virtual QWidget *createWidget() = 0 SIP_FACTORY;
432 
443  virtual QLabel *createLabel() SIP_FACTORY;
444 
453  virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
454 
460  virtual QVariant widgetValue() const = 0;
461 
471  virtual const QgsVectorLayer *linkedVectorLayer() const;
472 
473  protected:
474 
475  QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
476  QgsProcessingParametersGenerator *mParametersGenerator = nullptr;
478 
479  private slots:
480 
481  void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
482 
483  private:
484 
485  QgsProcessingGui::WidgetType mType = QgsProcessingGui::Standard;
486  const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
487 
488  void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
489 
490  QPointer< QWidget > mWidget;
491  QPointer< QgsPropertyOverrideButton > mPropertyButton;
492  QPointer< QLabel > mLabel;
493  std::unique_ptr< QgsVectorLayer > mDynamicLayer;
494 
495  friend class TestProcessingGui;
496 
497 };
498 
499 
514 {
515 
516  public:
517 
519 
523  virtual QString parameterType() const = 0;
524 
534 
550  virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
551  const QString &childId,
552  const QgsProcessingParameterDefinition *parameter,
553  QgsProcessingContext &context );
554 
579  virtual QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
580  QgsProcessingContext &context,
581  const QgsProcessingParameterWidgetContext &widgetContext,
582  const QgsProcessingParameterDefinition *definition = nullptr,
583  const QgsProcessingAlgorithm *algorithm = nullptr ) SIP_FACTORY;
584 
585  protected:
586 
601  virtual QStringList compatibleParameterTypes() const = 0;
602 
617  virtual QStringList compatibleOutputTypes() const = 0;
618 
633  virtual QList< int > compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
634 
644  virtual QString modelerExpressionFormatString() const;
645 
646 };
647 
661 {
662  public:
663 
670  QObject *parent SIP_TRANSFERTHIS = nullptr );
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 
688  QVariant mValue;
689  QPointer < const QgsVectorLayer > mLayer;
690 
691 };
692 
693 #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:85
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