QGIS API Documentation 4.3.0-Master (01f22706ec5)
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;
48
57{
58 public:
67
68 virtual ~QgsProcessingContextGenerator() = default;
69};
70
80{
81 public:
87 enum class Flag : int SIP_ENUM_BASETYPE( IntFlag )
88 {
89 SkipDefaultValueParameters = 1 << 0,
90 SkipValidation = 1 << 1,
91 };
92 Q_DECLARE_FLAGS( Flags, Flag )
93
94
102
104};
105
107
108
109#ifndef SIP_RUN
111class GUI_EXPORT QgsProcessingWidgetWrapperUtils
112{
113 public:
114 static QgsExpressionContext createExpressionContext(
115 QgsProcessingContextGenerator *processingContextGenerator = nullptr,
117 const QgsProcessingAlgorithm *algorithm = nullptr,
118 const QgsVectorLayer *linkedLayer = nullptr
119 );
120};
122#endif
123
144{
145 Q_OBJECT
146
147 public:
154 );
155
160
170 virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
171
180
192
206
211 QWidget *wrappedWidget();
212
217 QLabel *wrappedLabel();
218
223
224 // TODO QGIS 5.0 -- remove
225#ifdef SIP_RUN
226 % Property( name = param, get = parameterDefinition )
227#endif
228
237 void setParameterValue( const QVariant &value, QgsProcessingContext &context );
238
244 QVariant parameterValue() const;
245
249 virtual QVariantMap customProperties() const;
250
258
267
272 virtual void postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers );
273
281 virtual int stretch() const;
282
284
290 virtual void setDialog( QWidget *dialog );
291
292 signals:
293
294 // TODO QGIS 5.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
295 // yet can easily be retrieved by checking the sender()
296
301
302 protected:
310 virtual QWidget *createWidget() = 0 SIP_FACTORY;
311
322 virtual QLabel *createLabel() SIP_FACTORY;
323
332 virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
333
339 virtual QVariant widgetValue() const = 0;
340
350 virtual const QgsVectorLayer *linkedVectorLayer() const;
351
352 protected:
356
357 private slots:
358
359 void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
360
361 private:
362 Qgis::ProcessingMode mType = Qgis::ProcessingMode::Standard;
363 const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
364
365 void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
366
367 QPointer<QWidget> mWidget;
368 QPointer<QgsPropertyOverrideButton> mPropertyButton;
369 QPointer<QLabel> mLabel;
370 std::unique_ptr<QgsVectorLayer> mDynamicLayer;
371
372 friend class TestProcessingGui;
373};
374
375
390{
391 public:
393
397 virtual QString parameterType() const = 0;
398
407
424 QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context
425 );
426
452 QgsProcessingContext &context, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingParameterDefinition *definition = nullptr, const QgsProcessingAlgorithm *algorithm = nullptr
453 ) SIP_FACTORY;
454
455 protected:
470 virtual QStringList compatibleParameterTypes() const;
471
486 virtual QStringList compatibleOutputTypes() const;
487
502 virtual QList<int> compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
503
513 virtual QString modelerExpressionFormatString() const;
514
520 virtual Qgis::ProcessingModelChildParameterSource defaultModelSource( const QgsProcessingParameterDefinition *parameter ) const;
521};
522
536{
537 Q_OBJECT
538 public:
544
545 void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
546 QVariant widgetValue() const override;
547
548 const QgsVectorLayer *linkedVectorLayer() const override;
549
553 void setLinkedVectorLayer( const QgsVectorLayer *layer );
554
555 protected:
556 QWidget *createWidget() override;
557 QLabel *createLabel() override;
558
559 private:
560 QVariant mValue;
561 QPointer<const QgsVectorLayer> mLayer;
562};
563
564#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:3888
@ Standard
Standard (single-run) algorithm mode.
Definition qgis.h:3889
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...
An interface for objects which can create sets of parameter values for processing algorithms.
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_FACTORY
Definition qgis_sip.h:83
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)