This is what the decorator does. Except that I need it in a plugin: using the decorator rather than a manual register/unregister make it crash on each reloading (I need to reload it quickly during the development).
But even with the decorator, the problem is still the same: the 'feature' parameter of the custom function is not a QgsFeature anymore as it was on previous versions, but a QgsExpressionContext. And it seems there is no way to access the feature through the expression context. Looking at the source, the feature is stored in a variable called "_feature_", but trying to access this from the function returns None. On 04/09/2015 11:57, Barry Rowlingson wrote: > Maybe I've misunderstood, but are you trying to define a new function > to appear as an expression? Isn't that what the @qgsfunction decorator > does? Do you need to define a new class for this? > > http://nathanw.net/2015/01/19/function-editor-for-qgis-expressions/ > > On Thu, Sep 3, 2015 at 4:12 PM, Hugo Mercier <[email protected]> > wrote: >> Hi, >> >> I am using custom expressions functions for a plugin. >> Something like this : >> >> class MyFunction( QgsExpression.Function ): >> def func( self, values, feature, parent ): >> feature.geometry() >> ... >> >> The problem is that "feature" is now a QgsExpressionContext(), not a >> QgsFeature anymore. >> I cannot find how to access the feature from the context. Did I miss >> something ? >> >> Thanks >> _______________________________________________ >> Qgis-developer mailing list >> [email protected] >> http://lists.osgeo.org/mailman/listinfo/qgis-developer > _______________________________________________ Qgis-developer mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/qgis-developer
