Hi

In QgsVectorLayer, it is possible to define the edittype 'value relation' where a key is replaced by a value in a related layer. Now I'd like to make a function in QgsExpression that behaves similarly and returns the value in the related table.

My idea is to create a function 'valueRelation( value, layer_id, key_field, value_field )' to return that value, where layer_id is the id of the related layer, key_file and value_field the column names in the related layer.

One disadvantage of this approach is that if the relation in vectorlayer changes, the one in an expression needs to be changed as well. On the other hand it can be an advantage in certain situations to have a different relation in expression than in vector layer. I figured out it would be difficult to take the value relation dynamically from vectorlayer, as QgsExpression does not know its vectorlayer. A possibility would be to create a special column for the current layer id. However that seems not nice and it is too easy to forget to set that id when using the expression.

What are your opinions on that? Are there better ways to accomplish the value relation function in QgsExpression?

Regards,
Marco

--
Dr. Marco Hugentobler
Sourcepole -  Linux & Open Source Solutions
Weberstrasse 5, CH-8004 Zürich, Switzerland
[email protected] http://www.sourcepole.ch
Technical Advisor QGIS Project Steering Committee

_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to