QGIS API Documentation 3.43.0-Master (56aa1fd18d7)
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
33class QgsProcessingModelAlgorithm;
34class QLabel;
36class QgsVectorLayer;
37class QgsProcessingModelAlgorithm;
38class QgsMapCanvas;
41class QgsMessageBar;
43
52{
53 public:
62
63 virtual ~QgsProcessingContextGenerator() = default;
64};
65
75{
76 public:
82 enum class Flag : int SIP_ENUM_BASETYPE( IntFlag )
83 {
84 SkipDefaultValueParameters = 1 << 0,
85 SkipValidation = 1 << 1,
86 };
87 Q_DECLARE_FLAGS( Flags, Flag )
88
89
96 virtual QVariantMap createProcessingParameters( QgsProcessingParametersGenerator::Flags flags = QgsProcessingParametersGenerator::Flags() ) = 0;
97
99};
100
102
103
115{
116 public:
118
124 void setMapCanvas( QgsMapCanvas *canvas );
125
130 QgsMapCanvas *mapCanvas() const;
131
138 void setMessageBar( QgsMessageBar *bar );
139
146 QgsMessageBar *messageBar() const;
147
153 void setBrowserModel( QgsBrowserGuiModel *model );
154
160 QgsBrowserGuiModel *browserModel() const;
161
168 void setProject( QgsProject *project );
169
174 QgsProject *project() const;
175
182 QgsProcessingModelAlgorithm *model() const;
183
190 void setModel( QgsProcessingModelAlgorithm *model );
191
198 QString modelChildAlgorithmId() const;
199
206 void setModelChildAlgorithmId( const QString &id );
207
214 QgsMapLayer *activeLayer() const;
215
222 void setActiveLayer( QgsMapLayer *layer );
223
224 private:
225 QgsProcessingModelAlgorithm *mModel = nullptr;
226
227 QString mModelChildAlgorithmId;
228
229 QgsMapCanvas *mMapCanvas = nullptr;
230
231 QgsMessageBar *mMessageBar = nullptr;
232
233 QgsProject *mProject = nullptr;
234
235 QgsBrowserGuiModel *mBrowserModel = nullptr;
236
237 QgsMapLayer *mActiveLayer = nullptr;
238};
239
240#ifndef SIP_RUN
242class GUI_EXPORT QgsProcessingGuiUtils
243{
244 public:
245 static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr, const QgsProcessingParameterWidgetContext &widgetContext = QgsProcessingParameterWidgetContext(), const QgsProcessingAlgorithm *algorithm = nullptr, const QgsVectorLayer *linkedLayer = nullptr );
246};
248#endif
249
270{
271 Q_OBJECT
272
273 public:
279
283 Qgis::ProcessingMode type() const;
284
294 virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
295
303 const QgsProcessingParameterWidgetContext &widgetContext() const;
304
315 QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
316
329 QLabel *createWrappedLabel() SIP_FACTORY;
330
335 QWidget *wrappedWidget();
336
341 QLabel *wrappedLabel();
342
346 const QgsProcessingParameterDefinition *parameterDefinition() const;
347
348 // TODO QGIS 4.0 -- remove
349#ifdef SIP_RUN
350 % Property( name = param, get = parameterDefinition )
351#endif
352
361 void setParameterValue( const QVariant &value, QgsProcessingContext &context );
362
368 QVariant parameterValue() const;
369
373 virtual QVariantMap customProperties() const;
374
381 virtual void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
382
390 void registerProcessingParametersGenerator( QgsProcessingParametersGenerator *generator );
391
396 virtual void postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers );
397
405 virtual int stretch() const;
406
407 QgsExpressionContext createExpressionContext() const override;
408
414 virtual void setDialog( QDialog *dialog );
415
416 signals:
417
418 // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
419 // yet can easily be retrieved by checking the sender()
420
425
426 protected:
434 virtual QWidget *createWidget() = 0 SIP_FACTORY;
435
446 virtual QLabel *createLabel() SIP_FACTORY;
447
456 virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
457
463 virtual QVariant widgetValue() const = 0;
464
474 virtual const QgsVectorLayer *linkedVectorLayer() const;
475
476 protected:
477 QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
478 QgsProcessingParametersGenerator *mParametersGenerator = nullptr;
480
481 private slots:
482
483 void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
484
485 private:
486 Qgis::ProcessingMode mType = Qgis::ProcessingMode::Standard;
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
514{
515 public:
517
521 virtual QString parameterType() const = 0;
522
531
547 virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context );
548
573 virtual QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
574 QgsProcessingContext &context,
575 const QgsProcessingParameterWidgetContext &widgetContext,
576 const QgsProcessingParameterDefinition *definition = nullptr,
577 const QgsProcessingAlgorithm *algorithm = nullptr
578 ) SIP_FACTORY;
579
580 protected:
595 virtual QStringList compatibleParameterTypes() const;
596
611 virtual QStringList compatibleOutputTypes() const;
612
627 virtual QList<int> compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
628
638 virtual QString modelerExpressionFormatString() const;
639
645 virtual Qgis::ProcessingModelChildParameterSource defaultModelSource( const QgsProcessingParameterDefinition *parameter ) const;
646};
647
661{
662 Q_OBJECT
663 public:
669
670 void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
671 QVariant widgetValue() const override;
672
673 const QgsVectorLayer *linkedVectorLayer() const override;
674
678 void setLinkedVectorLayer( const QgsVectorLayer *layer );
679
680 protected:
681 QWidget *createWidget() override;
682 QLabel *createLabel() override;
683
684 private:
685 QVariant mValue;
686 QPointer<const QgsVectorLayer> mLayer;
687};
688
689#endif // QGSPROCESSINGWIDGETWRAPPER_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:54
ProcessingMode
Types of modes which Processing widgets can be created for.
Definition qgis.h:3537
@ Standard
Standard (single-run) algorithm mode.
A widget wrapper for Processing parameter value widgets.
void widgetValueHasChanged(QgsAbstractProcessingParameterWidgetWrapper *wrapper)
Emitted whenever the parameter value (as defined by the wrapped widget) is changed.
virtual QWidget * createWidget()=0
Creates a new widget which allows customization of the parameter's value.
A model for showing available data sources and other items in a structured tree.
Abstract interface for generating an expression context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:77
A bar for displaying non-blocking messages to the user.
Abstract base class for widgets which allow users to specify the properties of a Processing parameter...
Abstract base class for processing algorithms.
An interface for objects which can create Processing contexts.
virtual ~QgsProcessingContextGenerator()=default
virtual QgsProcessingContext * processingContext()=0
This method needs to be reimplemented in all classes which implement this interface and return a Proc...
Contains information about the context in which a processing algorithm is executed.
A widget wrapper for hidden widgets.
A widget for customising the value of Processing algorithm parameters inside a Processing model.
Base class for the definition of processing parameters.
Contains settings which reflect the context in which a Processing parameter widget is shown.
An interface for Processing widget wrapper factories.
virtual ~QgsProcessingParameterWidgetFactoryInterface()=default
virtual QString parameterType() const =0
Returns the type string for the parameter type the factory is associated with.
virtual QgsAbstractProcessingParameterWidgetWrapper * createWidgetWrapper(const QgsProcessingParameterDefinition *parameter, Qgis::ProcessingMode type)=0
Creates a new widget wrapper for the specified parameter definition.
An interface for objects which can create sets of parameter values for processing algorithms.
Flag
Flags controlling parameter generation.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
A button for controlling property overrides which may apply to a widget.
Represents a vector layer which manages a vector based dataset.
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
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_FACTORY
Definition qgis_sip.h:76
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)