Bug report #4441

Expression parser: some expressions evaluate to NULL when they shouldn't

Added by Alister Hood over 12 years ago. Updated over 12 years ago.

Status:Closed
Priority:Normal
Assignee:Martin Dobias
Category:Vectors
Affected QGIS version: Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:fixed
Crashes QGIS or corrupts data: Copied to github as #:14373

Description

example 1:
I can create a string attribute field called "test1" and fill it using $perimeter
I can then fill it using toint(test1)
But the entire column is set to NULL if I try to do this in one step using toint($perimeter)

example 2:
With the new expression based labelling in Trunk, with some expressions the result displays OK in the "expression based label" window's preview, but no labels are drawn on the canvas. e.g. this expression: toreal(toint($AREA/100))/100

But for some reason I can build a larger expression which includes it, and the labels are drawn successfully:
CNAME || '
SMU '|| CNUMBER || '
AREA = ' || tostring(toreal(toint($AREA/100))/100) || ' ha'

Associated revisions

History

#1 Updated by Nathan Woodrow over 12 years ago

  • Must fix set to Yes
  • Subject changed from Labelling/Field calculator: some expressions evaluate to NULL when they shouldn't to Expression parser: some expressions evaluate to NULL when they shouldn't
  • Assignee set to Martin Dobias

I have just changed the title because it's related to the underlying expression parser more then anything else.

#2 Updated by Martin Dobias over 12 years ago

  • Resolution set to fixed
  • Status changed from Open to Closed

Fixed in 699694

#3 Updated by Alister Hood over 12 years ago

I guess I should maybe open a new ticket - there is still be a problem for labelling.

As far as I can tell, the field calculator is working correctly, e.g. I can now fill a field with toint($perimeter), or regexp_replace( toint($area) ,'(\\\\d+)(\\\\d{3})','\\\\1,\\\\2'), and I can label with fields created that way.

But if I try to use either of those expressions for labelling, the label is shown correctly in the output preview, but no labels are drawn on the map.

#4 Updated by Alister Hood over 12 years ago

Actually, it seems like the labelling doesn't work with any expression except a field name. e.g. no labels are shown if I use the expression 1 or 1+1 or $perimeter

#5 Updated by Nathan Woodrow over 12 years ago

I noticed this too. I think I know what might be causing the issue.

My guess is that how I'm using QgsExpression::evaluate() is wrong.

In the widget I use:

QVariant value = exp.evaluate( &feature, mLayer->pendingFields() );

but in the labeling class I use:

QVariant result = exp->evaluate( &f, layer->dataProvider()->fields() );

Will patch it and see if that makes any difference.

#6 Updated by Nathan Woodrow over 12 years ago

Opened a new ticket at #4495 and supplied a patch.

Also available in: Atom PDF