QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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;
39 
49 {
50  public:
51 
59  virtual QgsProcessingContext *processingContext() = 0;
60 
61  virtual ~QgsProcessingContextGenerator() = default;
62 };
63 
74 {
75  public:
76 
81 
87  void setMapCanvas( QgsMapCanvas *canvas );
88 
93  QgsMapCanvas *mapCanvas() const;
94 
101  QgsProcessingModelAlgorithm *model() const;
102 
109  void setModel( QgsProcessingModelAlgorithm *model );
110 
117  QString modelChildAlgorithmId() const;
118 
125  void setModelChildAlgorithmId( const QString &id );
126 
127  private:
128 
129  QgsProcessingModelAlgorithm *mModel = nullptr;
130 
131  QString mModelChildAlgorithmId;
132 
133  QgsMapCanvas *mMapCanvas = nullptr;
134 
135 };
136 
157 {
158  Q_OBJECT
159 
160  public:
161 
168 
172  QgsProcessingGui::WidgetType type() const;
173 
183  virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
184 
192  const QgsProcessingParameterWidgetContext &widgetContext() const;
193 
204  QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
205 
218  QLabel *createWrappedLabel() SIP_FACTORY;
219 
224  QWidget *wrappedWidget();
225 
230  QLabel *wrappedLabel();
231 
235  const QgsProcessingParameterDefinition *parameterDefinition() const;
236 
237  // TODO QGIS 4.0 -- remove
238 #ifdef SIP_RUN
239  % Property( name = param, get = parameterDefinition )
240 #endif
241 
250  void setParameterValue( const QVariant &value, QgsProcessingContext &context );
251 
257  QVariant parameterValue() const;
258 
263  void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
264 
269  virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
270 
272 
273  signals:
274 
275  // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
276  // yet can easily be retrieved by checking the sender()
277 
281  void widgetValueHasChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
282 
283  protected:
284 
292  virtual QWidget *createWidget() = 0 SIP_FACTORY;
293 
304  virtual QLabel *createLabel() SIP_FACTORY;
305 
314  virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
315 
321  virtual QVariant widgetValue() const = 0;
322 
332  virtual const QgsVectorLayer *linkedVectorLayer() const;
333 
334  protected:
335 
336  QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
338 
339  private slots:
340 
341  void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
342 
343  private:
344 
346  const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
347 
348  void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
349 
350  QPointer< QWidget > mWidget;
351  QPointer< QgsPropertyOverrideButton > mPropertyButton;
352  QPointer< QLabel > mLabel;
353  std::unique_ptr< QgsVectorLayer > mDynamicLayer;
354 
355  friend class TestProcessingGui;
356 
357 };
358 
359 
374 {
375 
376  public:
377 
379 
383  virtual QString parameterType() const = 0;
384 
392  virtual QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter,
394 
410  virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
411  const QString &childId,
412  const QgsProcessingParameterDefinition *parameter,
413  QgsProcessingContext &context );
414 
415  protected:
416 
431  virtual QStringList compatibleParameterTypes() const = 0;
432 
447  virtual QStringList compatibleOutputTypes() const = 0;
448 
463  virtual QList< int > compatibleDataTypes() const = 0;
464 
474  virtual QString modelerExpressionFormatString() const;
475 
476 };
477 
478 #endif // QGSPROCESSINGWIDGETWRAPPER_H
A widget wrapper for Processing parameter value widgets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
WidgetType
Types of dialogs which Processing widgets can be created for.
An interface for Processing widget wrapper factories.
A widget for customising the value of Processing algorithm parameter inside a Processing model...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
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...
#define SIP_FACTORY
Definition: qgis_sip.h:69
QgsProcessingParameterWidgetContext mWidgetContext
Abstract interface for generating an expression context.
Contains settings which reflect the context in which a Processing parameter widget is shown...
Base class for the definition of processing parameters.
Represents a vector layer which manages a vector based data sets.
Contains information about the context in which a processing algorithm is executed.
Standard algorithm dialog.