Feature request #19858

QgsProcessingParameterNumber needs support for "data defined" parameter values

Added by Olivier Dalang over 6 years ago. Updated over 6 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Processing/Modeller
Pull Request or Patch supplied:No Resolution:fixed/implemented
Easy fix?:No Copied to github as #:27682

Description

Hi,

QgsProcessingParameterNumber doesn't seem to evaluate fields in processing models.

Steps to reproduce

1. Create a new model with an input vector layer
2. Add the "Set M Value" algorithm
3. Use an expression referring an attribute of the input layer.
4. Run

All points will have M Value to 0, as the expression doesn't evaluate correctly.

Notes

- expressions are evaluated, as if you use "3+4" as expression, the M value is set to 7.
- it works as expected outside of the processing modeler both by choosing the field or by setting an expression.

Logs (in a processing model)

Running Set M value [1/1]
Input Parameters:
{ INPUT: 'PointM?crs=EPSG:3460&field=fid:long&field=date%2Ftime:string(255)&field=lat:double&field=long:double&field=hPa:integer&field=cat:integer&field=kts:integer&uid={92a59f27-e18c-482a-a549-f934d0b735b0}', M_VALUE: [cat], OUTPUT: 'memory:' }

Logs (by running the algorithm directly)

Algorithm 'Set M value' starting…
Input parameters:
{ 'INPUT' : 'C:/Users/Olivier/temp/tracks.gpkg|layername=test-EPSG3460', 'M_VALUE' : QgsProperty.fromExpression('"cat"'), 'OUTPUT' : 'memory:' }

Note the difference in the M_VALUE parameter, not sure why I get [cat] there, while my expression is "cat".

I also tried some workarounds, like using attribute( $currentfeature, 'cat' ) instead of cat, but then, the MVALUE is None in the log.

History

#1 Updated by Nyall Dawson over 6 years ago

  • Subject changed from QgsProcessingParameterNumber doesn't evaluate fields in expressions when in processing models to QgsProcessingParameterNumber needs support for "data defined" parameter values
  • Tracker changed from Bug report to Feature request

This isn't technically a bug, rather it's a feature request.

When you enter an expression for a number parameter in modeler, it's evaluated ONCE before the algorithm is run, and the evaluated value is used for the entire execution of that child algorithm.

What you need here is the ability to set the "data defined" expression for the m value parameter. That's currently not possible, and requires porting of the QgsProcessingParameterNumber widget wrapper to the newer c++ QgsAbstractProcessingParameterWidgetWrapper class. That's targeted for 3.6 (it's not possible to do for 3.4 since we're in feature freeze).

#2 Updated by Olivier Dalang over 6 years ago

I see, I got confused, as from the UI, it looks like the expression based input in the modeler is equivalent to the data defined override when running the algorithms normally.

#3 Updated by Nyall Dawson over 6 years ago

  • Status changed from Open to In Progress

#4 Updated by Nyall Dawson over 6 years ago

  • Resolution set to fixed/implemented
  • Status changed from In Progress to Closed

Also available in: Atom PDF