-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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] support show/hide parameters in providers #6272
Conversation
c075d6c
to
80d6434
Compare
|
@rkanavath How does this differ from the current QgsProcessingAlgorithm.FlagHidden flag, which also hides a parameter from the gui? |
|
@nyalldawson, FlagHidden is not adding a widget and its associate QLabel(if any). So I cannot add simply hide those parameter(s) later. FlagHidden == NotAdded. Please see my other post on qgis-developer list about group parameters in OTB. All widgets are created and whether to hide/show them is based on user input. so setting visibility with a flag is better than add and then remove each time user changes a particular combobox index. Hope its clear |
|
How this will work in case of modeler, batch, scripts? How not visible parameters should be handled in different cases (visible and no value, hidden and value etc)? IMHO we need a QEP first. |
|
@alexbruy, it is only used in otb and is default is set to true. does modeler and batch scripts using such a feature now. ? What is the issue exactly here can you explain? |
|
Modeler and batch modes applied to any algorithm, including OTB. How not visible parameters will work if I use OTB in batch mode? in models? in conjunction with another algorithms? |
|
if it asks for list of parameters then give them what is only visible. Does that work? |
|
@alexbruy, can you point the source where list of parameters from an algorithm is taken in those cases?. Is it parametersdefinitions( ) ? |
|
Could we have this added only for AlgorithmDialog and not BATCH dialog? |
|
Ok, so you're wanting the widgets created, but hidden at a later stage? When would they be hidden? Have you got a code example? |
|
not a code example, but i think this graphic helps, see the application doc: https://www.orfeo-toolbox.org/CookBook/Applications/app_Smoothing.html |
|
a sample descriptor best clean way is to have some sub-parameter relation defined in descriptor files.. |
|
Why not make separate tools for different smoothing algorithms? What is the reason to keep them in the single algorithm (except fact that this is how it is implemented in OTB) if anyway user will use only single method at once and all methods have different set of parameters? |
|
@alexbruy, not visible parameters are skipped in modeler. Can you check all commits? |
|
separate algo for each type of smoothing isn't going to happen. We had talked about this already. The entire issue of mess in maintaining is due this single point. OTB has to split applications for QGIS. What is going to real issue here other than in batch processing? Can you explain why this change would be harmful? |
This commits allows one to control visiblity of parameters in AlgorithmDialog UI. mVisible flag in QgsProcessingParameterDefinition defines wheather the parameter widget and its associate QLabel is visible in AlgorithmDialog. A processing provider such as OTB requires one such feature for smooth integration of its application through gui. Rules that decide if parmeter should be visible at any point is left out for proivders to handle. OTB has a fixed scheme for this behaviour and it is explained here. https://lists.osgeo.org/pipermail/qgis-developer/2018-February/051797.html This flag is true by default so that existing providers will not be affected.
a0f8dc4
to
6320dc3
Compare
|
Looks good to me. It's true that, if it make it unnecesary to split algs each time a new version is released, that is a good step ahead. |
|
Sorry - I'm feeling lost here. I still do not see how this differs from the existing flag which prevents creation of the widgets. I thought the intention here was to dynamically show or hide parameters based on other parameter values, isn't it? If so, how does this pr work? I can't see where you link the parameters to show or hide based on, where that logic is, and where the parameters are dynamically hidden after the dialog is created. |
|
If you look at sample descriptor in #6272 (comment) , Since this particular widget is not part of other widgets in processing, I had to do this way. But still i need to hide them at start. Because current index changed cannot be triggered automatically once entire widget ui is created. I guess that part is clear to you. I agree that it could be simplified if there is QgsOTBParameter added among others in python/processing/gui/. |
|
Do you have a link to the relevant code in your custom widget? |
|
Nothing published yet. I am still working on it and testing locally. Can you see if any existing providers in core is affected?. |
|
I can only put that code when plugin is ready to be published. And I can't resume work on it until this issue is solved. I am open for a different solution if you can propose something. But, if you want to see how it works in OTB. Please try this standalone linux installer. It's fairly easy to install. https://www.orfeo-toolbox.org//packages/OTB-6.4.0-Linux64.run There are much complex ones such as otbgui_TrainImagesClassifier It won't take much time to download and see the example working in action. I already posted screenshot of otbgui applications. |
I also want to see code or at least QEP explaining how this will work in models and batch mode. Right now I have an impression that using algorithms with such widgets in models will break them. |
|
Okay. it is awful to put a simple PR for small stuff. I cannot go ask sponsors to give more money just because of you can't understand this simple stuff. Let's close this PR and end this discussion. From QEP page it says, "Generally smaller features do not require a QEP unless they can have large knock on effect." seriously, I did say, it didn't break other algorithms because nobody is using this flag. |
|
Hi |
|
@savmickael I had tested this on my machine and grass, saga, gdal works well!. I also found that the code doesn't break modeler and scripts for all other algorithm providers. so the change is okay to be merged from my point of view. Didn't do any testing above that. |
|
@nyalldawson , @alexbruy ..And when reading descriptor file #6272 (comment) we use custom widget wrapper with a simple check I hope this can clear your confusion and things can be merged. |
|
Thanks for the fruitful discussion last night, and being flexible with defering the technical discussion here.
Why is this needed though? You've already hidden the widget via so setting the parameter definition itself as invisible doesn't seem to be used anywhere anyway. Also keep in mind that these parameter definitions belong to the algorithm instance - and a new instance of an algorithm is used when it's executed. I.e. instead of changing the parameter definition here, what you actually need to do is change its value, since only the parameter's value (not the definition!) is passed to the algorithm when it's executed. In other words, the whole value of the parameter must be encapsulated in a QVariant so it can be included in the parameters dictionary passed to the algorithm. Definitions are immutable outside of an algorithm's initAlgorithm method. |
|
Thanks for review and comments on code. I agree it is more easy for you if the entire code is attached. I looked at line in question and have some notes. Here is a screenshot of qgis' log messages panel. It seems same by removing line you mentioned.
It all looks good upto here and there is no need to update parameterdefinition at this point. Below is the output after removing line in question. I guess, the code here is handles which parameters are show in Processing windows's "Log" tab. After setting, Any thoughts? |
Yes - what you need to do here is ensure that your custom widget returns an NULL value for the parameter if the widget is hidden. Then the existing processing api will handle everything else for you! What I'm wondering is whether a "preprocessParameters" method in QgsProcessingAlgorithm would be useful to help here. This method could be overridden to automatically remove any parameter values which don't apply in certain circumstances. E.g. here you could have the preprocessor clear the interpolation parameters which don't apply for certain interpolation types. To me that's a more elegant solution to this use case. What do you think @alexbruy ? |
|
I tried to set value to None in indexChanged slot but isn't working as expected. |
I'd do this in the widget wrapper's |
|
@nyalldawson , does this evaluates to true always? |
|
I tried another way to skip them but didn't work. |
|
@nyalldawson , can you discuss more about "preprocessParameters"? I am interested to try this one. |
|
@nyalldawson, Hope it helps |
|
thanks @rkanavath -- it's certainly much easier when we can see the code :) Here's my suggestion: OTBAlgorithm.py
to this: Then preprocessParameters becomes: and at the start of processAlgorithm: Lastly, you'll need to update OTBChoiceWidgetWrapper:
That approach should work with no changes in core/processing - so will work fine in 3.0/3.2 and will be fully compatible with models. @alexbruy do you agree? |
|
thanks for review and also for fix!. it will hide parameters when i change choice and is working upto there. When gui is loaded the it shows all parameters because widgets are set visible in ParametersPanel.py. |
Ah - you should be able to handle that by implementing postInitialize in OTBChoiceWidgetWrapper, with similar logic: There's a lot of duplicate code here -- it's for demo purposes only and you can probably refactor a lot to clean this up. |
|
looking better now. widgets are well hidden at startup. but labels are still showing up :( it would be nice if wrapper has label, then it be accessible with it. |
|
Maybe check self.widget.parent().labels? (Or self.widget.parent().parent().labels) |
|
AttributeError: 'QWidget' object has no attribute 'labels' |
|
Ok, I think you're right - you'll need to add a label member to WidgetWrapper and set it in the panel construction. |
|
below diff works for me. There is also a |
|
I have another one for you. |
|
checkParameterValues is virtual - so you should overwrite that with your method in OTBAlgorithm re the label change - can you send that in as a separate PR? |
|
yes override i will update plugin code and new pr soon. But you can see how is looks here: QgsMessageLog windows "Processing" tab.
AlgorithmDialog's "Log" tab: As you can see actual algorithm execution and log message are inconsistent and hence create confusion or "not-a-bug" reports from users ;) Here is a diff from AlgoritmDialog.py (missing required parts in core). Any thoughts? |
|
here is new PR for wrapper label #6614 |
|
@nyalldawson , any feedback on preprocessParameters method? |
I just started to do this - but looking more into it it's not straightforward. The issue is in where we call this -- if it's called as part of an algorithm execution (e.g. inside processAlgorithm() ), or in code paths prior to executing an algorithm (e.g. inside AlgorithmDialog.getParameterValues ). If we call it from both locations then there's potentially an issue if an algorithms preprocessing involves altering values ... say.... some type of string escaping, because we'll be preprocessing the same set of parameters twice before executing the alg (once by the dialog, once by the algorithm itself). So I think we need to choose just one of these options. My vote would go to preprocessing outside of the algorithm execution only - so in AlgorithmDialog. Does this work for you? |
|
Yes. change in AlgorithmDialog works for me. with that, I don't need to do call preprocessParameters inside processAlgorithm(). you can go on with option you vote ;) |
|
@rkanavath ok, done in #6658 |
|
#6658 and #6614 + fixes from @nyalldawson on plugin code closes this PR. Thanks to all |

This commits allows one to control visiblity of parameters in
AlgorithmDialog UI. mVisible flag in QgsProcessingParameterDefinition
defines whether the parameter widget and its associate QLabel is
visible in AlgorithmDialog.
A processing provider such as OTB requires one such feature for smooth
integration of its application through gui. Rules that decide if
parameter should be visible at any point is left out for providers to
handle. OTB has a fixed scheme for this behavior and it is explained
here.
https://lists.osgeo.org/pipermail/qgis-developer/2018-February/051797.html
This flag is true by default so that existing providers will not be affected.
Description
Include a few sentences describing the overall goals for this PR (pull request). If applicable also add screenshots.
Checklist
fixes #11111in the commit message next to the description[FEATURE]in the commit message[needs-docs]in the commit message and contain sufficient information in the commit message to be documentedscripts/prepare-commit.shscript before each commit