Skip to content
Browse files
[processing] Allow algorithms to provide additional configuration wid…
  • Loading branch information
m-kuhn committed Apr 9, 2018
1 parent 9e8c995 commit e6ef7639cb1b08b83a88e5b2a0de627e06ede8a9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
@@ -10,12 +10,10 @@

#include <qgsprocessingmodelalgorithm.h>

class QgsProcessingAlgorithm
@@ -351,6 +349,12 @@ If an algorithm subclass implements a custom parameters widget, a copy of this w
should be constructed and returned by this method.
The base class implementation returns None, which indicates that an autogenerated
parameters widget should be used.

virtual QgsProcessingAlgorithmConfigurationWidget *createModelerWidget() const /Factory/;
If an algorithm subclass implements a configuration widget for the algorithm itself,
a new instance of this widget should be returned by this method.

QgsExpressionContext createExpressionContext( const QVariantMap &parameters,
@@ -208,7 +208,7 @@ def editElement(self):
elif isinstance(self.element, QgsProcessingModelChildAlgorithm):
elemAlg = self.element.algorithm()
dlg = ModelerParametersDialog(elemAlg, self.model, self.element.childId())
dlg = ModelerParametersDialog(elemAlg, self.model, self.element.childId(), self.element.configuration())
if dlg.exec_():
alg = dlg.createAlgorithm()
@@ -63,13 +63,15 @@

class ModelerParametersDialog(QDialog):
def __init__(self, alg, model, algName=None):

def __init__(self, alg, model, algName=None, configuration=None):

self._alg = alg # The algorithm to define in this dialog. It is an instance of QgsProcessingAlgorithm
self.model = model # The model this algorithm is going to be added to. It is an instance of QgsProcessingModelAlgorithm
self.childId = algName # The name of the algorithm in the model, in case we are editing it and not defining it for the first time
self.configuration = configuration

self.params = None
@@ -87,6 +89,8 @@ def setupUi(self):
self.wrappers = {}
self.valueItems = {}
self.dependentItems = {}
self.algorithmItem = None

self.resize(650, 450)
self.buttonBox = QDialogButtonBox()
@@ -114,6 +118,10 @@ def setupUi(self):
self.algorithmItem = self._alg.createModelerWidget()
if self.configuration:

for param in self._alg.parameterDefinitions():
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
@@ -284,6 +292,8 @@ def createAlgorithm(self):
if self.algorithmItem:
for param in self._alg.parameterDefinitions():
if param.isDestination() or param.flags() & QgsProcessingParameterDefinition.FlagHidden:
@@ -131,6 +131,11 @@ QWidget *QgsProcessingAlgorithm::createCustomParametersWidget( QWidget * ) const
return nullptr;

QgsProcessingAlgorithmConfigurationWidget *QgsProcessingAlgorithm::createModelerWidget() const
return nullptr;

QgsExpressionContext QgsProcessingAlgorithm::createExpressionContext( const QVariantMap &parameters,
QgsProcessingContext &context, QgsProcessingFeatureSource *source ) const
@@ -33,15 +33,15 @@ class QgsProcessingProvider;
class QgsProcessingFeedback;
class QgsFeatureSink;
class QgsProcessingFeedback;

class QgsProcessingModelAlgorithm;
class QgsProcessingAlgorithmConfigurationWidget;

#ifdef SIP_RUN
% ModuleHeaderCode
#include <qgsprocessingmodelalgorithm.h>
% End

* \class QgsProcessingAlgorithm
* \ingroup core
@@ -356,6 +356,12 @@ class CORE_EXPORT QgsProcessingAlgorithm
virtual QWidget *createCustomParametersWidget( QWidget *parent = nullptr ) const SIP_FACTORY;

* If an algorithm subclass implements a configuration widget for the algorithm itself,
* a new instance of this widget should be returned by this method.
virtual QgsProcessingAlgorithmConfigurationWidget *createModelerWidget() const SIP_FACTORY;

* Creates an expression context relating to the algorithm. This can be called by algorithms
* to create a new expression context ready for evaluating expressions within the algorithm.

0 comments on commit e6ef763

Please sign in to comment.