[QGIS-Developer] PyQGIS: add feature (+defaults/expressions), with Form

Richard Duivenvoorde rdmailings at duif.net
Mon Nov 23 01:34:35 PST 2020


Hi Core Devs,

I'm thinking about a solution for this 

https://github.com/qgis/QGIS/issues/40213
(PyQGIS: iface.openFeatureForm() seems not to handle autofill fields)

My conclusion is: the normal handling of default values or expression based attribute values, and the opening of the form dialog, are 'locked' in QgsFeatureAction::addFeature (glued together with the opening of the form):

https://github.com/qgis/QGIS/blob/master/src/app/qgsfeatureaction.cpp#L168-L320
I do see a way to fix it (as in: use "iface.openFeatureForm: in PyQGIS WITH the handling of default and expression values).

I wonder if anybody has an opinion about moving part of this functionality to the vector layer.
Talking about
- setting defaults
- setting expression based values

So QgsFeatureAction::addFeature would be shrunken till: 
- layer.initAttributesForFeatures (or somethink like that)
- open feature form...

Is this OK for others? Or is the general opinion that you should copy all this to PyQGIS if you want to open the feature form?

Thanks for any input.

Regards,

Richard Duivenvoordd


More information about the QGIS-Developer mailing list