QGIS API Documentation  3.6.0-Noosa (5873452)
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  QgsProcessingModelAlgorithm *model() const;
103 
110  void setModel( QgsProcessingModelAlgorithm *model );
111 
118  QString modelChildAlgorithmId() const;
119 
126  void setModelChildAlgorithmId( const QString &id );
127 
128  private:
129 
130  QgsProcessingModelAlgorithm *mModel = nullptr;
131 
132  QString mModelChildAlgorithmId;
133 
134  QgsMapCanvas *mMapCanvas = nullptr;
135 
136 };
137 
138 #ifndef SIP_RUN
139 class GUI_EXPORT QgsProcessingGuiUtils
141 {
142  public:
143 
144  static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr,
146  const QgsProcessingAlgorithm *algorithm = nullptr,
147  const QgsVectorLayer *linkedLayer = nullptr );
148 
149 
150 };
152 #endif
153 
174 {
175  Q_OBJECT
176 
177  public:
178 
185 
189  QgsProcessingGui::WidgetType type() const;
190 
200  virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
201 
209  const QgsProcessingParameterWidgetContext &widgetContext() const;
210 
221  QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
222 
235  QLabel *createWrappedLabel() SIP_FACTORY;
236 
241  QWidget *wrappedWidget();
242 
247  QLabel *wrappedLabel();
248 
252  const QgsProcessingParameterDefinition *parameterDefinition() const;
253 
254  // TODO QGIS 4.0 -- remove
255 #ifdef SIP_RUN
256  % Property( name = param, get = parameterDefinition )
257 #endif
258 
267  void setParameterValue( const QVariant &value, QgsProcessingContext &context );
268 
274  QVariant parameterValue() const;
275 
280  void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
281 
286  virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
287 
289 
290  signals:
291 
292  // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
293  // yet can easily be retrieved by checking the sender()
294 
298  void widgetValueHasChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
299 
300  protected:
301 
309  virtual QWidget *createWidget() = 0 SIP_FACTORY;
310 
321  virtual QLabel *createLabel() SIP_FACTORY;
322 
331  virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
332 
338  virtual QVariant widgetValue() const = 0;
339 
349  virtual const QgsVectorLayer *linkedVectorLayer() const;
350 
351  protected:
352 
353  QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
355 
356  private slots:
357 
358  void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
359 
360  private:
361 
363  const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
364 
365  void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
366 
367  QPointer< QWidget > mWidget;
368  QPointer< QgsPropertyOverrideButton > mPropertyButton;
369  QPointer< QLabel > mLabel;
370  std::unique_ptr< QgsVectorLayer > mDynamicLayer;
371 
372  friend class TestProcessingGui;
373 
374 };
375 
376 
391 {
392 
393  public:
394 
396 
400  virtual QString parameterType() const = 0;
401 
409  virtual QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter,
411 
427  virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
428  const QString &childId,
429  const QgsProcessingParameterDefinition *parameter,
430  QgsProcessingContext &context );
431 
432  protected:
433 
448  virtual QStringList compatibleParameterTypes() const = 0;
449 
464  virtual QStringList compatibleOutputTypes() const = 0;
465 
480  virtual QList< int > compatibleDataTypes() const = 0;
481 
491  virtual QString modelerExpressionFormatString() const;
492 
493 };
494 
495 #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...
#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.