3

In QGIS I've set up some project variables called rv_farbe1, rv_farbe2 and so on. The contain color values in html notation like '#ff0080'.

enter image description here

Now in rule base labels I would like to setup data defined override by selecting the text color based on an attribute value sektor_lfd_nr. The idea is to concatenate a string @rv_farbe and the sektor_lfd_nr and evaluate the result in order to access the variable value like

eval('@rv_farbe' ||  "sektor_lfd_nr")

As far as I understand, in expression editor preview I should get the color value, but preview (german: 'Ausgabevoransicht') displays nothing:

enter image description here

Furthermore, the text with data defined override set for it's color does not display.

Both using the variable directly (@rv_farbe1) as well as using the html style color code directly ('#ff00bb') works, so do I miss something about eval() statement, or what might be wrong here?

Jochen Schwarze
  • 14,605
  • 7
  • 49
  • 117

1 Answers1

3

After a night of forensics, I found that the problem is not the eval() statement.

The Layer for which I tried what I described above is based on a PostgreSQL view, which under very special conditions is caused to be empty by a division by zero error.

So the message is: The eval() statement works fine and can be used to retrieve variable values from a prefix/attribute value combination, i.e. eval('@rv_farbe'||"sektor_lfd_nr")

After fixing my view definition, the result is as expected (note the output preview):

[Image 2b added]

Jochen Schwarze
  • 14,605
  • 7
  • 49
  • 117