QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
51 {
52  public:
53 
61  virtual QgsProcessingContext *processingContext() = 0;
62 
63  virtual ~QgsProcessingContextGenerator() = default;
64 };
65 
76 {
77  public:
78 
83 
89  void setMapCanvas( QgsMapCanvas *canvas );
90 
95  QgsMapCanvas *mapCanvas() const;
96 
103  void setProject( QgsProject *project );
104 
109  QgsProject *project() const;
110 
117  QgsProcessingModelAlgorithm *model() const;
118 
125  void setModel( QgsProcessingModelAlgorithm *model );
126 
133  QString modelChildAlgorithmId() const;
134 
141  void setModelChildAlgorithmId( const QString &id );
142 
143  private:
144 
145  QgsProcessingModelAlgorithm *mModel = nullptr;
146 
147  QString mModelChildAlgorithmId;
148 
149  QgsMapCanvas *mMapCanvas = nullptr;
150 
151  QgsProject *mProject = nullptr;
152 
153 };
154 
155 #ifndef SIP_RUN
156 class GUI_EXPORT QgsProcessingGuiUtils
158 {
159  public:
160 
161  static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr,
163  const QgsProcessingAlgorithm *algorithm = nullptr,
164  const QgsVectorLayer *linkedLayer = nullptr );
165 
166 
167 };
169 #endif
170 
191 {
192  Q_OBJECT
193 
194  public:
195 
202 
206  QgsProcessingGui::WidgetType type() const;
207 
217  virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
218 
226  const QgsProcessingParameterWidgetContext &widgetContext() const;
227 
238  QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
239 
252  QLabel *createWrappedLabel() SIP_FACTORY;
253 
258  QWidget *wrappedWidget();
259 
264  QLabel *wrappedLabel();
265 
269  const QgsProcessingParameterDefinition *parameterDefinition() const;
270 
271  // TODO QGIS 4.0 -- remove
272 #ifdef SIP_RUN
273  % Property( name = param, get = parameterDefinition )
274 #endif
275 
284  void setParameterValue( const QVariant &value, QgsProcessingContext &context );
285 
291  QVariant parameterValue() const;
292 
297  void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
298 
303  virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
304 
306 
312  virtual void setDialog( QDialog *dialog );
313 
314  signals:
315 
316  // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
317  // yet can easily be retrieved by checking the sender()
318 
322  void widgetValueHasChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
323 
324  protected:
325 
333  virtual QWidget *createWidget() = 0 SIP_FACTORY;
334 
345  virtual QLabel *createLabel() SIP_FACTORY;
346 
355  virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
356 
362  virtual QVariant widgetValue() const = 0;
363 
373  virtual const QgsVectorLayer *linkedVectorLayer() const;
374 
375  protected:
376 
377  QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
379 
380  private slots:
381 
382  void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
383 
384  private:
385 
387  const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
388 
389  void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
390 
391  QPointer< QWidget > mWidget;
392  QPointer< QgsPropertyOverrideButton > mPropertyButton;
393  QPointer< QLabel > mLabel;
394  std::unique_ptr< QgsVectorLayer > mDynamicLayer;
395 
396  friend class TestProcessingGui;
397 
398 };
399 
400 
415 {
416 
417  public:
418 
420 
424  virtual QString parameterType() const = 0;
425 
433  virtual QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter,
435 
451  virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
452  const QString &childId,
453  const QgsProcessingParameterDefinition *parameter,
454  QgsProcessingContext &context );
455 
480  virtual QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
481  QgsProcessingContext &context,
482  const QgsProcessingParameterWidgetContext &widgetContext,
483  const QgsProcessingParameterDefinition *definition = nullptr,
484  const QgsProcessingAlgorithm *algorithm = nullptr ) SIP_FACTORY;
485 
486  protected:
487 
502  virtual QStringList compatibleParameterTypes() const = 0;
503 
518  virtual QStringList compatibleOutputTypes() const = 0;
519 
534  virtual QList< int > compatibleDataTypes() const = 0;
535 
545  virtual QString modelerExpressionFormatString() const;
546 
547 };
548 
549 #endif // QGSPROCESSINGWIDGETWRAPPER_H
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 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:75
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...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:89
#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.
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.