Skip to content
Permalink
Browse files

[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.
  • Loading branch information
nyalldawson committed Sep 4, 2018
1 parent 644ef6a commit a717b85e2e8f7237d2aff2c96529a024118b9dcc
@@ -355,7 +355,7 @@ Attempts to convert the model to executable Python code.
Returns a list of possible sources which can be used for the parameters for a child
algorithm in the model. Returned sources are those which match either one of the
specified ``parameterTypes`` (see QgsProcessingParameterDefinition.type() ) or
on of the specified ``outputTypes`` (see QgsProcessingOutputDefinition.type() ).
one of the specified ``outputTypes`` (see QgsProcessingOutputDefinition.type() ).
If specified, an optional list of ``dataTypes`` can be used to filter the returned
sources to those with compatible data types for the parameter/outputs.
%End
@@ -0,0 +1,42 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/processing/qgsprocessinggui.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsProcessingGui
{
%Docstring

Contains general functions and values related to Processing GUI components.

.. versionadded:: 3.4
%End

%TypeHeaderCode
#include "qgsprocessinggui.h"
%End
public:

enum WidgetType
{
Standard,
Batch,
Modeler,
};

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/processing/qgsprocessinggui.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -61,7 +61,10 @@ and in this case, None will be returned.

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

Ownership of ``factory`` is transferred to the registry.

Returns true if the factory was successfully added, or false if the factory could not be added. Each
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

.. seealso:: :py:func:`createParameterWidgetWrapper`

.. seealso:: :py:func:`createModelerParameterWidget`

.. versionadded:: 3.4
%End

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

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

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

.. seealso:: :py:func:`createModelerParameterWidget`

.. seealso:: :py:func:`addParameterWidgetFactory`

.. versionadded:: 3.4
%End

QgsProcessingModelerParameterWidget *createModelerParameterWidget( QgsProcessingModelAlgorithm *model,
const QString &childId,
const QgsProcessingParameterDefinition *parameter, const QgsProcessingContext &context ) /Factory/;
%Docstring
Creates a new modeler parameter widget for the given ``parameter``. This widget allows
configuration of the parameter's value when used inside a Processing ``model``.

The ID of the child algorithm within the model must be specified via the ``childId``
argument. This value corresponds to the :py:func:`QgsProcessingModelChildAlgorithm.childId()`
string, which uniquely identifies which child algorithm the parameter is associated
with inside the given ``model``.

The caller takes ownership of the returned widget. If no factory is registered which
handles the given ``parameter``, a None will be returned.

.. seealso:: :py:func:`createParameterWidgetWrapper`

.. seealso:: :py:func:`addParameterWidgetFactory`

.. versionadded:: 3.4
%End

};
@@ -0,0 +1,113 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/processing/qgsprocessingmodelerwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/







class QgsProcessingModelerParameterWidget : QWidget
{
%Docstring

A widget for customising the value of Processing algorithm parameter inside
a Processing model.

The widget provides choice of the linked source for values for the parameter
inside the model. E.g. parameters can be a static value, an evaluated
expression results, the output from another child algorithm, or an input
parameter for the model itself.

Individual modeler parameter widgets are not usually created directly, instead they are
constructed through the central registry, via calls to
QgsGui.processingGuiRegistry()->createModelerParameterWidget().

.. versionadded:: 3.4
%End

%TypeHeaderCode
#include "qgsprocessingmodelerwidget.h"
%End
public:

QgsProcessingModelerParameterWidget( QgsProcessingModelAlgorithm *model,
const QString &childId,
const QgsProcessingParameterDefinition *parameter,
const QgsProcessingContext &context,
QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsProcessingModelerParameterWidget, for the specified
``parameter`` definition within the given ``model``.

The ID of the child algorithm within the model must be specified via the ``childId``
argument. This value corresponds to the :py:func:`QgsProcessingModelChildAlgorithm.childId()`
string, which uniquely identifies which child algorithm the parameter is associated
with inside the given ``model``.

A Processing ``context`` must also be specified, which allows the widget
to resolve parameter values which are context dependent. The context must
last for the lifetime of the widget.
%End

~QgsProcessingModelerParameterWidget();

void populateSources( const QStringList &compatibleParameterTypes,
const QStringList &compatibleOutputTypes,
const QList< int > &compatibleDataTypes );
%Docstring
Populates the widget with available sources for the parameter's value, e.g.
adding the available child algorithm outputs and model input parameter
choices.

In order to determine the available source, the ``compatibleParameterTypes``,
``compatibleOutputTypes`` arguments are used. These lists correspond to the
various available values for QgsProcessingParameterDefinition.type() (for
``compatibleParameterTypes``) and the values for :py:func:`QgsProcessingOutputDefinition.type()`
(for ``compatibleOutputTypes``).

The ``compatibleDataTypes`` list corresponds to the compatible data types
from QgsProcessing.SourceType.
%End

const QgsProcessingParameterDefinition *parameterDefinition() const;
%Docstring
Returns the parameter definition associated with this wrapper.
%End

QLabel *createLabel() /Factory/;
%Docstring
Creates a label for use identifying the associated parameter.

The caller takes ownership of the returned value.
%End

virtual void setWidgetValue( const QgsProcessingModelChildParameterSource &value );
%Docstring
Sets the current ``value`` for the parameter.

.. seealso:: :py:func:`value`
%End

virtual QgsProcessingModelChildParameterSource value() const;
%Docstring
Returns the current value of the parameter.

.. seealso:: :py:func:`setWidgetValue`
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/processing/qgsprocessingmodelerwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -10,7 +10,6 @@




class QgsAbstractProcessingParameterWidgetWrapper : QObject
{
%Docstring
@@ -36,21 +35,14 @@ QgsGui.processingGuiRegistry()->createParameterWidgetWrapper().
%End
public:

enum WidgetType
{
Standard,
Batch,
Modeler,
};

QgsAbstractProcessingParameterWidgetWrapper( const QgsProcessingParameterDefinition *parameter = 0,
WidgetType type = Standard, QObject *parent /TransferThis/ = 0 );
QgsProcessingGui::WidgetType type = QgsProcessingGui::Standard, QObject *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsAbstractProcessingParameterWidgetWrapper, for the specified
``parameter`` definition and dialog ``type``.
%End

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


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

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

The ``type`` argument indicates the dialog type to create a wrapper for.

.. seealso:: :py:func:`createModelerWidgetWrapper`
%End


virtual QgsProcessingModelerParameterWidget *createModelerWidgetWrapper( QgsProcessingModelAlgorithm *model,
const QString &childId,
const QgsProcessingParameterDefinition *parameter,
const QgsProcessingContext &context );
%Docstring
Creates a new modeler parameter widget for the given ``parameter``. This widget allows
configuration of the parameter's value when used inside a Processing ``model``.

The ID of the child algorithm within the model must be specified via the ``childId``
argument. This value corresponds to the :py:func:`QgsProcessingModelChildAlgorithm.childId()`
string, which uniquely identifies which child algorithm the parameter is associated
with inside the given ``model``.

A Processing ``context`` must also be specified, which allows the widget
to resolve parameter values which are context dependent. The context must
last for the lifetime of the widget.

.. seealso:: :py:func:`createWidgetWrapper`
%End

protected:

virtual QStringList compatibleParameterTypes() const = 0;
%Docstring
Returns a list of compatible Processing parameter types for inputs
for this parameter.

In order to determine the available sources for the parameter in a model
the types returned by this method are checked. The returned list corresponds to the
various available values for :py:func:`QgsProcessingParameterDefinition.type()`

Subclasses should return a list of all :py:func:`QgsProcessingParameterDefinition.type()`
values which can be used as input values for the parameter.

.. seealso:: :py:func:`compatibleOutputTypes`

.. seealso:: :py:func:`compatibleDataTypes`
%End

virtual QStringList compatibleOutputTypes() const = 0;
%Docstring
Returns a list of compatible Processing output types for inputs
for this parameter.

In order to determine the available sources for the parameter in a model
the types returned by this method are checked. The returned list corresponds to the
various available values for :py:func:`QgsProcessingOutputDefinition.type()`

Subclasses should return a list of all :py:func:`QgsProcessingOutputDefinition.type()`
values which can be used as values for the parameter.

.. seealso:: :py:func:`compatibleParameterTypes`

.. seealso:: :py:func:`compatibleDataTypes`
%End

virtual QList< int > compatibleDataTypes() const = 0;
%Docstring
Returns a list of compatible Processing data types for inputs
for this parameter.

In order to determine the available sources for the parameter in a model
the types returned by this method are checked. The returned list corresponds
to the various available values from QgsProcessing.SourceType.

Subclasses should return a list of all QgsProcessing.SourceType
values which can be used as values for the parameter.

.. seealso:: :py:func:`compatibleParameterTypes`

.. seealso:: :py:func:`compatibleOutputTypes`
%End

};
@@ -45,6 +45,7 @@
%Include auto_generated/layertree/qgslayertreeembeddedconfigwidget.sip
%Include auto_generated/layertree/qgslayertreeembeddedwidgetregistry.sip
%Include auto_generated/layout/qgslayoutviewmouseevent.sip
%Include auto_generated/processing/qgsprocessinggui.sip
%Include auto_generated/processing/qgsprocessingguiregistry.sip
%Include auto_generated/raster/qgsrasterrendererwidget.sip
%Include auto_generated/symbology/qgssymbolwidgetcontext.sip
@@ -316,6 +317,7 @@
%Include auto_generated/locator/qgslocatorwidget.sip
%Include auto_generated/processing/qgsprocessingalgorithmconfigurationwidget.sip
%Include auto_generated/processing/qgsprocessingalgorithmdialogbase.sip
%Include auto_generated/processing/qgsprocessingmodelerwidget.sip
%Include auto_generated/processing/qgsprocessingrecentalgorithmlog.sip
%Include auto_generated/processing/qgsprocessingtoolboxmodel.sip
%Include auto_generated/processing/qgsprocessingtoolboxtreeview.sip

0 comments on commit a717b85

Please sign in to comment.
You can’t perform that action at this time.