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

Nathan Woodrow madmanwoo at gmail.com
Tue Jul 10 04:27:05 PDT 2012


Marco,

Just added a section for it.

- Nathan

On Tue, Jul 10, 2012 at 9:19 PM, Marco Hugentobler
<marco.hugentobler at sourcepole.ch> wrote:
> Hi Nathan
>
> Could you add an entry to
> http://hub.qgis.org/wiki/quantum-gis/API_changes_for_version_20 ?
>
> Regards,
> Marco
>
> Am 10.07.2012 13:07, schrieb Nathan Woodrow:
>>
>> 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
>> _______________________________________________
>> Qgis-developer mailing list
>> Qgis-developer at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>
>
> --
> Dr. Marco Hugentobler
> Sourcepole -  Linux & Open Source Solutions
> Weberstrasse 5, CH-8004 Zürich, Switzerland
> marco.hugentobler at sourcepole.ch http://www.sourcepole.ch
> Technical Advisor QGIS Project Steering Committee
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer


More information about the Qgis-developer mailing list