[Kde-finance-apps] Porting KLocale::formatMoney()/readMoney() to Qt5/KF5, best practise?

Klaas Freitag freitag at kde.org
Wed Jan 6 09:06:48 UTC 2016


On 06.01.2016 08:12, Friedrich W. H. Kossebau wrote:
Hi Friedrich,

> (please keep cross-posting to both ml for now)
>
> I (not only with my Calligra developer hat on) would like to collect
> experiences and ideas for conversion of curreny values to and from
> strings when using Qt5/KF5, especially when porting from kdelibs4's
> KLocale.

cool, thanks for speaking up! This is way to silence due to real life 
constraints :-/

> PROBLEM
>
> QLocale is rather limited (as of Qt 5.5):
> - no currency string parsing method
> - string formatting method toCurrencyString() does not allow
>    to control precision
>
> KLocale and its currency related methods seem the last blocker to get
> rid of kdelibs4support in Calligra in the Qt5/KF5 port. Plan uses them
> for handling the costs of resources, and Sheets for the currency
> formatted cells. And both limitations are a blocker.
>
>
> APPROACHES
>
> Long term ideally QLocale gets support in its API for that. So we
> developers of currency data handling software should organize and
> draft an API.
>
> First and short term though, until some released & wide-spread Qt
> version has the improved QLocale, I am looking for a solution
> independent of QLocale.
> Most obvious might be to duplicate all currency things from KLocale,
> which would also include duplicating the database with all currency
> formatting data. This is what I would plan to do if there is no better
> idea.
> Especially the database duplication is painful though, I would like to
> avoid at least that if possible.
>
>
> QUESTIONS
>
> How have developers of e.g. Skrooge & KMyMoney approached the issue of
> conversion of currency values to/from strings?

The outcome of the KDE finance group so far is a lib called alkimia 
which was set up by the KMyMoney people, which is awesome. There you 
find a very powerful class AlkValue for financial numbers. And this one 
has a constructor that parses a QString. Maybe that is already enough 
for parsing?!

About formatting, yes, QLocale is really limited, found that out during 
my KF5 porting actions of Kraft as well. Not only for currency, but also 
for dates.

>
> Do you know about any activities to improve QLocale here?
>
> Seems that Calligra apps Plan & Sheets are the only KDE apps using
> KLocale::readMoney() ?
> https://lxr.kde.org/ident?v=stable-qt4&_i=readMoney&_remember=1
>
> But KLocale::formatMoney() might be used by KMyMoney, Skrooge, Kraft &
> others (did not check though if not custom code):
> https://lxr.kde.org/ident?v=stable-qt4&_i=formatMoney&_remember=1

Yes, and I do not konw how to solve that yet. What you described above 
might be the best option, but, as said, doesn't that apply to dates as 
well?

On a site note, KDE4 Kraft can deal with two different Locales, the one 
it was started with, and one for the specific document. That way you can 
write a lets say dutch invoice on a german desktop. That is nice, but I 
almost decided to drop that feature for KF5. Would be great if I could 
keep it.

regards,

klaas




More information about the Kde-finance-apps mailing list