QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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;
40 
50 {
51  public:
52 
60  virtual QgsProcessingContext *processingContext() = 0;
61 
62  virtual ~QgsProcessingContextGenerator() = default;
63 };
64 
75 {
76  public:
77 
82 
88  void setMapCanvas( QgsMapCanvas *canvas );
89 
94  QgsMapCanvas *mapCanvas() const;
95 
102  void setProject( QgsProject *project );
103 
108  QgsProject *project() const;
109 
116  QgsProcessingModelAlgorithm *model() const;
117 
124  void setModel( QgsProcessingModelAlgorithm *model );
125 
132  QString modelChildAlgorithmId() const;
133 
140  void setModelChildAlgorithmId( const QString &id );
141 
142  private:
143 
144  QgsProcessingModelAlgorithm *mModel = nullptr;
145 
146  QString mModelChildAlgorithmId;
147 
148  QgsMapCanvas *mMapCanvas = nullptr;
149 
150  QgsProject *mProject = nullptr;
151 
152 };
153 
154 #ifndef SIP_RUN
155 class GUI_EXPORT QgsProcessingGuiUtils
157 {
158  public:
159 
160  static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr,
162  const QgsProcessingAlgorithm *algorithm = nullptr,
163  const QgsVectorLayer *linkedLayer = nullptr );
164 
165 
166 };
168 #endif
169 
190 {
191  Q_OBJECT
192 
193  public:
194 
201 
205  QgsProcessingGui::WidgetType type() const;
206 
216  virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
217 
225  const QgsProcessingParameterWidgetContext &widgetContext() const;
226 
237  QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
238 
251  QLabel *createWrappedLabel() SIP_FACTORY;
252 
257  QWidget *wrappedWidget();
258 
263  QLabel *wrappedLabel();
264 
268  const QgsProcessingParameterDefinition *parameterDefinition() const;
269 
270  // TODO QGIS 4.0 -- remove
271 #ifdef SIP_RUN
272  % Property( name = param, get = parameterDefinition )
273 #endif
274 
283  void setParameterValue( const QVariant &value, QgsProcessingContext &context );
284 
290  QVariant parameterValue() const;
291 
296  void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
297 
302  virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
303 
305 
311  virtual void setDialog( QDialog *dialog );
312 
313  signals:
314 
315  // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
316  // yet can easily be retrieved by checking the sender()
317 
321  void widgetValueHasChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
322 
323  protected:
324 
332  virtual QWidget *createWidget() = 0 SIP_FACTORY;
333 
344  virtual QLabel *createLabel() SIP_FACTORY;
345 
354  virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
355 
361  virtual QVariant widgetValue() const = 0;
362 
372  virtual const QgsVectorLayer *linkedVectorLayer() const;
373 
374  protected:
375 
376  QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
378 
379  private slots:
380 
381  void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
382 
383  private:
384 
386  const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
387 
388  void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
389 
390  QPointer< QWidget > mWidget;
391  QPointer< QgsPropertyOverrideButton > mPropertyButton;
392  QPointer< QLabel > mLabel;
393  std::unique_ptr< QgsVectorLayer > mDynamicLayer;
394 
395  friend class TestProcessingGui;
396 
397 };
398 
399 
414 {
415 
416  public:
417 
419 
423  virtual QString parameterType() const = 0;
424 
432  virtual QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter,
434 
450  virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
451  const QString &childId,
452  const QgsProcessingParameterDefinition *parameter,
453  QgsProcessingContext &context );
454 
455  protected:
456 
471  virtual QStringList compatibleParameterTypes() const = 0;
472 
487  virtual QStringList compatibleOutputTypes() const = 0;
488 
503  virtual QList< int > compatibleDataTypes() const = 0;
504 
514  virtual QString modelerExpressionFormatString() const;
515 
516 };
517 
518 #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...
Abstract base class for processing algorithms.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:73
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...
Reads and writes project states.
Definition: qgsproject.h:89
#define SIP_FACTORY
Definition: qgis_sip.h:69
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.
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.