Skip to content

Commit e6ef763

Browse files
committedApr 9, 2018
[processing] Allow algorithms to provide additional configuration widgets
1 parent 9e8c995 commit e6ef763

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed
 

‎python/core/processing/qgsprocessingalgorithm.sip.in

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010

1111

1212

13-
1413
%ModuleHeaderCode
1514
#include <qgsprocessingmodelalgorithm.h>
1615
%End
1716

18-
1917
class QgsProcessingAlgorithm
2018
{
2119
%Docstring
@@ -351,6 +349,12 @@ If an algorithm subclass implements a custom parameters widget, a copy of this w
351349
should be constructed and returned by this method.
352350
The base class implementation returns None, which indicates that an autogenerated
353351
parameters widget should be used.
352+
%End
353+
354+
virtual QgsProcessingAlgorithmConfigurationWidget *createModelerWidget() const /Factory/;
355+
%Docstring
356+
If an algorithm subclass implements a configuration widget for the algorithm itself,
357+
a new instance of this widget should be returned by this method.
354358
%End
355359

356360
QgsExpressionContext createExpressionContext( const QVariantMap &parameters,

‎python/plugins/processing/modeler/ModelerGraphicItem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def editElement(self):
208208
self.scene.dialog.repaintModel()
209209
elif isinstance(self.element, QgsProcessingModelChildAlgorithm):
210210
elemAlg = self.element.algorithm()
211-
dlg = ModelerParametersDialog(elemAlg, self.model, self.element.childId())
211+
dlg = ModelerParametersDialog(elemAlg, self.model, self.element.childId(), self.element.configuration())
212212
if dlg.exec_():
213213
alg = dlg.createAlgorithm()
214214
alg.setChildId(self.element.childId())

‎python/plugins/processing/modeler/ModelerParametersDialog.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@
6363

6464

6565
class ModelerParametersDialog(QDialog):
66-
def __init__(self, alg, model, algName=None):
66+
67+
def __init__(self, alg, model, algName=None, configuration=None):
6768
QDialog.__init__(self)
6869
self.setModal(True)
6970

7071
self._alg = alg # The algorithm to define in this dialog. It is an instance of QgsProcessingAlgorithm
7172
self.model = model # The model this algorithm is going to be added to. It is an instance of QgsProcessingModelAlgorithm
7273
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
74+
self.configuration = configuration
7375

7476
self.setupUi()
7577
self.params = None
@@ -87,6 +89,8 @@ def setupUi(self):
8789
self.wrappers = {}
8890
self.valueItems = {}
8991
self.dependentItems = {}
92+
self.algorithmItem = None
93+
9094
self.resize(650, 450)
9195
self.buttonBox = QDialogButtonBox()
9296
self.buttonBox.setOrientation(Qt.Horizontal)
@@ -114,6 +118,10 @@ def setupUi(self):
114118
line.setFrameShape(QFrame.HLine)
115119
line.setFrameShadow(QFrame.Sunken)
116120
self.verticalLayout.addWidget(line)
121+
self.algorithmItem = self._alg.createModelerWidget()
122+
if self.configuration:
123+
self.algorithmItem.setConfiguration(self.configuration)
124+
self.verticalLayout.addWidget(self.algorithmItem)
117125

118126
for param in self._alg.parameterDefinitions():
119127
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
@@ -284,6 +292,8 @@ def createAlgorithm(self):
284292
else:
285293
alg.setChildId(self.childId)
286294
alg.setDescription(self.descriptionBox.text())
295+
if self.algorithmItem:
296+
alg.setConfiguration(self.algorithmItem.configuration())
287297
for param in self._alg.parameterDefinitions():
288298
if param.isDestination() or param.flags() & QgsProcessingParameterDefinition.FlagHidden:
289299
continue

‎src/core/processing/qgsprocessingalgorithm.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ QWidget *QgsProcessingAlgorithm::createCustomParametersWidget( QWidget * ) const
131131
return nullptr;
132132
}
133133

134+
QgsProcessingAlgorithmConfigurationWidget *QgsProcessingAlgorithm::createModelerWidget() const
135+
{
136+
return nullptr;
137+
}
138+
134139
QgsExpressionContext QgsProcessingAlgorithm::createExpressionContext( const QVariantMap &parameters,
135140
QgsProcessingContext &context, QgsProcessingFeatureSource *source ) const
136141
{

‎src/core/processing/qgsprocessingalgorithm.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ class QgsProcessingProvider;
3333
class QgsProcessingFeedback;
3434
class QgsFeatureSink;
3535
class QgsProcessingFeedback;
36-
36+
class QgsProcessingModelAlgorithm;
37+
class QgsProcessingAlgorithmConfigurationWidget;
3738

3839
#ifdef SIP_RUN
3940
% ModuleHeaderCode
4041
#include <qgsprocessingmodelalgorithm.h>
4142
% End
4243
#endif
4344

44-
4545
/**
4646
* \class QgsProcessingAlgorithm
4747
* \ingroup core
@@ -356,6 +356,12 @@ class CORE_EXPORT QgsProcessingAlgorithm
356356
*/
357357
virtual QWidget *createCustomParametersWidget( QWidget *parent = nullptr ) const SIP_FACTORY;
358358

359+
/**
360+
* If an algorithm subclass implements a configuration widget for the algorithm itself,
361+
* a new instance of this widget should be returned by this method.
362+
*/
363+
virtual QgsProcessingAlgorithmConfigurationWidget *createModelerWidget() const SIP_FACTORY;
364+
359365
/**
360366
* Creates an expression context relating to the algorithm. This can be called by algorithms
361367
* to create a new expression context ready for evaluating expressions within the algorithm.

0 commit comments

Comments
 (0)
Please sign in to comment.