New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Processing] Optional parameters for script and model #2396
[Processing] Optional parameters for script and model #2396
Conversation
The PR looks fine, it wont break anything and it will allow script to have optional layers. That is good. However, the rest of the changes are rather useless. With this change, you can define an optional parameter of type number or string (by makin param.optional = True)...but that will have no effect. The optional variable is only checked for layers, and Processing wont let you add that script in a model if there is not a value for that parameter, because it now ignores the optional property So, in shor, this loks good, but the core of Processing will require more changes to make this effective. I would suggest merging the changes for the scripts, but don't add the "required" combo box for models parameters until all those other changes have been implemented I will be happy to help on that if needed Let me know you opinion |
H @volaya, thanks for your review. I'd like to update the core of Processing to have optional in models. Which changes do you think I have to do ? I have noticed that if parameter value is set to None and the parameter is optional, the value will be:
I have time to make some changes, just let me know what I have to do. |
ACtually, I am seeing that most parameters have an optional parameter, so should be easy to do this Basically, you have to make sure that the setValue method of all parameters accepts a None value and does not complain in case they are optional (but returns False if the parameter is not optional) see for instance here https://github.com/qgis/QGIS/blob/master/python/plugins/processing/core/parameters.py#L203 Let me know if you have questions (here or by email) |
Hi @volaya, Do you think that the value for optional parameter has to be:
Thanks |
62895ed
to
8d7a672
Compare
Hi @volaya I updated the code to manage optional parameters. What do you think about it ? |
In processing core every parameters can be optional but in scripts there is no way to define a parameter as optional and in modeler only layers can be optional. For script, I propose a notation like output, if a parameter token starts with optional the parameter is optional. For model, I propose to add the required combobox to all parameters. This proposition does not change the value setter. This proposition can fix the issue http://hub.qgis.org/issues/5488.
Can't set parameters to null (None or '') if the parameter is not optional
8d7a672
to
2cc7949
Compare
I took your branch and added some changes. It is already in master. Could you check that it works fine and then close this PR? let me know if you have questions |
Thanks @volaya. I'll close this PR. |
In processing core every parameters can be optional but in scripts there is no way to define a parameter as optional and in modeler only layers can be optional.
For script, I propose a notation like output, if a parameter token starts with optional the parameter is optional.
For model, I propose to add the required combobox to all parameters.
This proposition does not change the value setter.
This proposition can fix the issue http://hub.qgis.org/issues/5488.