QGIS API Documentation 3.41.0-Master (cea29feecf2)
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 <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
113{
114 public:
116
122 void setMapCanvas( QgsMapCanvas *canvas );
123
128 QgsMapCanvas *mapCanvas() const;
129
136 void setMessageBar( QgsMessageBar *bar );
137
144 QgsMessageBar *messageBar() const;
145
151 void setBrowserModel( QgsBrowserGuiModel *model );
152
158 QgsBrowserGuiModel *browserModel() const;
159
166 void setProject( QgsProject *project );
167
172 QgsProject *project() const;
173
180 QgsProcessingModelAlgorithm *model() const;
181
188 void setModel( QgsProcessingModelAlgorithm *model );
189
196 QString modelChildAlgorithmId() const;
197
204 void setModelChildAlgorithmId( const QString &id );
205
212 QgsMapLayer *activeLayer() const;
213
220 void setActiveLayer( QgsMapLayer *layer );
221
222 private:
223 QgsProcessingModelAlgorithm *mModel = nullptr;
224
225 QString mModelChildAlgorithmId;
226
227 QgsMapCanvas *mMapCanvas = nullptr;
228
229 QgsMessageBar *mMessageBar = nullptr;
230
231 QgsProject *mProject = nullptr;
232
233 QgsBrowserGuiModel *mBrowserModel = nullptr;
234
235 QgsMapLayer *mActiveLayer = nullptr;
236};
237
238#ifndef SIP_RUN
240class GUI_EXPORT QgsProcessingGuiUtils
241{
242 public:
243 static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr, const QgsProcessingParameterWidgetContext &widgetContext = QgsProcessingParameterWidgetContext(), const QgsProcessingAlgorithm *algorithm = nullptr, const QgsVectorLayer *linkedLayer = nullptr );
244};
246#endif
247
268{
269 Q_OBJECT
270
271 public:
277
281 QgsProcessingGui::WidgetType type() const;
282
292 virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
293
301 const QgsProcessingParameterWidgetContext &widgetContext() const;
302
313 QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
314
327 QLabel *createWrappedLabel() SIP_FACTORY;
328
333 QWidget *wrappedWidget();
334
339 QLabel *wrappedLabel();
340
344 const QgsProcessingParameterDefinition *parameterDefinition() const;
345
346 // TODO QGIS 4.0 -- remove
347#ifdef SIP_RUN
348 % Property( name = param, get = parameterDefinition )
349#endif
350
359 void setParameterValue( const QVariant &value, QgsProcessingContext &context );
360
366 QVariant parameterValue() const;
367
371 virtual QVariantMap customProperties() const;
372
379 virtual void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
380
388 void registerProcessingParametersGenerator( QgsProcessingParametersGenerator *generator );
389
394 virtual void postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers );
395
403 virtual int stretch() const;
404
405 QgsExpressionContext createExpressionContext() const override;
406
412 virtual void setDialog( QDialog *dialog );
413
414 signals:
415
416 // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
417 // yet can easily be retrieved by checking the sender()
418
423
424 protected:
432 virtual QWidget *createWidget() = 0 SIP_FACTORY;
433
444 virtual QLabel *createLabel() SIP_FACTORY;
445
454 virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
455
461 virtual QVariant widgetValue() const = 0;
462
472 virtual const QgsVectorLayer *linkedVectorLayer() const;
473
474 protected:
475 QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
476 QgsProcessingParametersGenerator *mParametersGenerator = nullptr;
478
479 private slots:
480
481 void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
482
483 private:
484 QgsProcessingGui::WidgetType mType = QgsProcessingGui::Standard;
485 const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
486
487 void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
488
489 QPointer<QWidget> mWidget;
490 QPointer<QgsPropertyOverrideButton> mPropertyButton;
491 QPointer<QLabel> mLabel;
492 std::unique_ptr<QgsVectorLayer> mDynamicLayer;
493
494 friend class TestProcessingGui;
495};
496
497
512{
513 public:
515
519 virtual QString parameterType() const = 0;
520
529
545 virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context );
546
571 virtual QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
572 QgsProcessingContext &context,
573 const QgsProcessingParameterWidgetContext &widgetContext,
574 const QgsProcessingParameterDefinition *definition = nullptr,
575 const QgsProcessingAlgorithm *algorithm = nullptr
576 ) SIP_FACTORY;
577
578 protected:
593 virtual QStringList compatibleParameterTypes() const = 0;
594
609 virtual QStringList compatibleOutputTypes() const = 0;
610
625 virtual QList<int> compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
626
636 virtual QString modelerExpressionFormatString() const;
637
643 virtual Qgis::ProcessingModelChildParameterSource defaultModelSource( const QgsProcessingParameterDefinition *parameter ) const;
644};
645
659{
660 Q_OBJECT
661 public:
667
668 void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
669 QVariant widgetValue() const override;
670
671 const QgsVectorLayer *linkedVectorLayer() const override;
672
676 void setLinkedVectorLayer( const QgsVectorLayer *layer );
677
678 protected:
679 QWidget *createWidget() override;
680 QLabel *createLabel() override;
681
682 private:
683 QVariant mValue;
684 QPointer<const QgsVectorLayer> mLayer;
685};
686
687#endif // QGSPROCESSINGWIDGETWRAPPER_H
The Qgis class provides global constants 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:76
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.
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,...
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 data sets.
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)