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

Germán Carrillo carrillo.german at gmail.com
Tue Jul 12 15:33:33 PDT 2016


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>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160712/b9c3615a/attachment.html>


More information about the Qgis-developer mailing list