[Qgis-developer] QgsVectorLayer's attributeValueChanged SIGNAL emitted when it should not
Germán Carrillo
carrillo.german at gmail.com
Wed Jul 13 06:19:46 PDT 2016
Hi Matthias,
thanks for the response.
In the first message I've included a link to a sample Shapefile. It has a
single field (called id) with these properties: type:int, type
name:Integer, length:10, precision:0, fieldIndex:0, edit widget:text edit.
The SIGNAL is emitted when the first feature has a NULL value for id field.
It happens only the first time I click on Toggle Edit Mode (after the
attribute table is open), the second time I start an edit session from the
same attribute table window, the SIGNAL is not emitted. To get the SIGNAL
emitted once more, I just need to close the attribute table window and open
it again, then starting an edit session emits the SIGNAL again.
What you say about edit widgets makes sense, what I'd like to discuss is
whether the SIGNAL should be emitted in such cases.
Regards,
Germán
2016-07-13 1:12 GMT-05:00 Matthias Kuhn <matthias at opengis.ch>:
> 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 listQgis-developer at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>
>
> _______________________________________________
> 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
>
--
-----------
|\__
(:>__)(
|/
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/20160713/be1f744d/attachment.html>
More information about the Qgis-developer
mailing list