[Qgis-developer] Set QgsVectorLayer.EditType to value map and populate value:description pairs with python

Matthias Kuhn matthias.kuhn at gmx.ch
Mon Jan 27 15:40:00 PST 2014

Hi Eric,

On Mon 27 Jan 2014 20:21:35 CET, Eric Goddard wrote:
> Hi all,
> And this is where I'm stuck. I can't find anything in the API docs
> about how to set the value-description pairs. Any help would be
> greatly appreciated!
> Thanks,
> Eric

This was working in 1.8, but it's not working in 2.x releases (so far).
You may have heard of the update to "SIP API v2". Since we did this, Qt 
objects are converted to python objects to make it more natural to use 
for developers. Before that, you could just retrieve the existing 
valuemap and edit it in place, because when you called 
layer.valueMap(idx), you would receive a reference to the map QGIS 
internally works with. However, the new SIP API converts the map you 
receive to a native python dict and creates a copy of it. And if you 
edit this copy, QGIS doesn't realize, that there are changes.

So, in short: If you use 1.8, just edit the map you get back. If you 
use 2.0, I don't think there is a possibility and there won't be one in 
2.2. However, for 2.4 there will be an update which will make this 
possible again (with a new API).


More information about the Qgis-developer mailing list