QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
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
122
128 void setMapCanvas( QgsMapCanvas *canvas );
129
134 QgsMapCanvas *mapCanvas() const;
135
142 void setMessageBar( QgsMessageBar *bar );
143
150 QgsMessageBar *messageBar() const;
151
157 void setBrowserModel( QgsBrowserGuiModel *model );
158
164 QgsBrowserGuiModel *browserModel() const;
165
172 void setProject( QgsProject *project );
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
228 private:
229
230 QgsProcessingModelAlgorithm *mModel = nullptr;
231
232 QString mModelChildAlgorithmId;
233
234 QgsMapCanvas *mMapCanvas = nullptr;
235
236 QgsMessageBar *mMessageBar = nullptr;
237
238 QgsProject *mProject = nullptr;
239
240 QgsBrowserGuiModel *mBrowserModel = nullptr;
241
242 QgsMapLayer *mActiveLayer = nullptr;
243
244};
245
246#ifndef SIP_RUN
248class GUI_EXPORT QgsProcessingGuiUtils
249{
250 public:
251
252 static QgsExpressionContext createExpressionContext( QgsProcessingContextGenerator *processingContextGenerator = nullptr,
254 const QgsProcessingAlgorithm *algorithm = nullptr,
255 const QgsVectorLayer *linkedLayer = nullptr );
256
257
258};
260#endif
261
282{
283 Q_OBJECT
284
285 public:
286
293
297 QgsProcessingGui::WidgetType type() const;
298
308 virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
309
317 const QgsProcessingParameterWidgetContext &widgetContext() const;
318
329 QWidget *createWrappedWidget( QgsProcessingContext &context ) SIP_FACTORY;
330
343 QLabel *createWrappedLabel() SIP_FACTORY;
344
349 QWidget *wrappedWidget();
350
355 QLabel *wrappedLabel();
356
360 const QgsProcessingParameterDefinition *parameterDefinition() const;
361
362 // TODO QGIS 4.0 -- remove
363#ifdef SIP_RUN
364 % Property( name = param, get = parameterDefinition )
365#endif
366
375 void setParameterValue( const QVariant &value, QgsProcessingContext &context );
376
382 QVariant parameterValue() const;
383
387 virtual QVariantMap customProperties() const;
388
395 virtual void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
396
404 void registerProcessingParametersGenerator( QgsProcessingParametersGenerator *generator );
405
410 virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
411
419 virtual int stretch() const;
420
421 QgsExpressionContext createExpressionContext() const override;
422
428 virtual void setDialog( QDialog *dialog );
429
430 signals:
431
432 // TODO QGIS 4.0 - remove wrapper parameter - this is kept for compatibility with 3.x API,
433 // yet can easily be retrieved by checking the sender()
434
439
440 protected:
441
449 virtual QWidget *createWidget() = 0 SIP_FACTORY;
450
461 virtual QLabel *createLabel() SIP_FACTORY;
462
471 virtual void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) = 0;
472
478 virtual QVariant widgetValue() const = 0;
479
489 virtual const QgsVectorLayer *linkedVectorLayer() const;
490
491 protected:
492
493 QgsProcessingContextGenerator *mProcessingContextGenerator = nullptr;
494 QgsProcessingParametersGenerator *mParametersGenerator = nullptr;
496
497 private slots:
498
499 void parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper );
500
501 private:
502
503 QgsProcessingGui::WidgetType mType = QgsProcessingGui::Standard;
504 const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
505
506 void setDynamicParentLayerParameter( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
507
508 QPointer< QWidget > mWidget;
509 QPointer< QgsPropertyOverrideButton > mPropertyButton;
510 QPointer< QLabel > mLabel;
511 std::unique_ptr< QgsVectorLayer > mDynamicLayer;
512
513 friend class TestProcessingGui;
514
515};
516
517
532{
533
534 public:
535
537
541 virtual QString parameterType() const = 0;
542
552
568 virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
569 const QString &childId,
570 const QgsProcessingParameterDefinition *parameter,
571 QgsProcessingContext &context );
572
597 virtual QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
598 QgsProcessingContext &context,
599 const QgsProcessingParameterWidgetContext &widgetContext,
600 const QgsProcessingParameterDefinition *definition = nullptr,
602
603 protected:
604
619 virtual QStringList compatibleParameterTypes() const = 0;
620
635 virtual QStringList compatibleOutputTypes() const = 0;
636
651 virtual QList< int > compatibleDataTypes( const QgsProcessingParameterDefinition *parameter ) const;
652
662 virtual QString modelerExpressionFormatString() const;
663
669 virtual Qgis::ProcessingModelChildParameterSource defaultModelSource( const QgsProcessingParameterDefinition *parameter ) const;
670
671};
672
686{
687 Q_OBJECT
688 public:
689
696 QObject *parent SIP_TRANSFERTHIS = nullptr );
697
698 void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
699 QVariant widgetValue() const override;
700
701 const QgsVectorLayer *linkedVectorLayer() const override;
702
706 void setLinkedVectorLayer( const QgsVectorLayer *layer );
707
708 protected:
709 QWidget *createWidget() override;
710 QLabel *createLabel() override;
711
712 private:
713
714 QVariant mValue;
715 QPointer < const QgsVectorLayer > mLayer;
716
717};
718
719#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:74
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,...
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: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_FACTORY
Definition qgis_sip.h:76
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)