[QGIS-Developer] QgsField::displayString vs. QgsTextEditWrapper::setWidgetValue

Sandro Santilli strk at kbt.io
Wed Oct 19 02:04:47 PDT 2022


While working on a regression with how geometry attributes are handled
by the attributes editor widget I stumbled upon what looks like being
an unclear responsibility as to what should convert in/out of text
form various type of field values.

The QgsTextEditWrapper::setWidgetValue method contains different
special handling and passes non-special cases to
QgsField::displayString to produce the "widget value" (which is a text
representation of the value usable for editing it).

Now: QgsField::displayString is documented to a "string for display"
which is not a "string for editing". For the ReferencedGeometry case
such method returns a truncated WKT string, for example, which is
surely ok for "display" but not for "edit", which is what
QgsTextEditWrapper::setWidgetValue wants.

Similarly, QgsTextEditWrapper::value() invokes
QgsField::convertCompatible() but only in certain cases and not
in others, which makes me wonder who should be responsible for this
in/out conversion of QgsField values to text and back.

The question is: should QgsTextEditWrapper::setWidgetValue
keep relying on QgsField, with QgsField exposing specific
methods to convert to/from a "canonical text" form of values ?

--strk;

  Libre GIS consultant/developer
  https://strk.kbt.io/services.html


More information about the QGIS-Developer mailing list