[QGIS-Developer] Processing alg - best solution for a "value relation" form input ?

kimaidou kimaidou at gmail.com
Thu Jun 27 05:24:00 PDT 2019


Hi,

I would like to propose a QgsProcessingParameterEnum automatically filled
with data from a layer, exactly in the same way QGIS does with the form
value relation widget.
Basically, the alg author would choose the layer, the key field, the value
field, to order or not by value, and an optionnal filter.

I would like to know if someone had already done it, and if so, I there is
some example code online.

If not, I think I would do this:

* create a new QgsProcessingParameterValueRelationEnum inherited from
QgsProcessingParameterEnum
* use the input metadata to gather the parameters of the datasource. For
example for PostgreSQL, I would add the connection parameters (service) and
the schema and table name. An filter option would be great too.
* add methods (or override existing one ?) to gather the data and then use
the setConditions methods to fill in the combobox.
* I should also add a new method parameterAsValueRelationEnum to get the
code based on the selected item

I could also just call the setOptions method inside the alg, but it would
be harder to maintain accross algs, and it does not seem to be the right
"processing" way of doing it.

Or I could also use the setMetadata method with a widget_wrapper, such as
done for the ConnectionWidgetWrapper ?
        db_param.setMetadata({
            'widget_wrapper': {
                'class':
'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
            }
        })
and then do the magic inside a dedicated class ? How ?

Any help appreciated.

Regards,
Michaƫl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190627/900502f6/attachment.html>


More information about the QGIS-Developer mailing list