QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 class QgsBrowserGuiModel;
43 
53 {
54  public:
55 
63  virtual QgsProcessingContext *processingContext() = 0;
64 
65  virtual ~QgsProcessingContextGenerator() = default;
66 };
67 
77 {
78  public:
79 
84  virtual QVariantMap createProcessingParameters() = 0;
85 
86  virtual ~QgsProcessingParametersGenerator() = default;
87 };
88 
89 
100 {
101  public:
102 
107 
113  void setMapCanvas( QgsMapCanvas *canvas );
114 
119  QgsMapCanvas *mapCanvas() const;
120 
127  void setMessageBar( QgsMessageBar *bar );
128 
135  QgsMessageBar *messageBar() const;
136 
142  void setBrowserModel( QgsBrowserGuiModel *model );
143 
149  QgsBrowserGuiModel *browserModel() const;
150 
157  void setProject( QgsProject *project );
158 
163  QgsProject *project() const;
164 
171  QgsProcessingModelAlgorithm *model() const;
172 
179  void setModel( QgsProcessingModelAlgorithm *model );
180 
187  QString modelChildAlgorithmId() const;
188 
195  void setModelChildAlgorithmId( const QString &id );
196 
203  QgsMapLayer *activeLayer() const;
204 
211  void setActiveLayer( QgsMapLayer *layer );
212 
213  private:
214 
215  QgsProcessingModelAlgorithm *mModel = nullptr;
216 
217  QString mModelChildAlgorithmId;
218 
219  QgsMapCanvas *mMapCanvas = nullptr;
220 
221  QgsMessageBar *mMessageBar = nullptr;
222 
223  QgsProject *mProject = nullptr;
224 
225  QgsBrowserGuiModel *mBrowserModel = nullptr;
226 
227  QgsMapLayer *mActiveLayer = nullptr;
228 
229 };
230 
231 #ifndef SIP_RUN
232 class GUI_EXPORT QgsProcessingGuiUtils
234 {
235  public:
236 
237  static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr,
239  const QgsProcessingAlgorithm *algorithm = nullptr,
240  const QgsVectorLayer *linkedLayer = nullptr );
241 
242 
243 };
245 #endif
246 
267 {
268  Q_OBJECT
269 
270  public:
271 
278 
282  QgsProcessingGui::WidgetType type() const;
283 
293  virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
294 
302  const QgsProcessingParameterWidgetContext &widgetContext() const;
303 
314  QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
315 
328  QLabel *createWrappedLabel() SIP_FACTORY;
329 
334  QWidget *wrappedWidget();
335 
340  QLabel *wrappedLabel();
341 
345  const QgsProcessingParameterDefinition *parameterDefinition() const;
346 
347  // TODO QGIS 4.0 -- remove
348 #ifdef SIP_RUN
349  % Property( name = param, get = parameterDefinition )
350 #endif
351 
360  void setParameterValue( const QVariant &value, QgsProcessingContext &context );
361 
367  QVariant parameterValue() const;
368 
372  virtual QVariantMap customProperties() const;
373 
378  void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
379 
387  void registerProcessingParametersGenerator( QgsProcessingParametersGenerator *generator );
388 
393  virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
394 
402  virtual int stretch() const;
403 
405 
411  virtual void setDialog( QDialog *dialog );
412 
413  signals:
414 
415  // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
416  // yet can easily be retrieved by checking the sender()
417 
421  void widgetValueHasChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
422 
423  protected:
424 
432  virtual QWidget *createWidget() = 0 SIP_FACTORY;
433 
444  virtual QLabel *createLabel() SIP_FACTORY;
445 
454  virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
455 
461  virtual QVariant widgetValue() const = 0;
462 
472  virtual const QgsVectorLayer *linkedVectorLayer() const;
473 
474  protected:
475 
476  QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
477  QgsProcessingParametersGenerator *mParametersGenerator = nullptr;
479 
480  private slots:
481 
482  void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
483 
484  private:
485 
487  const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
488 
489  void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
490 
491  QPointer< QWidget > mWidget;
492  QPointer< QgsPropertyOverrideButton > mPropertyButton;
493  QPointer< QLabel > mLabel;
494  std::unique_ptr< QgsVectorLayer > mDynamicLayer;
495 
496  friend class TestProcessingGui;
497 
498 };
499 
500 
515 {
516 
517  public:
518 
520 
524  virtual QString parameterType() const = 0;
525 
533  virtual QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter,
535 
551  virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
552  const QString &childId,
553  const QgsProcessingParameterDefinition *parameter,
554  QgsProcessingContext &context );
555 
580  virtual QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
581  QgsProcessingContext &context,
582  const QgsProcessingParameterWidgetContext &widgetContext,
583  const QgsProcessingParameterDefinition *definition = nullptr,
584  const QgsProcessingAlgorithm *algorithm = nullptr ) SIP_FACTORY;
585 
586  protected:
587 
602  virtual QStringList compatibleParameterTypes() const = 0;
603 
618  virtual QStringList compatibleOutputTypes() const = 0;
619 
634  virtual QList< int > compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
635 
645  virtual QString modelerExpressionFormatString() const;
646 
647 };
648 
649 #endif // QGSPROCESSINGWIDGETWRAPPER_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
QgsProcessingParameterWidgetContext
Definition: qgsprocessingwidgetwrapper.h:99
algorithm
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
QgsMapCanvas
Definition: qgsmapcanvas.h:83
QgsProcessingParameterDefinition
Definition: qgsprocessingparameters.h:330
QgsAbstractProcessingParameterWidgetWrapper
Definition: qgsprocessingwidgetwrapper.h:266
QgsProject
Definition: qgsproject.h:92
QgsProcessingGui::Standard
@ Standard
Standard algorithm dialog.
Definition: qgsprocessinggui.h:40
QgsPropertyOverrideButton
Definition: qgspropertyoverridebutton.h:50
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsProcessingContext
Definition: qgsprocessingcontext.h:43
qgsprocessinggui.h
qgis_sip.h
QgsMessageBar
Definition: qgsmessagebar.h:60
QgsProcessingModelerParameterWidget
Definition: qgsprocessingmodelerparameterwidget.h:61
QgsExpressionContextGenerator::createExpressionContext
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsProcessingParametersGenerator
Definition: qgsprocessingwidgetwrapper.h:76
QgsProcessingAbstractParameterDefinitionWidget
Abstract base class for widgets which allow users to specify the properties of a Processing parameter...
Definition: qgsprocessingparameterdefinitionwidget.h:43
qgsvectorlayer.h
QgsProcessingGui::WidgetType
WidgetType
Types of dialogs which Processing widgets can be created for.
Definition: qgsprocessinggui.h:38
QgsProcessingParameterWidgetFactoryInterface
Definition: qgsprocessingwidgetwrapper.h:514
QgsProcessingAlgorithm
Definition: qgsprocessingalgorithm.h:51
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsAbstractProcessingParameterWidgetWrapper::mWidgetContext
QgsProcessingParameterWidgetContext mWidgetContext
Definition: qgsprocessingwidgetwrapper.h:478
QgsExpressionContextGenerator
Definition: qgsexpressioncontextgenerator.h:36
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsBrowserGuiModel
Definition: qgsbrowserguimodel.h:37
QgsProcessingContextGenerator
Definition: qgsprocessingwidgetwrapper.h:52