QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
23 #include "qgis.h"
24 #include "qgslogger.h"
25 
27 {
28  addAlgorithmConfigurationWidgetFactory( new QgsFilterAlgorithmConfigurationWidgetFactory() );
29 
30  addParameterWidgetFactory( new QgsProcessingBooleanWidgetWrapper() );
31  addParameterWidgetFactory( new QgsProcessingCrsWidgetWrapper() );
32  addParameterWidgetFactory( new QgsProcessingStringWidgetWrapper() );
33  addParameterWidgetFactory( new QgsProcessingNumericWidgetWrapper() );
34  addParameterWidgetFactory( new QgsProcessingDistanceWidgetWrapper() );
35  addParameterWidgetFactory( new QgsProcessingScaleWidgetWrapper() );
36  addParameterWidgetFactory( new QgsProcessingRangeWidgetWrapper() );
37  addParameterWidgetFactory( new QgsProcessingAuthConfigWidgetWrapper() );
38  addParameterWidgetFactory( new QgsProcessingMatrixWidgetWrapper() );
39  addParameterWidgetFactory( new QgsProcessingFileWidgetWrapper() );
40  addParameterWidgetFactory( new QgsProcessingExpressionWidgetWrapper() );
41  addParameterWidgetFactory( new QgsProcessingEnumWidgetWrapper() );
42  addParameterWidgetFactory( new QgsProcessingLayoutWidgetWrapper() );
43  addParameterWidgetFactory( new QgsProcessingLayoutItemWidgetWrapper() );
44  addParameterWidgetFactory( new QgsProcessingPointWidgetWrapper() );
45  addParameterWidgetFactory( new QgsProcessingColorWidgetWrapper() );
46 }
47 
49 {
50  const QList< QgsProcessingAlgorithmConfigurationWidgetFactory * > factories = mAlgorithmConfigurationWidgetFactories;
51  for ( QgsProcessingAlgorithmConfigurationWidgetFactory *factory : factories )
53  const QMap< QString, QgsProcessingParameterWidgetFactoryInterface * > paramFactories = mParameterWidgetFactories;
54  for ( auto it = paramFactories.constBegin(); it != paramFactories.constEnd(); ++it )
55  removeParameterWidgetFactory( it.value() );
56 }
57 
59 {
60  mAlgorithmConfigurationWidgetFactories.append( factory );
61 }
62 
64 {
65  mAlgorithmConfigurationWidgetFactories.removeAll( factory );
66  delete factory;
67 }
68 
70 {
71  for ( const auto *factory : mAlgorithmConfigurationWidgetFactories )
72  {
73  if ( factory->canCreateFor( algorithm ) )
74  {
75  std::unique_ptr< QgsProcessingAlgorithmConfigurationWidget > widget( factory->create( algorithm ) );
76  if ( widget )
77  widget->setAlgorithm( algorithm );
78  return widget.release();
79  }
80  }
81 
82  return nullptr;
83 }
84 
86 {
87  if ( !factory )
88  return false;
89 
90  if ( mParameterWidgetFactories.contains( factory->parameterType() ) )
91  {
92  QgsLogger::warning( QStringLiteral( "Duplicate parameter factory for %1 registered" ).arg( factory->parameterType() ) );
93  return false;
94  }
95 
96  mParameterWidgetFactories.insert( factory->parameterType(), factory );
97  return true;
98 }
99 
101 {
102  if ( !factory )
103  return;
104 
105  mParameterWidgetFactories.remove( factory->parameterType() );
106  delete factory;
107 }
108 
110 {
111  if ( !parameter )
112  return nullptr;
113 
114  const QString parameterType = parameter->type();
115  if ( !mParameterWidgetFactories.contains( parameterType ) )
116  return nullptr;
117 
118  return mParameterWidgetFactories.value( parameterType )->createWidgetWrapper( parameter, type );
119 }
120 
122 {
123  if ( !parameter )
124  return nullptr;
125 
126  const QString parameterType = parameter->type();
127  if ( !mParameterWidgetFactories.contains( parameterType ) )
128  return nullptr;
129 
130  return mParameterWidgetFactories.value( parameterType )->createModelerWidgetWrapper( model, childId, parameter, context );
131 }
132 
134  QgsProcessingContext &context,
135  const QgsProcessingParameterWidgetContext &widgetContext,
136  const QgsProcessingParameterDefinition *definition,
138 {
139  if ( !mParameterWidgetFactories.contains( type ) )
140  return nullptr;
141 
142  return mParameterWidgetFactories.value( type )->createParameterDefinitionWidget( context, widgetContext, definition, algorithm );
143 }
144 
A widget wrapper for Processing parameter value widgets.
Abstract base class for widgets which allow users to specify the properties of a Processing parameter...
WidgetType
Types of dialogs which Processing widgets can be created for.
static void warning(const QString &msg)
Goes to qWarning.
Definition: qgslogger.cpp:121
QgsProcessingModelerParameterWidget * createModelerParameterWidget(QgsProcessingModelAlgorithm *model, const QString &childId, const QgsProcessingParameterDefinition *parameter, QgsProcessingContext &context)
Creates a new modeler parameter widget for the given parameter.
An interface for Processing widget wrapper factories.
A widget for customising the value of Processing algorithm parameter inside a Processing model...
Abstract base class for processing algorithms.
virtual QString type() const =0
Unique parameter type name.
QgsAbstractProcessingParameterWidgetWrapper * createParameterWidgetWrapper(const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type)
Creates a new parameter widget wrapper for the given parameter.
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
QgsProcessingAlgorithmConfigurationWidget * algorithmConfigurationWidget(const QgsProcessingAlgorithm *algorithm) const
Gets the configuration widget for an algorithm.
void setAlgorithm(const QgsProcessingAlgorithm *algorithm)
Sets the algorithm instance associated with the widget.
void addAlgorithmConfigurationWidgetFactory(QgsProcessingAlgorithmConfigurationWidgetFactory *factory)
Add a new configuration widget factory for customized algorithm configuration widgets.
virtual QString parameterType() const =0
Returns the type string for the parameter type the factory is associated with.
Interface base class for factories for algorithm configuration widgets.
Contains settings which reflect the context in which a Processing parameter widget is shown...
A configuration widget for processing algorithms allows providing additional configuration options di...
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.
Base class for the definition of processing parameters.
void removeParameterWidgetFactory(QgsProcessingParameterWidgetFactoryInterface *factory)
Removes a parameter widget factory from the registry.
Contains information about the context in which a processing algorithm is executed.
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...