On 30/05/14 13:10, Thomas Baumgart wrote:
Allen,
On Friday 30 May 2014 12:25:10 Allan wrote:
Hi Thomas
On 30/05/14 07:00, Thomas Baumgart wrote:
Hi Allen,
On Thursday 29 May 2014 12:36:42 Allan wrote:
Previously, I dealt successfully with importing with a user's locale,
but now I'm hitting a problem.
I'm working on a patch to fix "[Bug 334995] CSV import Debit/Credit mode
only looks at one column, credits become 0.00". I have the patch
working for my own locale - UK. However, for other locales, I converted
my test file to use comma decimal and semi-colon separator. This is
giving me grief. What I'm trying to do is to convert a QString currency
amount to double, to be able to test if the amount is non-zero, as
against empty.
The basic problem came as a surprise, when I found that QString was not
locale-aware. I'm getting caught between QLocale and KLocale. I am
setting the country to, say, France. However, QLocale still seems to be
set to UK. Things seem to work if I set QLocale::default() to France,
but how do I know which country the user is in?
It looks like QLocale doesn't take account of KDE country change, but
retains the original system locale. How can I get the KDE locale to
give a country that QLocale will accept?
Or, am I missing the simple answer?
Doesn't KLocale::readMoney(const QString &numStr, bool * ok) work for you?
Sadly, no.
In the importer, when importing a comma symbol file, the comma becomes a
dot.
As a quick test, if I do -
bool OK;
KLocale* loc = KGlobal::locale();
QString str1 = "123.45";
QString str2 = "123,45";
qDebug()<<"QIFProc"<<(QString::number(loc->readMoney(str1, &OK),
'f', 2))<<loc->country()<<loc->countryCodeToName(loc->country());
qDebug()<<"QIFProc"<<loc->readMoney(str2)<<loc->country()<<loc->countryCodeT
oName(loc->country());
the first fails, and the second gives -
QIFProc "123.45" "fr" "France".
So, it's picking up my current locale of France, but converts to UK (my
normal locale) for some reason.
I can't see what I'm doing wrongly. Help!
I expect the first one fails, because the number does not match the format
required by the locale (French).
The second one is a bit tricky:
loc->readMoney() is supposed to return a double. Using that one in a debug
stream as you do, uses the standard Qt functions to convert it into a string
(I doubt they are locale aware). So I expect the problem to be right there.
What happens, if you use
qDebug() << QLocale::toCurrencyString(loc->readMoney(str, ok));
or
qDebug() << QLocale::toString(loc->readMoney(str, ok), 'f', 2);
Does that print the value with a comma? Or stick with KLocale::formatMoney().
I am really not sure, what you try to achieve.
I need to convert a monetary string to double in order to test if it is
zero, or empty. Previously, when there was either a valid debit or
credit value, I didn't take the other field into account. This bug was
from a file where instead of the 'other' field being empty, it contained
a zero value. I could replace the zero with empty, but I've been trying
to detect it to warn the user before clearing it.
QLocale::toCurrencyString or QLocale::toString(loc->readMoney won't work
as they are not static, so I had to provide an object. This goes back
to my original problem, though. I need to create a default QLocale, but
I can't do that as I don't know what country I'm running in. I can get
the KLocale locale setting, but can't convert that to a QLocale.
Roll on Qt5.FW5, at least I hope.
Either I need to work round this issue, or resort to symbol
substitution, I think.
Allan
_______________________________________________
KMyMoney-devel mailing list
KMyMoney-devel@kde.org
https://mail.kde.org/mailman/listinfo/kmymoney-devel