[Qgis-developer] QgsVectorLayer's attributeValueChanged SIGNAL emitted when it should not

Matthias Kuhn matthias at opengis.ch
Tue Jul 12 23:12:03 PDT 2016


Hi Germán,

I think some edit widgets have effects like this, when an unsupported
value is set on them, they will just convert it to a supported one and
change it.
Like some widgets may not support NULL values so they just change it to
something else.
Please check which field is affected, what edit type is set and what's
the value of the first (topmost) feature on the attribute table for this
field.

Thanks
Matthias

On 13/07/16 00:33, Germán Carrillo wrote:
> Hi All,
>
> I'm working on a plugin and trying to connect a SLOT to
> layer.attributeValueChanged SIGNAL. However, I found that such SIGNAL
> is (weirdly) emitted in the following scenario:
>
> 1. Load a vector file (I've tested this with a Shapefile and an SQLITE
> file) with a numeric (int or real) field, whose value for the first
> feature is NULL.
> 2. Open the attribute table of the vector layer.
> 3. Start an edit session cliking on "Toggle Edit Mode" button from the
> Attribute table window.
>
> As soon as the edit session starts, the SIGNAL is emitted. Now, if I
> click on the "Toggle Edit Mode" button from the Attribute table
> window, I have to choose among Save, Cancel, or Close Without Saving
> options, even without changing any attribute value at all. Once I
> choose Close Without Saving, the layer.attributeValueChanged SIGNAL is
> emitted once more.
>
> Such behavior is hampering my plugin, which will depend on the
> aforementioned SIGNAL.
>
> Is this a bug? Do you know why layer.attributeValueChanged is being
> emitted in such scenario? I've noticed that sometimes a blockSignals()
> method is used in QGIS source code; couldn't we use blockSignals() to
> avoid emitting the SIGNAL in this case?
>
> ######################################
> Note: I use this code snippet in the QGIS Python console to be
> notified when layer.attributeValueChanged is emitted:
>
> ##
> def f(fid, idx, value):
>   print fid,idx,value
>
> l = iface.activeLayer()
> l.attributeValueChanged.connect( f )
> ##
>
> I'm getting these messages printed (4 is the index of the numeric
> field whose value for the first feature is NULL):
>
> 0 4 NULL # When I open the edit session.
> 0 4 NULL # When I close the edit session.
>
> If you want to reproduce the problem, you can use a sample Shapefile
> from here: http://downloads.tuxfamily.org/tuxgis/tmp/test.zip
> ######################################
>
>
> Regards,
>
> Germán
>
>
> -- 
> -----------
>    |\__ 
> (:>__)(
>    |/   
> Soluciones Geoinformáticas Libres                            
> http://geotux.tuxfamily.org/
> http://twitter.com/GeoTux2
> http://about.me/germancarrillo
>
> <http://gis.stackexchange.com/users/4972/germ%c3%a1n-carrillo>
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160713/96bc155a/attachment.html>


More information about the Qgis-developer mailing list