QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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"
26#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;
47
56{
57 public:
66
67 virtual ~QgsProcessingContextGenerator() = default;
68};
69
79{
80 public:
86 enum class Flag : int SIP_ENUM_BASETYPE( IntFlag )
87 {
88 SkipDefaultValueParameters = 1 << 0,
89 SkipValidation = 1 << 1,
90 };
91 Q_DECLARE_FLAGS( Flags, Flag )
92
93
101
103};
104
106
107
119{
120 public:
122
128 void setMapCanvas( QgsMapCanvas *canvas );
129
134 QgsMapCanvas *mapCanvas() const;
135
142 void setMessageBar( QgsMessageBar *bar );
143
150 QgsMessageBar *messageBar() const;
151
158
165
173
178 QgsProject *project() const;
179
186 QgsProcessingModelAlgorithm *model() const;
187
194 void setModel( QgsProcessingModelAlgorithm *model );
195
202 QString modelChildAlgorithmId() const;
203
210 void setModelChildAlgorithmId( const QString &id );
211
218 QgsMapLayer *activeLayer() const;
219
226 void setActiveLayer( QgsMapLayer *layer );
227
239
248
257 QgsModelDesignerDialog *modelDesignerDialog() const;
258
267 void setModelDesignerDialog( QgsModelDesignerDialog *dialog );
268
269 private:
270 QgsProcessingModelAlgorithm *mModel = nullptr;
271
272 QString mModelChildAlgorithmId;
273
274 QgsMapCanvas *mMapCanvas = nullptr;
275
276 QgsMessageBar *mMessageBar = nullptr;
277
278 QgsProject *mProject = nullptr;
279
280 QgsBrowserGuiModel *mBrowserModel = nullptr;
281
282 QgsMapLayer *mActiveLayer = nullptr;
283
284 QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
285
286 QgsModelDesignerDialog *mModelDialog = nullptr;
287};
288
289#ifndef SIP_RUN
291class GUI_EXPORT QgsProcessingWidgetWrapperUtils
292{
293 public:
294 static QgsExpressionContext createExpressionContext(
295 QgsProcessingContextGenerator *processingContextGenerator = nullptr,
297 const QgsProcessingAlgorithm *algorithm = nullptr,
298 const QgsVectorLayer *linkedLayer = nullptr
299 );
300};
302#endif
303
324{
325 Q_OBJECT
326
327 public:
334 );
335
340
350 virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
351
360
372
386
391 QWidget *wrappedWidget();
392
397 QLabel *wrappedLabel();
398
403
404 // TODO QGIS 5.0 -- remove
405#ifdef SIP_RUN
406 % Property( name = param, get = parameterDefinition )
407#endif
408
417 void setParameterValue( const QVariant &value, QgsProcessingContext &context );
418
424 QVariant parameterValue() const;
425
429 virtual QVariantMap customProperties() const;
430
438
447
452 virtual void postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers );
453
461 virtual int stretch() const;
462
464
470 virtual void setDialog( QDialog *dialog );
471
472 signals:
473
474 // TODO QGIS 5.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
475 // yet can easily be retrieved by checking the sender()
476
481
482 protected:
490 virtual QWidget *createWidget() = 0 SIP_FACTORY;
491
502 virtual QLabel *createLabel() SIP_FACTORY;
503
512 virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
513
519 virtual QVariant widgetValue() const = 0;
520
530 virtual const QgsVectorLayer *linkedVectorLayer() const;
531
532 protected:
536
537 private slots:
538
539 void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
540
541 private:
542 Qgis::ProcessingMode mType = Qgis::ProcessingMode::Standard;
543 const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
544
545 void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
546
547 QPointer<QWidget> mWidget;
548 QPointer<QgsPropertyOverrideButton> mPropertyButton;
549 QPointer<QLabel> mLabel;
550 std::unique_ptr<QgsVectorLayer> mDynamicLayer;
551
552 friend class TestProcessingGui;
553};
554
555
570{
571 public:
573
577 virtual QString parameterType() const = 0;
578
587
604 QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context
605 );
606
632 QgsProcessingContext &context, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingParameterDefinition *definition = nullptr, const QgsProcessingAlgorithm *algorithm = nullptr
633 ) SIP_FACTORY;
634
635 protected:
650 virtual QStringList compatibleParameterTypes() const;
651
666 virtual QStringList compatibleOutputTypes() const;
667
682 virtual QList<int> compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
683
693 virtual QString modelerExpressionFormatString() const;
694
700 virtual Qgis::ProcessingModelChildParameterSource defaultModelSource( const QgsProcessingParameterDefinition *parameter ) const;
701};
702
716{
717 Q_OBJECT
718 public:
724
725 void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
726 QVariant widgetValue() const override;
727
728 const QgsVectorLayer *linkedVectorLayer() const override;
729
733 void setLinkedVectorLayer( const QgsVectorLayer *layer );
734
735 protected:
736 QWidget *createWidget() override;
737 QLabel *createLabel() override;
738
739 private:
740 QVariant mValue;
741 QPointer<const QgsVectorLayer> mLayer;
742};
743
744#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:3786
@ Standard
Standard (single-run) algorithm mode.
Definition qgis.h:3787
A widget wrapper for Processing parameter value widgets.
QVariant parameterValue() const
Returns the current value of the parameter.
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 setDialog(QDialog *dialog)
Sets the parent dialog in which the wrapper is shown.
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.
Base class for all map layer types.
Definition qgsmaplayer.h:83
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.
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.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsProject * project() const
Returns the project associated with the widget.
QgsBrowserGuiModel * browserModel() const
Returns the browser model associated with the widget.
void setActiveLayer(QgsMapLayer *layer)
Sets the current active layer.
QgsModelDesignerDialog * modelDesignerDialog() const
Returns the associated model designer dialog, if applicable.
void setModelChildAlgorithmId(const QString &id)
Sets the child algorithm id within the model which the parameter widget is associated with.
void setProject(QgsProject *project)
Sets the project associated with the widget.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
void setBrowserModel(QgsBrowserGuiModel *model)
Sets the browser model associated with the widget.
QgsProcessingModelAlgorithm * model() const
Returns the model which the parameter widget is associated with.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
QgsMapLayer * activeLayer() const
Returns the current active layer.
void setModelDesignerDialog(QgsModelDesignerDialog *dialog)
Sets the associated model designer dialog, if applicable.
void setModel(QgsProcessingModelAlgorithm *model)
Sets the model which the parameter widget is associated with.
QgsProcessingContextGenerator * processingContextGenerator()
Returns the Processing context generator class that will be used to retrieve a Processing context for...
void registerProcessingContextGenerator(QgsProcessingContextGenerator *generator)
Registers a Processing context generator class that will be used to retrieve a Processing context for...
QString modelChildAlgorithmId() const
Returns the child algorithm ID within the model which the parameter widget is associated with.
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...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:113
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:274
#define SIP_FACTORY
Definition qgis_sip.h:83
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)