QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsprocessingguiregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingguiregistry.cpp
3 ---------------------
4 begin : April 2018
5 copyright : (C) 2018 by Matthias Kuhn
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
30#include "qgis.h"
31#include "qgslogger.h"
32
34{
35 addAlgorithmConfigurationWidgetFactory( new QgsFilterAlgorithmConfigurationWidgetFactory() );
36 addAlgorithmConfigurationWidgetFactory( new QgsConditionalBranchAlgorithmConfigurationWidgetFactory() );
37
38 addParameterWidgetFactory( new QgsProcessingAlignRasterLayersWidgetWrapper() );
39 addParameterWidgetFactory( new QgsProcessingBooleanWidgetWrapper() );
40 addParameterWidgetFactory( new QgsProcessingCrsWidgetWrapper() );
41 addParameterWidgetFactory( new QgsProcessingStringWidgetWrapper() );
42 addParameterWidgetFactory( new QgsProcessingNumericWidgetWrapper() );
43 addParameterWidgetFactory( new QgsProcessingDistanceWidgetWrapper() );
44 addParameterWidgetFactory( new QgsProcessingDurationWidgetWrapper() );
45 addParameterWidgetFactory( new QgsProcessingScaleWidgetWrapper() );
46 addParameterWidgetFactory( new QgsProcessingRangeWidgetWrapper() );
47 addParameterWidgetFactory( new QgsProcessingAuthConfigWidgetWrapper() );
48 addParameterWidgetFactory( new QgsProcessingMatrixWidgetWrapper() );
49 addParameterWidgetFactory( new QgsProcessingFileWidgetWrapper() );
50 addParameterWidgetFactory( new QgsProcessingExpressionWidgetWrapper() );
51 addParameterWidgetFactory( new QgsProcessingEnumWidgetWrapper() );
52 addParameterWidgetFactory( new QgsProcessingLayoutWidgetWrapper() );
53 addParameterWidgetFactory( new QgsProcessingLayoutItemWidgetWrapper() );
54 addParameterWidgetFactory( new QgsProcessingPointWidgetWrapper() );
55 addParameterWidgetFactory( new QgsProcessingGeometryWidgetWrapper() );
56 addParameterWidgetFactory( new QgsProcessingColorWidgetWrapper() );
57 addParameterWidgetFactory( new QgsProcessingCoordinateOperationWidgetWrapper() );
58 addParameterWidgetFactory( new QgsProcessingFieldWidgetWrapper() );
59 addParameterWidgetFactory( new QgsProcessingMapThemeWidgetWrapper() );
60 addParameterWidgetFactory( new QgsProcessingDateTimeWidgetWrapper() );
61 addParameterWidgetFactory( new QgsProcessingProviderConnectionWidgetWrapper() );
62 addParameterWidgetFactory( new QgsProcessingDatabaseSchemaWidgetWrapper() );
63 addParameterWidgetFactory( new QgsProcessingDatabaseTableWidgetWrapper() );
64 addParameterWidgetFactory( new QgsProcessingExtentWidgetWrapper() );
65 addParameterWidgetFactory( new QgsProcessingMapLayerWidgetWrapper() );
66 addParameterWidgetFactory( new QgsProcessingVectorLayerWidgetWrapper() );
67 addParameterWidgetFactory( new QgsProcessingFeatureSourceWidgetWrapper() );
68 addParameterWidgetFactory( new QgsProcessingRasterLayerWidgetWrapper() );
69 addParameterWidgetFactory( new QgsProcessingMeshLayerWidgetWrapper() );
70 addParameterWidgetFactory( new QgsProcessingBandWidgetWrapper() );
71 addParameterWidgetFactory( new QgsProcessingMultipleLayerWidgetWrapper() );
72 addParameterWidgetFactory( new QgsProcessingVectorTileWriterLayersWidgetWrapper() );
73 addParameterWidgetFactory( new QgsProcessingFeatureSinkWidgetWrapper() );
74 addParameterWidgetFactory( new QgsProcessingVectorDestinationWidgetWrapper() );
75 addParameterWidgetFactory( new QgsProcessingRasterDestinationWidgetWrapper() );
76 addParameterWidgetFactory( new QgsProcessingFileDestinationWidgetWrapper() );
77 addParameterWidgetFactory( new QgsProcessingFolderDestinationWidgetWrapper() );
78 addParameterWidgetFactory( new QgsProcessingFieldMapWidgetWrapper() );
79 addParameterWidgetFactory( new QgsProcessingAggregateWidgetWrapper() );
80 addParameterWidgetFactory( new QgsProcessingTinInputLayersWidgetWrapper() );
81 addParameterWidgetFactory( new QgsProcessingDxfLayersWidgetWrapper() );
82 addParameterWidgetFactory( new QgsProcessingMeshDatasetGroupsWidgetWrapper() );
83 addParameterWidgetFactory( new QgsProcessingMeshDatasetTimeWidgetWrapper() );
84 addParameterWidgetFactory( new QgsProcessingPointCloudLayerWidgetWrapper() );
85 addParameterWidgetFactory( new QgsProcessingAnnotationLayerWidgetWrapper() );
86 addParameterWidgetFactory( new QgsProcessingPointCloudDestinationWidgetWrapper() );
87 addParameterWidgetFactory( new QgsProcessingPointCloudAttributeWidgetWrapper() );
88 addParameterWidgetFactory( new QgsProcessingVectorTileDestinationWidgetWrapper() );
89}
90
92{
93 const QList< QgsProcessingAlgorithmConfigurationWidgetFactory * > factories = mAlgorithmConfigurationWidgetFactories;
94 for ( QgsProcessingAlgorithmConfigurationWidgetFactory *factory : factories )
96 const QMap< QString, QgsProcessingParameterWidgetFactoryInterface * > paramFactories = mParameterWidgetFactories;
97 for ( auto it = paramFactories.constBegin(); it != paramFactories.constEnd(); ++it )
98 removeParameterWidgetFactory( it.value() );
99}
100
102{
103 mAlgorithmConfigurationWidgetFactories.append( factory );
104}
105
107{
108 mAlgorithmConfigurationWidgetFactories.removeAll( factory );
109 delete factory;
110}
111
113{
114 for ( const auto *factory : mAlgorithmConfigurationWidgetFactories )
115 {
116 if ( factory->canCreateFor( algorithm ) )
117 {
118 std::unique_ptr< QgsProcessingAlgorithmConfigurationWidget > widget( factory->create( algorithm ) );
119 if ( widget )
120 widget->setAlgorithm( algorithm );
121 return widget.release();
122 }
123 }
124
125 return nullptr;
126}
127
129{
130 if ( !factory )
131 return false;
132
133 if ( mParameterWidgetFactories.contains( factory->parameterType() ) )
134 {
135 QgsLogger::warning( QStringLiteral( "Duplicate parameter factory for %1 registered" ).arg( factory->parameterType() ) );
136 return false;
137 }
138
139 mParameterWidgetFactories.insert( factory->parameterType(), factory );
140 return true;
141}
142
144{
145 if ( !factory )
146 return;
147
148 mParameterWidgetFactories.remove( factory->parameterType() );
149 delete factory;
150}
151
153{
154 if ( !parameter )
155 return nullptr;
156
157 const QString parameterType = parameter->type();
158 if ( !mParameterWidgetFactories.contains( parameterType ) )
159 return nullptr;
160
161 return mParameterWidgetFactories.value( parameterType )->createWidgetWrapper( parameter, type );
162}
163
165{
166 if ( !parameter )
167 return nullptr;
168
169 const QString parameterType = parameter->type();
170 if ( !mParameterWidgetFactories.contains( parameterType ) )
171 return nullptr;
172
173 return mParameterWidgetFactories.value( parameterType )->createModelerWidgetWrapper( model, childId, parameter, context );
174}
175
177 QgsProcessingContext &context,
178 const QgsProcessingParameterWidgetContext &widgetContext,
179 const QgsProcessingParameterDefinition *definition,
181{
182 if ( !mParameterWidgetFactories.contains( type ) )
183 return nullptr;
184
185 return mParameterWidgetFactories.value( type )->createParameterDefinitionWidget( context, widgetContext, definition, algorithm );
186}
187
A widget wrapper for Processing parameter value widgets.
static void warning(const QString &msg)
Goes to qWarning.
Abstract base class for widgets which allow users to specify the properties of a Processing parameter...
Interface base class for factories for algorithm configuration widgets.
A configuration widget for processing algorithms allows providing additional configuration options di...
Abstract base class for processing algorithms.
Contains information about the context in which a processing algorithm is executed.
void addAlgorithmConfigurationWidgetFactory(QgsProcessingAlgorithmConfigurationWidgetFactory *factory)
Add a new configuration widget factory for customized algorithm configuration widgets.
QgsAbstractProcessingParameterWidgetWrapper * createParameterWidgetWrapper(const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type)
Creates a new parameter widget wrapper for the given parameter.
bool addParameterWidgetFactory(QgsProcessingParameterWidgetFactoryInterface *factory)
Adds a parameter widget factory to the registry, allowing widget creation for parameters of the match...
void removeAlgorithmConfigurationWidgetFactory(QgsProcessingAlgorithmConfigurationWidgetFactory *factory)
Remove a configuration widget factory for customized algorithm configuration widgets.
QgsProcessingAlgorithmConfigurationWidget * algorithmConfigurationWidget(const QgsProcessingAlgorithm *algorithm) const
Gets the configuration widget for an algorithm.
QgsProcessingAbstractParameterDefinitionWidget * createParameterDefinitionWidget(const QString &type, 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 a specific par...
QgsProcessingModelerParameterWidget * createModelerParameterWidget(QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context)
Creates a new modeler parameter widget for the given parameter.
void removeParameterWidgetFactory(QgsProcessingParameterWidgetFactoryInterface *factory)
Removes a parameter widget factory from the registry.
WidgetType
Types of dialogs which Processing widgets can be created for.
A widget for customising the value of Processing algorithm parameter inside a Processing model.
Base class for the definition of processing parameters.
virtual QString type() const =0
Unique parameter type name.
Contains settings which reflect the context in which a Processing parameter widget is shown,...
An interface for Processing widget wrapper factories.
virtual QString parameterType() const =0
Returns the type string for the parameter type the factory is associated with.
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