[Qgis-developer] Questions about QgsEditorWidgetWrapper value() / setValue()
Matthias Kuhn
matthias at opengis.ch
Fri Apr 22 06:43:50 PDT 2016
Hi Even
On 22/04/16 14:38, Even Rouault wrote:
> Hi,
>
> I'm trying to understand the abstraction of QgsEditorWidgetWrapper.
>
> 1) Semantics question
> Am I right that there's no guarantee (and that's actually intended) that the
> following pseudo-code is true :
> setValue(v)
> assert value() == v
It should in theory either return the same value or an invalid QVariant
which should be interpreted by the outside world as "no change". But I
admit that I doubt that all widgets effectively follow this rule.
> For example in the QgsValueRelationWidgetWrapper(), value() returns the value
> of the value column of the referenced layer, which corresponds to the key
> provided to setValue().
> And that's value() that is used when displaying the attribute table in table
> view mode.
> So this value() method is more a displayValue(), right ? And setValue() would
> be setRawValue() / setSourceValue() ?
value() should return the real/raw value. Returning the display value is
wrong.
> 2) Implementation of QgsRelationReferenceWidgetWrapper.
> The value() method in that case actually returns the foreign key set by
> setValue(). Is that intended ? To have similar behaviour as
> QgsValueRelationWidgetWrapper, one could rather expect value() to return the
> evaluation of the display expression, no ?
> If the current behaviour is intended, is there something in the abstraction of
> QgsEditorWidgetWrapper that could return the evaluation of the display
> expression for a QgsRelationReferenceWidgetWrapper ?
For this there is QgsEditorWidgetFactory::representString
https://qgis.org/api/classQgsEditorWidgetFactory.html#a6805c62cc859478b4d4715b3819ce24f
Matthias
> Thanks
>
> Even
>
More information about the Qgis-developer
mailing list