QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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
6  email : [email protected]
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 
27 #include "qgis.h"
28 #include "qgslogger.h"
29 
31 {
32  addAlgorithmConfigurationWidgetFactory( new QgsFilterAlgorithmConfigurationWidgetFactory() );
33  addAlgorithmConfigurationWidgetFactory( new QgsConditionalBranchAlgorithmConfigurationWidgetFactory() );
34 
35  addParameterWidgetFactory( new QgsProcessingBooleanWidgetWrapper() );
36  addParameterWidgetFactory( new QgsProcessingCrsWidgetWrapper() );
37  addParameterWidgetFactory( new QgsProcessingStringWidgetWrapper() );
38  addParameterWidgetFactory( new QgsProcessingNumericWidgetWrapper() );
39  addParameterWidgetFactory( new QgsProcessingDistanceWidgetWrapper() );
40  addParameterWidgetFactory( new QgsProcessingScaleWidgetWrapper() );
41  addParameterWidgetFactory( new QgsProcessingRangeWidgetWrapper() );
42  addParameterWidgetFactory( new QgsProcessingAuthConfigWidgetWrapper() );
43  addParameterWidgetFactory( new QgsProcessingMatrixWidgetWrapper() );
44  addParameterWidgetFactory( new QgsProcessingFileWidgetWrapper() );
45  addParameterWidgetFactory( new QgsProcessingExpressionWidgetWrapper() );
46  addParameterWidgetFactory( new QgsProcessingEnumWidgetWrapper() );
47  addParameterWidgetFactory( new QgsProcessingLayoutWidgetWrapper() );
48  addParameterWidgetFactory( new QgsProcessingLayoutItemWidgetWrapper() );
49  addParameterWidgetFactory( new QgsProcessingPointWidgetWrapper() );
50  addParameterWidgetFactory( new QgsProcessingGeometryWidgetWrapper() );
51  addParameterWidgetFactory( new QgsProcessingColorWidgetWrapper() );
52  addParameterWidgetFactory( new QgsProcessingCoordinateOperationWidgetWrapper() );
53  addParameterWidgetFactory( new QgsProcessingFieldWidgetWrapper() );
54  addParameterWidgetFactory( new QgsProcessingMapThemeWidgetWrapper() );
55  addParameterWidgetFactory( new QgsProcessingDateTimeWidgetWrapper() );
56  addParameterWidgetFactory( new QgsProcessingProviderConnectionWidgetWrapper() );
57  addParameterWidgetFactory( new QgsProcessingDatabaseSchemaWidgetWrapper() );
58  addParameterWidgetFactory( new QgsProcessingDatabaseTableWidgetWrapper() );
59  addParameterWidgetFactory( new QgsProcessingExtentWidgetWrapper() );
60  addParameterWidgetFactory( new QgsProcessingMapLayerWidgetWrapper() );
61  addParameterWidgetFactory( new QgsProcessingVectorLayerWidgetWrapper() );
62  addParameterWidgetFactory( new QgsProcessingFeatureSourceWidgetWrapper() );
63  addParameterWidgetFactory( new QgsProcessingRasterLayerWidgetWrapper() );
64  addParameterWidgetFactory( new QgsProcessingMeshLayerWidgetWrapper() );
65  addParameterWidgetFactory( new QgsProcessingBandWidgetWrapper() );
66  addParameterWidgetFactory( new QgsProcessingMultipleLayerWidgetWrapper() );
67  addParameterWidgetFactory( new QgsProcessingVectorTileWriterLayersWidgetWrapper() );
68  addParameterWidgetFactory( new QgsProcessingFeatureSinkWidgetWrapper() );
69  addParameterWidgetFactory( new QgsProcessingVectorDestinationWidgetWrapper() );
70  addParameterWidgetFactory( new QgsProcessingRasterDestinationWidgetWrapper() );
71  addParameterWidgetFactory( new QgsProcessingFileDestinationWidgetWrapper() );
72  addParameterWidgetFactory( new QgsProcessingFolderDestinationWidgetWrapper() );
73  addParameterWidgetFactory( new QgsProcessingFieldMapWidgetWrapper() );
74  addParameterWidgetFactory( new QgsProcessingAggregateWidgetWrapper() );
75  addParameterWidgetFactory( new QgsProcessingTinInputLayersWidgetWrapper() );
76 }
77 
79 {
80  const QList< QgsProcessingAlgorithmConfigurationWidgetFactory * > factories = mAlgorithmConfigurationWidgetFactories;
81  for ( QgsProcessingAlgorithmConfigurationWidgetFactory *factory : factories )
83  const QMap< QString, QgsProcessingParameterWidgetFactoryInterface * > paramFactories = mParameterWidgetFactories;
84  for ( auto it = paramFactories.constBegin(); it != paramFactories.constEnd(); ++it )
85  removeParameterWidgetFactory( it.value() );
86 }
87 
89 {
90  mAlgorithmConfigurationWidgetFactories.append( factory );
91 }
92 
94 {
95  mAlgorithmConfigurationWidgetFactories.removeAll( factory );
96  delete factory;
97 }
98 
100 {
101  for ( const auto *factory : mAlgorithmConfigurationWidgetFactories )
102  {
103  if ( factory->canCreateFor( algorithm ) )
104  {
105  std::unique_ptr< QgsProcessingAlgorithmConfigurationWidget > widget( factory->create( algorithm ) );
106  if ( widget )
107  widget->setAlgorithm( algorithm );
108  return widget.release();
109  }
110  }
111 
112  return nullptr;
113 }
114 
116 {
117  if ( !factory )
118  return false;
119 
120  if ( mParameterWidgetFactories.contains( factory->parameterType() ) )
121  {
122  QgsLogger::warning( QStringLiteral( "Duplicate parameter factory for %1 registered" ).arg( factory->parameterType() ) );
123  return false;
124  }
125 
126  mParameterWidgetFactories.insert( factory->parameterType(), factory );
127  return true;
128 }
129 
131 {
132  if ( !factory )
133  return;
134 
135  mParameterWidgetFactories.remove( factory->parameterType() );
136  delete factory;
137 }
138 
140 {
141  if ( !parameter )
142  return nullptr;
143 
144  const QString parameterType = parameter->type();
145  if ( !mParameterWidgetFactories.contains( parameterType ) )
146  return nullptr;
147 
148  return mParameterWidgetFactories.value( parameterType )->createWidgetWrapper( parameter, type );
149 }
150 
152 {
153  if ( !parameter )
154  return nullptr;
155 
156  const QString parameterType = parameter->type();
157  if ( !mParameterWidgetFactories.contains( parameterType ) )
158  return nullptr;
159 
160  return mParameterWidgetFactories.value( parameterType )->createModelerWidgetWrapper( model, childId, parameter, context );
161 }
162 
164  QgsProcessingContext &context,
165  const QgsProcessingParameterWidgetContext &widgetContext,
166  const QgsProcessingParameterDefinition *definition,
168 {
169  if ( !mParameterWidgetFactories.contains( type ) )
170  return nullptr;
171 
172  return mParameterWidgetFactories.value( type )->createParameterDefinitionWidget( context, widgetContext, definition, algorithm );
173 }
174 
QgsProcessingParameterWidgetContext
Contains settings which reflect the context in which a Processing parameter widget is shown,...
Definition: qgsprocessingwidgetwrapper.h:100
qgsprocessingtininputlayerswidget.h
algorithm
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
QgsProcessingGuiRegistry::createParameterWidgetWrapper
QgsAbstractProcessingParameterWidgetWrapper * createParameterWidgetWrapper(const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type)
Creates a new parameter widget wrapper for the given parameter.
Definition: qgsprocessingguiregistry.cpp:139
QgsProcessingGuiRegistry::algorithmConfigurationWidget
QgsProcessingAlgorithmConfigurationWidget * algorithmConfigurationWidget(const QgsProcessingAlgorithm *algorithm) const
Gets the configuration widget for an algorithm.
Definition: qgsprocessingguiregistry.cpp:99
qgis.h
QgsProcessingParameterDefinition
Base class for the definition of processing parameters.
Definition: qgsprocessingparameters.h:331
QgsProcessingGuiRegistry::addParameterWidgetFactory
bool addParameterWidgetFactory(QgsProcessingParameterWidgetFactoryInterface *factory)
Adds a parameter widget factory to the registry, allowing widget creation for parameters of the match...
Definition: qgsprocessingguiregistry.cpp:115
QgsAbstractProcessingParameterWidgetWrapper
A widget wrapper for Processing parameter value widgets.
Definition: qgsprocessingwidgetwrapper.h:267
QgsProcessingGuiRegistry::~QgsProcessingGuiRegistry
~QgsProcessingGuiRegistry()
Definition: qgsprocessingguiregistry.cpp:78
QgsProcessingAlgorithmConfigurationWidgetFactory
Interface base class for factories for algorithm configuration widgets.
Definition: qgsprocessingalgorithmconfigurationwidget.h:125
QgsProcessingGuiRegistry::removeParameterWidgetFactory
void removeParameterWidgetFactory(QgsProcessingParameterWidgetFactoryInterface *factory)
Removes a parameter widget factory from the registry.
Definition: qgsprocessingguiregistry.cpp:130
QgsProcessingParameterWidgetFactoryInterface::parameterType
virtual QString parameterType() const =0
Returns the type string for the parameter type the factory is associated with.
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition: qgsprocessingcontext.h:44
QgsProcessingGuiRegistry::createModelerParameterWidget
QgsProcessingModelerParameterWidget * createModelerParameterWidget(QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context)
Creates a new modeler parameter widget for the given parameter.
Definition: qgsprocessingguiregistry.cpp:151
QgsProcessingModelerParameterWidget
A widget for customising the value of Processing algorithm parameter inside a Processing model.
Definition: qgsprocessingmodelerparameterwidget.h:62
QgsLogger::warning
static void warning(const QString &msg)
Goes to qWarning.
Definition: qgslogger.cpp:122
qgsprocessingalgorithmconfigurationwidget.h
qgsprocessingwidgetwrapperimpl.h
QgsProcessingAbstractParameterDefinitionWidget
Abstract base class for widgets which allow users to specify the properties of a Processing parameter...
Definition: qgsprocessingparameterdefinitionwidget.h:44
qgsprocessingparameters.h
QgsProcessingGui::WidgetType
WidgetType
Types of dialogs which Processing widgets can be created for.
Definition: qgsprocessinggui.h:39
QgsProcessingParameterWidgetFactoryInterface
An interface for Processing widget wrapper factories.
Definition: qgsprocessingwidgetwrapper.h:515
QgsProcessingAlgorithm
Abstract base class for processing algorithms.
Definition: qgsprocessingalgorithm.h:52
QgsProcessingGuiRegistry::createParameterDefinitionWidget
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...
Definition: qgsprocessingguiregistry.cpp:163
qgsprocessingfieldmapwidgetwrapper.h
QgsProcessingParameterDefinition::type
virtual QString type() const =0
Unique parameter type name.
qgslogger.h
qgsprocessingguiregistry.h
qgsprocessingconfigurationwidgets.h
qgsprocessingaggregatewidgetwrapper.h
QgsProcessingAlgorithmConfigurationWidget
A configuration widget for processing algorithms allows providing additional configuration options di...
Definition: qgsprocessingalgorithmconfigurationwidget.h:41
QgsProcessingGuiRegistry::QgsProcessingGuiRegistry
QgsProcessingGuiRegistry()
Constructor.
Definition: qgsprocessingguiregistry.cpp:30
qgsprocessingvectortilewriterlayerswidgetwrapper.h
QgsProcessingGuiRegistry::addAlgorithmConfigurationWidgetFactory
void addAlgorithmConfigurationWidgetFactory(QgsProcessingAlgorithmConfigurationWidgetFactory *factory)
Add a new configuration widget factory for customized algorithm configuration widgets.
Definition: qgsprocessingguiregistry.cpp:88
QgsProcessingGuiRegistry::removeAlgorithmConfigurationWidgetFactory
void removeAlgorithmConfigurationWidgetFactory(QgsProcessingAlgorithmConfigurationWidgetFactory *factory)
Remove a configuration widget factory for customized algorithm configuration widgets.
Definition: qgsprocessingguiregistry.cpp:93