QGIS API Documentation 4.3.0-Master (0cfde48c85b)
Loading...
Searching...
No Matches
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 <memory>
22
23#include "qgis_gui.h"
24#include "qgis_sip.h"
25#include "qgsprocessinggui.h"
27#include "qgsvectorlayer.h"
28
29#include <QObject>
30#include <QPointer>
31#include <QWidget>
32
36class QgsProcessingModelAlgorithm;
37class QLabel;
39class QgsVectorLayer;
40class QgsProcessingModelAlgorithm;
41class QgsMapCanvas;
44class QgsMessageBar;
46class QgsModelGraphicsScene;
47class QgsModelDesignerDialog;
49
58{
59 public:
68
69 virtual ~QgsProcessingContextGenerator() = default;
70};
71
81{
82 public:
88 enum class Flag : int SIP_ENUM_BASETYPE( IntFlag )
89 {
90 SkipDefaultValueParameters = 1 << 0,
91 SkipValidation = 1 << 1,
92 };
93 Q_DECLARE_FLAGS( Flags, Flag )
94
95
103
105
112 {
113 Valid,
114 InvalidOutputExtension,
115 InvalidValue,
116 };
117
136};
137
139
140
141#ifndef SIP_RUN
143class GUI_EXPORT QgsProcessingWidgetWrapperUtils
144{
145 public:
146 static QgsExpressionContext createExpressionContext(
147 QgsProcessingContextGenerator *processingContextGenerator = nullptr,
149 const QgsProcessingAlgorithm *algorithm = nullptr,
150 const QgsVectorLayer *linkedLayer = nullptr
151 );
152};
154#endif
155
176{
177 Q_OBJECT
178
179 public:
186 );
187
192
202 virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
203
212
224
238
243 QWidget *wrappedWidget();
244
249 QLabel *wrappedLabel();
250
255
256 // TODO QGIS 5.0 -- remove
257#ifdef SIP_RUN
258 % Property( name = param, get = parameterDefinition )
259#endif
260
269 void setParameterValue( const QVariant &value, QgsProcessingContext &context );
270
276 QVariant parameterValue() const;
277
281 virtual QVariantMap customProperties() const;
282
290
299
304 virtual void postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers );
305
313 virtual int stretch() const;
314
316
322 virtual void setDialog( QWidget *dialog );
323
324 signals:
325
326 // TODO QGIS 5.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
327 // yet can easily be retrieved by checking the sender()
328
333
334 protected:
342 virtual QWidget *createWidget() = 0 SIP_FACTORY;
343
354 virtual QLabel *createLabel() SIP_FACTORY;
355
364 virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
365
371 virtual QVariant widgetValue() const = 0;
372
382 virtual const QgsVectorLayer *linkedVectorLayer() const;
383
384 protected:
388
389 private slots:
390
391 void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
392
393 private:
394 Qgis::ProcessingMode mType = Qgis::ProcessingMode::Standard;
395 const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
396
397 void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
398
399 QPointer<QWidget> mWidget;
400 QPointer<QgsPropertyOverrideButton> mPropertyButton;
401 QPointer<QLabel> mLabel;
402 std::unique_ptr<QgsVectorLayer> mDynamicLayer;
403
404 friend class TestProcessingGui;
405};
406
407
422{
423 public:
425
429 virtual QString parameterType() const = 0;
430
439
456 QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context
457 );
458
484 QgsProcessingContext &context, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingParameterDefinition *definition = nullptr, const QgsProcessingAlgorithm *algorithm = nullptr
486
487 protected:
502 virtual QStringList compatibleParameterTypes() const;
503
518 virtual QStringList compatibleOutputTypes() const;
519
534 virtual QList<int> compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
535
545 virtual QString modelerExpressionFormatString() const;
546
552 virtual Qgis::ProcessingModelChildParameterSource defaultModelSource( const QgsProcessingParameterDefinition *parameter ) const;
553};
554
568{
569 Q_OBJECT
570 public:
576
577 void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
578 QVariant widgetValue() const override;
579
580 const QgsVectorLayer *linkedVectorLayer() const override;
581
585 void setLinkedVectorLayer( const QgsVectorLayer *layer );
586
587 protected:
588 QWidget *createWidget() override;
589 QLabel *createLabel() override;
590
591 private:
592 QVariant mValue;
593 QPointer<const QgsVectorLayer> mLayer;
594};
595
596#endif // QGSPROCESSINGWIDGETWRAPPER_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
ProcessingMode
Types of modes which Processing widgets can be created for.
Definition qgis.h:3910
@ Standard
Standard (single-run) algorithm mode.
Definition qgis.h:3911
A widget wrapper for Processing parameter value widgets.
QVariant parameterValue() const
Returns the current value of the parameter.
virtual void setDialog(QWidget *dialog)
Sets the parent dialog (or widget) in which the wrapper is shown.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Qgis::ProcessingMode type() const
Returns the dialog type for which widgets and labels will be created by this wrapper.
virtual QVariantMap customProperties() const
Returns any custom properties set by the wrapper.
virtual void setWidgetValue(const QVariant &value, QgsProcessingContext &context)=0
Sets the current value for the parameter to show in the widget.
virtual QLabel * createLabel()
Creates a new label to accompany widgets created by the wrapper.
void registerProcessingParametersGenerator(QgsProcessingParametersGenerator *generator)
Registers a Processing parameters generator class that will be used to retrieve algorithm parameters ...
QgsProcessingParameterWidgetContext mWidgetContext
QgsProcessingParametersGenerator * mParametersGenerator
virtual void registerProcessingContextGenerator(QgsProcessingContextGenerator *generator)
Registers a Processing context generator class that will be used to retrieve a Processing context for...
const QgsProcessingParameterWidgetContext & widgetContext() const
Returns the context in which the Processing parameter widget is shown, e.g., the parent model algorit...
QLabel * createWrappedLabel()
Creates and returns a new label to accompany widgets created by the wrapper.
QWidget * createWrappedWidget(QgsProcessingContext &context)
Creates and return a new wrapped widget which allows customization of the parameter's value.
QgsProcessingContextGenerator * mProcessingContextGenerator
void widgetValueHasChanged(QgsAbstractProcessingParameterWidgetWrapper *wrapper)
Emitted whenever the parameter value (as defined by the wrapped widget) is changed.
virtual void postInitialize(const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers)
Called after all wrappers have been created within a particular dialog or context,...
virtual const QgsVectorLayer * linkedVectorLayer() const
Returns the optional vector layer associated with this widget wrapper, or nullptr if no vector layer ...
QWidget * wrappedWidget()
Returns the current wrapped widget, if any.
const QgsProcessingParameterDefinition * parameterDefinition() const
Returns the parameter definition associated with this wrapper.
QLabel * wrappedLabel()
Returns the current wrapped label, if any.
virtual QVariant widgetValue() const =0
Returns the current value of the parameter.
QgsAbstractProcessingParameterWidgetWrapper(const QgsProcessingParameterDefinition *parameter=nullptr, Qgis::ProcessingMode type=Qgis::ProcessingMode::Standard, QObject *parent=nullptr)
Constructor for QgsAbstractProcessingParameterWidgetWrapper, for the specified parameter definition a...
virtual QWidget * createWidget()=0
Creates a new widget which allows customization of the parameter's value.
virtual int stretch() const
Returns the Qt layout "stretch" factor to use when adding this widget to a layout.
virtual void setWidgetContext(const QgsProcessingParameterWidgetContext &context)
Sets the context in which the Processing parameter widget is shown, e.g., the parent model algorithm,...
void setParameterValue(const QVariant &value, QgsProcessingContext &context)
Sets the current value for the parameter.
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.
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() const =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.
QgsProcessingHiddenWidgetWrapper(const QgsProcessingParameterDefinition *parameter=nullptr, Qgis::ProcessingMode type=Qgis::ProcessingMode::Standard, QObject *parent=nullptr)
Constructor for QgsProcessingHiddenWidgetWrapper, for the specified parameter definition and dialog t...
QVariant widgetValue() const override
Returns the current value of the parameter.
QWidget * createWidget() override
Creates a new widget which allows customization of the parameter's value.
void setWidgetValue(const QVariant &value, QgsProcessingContext &context) override
Sets the current value for the parameter to show in the widget.
void setLinkedVectorLayer(const QgsVectorLayer *layer)
Sets the vector layer linked to the wrapper.
QLabel * createLabel() override
Creates a new label to accompany widgets created by the wrapper.
const QgsVectorLayer * linkedVectorLayer() const override
Returns the optional vector layer associated with this widget wrapper, or nullptr if no vector layer ...
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 QStringList compatibleParameterTypes() const
Returns a list of compatible Processing parameter types for inputs for this parameter.
virtual QList< int > compatibleDataTypes(const QgsProcessingParameterDefinition *parameter) const
Returns a list of compatible Processing data types for inputs for this widget for the specified param...
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.
virtual QgsProcessingAbstractParameterDefinitionWidget * createParameterDefinitionWidget(QgsProcessingContext &context, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingParameterDefinition *definition=nullptr, const QgsProcessingAlgorithm *algorithm=nullptr)
Creates a new parameter definition widget allowing for configuration of an instance of the parameter ...
virtual QgsProcessingModelerParameterWidget * createModelerWidgetWrapper(QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context)
Creates a new modeler parameter widget for the given parameter.
virtual QStringList compatibleOutputTypes() const
Returns a list of compatible Processing output types for inputs for this parameter.
virtual Qgis::ProcessingModelChildParameterSource defaultModelSource(const QgsProcessingParameterDefinition *parameter) const
Returns the default source type to use for the widget for the specified parameter.
virtual QString modelerExpressionFormatString() const
Returns the expected expression format string for expression results for the parameter within model c...
Encapsulates the result of validating parameters shown in the generator.
QgsProcessingParametersGenerator::ValidationResult result
Validation result.
An interface for objects which can create sets of parameter values for processing algorithms.
ValidationResult
Results of validating a parameter.
Flag
Flags controlling parameter generation.
virtual QVariantMap createProcessingParameters(QgsProcessingParametersGenerator::Flags flags=QgsProcessingParametersGenerator::Flags())=0
This method needs to be reimplemented in all classes which implement this interface and return a algo...
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:52
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:277
#define SIP_TRANSFERBACK
Definition qgis_sip.h:47
#define SIP_FACTORY
Definition qgis_sip.h:83
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)