[QGIS-Developer] QgsProcessingParameterMultipleLayers does not seem to use optional parameter

Jean-Charles Quillet jeancharles.quillet at gmail.com
Wed Mar 4 01:44:10 PST 2020


Le mer. 4 mars 2020 à 10:14, Håvard Tveite <havard.tveite at nmbu.no> a écrit :

> I guess that an empty list of layers is regarded as acceptable,
> as long as the parameter is present in the call.
> Perhaps you can use setMinimumNumberInputs to achieve what you
> want?
>
> Something like:
>
>            self.addParameter(
>                QgsProcessingParameterMultipleLayers(
>                    self.INPUT_LINES, self.tr <http://self.tr>("Lines"),
>                    QgsProcessing.TypeVectorLine,
>                    optional=False
>                ).setMinimumNumberInputs(1)
>            )
>
> Håvard
>

So I was missing something, thanks Håvard !

The working code is a bit different as setMinimumNumberInputs returns void.
I put it below if other people are running in the same issue:

        parameter = QgsProcessingParameterMultipleLayers(
                self.INPUT_LINES,
                self.tr("Lines"),
                QgsProcessing.TypeVectorLine,
                optional=False
            )
        parameter.setMinimumNumberInputs(1)
        self.addParameter(parameter)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200304/09c23497/attachment.html>


More information about the QGIS-Developer mailing list