The @atlas_feature
is a variable which is provided in the expression context from the environment. Such variables are normally passed as parameters into functions, just like you are passing it here as a parameter to a function attribute
.
You can do the same in your own function which then looks like this:
@qgsfunction(args=1, group='shorthands')
def get_atlas_attribute(atlasfeature, feature, parent):
return atlasfeature['FIELD_NAME']
And you would call it like this
get_atlas_attribute(@atlas_feature)
I am not sure if this is of big help for you just as well as I am not sure what exactly you want to achieve.
I guess it's mostly about making your expressions more readable by delegating repeated code to a dedicated function. I think that's fine (although it adds another layer of potential failures).
I just found that equivalent PyQGIS within function body tends to be ironically even longer
That is very likely to be true. And I don't think there is anything ironic about it. The expression engine is built for this very purpose. Take yet another language and you will have even more code ;)