In QGIS 3.22. For a vector layer, I would like to have a certain attribute (Field_A) be both
- editable by a user, AND
- automatically filled in by an expression for features that are not user-edited.
As a simple example, say that Field_A corresponds to the polygon surface area;
- Most of the time, polygons should simply be automatically filled with the expression
$area, and update dynamically as such (via a Default Value, for example). - However, occasionally, there is a polygon that the user knows should be filled with a different value (perhaps the real surface area concerned with the project is different). The user does not want to change the polygon and would rather simply edit the value to whatever they want, and have this new, edited value remain that way (i.e. not update automatically to
$areathe next time there is a change).
So what I am looking for is a way for an attribute to distinguish between user-edited values (to be preserved as such) and non-user edited values (to be updated dynamically by a default expression). Or in other words, a way of allowing a user override of the default expression.
There are a few methods of automatically updating attribute values that I am aware of, but do not make this distinction:
'Default Values' (layer properties-->attributes form) allows dynamic updates, but the field becomes uneditable.
'Virtual Fields' (layer properties-->fields, and created with field calculator) also allows dynamic updates, but the field is uneditable; additionally, the values are not saved in the data.
the 'AutoFields' plugin is, as far as I can tell, no longer available.
I know that Python-based methods exist, though as far as I know they do not allow for this distinction.
It seems like it should be possible to allow a "user override" of the default -- such as a conditional statement where IF a user edits a value, the value to keep is that edited value, and ELSE the value to keep should be calculated from a given expression. Is it possible to refer to a "user edit" as an expression term? Any other ideas?
NULL), return$area, otherwise the manually entered value of that field.Apply default value on updateunchecked in theLayer properties --> Default Valuessection, and still setting a default value expression (e.g.,$areaorarea($geometry)) could help you. It will give you an automatic value but also will preserve user edits.Apply default value on updateunchecked will only supply the default value upon creating a new feature; it does not update an existing feature dynamically when it is modified (including those without user edits).