<div dir="ltr">So why is there a separate way to create features? Should these be cross referenced in the documentation as to why one method should be used vs. the other? This solves the openFeatureForm problem. Perhaps the documentation should also mention that if you use openFeatureForm then you need to use QgsVectorLayerUtils.createFeature(...).<div><br></div><div>Thanks,</div><div><br></div><div>Calvin</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 23, 2020 at 5:45 AM Richard Duivenvoorde <<a href="mailto:rdmailings@duif.net">rdmailings@duif.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">In the issue Alessandro pointed to:<br>
<br>
QgsVectorLayerUtils.createFeature<br>
<br>
<a href="https://qgis.org/pyqgis/master/core/QgsVectorLayerUtils.html?highlight=qgsvectorlayerutils#qgis.core.QgsVectorLayerUtils.createFeature" rel="noreferrer" target="_blank">https://qgis.org/pyqgis/master/core/QgsVectorLayerUtils.html?highlight=qgsvectorlayerutils#qgis.core.QgsVectorLayerUtils.createFeature</a><br>
<br>
THAT one takes the expression context into account!<br>
<br>
So:<br>
Given an editable layer 'layer' and a valid 'geom":<br>
<br>
feat = QgsVectorLayerUtils.createFeature(layer, geom, {}, layer.createExpressionContext() )<br>
iface.openFeatureForm(layer, feat)<br>
<br>
works!!<br>
<br>
Thanks Alessandro,<br>
<br>
Regards,<br>
<br>
Richard Duivenvoorde<br>
<br>
<br>
On 11/23/20 10:34 AM, Richard Duivenvoorde wrote:<br>
> Hi Core Devs,<br>
> <br>
> I'm thinking about a solution for this <br>
> <br>
> <a href="https://github.com/qgis/QGIS/issues/40213" rel="noreferrer" target="_blank">https://github.com/qgis/QGIS/issues/40213</a><br>
> (PyQGIS: iface.openFeatureForm() seems not to handle autofill fields)<br>
> <br>
> 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):<br>
> <br>
> <a href="https://github.com/qgis/QGIS/blob/master/src/app/qgsfeatureaction.cpp#L168-L320" rel="noreferrer" target="_blank">https://github.com/qgis/QGIS/blob/master/src/app/qgsfeatureaction.cpp#L168-L320</a><br>
> I do see a way to fix it (as in: use "iface.openFeatureForm: in PyQGIS WITH the handling of default and expression values).<br>
> <br>
> I wonder if anybody has an opinion about moving part of this functionality to the vector layer.<br>
> Talking about<br>
> - setting defaults<br>
> - setting expression based values<br>
> <br>
> So QgsFeatureAction::addFeature would be shrunken till: <br>
> - layer.initAttributesForFeatures (or somethink like that)<br>
> - open feature form...<br>
> <br>
> 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?<br>
> <br>
> Thanks for any input.<br>
> <br>
> Regards,<br>
> <br>
> Richard Duivenvoordd<br>
> _______________________________________________<br>
> QGIS-Developer mailing list<br>
> <a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
> List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
> Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
> <br>
<br>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div>