[Qgis-developer] Custom form init function changes - Kind of API break

Marco Bernasocchi marco at bernawebdesign.ch
Tue Jul 10 04:50:08 PDT 2012


Super, thx

Marco Bernasocchi (mobile)
http://opengis.ch
On Jul 10, 2012 1:07 PM, "Nathan Woodrow" <madmanwoo at gmail.com> wrote:

> Hey All,
>
> This is a just a quick email to let everyone know that I have changed
> the way that arguments are passed to a layers Init Python function.
> That is the option that you find in the Layer Properties dialog on the
> General tab. If you are using this then this will affect you and you
> will know what I'm talking about.
>
> I have changed it so that the reference to the layer and feature are
> now passed into the function rather then just ids.  The issue with
> just passing the feature id was that you couldn't get access to the
> new feature and geometry because you were given a 0 as the id and 0 is
> a valid id for already existing feature.
>
> So now instead of this:
>
> def myFunction(dialog, layer_id, feature_id)
>
> where layer_id and feature_id are integers.  You now do this:
>
> def myFunction(dialog, layer, feature)
>
> layer is a instance of QgsVectorLayer
> feature is a instance of QgsFeature
>
> You can now do things like:
>
> def myFunction(dialog, layer, feature):
>       id = layer.id()
>       name = layer.name()
>       geom = feature.geometry()
>       geom.length()
>       # etc
>
> This change will break your custom form logic if your code is
> expecting a interger for the feature argument but you get a QgsFeature
>
> Just a FYI so you don't freak out when you form logic doesn't work anymore.
>
> - Nathan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20120710/2f0e7324/attachment.html>


More information about the Qgis-developer mailing list