Skip to content

Commit a717b85

Browse files
committedSep 4, 2018
[FEATURE][processing] New modeler parameter widget
A new widget which handles parameter values for child algorithms within a model. Instead of the previous approach of requiring individual widget wrappers to handle creation of a suitable model widget, we do all this automatically for them. This widget uses a stacked widget with a toolbutton to select the parameter's source, instead of the previous combo box approach (which didn't scale well for large models). I.e. users select first whether the value is taken from a static value, a model input, or an output from a different child algorithm. The widget then changes appearance and behavior based on this choice. Additionally, a new option is present for all parameters of using a "precalculated expression". This expression is evaluated once before the child algorithm is executed and used during the execution of that algorithm.
1 parent 644ef6a commit a717b85

21 files changed

+1157
-87
lines changed
 

‎python/core/auto_generated/processing/models/qgsprocessingmodelalgorithm.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ Attempts to convert the model to executable Python code.
355355
Returns a list of possible sources which can be used for the parameters for a child
356356
algorithm in the model. Returned sources are those which match either one of the
357357
specified ``parameterTypes`` (see QgsProcessingParameterDefinition.type() ) or
358-
on of the specified ``outputTypes`` (see QgsProcessingOutputDefinition.type() ).
358+
one of the specified ``outputTypes`` (see QgsProcessingOutputDefinition.type() ).
359359
If specified, an optional list of ``dataTypes`` can be used to filter the returned
360360
sources to those with compatible data types for the parameter/outputs.
361361
%End
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/processing/qgsprocessinggui.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
class QgsProcessingGui
14+
{
15+
%Docstring
16+
17+
Contains general functions and values related to Processing GUI components.
18+
19+
.. versionadded:: 3.4
20+
%End
21+
22+
%TypeHeaderCode
23+
#include "qgsprocessinggui.h"
24+
%End
25+
public:
26+
27+
enum WidgetType
28+
{
29+
Standard,
30+
Batch,
31+
Modeler,
32+
};
33+
34+
};
35+
36+
/************************************************************************
37+
* This file has been generated automatically from *
38+
* *
39+
* src/gui/processing/qgsprocessinggui.h *
40+
* *
41+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
42+
************************************************************************/

‎python/gui/auto_generated/processing/qgsprocessingguiregistry.sip.in

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ and in this case, None will be returned.
6161

6262
bool addParameterWidgetFactory( QgsProcessingParameterWidgetFactoryInterface *factory /Transfer/ );
6363
%Docstring
64-
Adds a parameter widget ``factory`` to the registry. Ownership of ``factory`` is transferred to the registry.
64+
Adds a parameter widget ``factory`` to the registry, allowing widget creation for parameters of the matching
65+
type via createParameterWidgetWrapper() and createModelerParameterWidget().
66+
67+
Ownership of ``factory`` is transferred to the registry.
6568

6669
Returns true if the factory was successfully added, or false if the factory could not be added. Each
6770
factory must return a unique value for QgsProcessingParameterWidgetFactoryInterface.parameterType(),
@@ -71,6 +74,8 @@ and attempting to add a new factory with a duplicate type will result in failure
7174

7275
.. seealso:: :py:func:`createParameterWidgetWrapper`
7376

77+
.. seealso:: :py:func:`createModelerParameterWidget`
78+
7479
.. versionadded:: 3.4
7580
%End
7681

@@ -83,15 +88,41 @@ Removes a parameter widget ``factory`` from the registry. The factory will be de
8388
.. versionadded:: 3.4
8489
%End
8590

86-
QgsAbstractProcessingParameterWidgetWrapper *createParameterWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsAbstractProcessingParameterWidgetWrapper::WidgetType type ) /Factory/;
91+
QgsAbstractProcessingParameterWidgetWrapper *createParameterWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type ) /Factory/;
8792
%Docstring
8893
Creates a new parameter widget wrapper for the given ``parameter``. The ``type`` argument
8994
dictates the type of dialog the wrapper should be created for. The caller takes ownership
9095
of the returned wrapper.
9196

9297
If no factory is registered which handles the given ``parameter``, a None will be returned.
9398

99+
.. seealso:: :py:func:`createModelerParameterWidget`
100+
101+
.. seealso:: :py:func:`addParameterWidgetFactory`
102+
103+
.. versionadded:: 3.4
104+
%End
105+
106+
QgsProcessingModelerParameterWidget *createModelerParameterWidget( QgsProcessingModelAlgorithm *model,
107+
const QString &childId,
108+
const QgsProcessingParameterDefinition *parameter, const QgsProcessingContext &context ) /Factory/;
109+
%Docstring
110+
Creates a new modeler parameter widget for the given ``parameter``. This widget allows
111+
configuration of the parameter's value when used inside a Processing ``model``.
112+
113+
The ID of the child algorithm within the model must be specified via the ``childId``
114+
argument. This value corresponds to the :py:func:`QgsProcessingModelChildAlgorithm.childId()`
115+
string, which uniquely identifies which child algorithm the parameter is associated
116+
with inside the given ``model``.
117+
118+
The caller takes ownership of the returned widget. If no factory is registered which
119+
handles the given ``parameter``, a None will be returned.
120+
121+
.. seealso:: :py:func:`createParameterWidgetWrapper`
122+
94123
.. seealso:: :py:func:`addParameterWidgetFactory`
124+
125+
.. versionadded:: 3.4
95126
%End
96127

97128
};
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/processing/qgsprocessingmodelerwidget.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
14+
15+
class QgsProcessingModelerParameterWidget : QWidget
16+
{
17+
%Docstring
18+
19+
A widget for customising the value of Processing algorithm parameter inside
20+
a Processing model.
21+
22+
The widget provides choice of the linked source for values for the parameter
23+
inside the model. E.g. parameters can be a static value, an evaluated
24+
expression results, the output from another child algorithm, or an input
25+
parameter for the model itself.
26+
27+
Individual modeler parameter widgets are not usually created directly, instead they are
28+
constructed through the central registry, via calls to
29+
QgsGui.processingGuiRegistry()->createModelerParameterWidget().
30+
31+
.. versionadded:: 3.4
32+
%End
33+
34+
%TypeHeaderCode
35+
#include "qgsprocessingmodelerwidget.h"
36+
%End
37+
public:
38+
39+
QgsProcessingModelerParameterWidget( QgsProcessingModelAlgorithm *model,
40+
const QString &childId,
41+
const QgsProcessingParameterDefinition *parameter,
42+
const QgsProcessingContext &context,
43+
QWidget *parent /TransferThis/ = 0 );
44+
%Docstring
45+
Constructor for QgsProcessingModelerParameterWidget, for the specified
46+
``parameter`` definition within the given ``model``.
47+
48+
The ID of the child algorithm within the model must be specified via the ``childId``
49+
argument. This value corresponds to the :py:func:`QgsProcessingModelChildAlgorithm.childId()`
50+
string, which uniquely identifies which child algorithm the parameter is associated
51+
with inside the given ``model``.
52+
53+
A Processing ``context`` must also be specified, which allows the widget
54+
to resolve parameter values which are context dependent. The context must
55+
last for the lifetime of the widget.
56+
%End
57+
58+
~QgsProcessingModelerParameterWidget();
59+
60+
void populateSources( const QStringList &compatibleParameterTypes,
61+
const QStringList &compatibleOutputTypes,
62+
const QList< int > &compatibleDataTypes );
63+
%Docstring
64+
Populates the widget with available sources for the parameter's value, e.g.
65+
adding the available child algorithm outputs and model input parameter
66+
choices.
67+
68+
In order to determine the available source, the ``compatibleParameterTypes``,
69+
``compatibleOutputTypes`` arguments are used. These lists correspond to the
70+
various available values for QgsProcessingParameterDefinition.type() (for
71+
``compatibleParameterTypes``) and the values for :py:func:`QgsProcessingOutputDefinition.type()`
72+
(for ``compatibleOutputTypes``).
73+
74+
The ``compatibleDataTypes`` list corresponds to the compatible data types
75+
from QgsProcessing.SourceType.
76+
%End
77+
78+
const QgsProcessingParameterDefinition *parameterDefinition() const;
79+
%Docstring
80+
Returns the parameter definition associated with this wrapper.
81+
%End
82+
83+
QLabel *createLabel() /Factory/;
84+
%Docstring
85+
Creates a label for use identifying the associated parameter.
86+
87+
The caller takes ownership of the returned value.
88+
%End
89+
90+
virtual void setWidgetValue( const QgsProcessingModelChildParameterSource &value );
91+
%Docstring
92+
Sets the current ``value`` for the parameter.
93+
94+
.. seealso:: :py:func:`value`
95+
%End
96+
97+
virtual QgsProcessingModelChildParameterSource value() const;
98+
%Docstring
99+
Returns the current value of the parameter.
100+
101+
.. seealso:: :py:func:`setWidgetValue`
102+
%End
103+
104+
};
105+
106+
107+
/************************************************************************
108+
* This file has been generated automatically from *
109+
* *
110+
* src/gui/processing/qgsprocessingmodelerwidget.h *
111+
* *
112+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
113+
************************************************************************/

‎python/gui/auto_generated/processing/qgsprocessingwidgetwrapper.sip.in

Lines changed: 80 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111

1212

13-
1413
class QgsAbstractProcessingParameterWidgetWrapper : QObject
1514
{
1615
%Docstring
@@ -36,21 +35,14 @@ QgsGui.processingGuiRegistry()->createParameterWidgetWrapper().
3635
%End
3736
public:
3837

39-
enum WidgetType
40-
{
41-
Standard,
42-
Batch,
43-
Modeler,
44-
};
45-
4638
QgsAbstractProcessingParameterWidgetWrapper( const QgsProcessingParameterDefinition *parameter = 0,
47-
WidgetType type = Standard, QObject *parent /TransferThis/ = 0 );
39+
QgsProcessingGui::WidgetType type = QgsProcessingGui::Standard, QObject *parent /TransferThis/ = 0 );
4840
%Docstring
4941
Constructor for QgsAbstractProcessingParameterWidgetWrapper, for the specified
5042
``parameter`` definition and dialog ``type``.
5143
%End
5244

53-
WidgetType type() const;
45+
QgsProcessingGui::WidgetType type() const;
5446
%Docstring
5547
Returns the dialog type for which widgets and labels will be created by this wrapper.
5648
%End
@@ -100,6 +92,7 @@ Returns the current wrapped label, if any.
10092
Returns the parameter definition associated with this wrapper.
10193
%End
10294

95+
10396
virtual void setWidgetValue( const QVariant &value, const QgsProcessingContext &context ) = 0;
10497
%Docstring
10598
Sets the current ``value`` for the parameter.
@@ -176,11 +169,87 @@ Returns the type string for the parameter type the factory is associated with.
176169
%End
177170

178171
virtual QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter,
179-
QgsAbstractProcessingParameterWidgetWrapper::WidgetType type ) = 0 /Factory/;
172+
QgsProcessingGui::WidgetType type ) = 0 /Factory/;
180173
%Docstring
181174
Creates a new widget wrapper for the specified ``parameter`` definition.
182175

183176
The ``type`` argument indicates the dialog type to create a wrapper for.
177+
178+
.. seealso:: :py:func:`createModelerWidgetWrapper`
179+
%End
180+
181+
182+
virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
183+
const QString &childId,
184+
const QgsProcessingParameterDefinition *parameter,
185+
const QgsProcessingContext &context );
186+
%Docstring
187+
Creates a new modeler parameter widget for the given ``parameter``. This widget allows
188+
configuration of the parameter's value when used inside a Processing ``model``.
189+
190+
The ID of the child algorithm within the model must be specified via the ``childId``
191+
argument. This value corresponds to the :py:func:`QgsProcessingModelChildAlgorithm.childId()`
192+
string, which uniquely identifies which child algorithm the parameter is associated
193+
with inside the given ``model``.
194+
195+
A Processing ``context`` must also be specified, which allows the widget
196+
to resolve parameter values which are context dependent. The context must
197+
last for the lifetime of the widget.
198+
199+
.. seealso:: :py:func:`createWidgetWrapper`
200+
%End
201+
202+
protected:
203+
204+
virtual QStringList compatibleParameterTypes() const = 0;
205+
%Docstring
206+
Returns a list of compatible Processing parameter types for inputs
207+
for this parameter.
208+
209+
In order to determine the available sources for the parameter in a model
210+
the types returned by this method are checked. The returned list corresponds to the
211+
various available values for :py:func:`QgsProcessingParameterDefinition.type()`
212+
213+
Subclasses should return a list of all :py:func:`QgsProcessingParameterDefinition.type()`
214+
values which can be used as input values for the parameter.
215+
216+
.. seealso:: :py:func:`compatibleOutputTypes`
217+
218+
.. seealso:: :py:func:`compatibleDataTypes`
219+
%End
220+
221+
virtual QStringList compatibleOutputTypes() const = 0;
222+
%Docstring
223+
Returns a list of compatible Processing output types for inputs
224+
for this parameter.
225+
226+
In order to determine the available sources for the parameter in a model
227+
the types returned by this method are checked. The returned list corresponds to the
228+
various available values for :py:func:`QgsProcessingOutputDefinition.type()`
229+
230+
Subclasses should return a list of all :py:func:`QgsProcessingOutputDefinition.type()`
231+
values which can be used as values for the parameter.
232+
233+
.. seealso:: :py:func:`compatibleParameterTypes`
234+
235+
.. seealso:: :py:func:`compatibleDataTypes`
236+
%End
237+
238+
virtual QList< int > compatibleDataTypes() const = 0;
239+
%Docstring
240+
Returns a list of compatible Processing data types for inputs
241+
for this parameter.
242+
243+
In order to determine the available sources for the parameter in a model
244+
the types returned by this method are checked. The returned list corresponds
245+
to the various available values from QgsProcessing.SourceType.
246+
247+
Subclasses should return a list of all QgsProcessing.SourceType
248+
values which can be used as values for the parameter.
249+
250+
.. seealso:: :py:func:`compatibleParameterTypes`
251+
252+
.. seealso:: :py:func:`compatibleOutputTypes`
184253
%End
185254

186255
};

‎python/gui/gui_auto.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
%Include auto_generated/layertree/qgslayertreeembeddedconfigwidget.sip
4646
%Include auto_generated/layertree/qgslayertreeembeddedwidgetregistry.sip
4747
%Include auto_generated/layout/qgslayoutviewmouseevent.sip
48+
%Include auto_generated/processing/qgsprocessinggui.sip
4849
%Include auto_generated/processing/qgsprocessingguiregistry.sip
4950
%Include auto_generated/raster/qgsrasterrendererwidget.sip
5051
%Include auto_generated/symbology/qgssymbolwidgetcontext.sip
@@ -316,6 +317,7 @@
316317
%Include auto_generated/locator/qgslocatorwidget.sip
317318
%Include auto_generated/processing/qgsprocessingalgorithmconfigurationwidget.sip
318319
%Include auto_generated/processing/qgsprocessingalgorithmdialogbase.sip
320+
%Include auto_generated/processing/qgsprocessingmodelerwidget.sip
319321
%Include auto_generated/processing/qgsprocessingrecentalgorithmlog.sip
320322
%Include auto_generated/processing/qgsprocessingtoolboxmodel.sip
321323
%Include auto_generated/processing/qgsprocessingtoolboxtreeview.sip

0 commit comments

Comments
 (0)
Please sign in to comment.