QGIS API Documentation 3.39.0-Master (47f7b3a4989)
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
31#include "qgis.h"
32#include "qgslogger.h"
33
35{
36 addAlgorithmConfigurationWidgetFactory( new QgsFilterAlgorithmConfigurationWidgetFactory() );
37 addAlgorithmConfigurationWidgetFactory( new QgsConditionalBranchAlgorithmConfigurationWidgetFactory() );
38
39 addParameterWidgetFactory( new QgsProcessingAlignRasterLayersWidgetWrapper() );
40 addParameterWidgetFactory( new QgsProcessingBooleanWidgetWrapper() );
41 addParameterWidgetFactory( new QgsProcessingCrsWidgetWrapper() );
42 addParameterWidgetFactory( new QgsProcessingStringWidgetWrapper() );
43 addParameterWidgetFactory( new QgsProcessingNumericWidgetWrapper() );
44 addParameterWidgetFactory( new QgsProcessingDistanceWidgetWrapper() );
45 addParameterWidgetFactory( new QgsProcessingDurationWidgetWrapper() );
46 addParameterWidgetFactory( new QgsProcessingScaleWidgetWrapper() );
47 addParameterWidgetFactory( new QgsProcessingRangeWidgetWrapper() );
48 addParameterWidgetFactory( new QgsProcessingAuthConfigWidgetWrapper() );
49 addParameterWidgetFactory( new QgsProcessingMatrixWidgetWrapper() );
50 addParameterWidgetFactory( new QgsProcessingFileWidgetWrapper() );
51 addParameterWidgetFactory( new QgsProcessingExpressionWidgetWrapper() );
52 addParameterWidgetFactory( new QgsProcessingEnumWidgetWrapper() );
53 addParameterWidgetFactory( new QgsProcessingLayoutWidgetWrapper() );
54 addParameterWidgetFactory( new QgsProcessingLayoutItemWidgetWrapper() );
55 addParameterWidgetFactory( new QgsProcessingPointWidgetWrapper() );
56 addParameterWidgetFactory( new QgsProcessingGeometryWidgetWrapper() );
57 addParameterWidgetFactory( new QgsProcessingColorWidgetWrapper() );
58 addParameterWidgetFactory( new QgsProcessingCoordinateOperationWidgetWrapper() );
59 addParameterWidgetFactory( new QgsProcessingFieldWidgetWrapper() );
60 addParameterWidgetFactory( new QgsProcessingMapThemeWidgetWrapper() );
61 addParameterWidgetFactory( new QgsProcessingDateTimeWidgetWrapper() );
62 addParameterWidgetFactory( new QgsProcessingProviderConnectionWidgetWrapper() );
63 addParameterWidgetFactory( new QgsProcessingDatabaseSchemaWidgetWrapper() );
64 addParameterWidgetFactory( new QgsProcessingDatabaseTableWidgetWrapper() );
65 addParameterWidgetFactory( new QgsProcessingExtentWidgetWrapper() );
66 addParameterWidgetFactory( new QgsProcessingMapLayerWidgetWrapper() );
67 addParameterWidgetFactory( new QgsProcessingVectorLayerWidgetWrapper() );
68 addParameterWidgetFactory( new QgsProcessingFeatureSourceWidgetWrapper() );
69 addParameterWidgetFactory( new QgsProcessingRasterLayerWidgetWrapper() );
70 addParameterWidgetFactory( new QgsProcessingMeshLayerWidgetWrapper() );
71 addParameterWidgetFactory( new QgsProcessingBandWidgetWrapper() );
72 addParameterWidgetFactory( new QgsProcessingMultipleLayerWidgetWrapper() );
73 addParameterWidgetFactory( new QgsProcessingVectorTileWriterLayersWidgetWrapper() );
74 addParameterWidgetFactory( new QgsProcessingFeatureSinkWidgetWrapper() );
75 addParameterWidgetFactory( new QgsProcessingVectorDestinationWidgetWrapper() );
76 addParameterWidgetFactory( new QgsProcessingRasterDestinationWidgetWrapper() );
77 addParameterWidgetFactory( new QgsProcessingFileDestinationWidgetWrapper() );
78 addParameterWidgetFactory( new QgsProcessingFolderDestinationWidgetWrapper() );
79 addParameterWidgetFactory( new QgsProcessingFieldMapWidgetWrapper() );
80 addParameterWidgetFactory( new QgsProcessingAggregateWidgetWrapper() );
81 addParameterWidgetFactory( new QgsProcessingTinInputLayersWidgetWrapper() );
82 addParameterWidgetFactory( new QgsProcessingDxfLayersWidgetWrapper() );
83 addParameterWidgetFactory( new QgsProcessingMeshDatasetGroupsWidgetWrapper() );
84 addParameterWidgetFactory( new QgsProcessingMeshDatasetTimeWidgetWrapper() );
85 addParameterWidgetFactory( new QgsProcessingPointCloudLayerWidgetWrapper() );
86 addParameterWidgetFactory( new QgsProcessingAnnotationLayerWidgetWrapper() );
87 addParameterWidgetFactory( new QgsProcessingPointCloudDestinationWidgetWrapper() );
88 addParameterWidgetFactory( new QgsProcessingPointCloudAttributeWidgetWrapper() );
89 addParameterWidgetFactory( new QgsProcessingVectorTileDestinationWidgetWrapper() );
90 addParameterWidgetFactory( new QgsProcessingRasterOptionsWidgetWrapper() );
91}
92
94{
95 const QList< QgsProcessingAlgorithmConfigurationWidgetFactory * > factories = mAlgorithmConfigurationWidgetFactories;
96 for ( QgsProcessingAlgorithmConfigurationWidgetFactory *factory : factories )
98 const QMap< QString, QgsProcessingParameterWidgetFactoryInterface * > paramFactories = mParameterWidgetFactories;
99 for ( auto it = paramFactories.constBegin(); it != paramFactories.constEnd(); ++it )
100 removeParameterWidgetFactory( it.value() );
101}
102
104{
105 mAlgorithmConfigurationWidgetFactories.append( factory );
106}
107
109{
110 mAlgorithmConfigurationWidgetFactories.removeAll( factory );
111 delete factory;
112}
113
115{
116 for ( const auto *factory : mAlgorithmConfigurationWidgetFactories )
117 {
118 if ( factory->canCreateFor( algorithm ) )
119 {
120 std::unique_ptr< QgsProcessingAlgorithmConfigurationWidget > widget( factory->create( algorithm ) );
121 if ( widget )
122 widget->setAlgorithm( algorithm );
123 return widget.release();
124 }
125 }
126
127 return nullptr;
128}
129
131{
132 if ( !factory )
133 return false;
134
135 if ( mParameterWidgetFactories.contains( factory->parameterType() ) )
136 {
137 QgsLogger::warning( QStringLiteral( "Duplicate parameter factory for %1 registered" ).arg( factory->parameterType() ) );
138 return false;
139 }
140
141 mParameterWidgetFactories.insert( factory->parameterType(), factory );
142 return true;
143}
144
146{
147 if ( !factory )
148 return;
149
150 mParameterWidgetFactories.remove( factory->parameterType() );
151 delete factory;
152}
153
155{
156 if ( !parameter )
157 return nullptr;
158
159 const QVariantMap metadata = parameter->metadata();
160 const QString widgetType = metadata.value( QStringLiteral( "widget_wrapper" ) ).toMap().value( QStringLiteral( "widget_type" ) ).toString();
161 const QString parameterType = !widgetType.isEmpty() ? widgetType : parameter->type();
162 if ( !mParameterWidgetFactories.contains( parameterType ) )
163 return nullptr;
164
165 return mParameterWidgetFactories.value( parameterType )->createWidgetWrapper( parameter, type );
166}
167
169{
170 if ( !parameter )
171 return nullptr;
172
173 const QString parameterType = parameter->type();
174 if ( !mParameterWidgetFactories.contains( parameterType ) )
175 return nullptr;
176
177 return mParameterWidgetFactories.value( parameterType )->createModelerWidgetWrapper( model, childId, parameter, context );
178}
179
181 QgsProcessingContext &context,
182 const QgsProcessingParameterWidgetContext &widgetContext,
183 const QgsProcessingParameterDefinition *definition,
185{
186 if ( !mParameterWidgetFactories.contains( type ) )
187 return nullptr;
188
189 return mParameterWidgetFactories.value( type )->createParameterDefinitionWidget( context, widgetContext, definition, algorithm );
190}
191
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.
QVariantMap metadata() const
Returns the parameter's freeform metadata.
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