I have started using the QGIS Bézier Editing Plugin by Takayuki Mizutani v.1.3.4. Plotting line features in my project works well, but on saving the feature the attributes dialog is empty, whereas when I save a feature via the standard procedure, the attribute rules provide a new id-number from the database. Which pyqgis function applies the attribute rules to a new feature ? My QGIS version is 3.4.11-Madeira.
** Partial answer **
Playing with the excellent and necessary plugin IPython to inspect the data model, I found this Python expression:
which evaluates to
which is the default id number expression I am looking for. Then I grepped the codebase to search for "expression" and found the class
QgsExpression. It can be instantiated with the string representation of the above expression, which is automatically parsed on init. You can query the
hasParserErrors property or the
isValid property to check all is right.
But then you are on your own again. The expression class has a method
evaluate which should return the new id value, but it needs a
QgsExpressionContext to provide the expression with the attributes of the
testlayer features to calculate its result. The constructor of the expression context class only has a
QgsExpressionContextScope stack as arguments. There also exists a
QgsExpressionContextGenerator abstract interface, which should be implemented by the user.
So my question is narrowed down to how does the standard new feature dialog for
LineString features with among others an
id attribute create this expression context ?