QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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"
30 
34 class QgsProcessingModelAlgorithm;
35 class QLabel;
37 class QgsVectorLayer;
38 class QgsProcessingModelAlgorithm;
39 class QgsMapCanvas;
42 class QgsMessageBar;
43 class QgsBrowserGuiModel;
44 
53 {
54  public:
55 
63  virtual QgsProcessingContext *processingContext() = 0;
64 
65  virtual ~QgsProcessingContextGenerator() = default;
66 };
67 
77 {
78  public:
79 
85  enum class Flag : int
86  {
87  SkipDefaultValueParameters = 1 << 0,
88  };
89  Q_DECLARE_FLAGS( Flags, Flag )
90 
91 
98  virtual QVariantMap createProcessingParameters( QgsProcessingParametersGenerator::Flags flags = QgsProcessingParametersGenerator::Flags() ) = 0;
99 
100  virtual ~QgsProcessingParametersGenerator() = default;
101 };
102 
103 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingParametersGenerator::Flags )
104 
105 
106 
116 {
117  public:
118 
123 
129  void setMapCanvas( QgsMapCanvas *canvas );
130 
135  QgsMapCanvas *mapCanvas() const;
136 
143  void setMessageBar( QgsMessageBar *bar );
144 
151  QgsMessageBar *messageBar() const;
152 
158  void setBrowserModel( QgsBrowserGuiModel *model );
159 
165  QgsBrowserGuiModel *browserModel() const;
166 
173  void setProject( QgsProject *project );
174 
179  QgsProject *project() const;
180 
187  QgsProcessingModelAlgorithm *model() const;
188 
195  void setModel( QgsProcessingModelAlgorithm *model );
196 
203  QString modelChildAlgorithmId() const;
204 
211  void setModelChildAlgorithmId( const QString &id );
212 
219  QgsMapLayer *activeLayer() const;
220 
227  void setActiveLayer( QgsMapLayer *layer );
228 
229  private:
230 
231  QgsProcessingModelAlgorithm *mModel = nullptr;
232 
233  QString mModelChildAlgorithmId;
234 
235  QgsMapCanvas *mMapCanvas = nullptr;
236 
237  QgsMessageBar *mMessageBar = nullptr;
238 
239  QgsProject *mProject = nullptr;
240 
241  QgsBrowserGuiModel *mBrowserModel = nullptr;
242 
243  QgsMapLayer *mActiveLayer = nullptr;
244 
245 };
246 
247 #ifndef SIP_RUN
248 class GUI_EXPORT QgsProcessingGuiUtils
250 {
251  public:
252 
253  static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr,
255  const QgsProcessingAlgorithm *algorithm = nullptr,
256  const QgsVectorLayer *linkedLayer = nullptr );
257 
258 
259 };
261 #endif
262 
283 {
284  Q_OBJECT
285 
286  public:
287 
294 
298  QgsProcessingGui::WidgetType type() const;
299 
309  virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
310 
318  const QgsProcessingParameterWidgetContext &widgetContext() const;
319 
330  QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
331 
344  QLabel *createWrappedLabel() SIP_FACTORY;
345 
350  QWidget *wrappedWidget();
351 
356  QLabel *wrappedLabel();
357 
361  const QgsProcessingParameterDefinition *parameterDefinition() const;
362 
363  // TODO QGIS 4.0 -- remove
364 #ifdef SIP_RUN
365  % Property( name = param, get = parameterDefinition )
366 #endif
367 
376  void setParameterValue( const QVariant &value, QgsProcessingContext &context );
377 
383  QVariant parameterValue() const;
384 
388  virtual QVariantMap customProperties() const;
389 
396  virtual void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
397 
405  void registerProcessingParametersGenerator( QgsProcessingParametersGenerator *generator );
406 
411  virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
412 
420  virtual int stretch() const;
421 
423 
429  virtual void setDialog( QDialog *dialog );
430 
431  signals:
432 
433  // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
434  // yet can easily be retrieved by checking the sender()
435 
439  void widgetValueHasChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
440 
441  protected:
442 
450  virtual QWidget *createWidget() = 0 SIP_FACTORY;
451 
462  virtual QLabel *createLabel() SIP_FACTORY;
463 
472  virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
473 
479  virtual QVariant widgetValue() const = 0;
480 
490  virtual const QgsVectorLayer *linkedVectorLayer() const;
491 
492  protected:
493 
494  QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
495  QgsProcessingParametersGenerator *mParametersGenerator = nullptr;
497 
498  private slots:
499 
500  void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
501 
502  private:
503 
505  const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
506 
507  void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
508 
509  QPointer< QWidget > mWidget;
510  QPointer< QgsPropertyOverrideButton > mPropertyButton;
511  QPointer< QLabel > mLabel;
512  std::unique_ptr< QgsVectorLayer > mDynamicLayer;
513 
514  friend class TestProcessingGui;
515 
516 };
517 
518 
533 {
534 
535  public:
536 
538 
542  virtual QString parameterType() const = 0;
543 
551  virtual QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter,
553 
569  virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
570  const QString &childId,
571  const QgsProcessingParameterDefinition *parameter,
572  QgsProcessingContext &context );
573 
598  virtual QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
599  QgsProcessingContext &context,
600  const QgsProcessingParameterWidgetContext &widgetContext,
601  const QgsProcessingParameterDefinition *definition = nullptr,
602  const QgsProcessingAlgorithm *algorithm = nullptr ) SIP_FACTORY;
603 
604  protected:
605 
620  virtual QStringList compatibleParameterTypes() const = 0;
621 
636  virtual QStringList compatibleOutputTypes() const = 0;
637 
652  virtual QList< int > compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
653 
663  virtual QString modelerExpressionFormatString() const;
664 
670  virtual QgsProcessingModelChildParameterSource::Source defaultModelSource( const QgsProcessingParameterDefinition *parameter ) const;
671 
672 };
673 
687 {
688  public:
689 
696  QObject *parent SIP_TRANSFERTHIS = nullptr );
697 
698  void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
699  QVariant widgetValue() const override;
700 
701  const QgsVectorLayer *linkedVectorLayer() const override;
702 
706  void setLinkedVectorLayer( const QgsVectorLayer *layer );
707 
708  protected:
709  QWidget *createWidget() override;
710  QLabel *createLabel() override;
711 
712  private:
713 
714  QVariant mValue;
715  QPointer < const QgsVectorLayer > mLayer;
716 
717 };
718 
719 #endif // QGSPROCESSINGWIDGETWRAPPER_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsProcessingParameterWidgetContext
Contains settings which reflect the context in which a Processing parameter widget is shown,...
Definition: qgsprocessingwidgetwrapper.h:115
QgsAbstractProcessingParameterWidgetWrapper::createWidget
virtual QWidget * createWidget()=0
Creates a new widget which allows customization of the parameter's value.
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
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
QgsProcessingParameterDefinition
Base class for the definition of processing parameters.
Definition: qgsprocessingparameters.h:334
QgsAbstractProcessingParameterWidgetWrapper
A widget wrapper for Processing parameter value widgets.
Definition: qgsprocessingwidgetwrapper.h:282
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsProcessingHiddenWidgetWrapper
An widget wrapper for hidden widgets.
Definition: qgsprocessingwidgetwrapper.h:686
QgsProcessingGui::Standard
@ Standard
Standard algorithm dialog.
Definition: qgsprocessinggui.h:40
QgsPropertyOverrideButton
A button for controlling property overrides which may apply to a widget.
Definition: qgspropertyoverridebutton.h:50
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsAbstractProcessingParameterWidgetWrapper::setWidgetValue
virtual void setWidgetValue(const QVariant &value, QgsProcessingContext &context)=0
Sets the current value for the parameter to show in the widget.
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition: qgsprocessingcontext.h:46
qgsprocessinggui.h
qgis_sip.h
QgsMessageBar
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:60
Q_DECLARE_OPERATORS_FOR_FLAGS
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
QgsProcessingModelerParameterWidget
A widget for customising the value of Processing algorithm parameter inside a Processing model.
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
An interface for objects which can create sets of parameter values for processing algorithms.
Definition: qgsprocessingwidgetwrapper.h:76
QgsAbstractProcessingParameterWidgetWrapper::linkedVectorLayer
virtual const QgsVectorLayer * linkedVectorLayer() const
Returns the optional vector layer associated with this widget wrapper, or nullptr if no vector layer ...
Definition: qgsprocessingwidgetwrapper.cpp:245
QgsProcessingAbstractParameterDefinitionWidget
Abstract base class for widgets which allow users to specify the properties of a Processing parameter...
Definition: qgsprocessingparameterdefinitionwidget.h:46
qgsvectorlayer.h
QgsAbstractProcessingParameterWidgetWrapper::createLabel
virtual QLabel * createLabel()
Creates a new label to accompany widgets created by the wrapper.
Definition: qgsprocessingwidgetwrapper.cpp:224
QgsProcessingGui::WidgetType
WidgetType
Types of dialogs which Processing widgets can be created for.
Definition: qgsprocessinggui.h:38
QgsProcessingParameterWidgetFactoryInterface
An interface for Processing widget wrapper factories.
Definition: qgsprocessingwidgetwrapper.h:532
QgsProcessingAlgorithm
Abstract base class for processing algorithms.
Definition: qgsprocessingalgorithm.h:52
QgsAbstractProcessingParameterWidgetWrapper::widgetValue
virtual QVariant widgetValue() const =0
Returns the current value of the parameter.
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsAbstractProcessingParameterWidgetWrapper::mWidgetContext
QgsProcessingParameterWidgetContext mWidgetContext
Definition: qgsprocessingwidgetwrapper.h:496
qgsprocessingmodelchildparametersource.h
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:36
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsProcessingParametersGenerator::Flag
Flag
Flags controlling parameter generation.
Definition: qgsprocessingwidgetwrapper.h:85
QgsBrowserGuiModel
A model for showing available data sources and other items in a structured tree.
Definition: qgsbrowserguimodel.h:36
QgsProcessingContextGenerator
An interface for objects which can create Processing contexts.
Definition: qgsprocessingwidgetwrapper.h:52