QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 
52 {
53  public:
54 
62  virtual QgsProcessingContext *processingContext() = 0;
63 
64  virtual ~QgsProcessingContextGenerator() = default;
65 };
66 
77 {
78  public:
79 
84 
90  void setMapCanvas( QgsMapCanvas *canvas );
91 
96  QgsMapCanvas *mapCanvas() const;
97 
104  void setMessageBar( QgsMessageBar *bar );
105 
112  QgsMessageBar *messageBar() const;
113 
120  void setProject( QgsProject *project );
121 
126  QgsProject *project() const;
127 
134  QgsProcessingModelAlgorithm *model() const;
135 
142  void setModel( QgsProcessingModelAlgorithm *model );
143 
150  QString modelChildAlgorithmId() const;
151 
158  void setModelChildAlgorithmId( const QString &id );
159 
160  private:
161 
162  QgsProcessingModelAlgorithm *mModel = nullptr;
163 
164  QString mModelChildAlgorithmId;
165 
166  QgsMapCanvas *mMapCanvas = nullptr;
167 
168  QgsMessageBar *mMessageBar = nullptr;
169 
170  QgsProject *mProject = nullptr;
171 
172 };
173 
174 #ifndef SIP_RUN
175 class GUI_EXPORT QgsProcessingGuiUtils
177 {
178  public:
179 
180  static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr,
182  const QgsProcessingAlgorithm *algorithm = nullptr,
183  const QgsVectorLayer *linkedLayer = nullptr );
184 
185 
186 };
188 #endif
189 
210 {
211  Q_OBJECT
212 
213  public:
214 
221 
225  QgsProcessingGui::WidgetType type() const;
226 
236  virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
237 
245  const QgsProcessingParameterWidgetContext &widgetContext() const;
246 
257  QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
258 
271  QLabel *createWrappedLabel() SIP_FACTORY;
272 
277  QWidget *wrappedWidget();
278 
283  QLabel *wrappedLabel();
284 
288  const QgsProcessingParameterDefinition *parameterDefinition() const;
289 
290  // TODO QGIS 4.0 -- remove
291 #ifdef SIP_RUN
292  % Property( name = param, get = parameterDefinition )
293 #endif
294 
303  void setParameterValue( const QVariant &value, QgsProcessingContext &context );
304 
310  QVariant parameterValue() const;
311 
316  void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
317 
322  virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
323 
325 
331  virtual void setDialog( QDialog *dialog );
332 
333  signals:
334 
335  // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
336  // yet can easily be retrieved by checking the sender()
337 
341  void widgetValueHasChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
342 
343  protected:
344 
352  virtual QWidget *createWidget() = 0 SIP_FACTORY;
353 
364  virtual QLabel *createLabel() SIP_FACTORY;
365 
374  virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
375 
381  virtual QVariant widgetValue() const = 0;
382 
392  virtual const QgsVectorLayer *linkedVectorLayer() const;
393 
394  protected:
395 
396  QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
398 
399  private slots:
400 
401  void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
402 
403  private:
404 
406  const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
407 
408  void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
409 
410  QPointer< QWidget > mWidget;
411  QPointer< QgsPropertyOverrideButton > mPropertyButton;
412  QPointer< QLabel > mLabel;
413  std::unique_ptr< QgsVectorLayer > mDynamicLayer;
414 
415  friend class TestProcessingGui;
416 
417 };
418 
419 
434 {
435 
436  public:
437 
439 
443  virtual QString parameterType() const = 0;
444 
452  virtual QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter,
454 
470  virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
471  const QString &childId,
472  const QgsProcessingParameterDefinition *parameter,
473  QgsProcessingContext &context );
474 
499  virtual QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
500  QgsProcessingContext &context,
501  const QgsProcessingParameterWidgetContext &widgetContext,
502  const QgsProcessingParameterDefinition *definition = nullptr,
503  const QgsProcessingAlgorithm *algorithm = nullptr ) SIP_FACTORY;
504 
505  protected:
506 
521  virtual QStringList compatibleParameterTypes() const = 0;
522 
537  virtual QStringList compatibleOutputTypes() const = 0;
538 
553  virtual QList< int > compatibleDataTypes() const = 0;
554 
564  virtual QString modelerExpressionFormatString() const;
565 
566 };
567 
568 #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 bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
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:91
#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.