Bug report #19785

[processing] Scripts with QgsProcessingParameterRange can't be added to Model

Added by Luigi Pirelli almost 6 years ago. Updated almost 6 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Processing/Modeller
Affected QGIS version:3.3(master) Regression?:No
Operating System:Linux Easy fix?:No
Pull Request or Patch supplied:Yes Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:27610

Description

Any processing script having defined a QgsProcessingParameterRange,
rise exception adding the script to the modeler.

Have this issue to be assigned to Arnoud or Nyall or whatelse?
No idea if this works on previous to Master versions.

premise
The only way I found to setp the range (reversing the code) is defining the parameter in this way:
QgsProcessingParameterRange(
name=self.INPUT_PCL_S1_INTENSITY_RANGE,
description=self.tr('PCL intensity range to extract street signs (Strip1)'),
type=QgsProcessingParameterNumber.Double,
defaultValue="3000,3200", <----------
optional=True
)

  • the exception *******

2018-09-06T13:29:40 WARNING Traceback (most recent call last):
File "/home/ginetto/PROGRAMMING/QGIS/QGIS-master/build/output/python/plugins/processing/modeler/ModelerDialog.py", line 319, in _dropEvent
self._addAlgorithm(alg, event.pos())
File "/home/ginetto/PROGRAMMING/QGIS/QGIS-master/build/output/python/plugins/processing/modeler/ModelerDialog.py", line 783, in _addAlgorithm
dlg = ModelerParametersDialog(alg, self.model)
File "/home/ginetto/PROGRAMMING/QGIS/QGIS-master/build/output/python/plugins/processing/modeler/ModelerParametersDialog.py", line 81, in init
self.setupUi()
File "/home/ginetto/PROGRAMMING/QGIS/QGIS-master/build/output/python/plugins/processing/modeler/ModelerParametersDialog.py", line 146, in setupUi
wrapper = WidgetWrapperFactory.create_wrapper(param, self)
File "/home/ginetto/PROGRAMMING/QGIS/QGIS-master/build/output/python/plugins/processing/gui/wrappers.py", line 1795, in create_wrapper
return WidgetWrapperFactory.create_wrapper_from_class(param, dialog, row, col)
File "/home/ginetto/PROGRAMMING/QGIS/QGIS-master/build/output/python/plugins/processing/gui/wrappers.py", line 1859, in create_wrapper_from_class
return wrapper(param, dialog, row, col)
File "/home/ginetto/PROGRAMMING/QGIS/QGIS-master/build/output/python/plugins/processing/gui/wrappers.py", line 166, in init
self.setValue(param.defaultValue())
File "/home/ginetto/PROGRAMMING/QGIS/QGIS-master/build/output/python/plugins/processing/gui/wrappers.py", line 826, in setValue
self.widget.setValue(value)
AttributeError: 'NoneType' object has no attribute 'setValue'

Associated revisions

Revision 1ec36544
Added by Nyall Dawson almost 6 years ago

[processing] Port Range parameter widget to new API

Fixes use of range parameters inside models, allowing range
inputs to be used for range parameter values.

Fixes #19785

History

#1 Updated by Luigi Pirelli almost 6 years ago

can be related to this control?
https://github.com/qgis/QGIS/blob/master/python/plugins/processing/gui/wrappers.py#L815 and following commented lines?

#2 Updated by Luigi Pirelli almost 6 years ago

Luigi Pirelli wrote:

can be related to this control?
https://github.com/qgis/QGIS/blob/master/python/plugins/processing/gui/wrappers.py#L815 and following commented lines?

seems that only setting:

def createWidget(self):
widget = RangePanel(self.parameterDefinition())
widget.hasChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
return widget

in wrappers.py solve the problem...

#3 Updated by Nyall Dawson almost 6 years ago

It seems range parameters have never been supported in models (I gather they aren't widely used yet).

I'd be tempted to defer fixing this until range widget is ported to the newer c++ wrapper API.

#4 Updated by Luigi Pirelli almost 6 years ago

Nyall Dawson wrote:

It seems range parameters have never been supported in models (I gather they aren't widely used yet).

I'd be tempted to defer fixing this until range widget is ported to the newer c++ wrapper API.

Ho my god, I doing the effort to avoid to go back to 2.18 because all have to move to 3.x. And if we do not start, we'll face more issues later than before.
My struggle is that I've limited time and I've to process data and in the mean time fix issue... I can see that implementation of range in model is not hard, but it's a matter of time. Other problem is that probably I don't have the general architectural vision of processing classes and I can't figure out why just using the rangewidget shouldn't work in all context... I just tried and it seems working, but I dint't wrote any test...

So your suggestion is to use the two Number parameters instead of range in my algorithms.... I'll try to simplify in this way.

tnx for you suggestion

#5 Updated by Luigi Pirelli almost 6 years ago

lesson learned... never be core developer in a project that involve you as user... or plan 100% more project time ;)

#6 Updated by Luigi Pirelli almost 6 years ago

Nyall Dawson wrote:

It seems range parameters have never been supported in models (I gather they aren't widely used yet).

I'd be tempted to defer fixing this until range widget is ported to the newer c++ wrapper API.

I'm temped too... the proposed fix above just allow setting parameter in modeler, but does not expose the parameter as possible input in the modeler.
Can be considered a "preliminary fix"? I'll move discussion in a PR eventually that can be closed.

#7 Updated by Luigi Pirelli almost 6 years ago

  • Pull Request or Patch supplied changed from No to Yes

#8 Updated by Nyall Dawson almost 6 years ago

Sorry, I wasn't implying that you should do the port (that's my responsibility). I was instead just conveying that it's not a regression in that it's always been broken!

#9 Updated by Nyall Dawson almost 6 years ago

https://github.com/qgis/QGIS/pull/7972 fixes this, by porting the range wrapper to the new api it correctly allows range inputs to be used for range parameters

#10 Updated by Nyall Dawson almost 6 years ago

Oops, one last thing -- while https://github.com/qgis/QGIS/pull/7972 fixes most of the issues here, I've noticed that the range parameter widget doesn't correctly allow for optional range parameters. There's no way to set the widget to a "not set" state, so effectively there's no such thing as an optional range parameter. We'll need to address that at some later stage, but I'm not suite sure what a nice way to expose this in the widget itself is....

#11 Updated by Nyall Dawson almost 6 years ago

  • % Done changed from 0 to 100
  • Status changed from Open to Closed

Also available in: Atom PDF