QGIS API Documentation 3.39.0-Master (93ce9bf5c90)
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:
54
63
64 virtual ~QgsProcessingContextGenerator() = default;
65};
66
76{
77 public:
78
84 enum class Flag : int SIP_ENUM_BASETYPE( IntFlag )
85 {
86 SkipDefaultValueParameters = 1 << 0,
87 };
88 Q_DECLARE_FLAGS( Flags, Flag )
89
90
97 virtual QVariantMap createProcessingParameters( QgsProcessingParametersGenerator::Flags flags = QgsProcessingParametersGenerator::Flags() ) = 0;
98
100};
101
103
104
115{
116 public:
117
119
125 void setMapCanvas( QgsMapCanvas *canvas );
126
131 QgsMapCanvas *mapCanvas() const;
132
139 void setMessageBar( QgsMessageBar *bar );
140
147 QgsMessageBar *messageBar() const;
148
154 void setBrowserModel( QgsBrowserGuiModel *model );
155
161 QgsBrowserGuiModel *browserModel() const;
162
169 void setProject( QgsProject *project );
170
175 QgsProject *project() const;
176
183 QgsProcessingModelAlgorithm *model() const;
184
191 void setModel( QgsProcessingModelAlgorithm *model );
192
199 QString modelChildAlgorithmId() const;
200
207 void setModelChildAlgorithmId( const QString &id );
208
215 QgsMapLayer *activeLayer() const;
216
223 void setActiveLayer( QgsMapLayer *layer );
224
225 private:
226
227 QgsProcessingModelAlgorithm *mModel = nullptr;
228
229 QString mModelChildAlgorithmId;
230
231 QgsMapCanvas *mMapCanvas = nullptr;
232
233 QgsMessageBar *mMessageBar = nullptr;
234
235 QgsProject *mProject = nullptr;
236
237 QgsBrowserGuiModel *mBrowserModel = nullptr;
238
239 QgsMapLayer *mActiveLayer = nullptr;
240
241};
242
243#ifndef SIP_RUN
245class GUI_EXPORT QgsProcessingGuiUtils
246{
247 public:
248
249 static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr,
251 const QgsProcessingAlgorithm *algorithm = nullptr,
252 const QgsVectorLayer *linkedLayer = nullptr );
253
254
255};
257#endif
258
279{
280 Q_OBJECT
281
282 public:
283
290
294 QgsProcessingGui::WidgetType type() const;
295
305 virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
306
314 const QgsProcessingParameterWidgetContext &widgetContext() const;
315
326 QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
327
340 QLabel *createWrappedLabel() SIP_FACTORY;
341
346 QWidget *wrappedWidget();
347
352 QLabel *wrappedLabel();
353
357 const QgsProcessingParameterDefinition *parameterDefinition() const;
358
359 // TODO QGIS 4.0 -- remove
360#ifdef SIP_RUN
361 % Property( name = param, get = parameterDefinition )
362#endif
363
372 void setParameterValue( const QVariant &value, QgsProcessingContext &context );
373
379 QVariant parameterValue() const;
380
384 virtual QVariantMap customProperties() const;
385
392 virtual void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
393
401 void registerProcessingParametersGenerator( QgsProcessingParametersGenerator *generator );
402
407 virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
408
416 virtual int stretch() const;
417
418 QgsExpressionContext createExpressionContext() const override;
419
425 virtual void setDialog( QDialog *dialog );
426
427 signals:
428
429 // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
430 // yet can easily be retrieved by checking the sender()
431
436
437 protected:
438
446 virtual QWidget *createWidget() = 0 SIP_FACTORY;
447
458 virtual QLabel *createLabel() SIP_FACTORY;
459
468 virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
469
475 virtual QVariant widgetValue() const = 0;
476
486 virtual const QgsVectorLayer *linkedVectorLayer() const;
487
488 protected:
489
490 QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
491 QgsProcessingParametersGenerator *mParametersGenerator = nullptr;
493
494 private slots:
495
496 void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
497
498 private:
499
500 QgsProcessingGui::WidgetType mType = QgsProcessingGui::Standard;
501 const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
502
503 void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
504
505 QPointer< QWidget > mWidget;
506 QPointer< QgsPropertyOverrideButton > mPropertyButton;
507 QPointer< QLabel > mLabel;
508 std::unique_ptr< QgsVectorLayer > mDynamicLayer;
509
510 friend class TestProcessingGui;
511
512};
513
514
529{
530
531 public:
532
534
538 virtual QString parameterType() const = 0;
539
549
565 virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
566 const QString &childId,
567 const QgsProcessingParameterDefinition *parameter,
568 QgsProcessingContext &context );
569
594 virtual QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
595 QgsProcessingContext &context,
596 const QgsProcessingParameterWidgetContext &widgetContext,
597 const QgsProcessingParameterDefinition *definition = nullptr,
599
600 protected:
601
616 virtual QStringList compatibleParameterTypes() const = 0;
617
632 virtual QStringList compatibleOutputTypes() const = 0;
633
648 virtual QList< int > compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
649
659 virtual QString modelerExpressionFormatString() const;
660
666 virtual Qgis::ProcessingModelChildParameterSource defaultModelSource( const QgsProcessingParameterDefinition *parameter ) const;
667
668};
669
683{
684 Q_OBJECT
685 public:
686
693 QObject *parent SIP_TRANSFERTHIS = nullptr );
694
695 void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
696 QVariant widgetValue() const override;
697
698 const QgsVectorLayer *linkedVectorLayer() const override;
699
703 void setLinkedVectorLayer( const QgsVectorLayer *layer );
704
705 protected:
706 QWidget *createWidget() override;
707 QLabel *createLabel() override;
708
709 private:
710
711 QVariant mValue;
712 QPointer < const QgsVectorLayer > mLayer;
713
714};
715
716#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)