QGIS API Documentation 3.43.0-Master (b60ef06885e)
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 };
86 Q_DECLARE_FLAGS( Flags, Flag )
87
88
95 virtual QVariantMap createProcessingParameters( QgsProcessingParametersGenerator::Flags flags = QgsProcessingParametersGenerator::Flags() ) = 0;
96
98};
99
101
102
114{
115 public:
117
123 void setMapCanvas( QgsMapCanvas *canvas );
124
129 QgsMapCanvas *mapCanvas() const;
130
137 void setMessageBar( QgsMessageBar *bar );
138
145 QgsMessageBar *messageBar() const;
146
152 void setBrowserModel( QgsBrowserGuiModel *model );
153
159 QgsBrowserGuiModel *browserModel() const;
160
167 void setProject( QgsProject *project );
168
173 QgsProject *project() const;
174
181 QgsProcessingModelAlgorithm *model() const;
182
189 void setModel( QgsProcessingModelAlgorithm *model );
190
197 QString modelChildAlgorithmId() const;
198
205 void setModelChildAlgorithmId( const QString &id );
206
213 QgsMapLayer *activeLayer() const;
214
221 void setActiveLayer( QgsMapLayer *layer );
222
223 private:
224 QgsProcessingModelAlgorithm *mModel = nullptr;
225
226 QString mModelChildAlgorithmId;
227
228 QgsMapCanvas *mMapCanvas = nullptr;
229
230 QgsMessageBar *mMessageBar = nullptr;
231
232 QgsProject *mProject = nullptr;
233
234 QgsBrowserGuiModel *mBrowserModel = nullptr;
235
236 QgsMapLayer *mActiveLayer = nullptr;
237};
238
239#ifndef SIP_RUN
241class GUI_EXPORT QgsProcessingGuiUtils
242{
243 public:
244 static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr, const QgsProcessingParameterWidgetContext &widgetContext = QgsProcessingParameterWidgetContext(), const QgsProcessingAlgorithm *algorithm = nullptr, const QgsVectorLayer *linkedLayer = nullptr );
245};
247#endif
248
269{
270 Q_OBJECT
271
272 public:
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
380 virtual void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
381
389 void registerProcessingParametersGenerator( QgsProcessingParametersGenerator *generator );
390
395 virtual void postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers );
396
404 virtual int stretch() const;
405
406 QgsExpressionContext createExpressionContext() const override;
407
413 virtual void setDialog( QDialog *dialog );
414
415 signals:
416
417 // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
418 // yet can easily be retrieved by checking the sender()
419
424
425 protected:
433 virtual QWidget *createWidget() = 0 SIP_FACTORY;
434
445 virtual QLabel *createLabel() SIP_FACTORY;
446
455 virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
456
462 virtual QVariant widgetValue() const = 0;
463
473 virtual const QgsVectorLayer *linkedVectorLayer() const;
474
475 protected:
476 QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
477 QgsProcessingParametersGenerator *mParametersGenerator = nullptr;
479
480 private slots:
481
482 void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
483
484 private:
485 QgsProcessingGui::WidgetType mType = QgsProcessingGui::Standard;
486 const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
487
488 void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
489
490 QPointer<QWidget> mWidget;
491 QPointer<QgsPropertyOverrideButton> mPropertyButton;
492 QPointer<QLabel> mLabel;
493 std::unique_ptr<QgsVectorLayer> mDynamicLayer;
494
495 friend class TestProcessingGui;
496};
497
498
513{
514 public:
516
520 virtual QString parameterType() const = 0;
521
530
546 virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context );
547
572 virtual QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
573 QgsProcessingContext &context,
574 const QgsProcessingParameterWidgetContext &widgetContext,
575 const QgsProcessingParameterDefinition *definition = nullptr,
576 const QgsProcessingAlgorithm *algorithm = nullptr
577 ) SIP_FACTORY;
578
579 protected:
594 virtual QStringList compatibleParameterTypes() const = 0;
595
610 virtual QStringList compatibleOutputTypes() const = 0;
611
626 virtual QList<int> compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
627
637 virtual QString modelerExpressionFormatString() const;
638
644 virtual Qgis::ProcessingModelChildParameterSource defaultModelSource( const QgsProcessingParameterDefinition *parameter ) const;
645};
646
660{
661 Q_OBJECT
662 public:
668
669 void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
670 QVariant widgetValue() const override;
671
672 const QgsVectorLayer *linkedVectorLayer() const override;
673
677 void setLinkedVectorLayer( const QgsVectorLayer *layer );
678
679 protected:
680 QWidget *createWidget() override;
681 QLabel *createLabel() override;
682
683 private:
684 QVariant mValue;
685 QPointer<const QgsVectorLayer> mLayer;
686};
687
688#endif // QGSPROCESSINGWIDGETWRAPPER_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:54
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.
Contains general functions and values related to Processing GUI components.
WidgetType
Types of dialogs which Processing widgets can be created for.
@ Standard
Standard algorithm dialog.
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 QgsAbstractProcessingParameterWidgetWrapper * createWidgetWrapper(const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type)=0
Creates a new widget wrapper for the specified parameter definition.
virtual ~QgsProcessingParameterWidgetFactoryInterface()=default
virtual QString parameterType() const =0
Returns the type string for the parameter type the factory is associated with.
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)