[Qgis-developer] Adding attributes to data provider, python

Chris Crook ccrook at linz.govt.nz
Mon Jan 16 15:02:23 EST 2012


Hi All 

Since updating QGIS (from 1.6 I think) several plugins I use are no longer working properly, because of the issue raised as bug 4687 http://hub.qgis.org/issues/4687.  

Basically they are using the approach in the python cookbook for creating memory layers using the data provider addAttributes.  This was broken by the change adding the table-join feature, which requires the vector layer to maintain cached attribute data.   This no longer works without also calling the vector layer updateFieldMap() member function, put in to support the table-join feature.

Options I can see for fixing are:

1) Add a call to updateFieldMap() in pendingFields(), so that the field list is updated every time it is accessed.  Simple, possibly inefficient, but probably very little practical impact.

2) Accept the breaking change, and require many plugins to be updated.  We already have to call updateExtents if we add features via the provider, so calling updateFieldMap is consistent. (For the memory provider we can also include the fields in the uri, in which case they are handled correctly). 

3) Modify QGIs to update the field map when vector layers are added to the layer registry - this will fix most plugins, as  the pattern is generally to create the layer, add attributes to the memory provider, then  register the layer.  This seems a bit messy as registry doesn't know it is dealing with a vector layer.

4) Have the provider signal changes to the schema, which the layer can use to trigger an update.  Hard to implement (many different providers) and inconsistent with the rest of the code.

My inclination is to option 1, and option 2 for significant plugins to support users of version 1.7. 

Any thoughts on better alternatives?
#####################################################################################

This message contains information, which is confidential and may be subject to legal privilege. 
If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message.
If you have received this message in error, please notify us immediately (Phone 0800 665 463 or info at linz.govt.nz) and destroy the original message.
LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from LINZ.

Thank You.

#####################################################################################


More information about the Qgis-developer mailing list