[Qgis-developer] Keeping line breaks in QGIS expressions

Martin Dobias wonder.sk at gmail.com
Wed Sep 24 12:42:06 PDT 2014


Hi Matthias

On Thu, Sep 25, 2014 at 2:00 AM, Matthias Kuhn <matthias.kuhn at gmx.ch> wrote:
>> This is probably due to the fact that in _some_ cases expressions are
>> (unfortunately) not kept in verbatim format as they were input -
>> instead they are parsed and later converted back to text, loosing all
>> formatting.
>
> I once introduced a method QgsExpression::expression() along
> QgsExpression::dump() which originally returned the saved verbatim
> string and was subsequently changed several times (responsibility for
> this including myself) to call dump() or return the original string.
>
> Last time I wanted to change this back to the saved string, I was
> stopped me because IIRC there are situations where the expression gets
> modified directly, so the input string does not correctly represent the
> expression and needs to be recreated.

Right... When I initially designed QgsExpression, the idea was to have
expression() return always the original expressions (no modifications
were allowed) and dump() was just for debugging without the purpose to
return a valid expression. With time dump() however got updated to a
state when it returned correct expression - and things got more
complicated :)


> I would propose the following:
>
>   - QgsExpression::dump() should always recreate the string from the
> data structure
>   - save the original expression string and return it with
> QgsExpression::expression()
>   - unless the expression is modified by other means, which will set the
> saved string to a NULL string in which case QgsExpression::expression()
> will be forwarded to QgsExpression::dump()

This logic makes sense to me. For the third item I would just suggest
that any modification would immediately regenerate the saved
expression string using dump() - so there would be no forwarding from
expression() to dump().


Cheers
Martin


More information about the Qgis-developer mailing list