QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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"
30
34class QgsProcessingModelAlgorithm;
35class QLabel;
37class QgsVectorLayer;
38class QgsProcessingModelAlgorithm;
39class QgsMapCanvas;
42class QgsMessageBar;
44
53{
54 public:
55
64
65 virtual ~QgsProcessingContextGenerator() = default;
66};
67
77{
78 public:
79
85 enum class Flag : int
86 {
87 SkipDefaultValueParameters = 1 << 0,
88 };
89 Q_DECLARE_FLAGS( Flags, Flag )
90
91
98 virtual QVariantMap createProcessingParameters( QgsProcessingParametersGenerator::Flags flags = QgsProcessingParametersGenerator::Flags() ) = 0;
99
101};
102
104
105
116{
117 public:
118
123
129 void setMapCanvas( QgsMapCanvas *canvas );
130
135 QgsMapCanvas *mapCanvas() const;
136
143 void setMessageBar( QgsMessageBar *bar );
144
151 QgsMessageBar *messageBar() const;
152
158 void setBrowserModel( QgsBrowserGuiModel *model );
159
165 QgsBrowserGuiModel *browserModel() const;
166
173 void setProject( QgsProject *project );
174
179 QgsProject *project() const;
180
187 QgsProcessingModelAlgorithm *model() const;
188
195 void setModel( QgsProcessingModelAlgorithm *model );
196
203 QString modelChildAlgorithmId() const;
204
211 void setModelChildAlgorithmId( const QString &id );
212
219 QgsMapLayer *activeLayer() const;
220
227 void setActiveLayer( QgsMapLayer *layer );
228
229 private:
230
231 QgsProcessingModelAlgorithm *mModel = nullptr;
232
233 QString mModelChildAlgorithmId;
234
235 QgsMapCanvas *mMapCanvas = nullptr;
236
237 QgsMessageBar *mMessageBar = nullptr;
238
239 QgsProject *mProject = nullptr;
240
241 QgsBrowserGuiModel *mBrowserModel = nullptr;
242
243 QgsMapLayer *mActiveLayer = nullptr;
244
245};
246
247#ifndef SIP_RUN
249class GUI_EXPORT QgsProcessingGuiUtils
250{
251 public:
252
253 static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr,
255 const QgsProcessingAlgorithm *algorithm = nullptr,
256 const QgsVectorLayer *linkedLayer = nullptr );
257
258
259};
261#endif
262
283{
284 Q_OBJECT
285
286 public:
287
294
298 QgsProcessingGui::WidgetType type() const;
299
309 virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
310
318 const QgsProcessingParameterWidgetContext &widgetContext() const;
319
330 QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
331
344 QLabel *createWrappedLabel() SIP_FACTORY;
345
350 QWidget *wrappedWidget();
351
356 QLabel *wrappedLabel();
357
361 const QgsProcessingParameterDefinition *parameterDefinition() const;
362
363 // TODO QGIS 4.0 -- remove
364#ifdef SIP_RUN
365 % Property( name = param, get = parameterDefinition )
366#endif
367
376 void setParameterValue( const QVariant &value, QgsProcessingContext &context );
377
383 QVariant parameterValue() const;
384
388 virtual QVariantMap customProperties() const;
389
396 virtual void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
397
405 void registerProcessingParametersGenerator( QgsProcessingParametersGenerator *generator );
406
411 virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
412
420 virtual int stretch() const;
421
422 QgsExpressionContext createExpressionContext() const override;
423
429 virtual void setDialog( QDialog *dialog );
430
431 signals:
432
433 // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
434 // yet can easily be retrieved by checking the sender()
435
440
441 protected:
442
450 virtual QWidget *createWidget() = 0 SIP_FACTORY;
451
462 virtual QLabel *createLabel() SIP_FACTORY;
463
472 virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
473
479 virtual QVariant widgetValue() const = 0;
480
490 virtual const QgsVectorLayer *linkedVectorLayer() const;
491
492 protected:
493
494 QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
495 QgsProcessingParametersGenerator *mParametersGenerator = nullptr;
497
498 private slots:
499
500 void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
501
502 private:
503
504 QgsProcessingGui::WidgetType mType = QgsProcessingGui::Standard;
505 const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
506
507 void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
508
509 QPointer< QWidget > mWidget;
510 QPointer< QgsPropertyOverrideButton > mPropertyButton;
511 QPointer< QLabel > mLabel;
512 std::unique_ptr< QgsVectorLayer > mDynamicLayer;
513
514 friend class TestProcessingGui;
515
516};
517
518
533{
534
535 public:
536
538
542 virtual QString parameterType() const = 0;
543
553
569 virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
570 const QString &childId,
571 const QgsProcessingParameterDefinition *parameter,
572 QgsProcessingContext &context );
573
598 virtual QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
599 QgsProcessingContext &context,
600 const QgsProcessingParameterWidgetContext &widgetContext,
601 const QgsProcessingParameterDefinition *definition = nullptr,
603
604 protected:
605
620 virtual QStringList compatibleParameterTypes() const = 0;
621
636 virtual QStringList compatibleOutputTypes() const = 0;
637
652 virtual QList< int > compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
653
663 virtual QString modelerExpressionFormatString() const;
664
670 virtual QgsProcessingModelChildParameterSource::Source defaultModelSource( const QgsProcessingParameterDefinition *parameter ) const;
671
672};
673
687{
688 Q_OBJECT
689 public:
690
697 QObject *parent SIP_TRANSFERTHIS = nullptr );
698
699 void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
700 QVariant widgetValue() const override;
701
702 const QgsVectorLayer *linkedVectorLayer() const override;
703
707 void setLinkedVectorLayer( const QgsVectorLayer *layer );
708
709 protected:
710 QWidget *createWidget() override;
711 QLabel *createLabel() override;
712
713 private:
714
715 QVariant mValue;
716 QPointer < const QgsVectorLayer > mLayer;
717
718};
719
720#endif // QGSPROCESSINGWIDGETWRAPPER_H
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.
Definition: qgsmapcanvas.h:90
Base class for all map layer types.
Definition: qgsmaplayer.h:73
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
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.
An widget wrapper for hidden widgets.
A widget for customising the value of Processing algorithm parameter 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,...
QgsProcessingParameterWidgetContext()=default
Constructor for QgsProcessingParameterWidgetContext.
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:104
A button for controlling property overrides which may apply to a widget.
Represents a vector layer which manages a vector based data sets.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:74
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_FACTORY
Definition: qgis_sip.h:76
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.