summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlocale.cpp
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2011-02-25 15:08:57 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2011-02-25 17:51:26 (GMT)
commit0c2ec3cef9f0a91b08d5103ac0bafd173f2a20df (patch)
tree76f7d93f5babfaae6fbeef8f62f26866c8b4108f /src/corelib/tools/qlocale.cpp
parent08868df5e94a5b89d9f8ce904e97b43a48313fc1 (diff)
downloadQt-0c2ec3cef9f0a91b08d5103ac0bafd173f2a20df.zip
Qt-0c2ec3cef9f0a91b08d5103ac0bafd173f2a20df.tar.gz
Qt-0c2ec3cef9f0a91b08d5103ac0bafd173f2a20df.tar.bz2
Improved currency value to string conversion in QLocale.
Added a second, optional, argument to QLocale::toCurrencyString() that represents a currency symbol that is supposed to be added to the formatted string. Task-number: QTBUG-17100 Reviewed-by: Zeno Albisser Reviewed-by: Olivier Goffart
Diffstat (limited to 'src/corelib/tools/qlocale.cpp')
-rw-r--r--src/corelib/tools/qlocale.cpp58
1 files changed, 34 insertions, 24 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index 5027d00..4925129 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -2802,7 +2802,7 @@ qulonglong QLocalePrivate::bytearrayToUnsLongLong(const char *num, int base, boo
/*!
\since 4.8
- \enum QLocale::CurrencyFormat
+ \enum QLocale::CurrencySymbolFormat
Specifies the format of the currency symbol.
@@ -2847,30 +2847,30 @@ QString QLocale::currencySymbol(QLocale::CurrencySymbolFormat format) const
}
/*!
- \fn QString QLocale::toCurrencyString(short) const
+ \fn QString QLocale::toCurrencyString(short, const QString &) const
\since 4.8
\overload
*/
/*!
- \fn QString QLocale::toCurrencyString(ushort) const
+ \fn QString QLocale::toCurrencyString(ushort, const QString &) const
\since 4.8
\overload
*/
/*!
- \fn QString QLocale::toCurrencyString(int) const
+ \fn QString QLocale::toCurrencyString(int, const QString &) const
\since 4.8
\overload
*/
/*!
- \fn QString QLocale::toCurrencyString(uint) const
+ \fn QString QLocale::toCurrencyString(uint, const QString &) const
\since 4.8
\overload
*/
/*!
- \fn QString QLocale::toCurrencyString(float) const
+ \fn QString QLocale::toCurrencyString(float, const QString &) const
\since 4.8
\overload
*/
@@ -2879,12 +2879,16 @@ QString QLocale::currencySymbol(QLocale::CurrencySymbolFormat format) const
\since 4.8
Returns a localized string representation of \a value as a currency.
+ If the \a symbol is provided it is used instead of the default currency symbol.
+
+ \sa currencySymbol
*/
-QString QLocale::toCurrencyString(qlonglong value) const
+QString QLocale::toCurrencyString(qlonglong value, const QString &symbol) const
{
#ifndef QT_NO_SYSTEMLOCALE
if (d() == systemPrivate()) {
- QVariant res = systemLocale()->query(QSystemLocale::CurrencyToString, value);
+ QSystemLocale::CurrencyToStringArgument arg(value, symbol);
+ QVariant res = systemLocale()->query(QSystemLocale::CurrencyToString, QVariant::fromValue(arg));
if (!res.isNull())
return res.toString();
}
@@ -2898,22 +2902,23 @@ QString QLocale::toCurrencyString(qlonglong value) const
value = -value;
}
QString str = d->longLongToString(value);
- QString symbol = currencySymbol();
- if (symbol.isEmpty())
- symbol = currencySymbol(QLocale::CurrencyIsoCode);
+ QString sym = symbol.isEmpty() ? currencySymbol() : symbol;
+ if (sym.isEmpty())
+ sym = currencySymbol(QLocale::CurrencyIsoCode);
QString format = getLocaleData(currency_format_data + idx, size);
- return format.arg(str, symbol);
+ return format.arg(str, sym);
}
/*!
\since 4.8
\overload
*/
-QString QLocale::toCurrencyString(qulonglong value) const
+QString QLocale::toCurrencyString(qulonglong value, const QString &symbol) const
{
#ifndef QT_NO_SYSTEMLOCALE
if (d() == systemPrivate()) {
- QVariant res = systemLocale()->query(QSystemLocale::CurrencyToString, value);
+ QSystemLocale::CurrencyToStringArgument arg(value, symbol);
+ QVariant res = systemLocale()->query(QSystemLocale::CurrencyToString, QVariant::fromValue(arg));
if (!res.isNull())
return res.toString();
}
@@ -2922,18 +2927,23 @@ QString QLocale::toCurrencyString(qulonglong value) const
quint8 idx = d->m_currency_format_idx;
quint8 size = d->m_currency_format_size;
QString str = d->unsLongLongToString(value);
- QString symbol = currencySymbol();
- if (symbol.isEmpty())
- symbol = currencySymbol(QLocale::CurrencyIsoCode);
+ QString sym = symbol.isEmpty() ? currencySymbol() : symbol;
+ if (sym.isEmpty())
+ sym = currencySymbol(QLocale::CurrencyIsoCode);
QString format = getLocaleData(currency_format_data + idx, size);
- return format.arg(str, symbol);
+ return format.arg(str, sym);
}
-QString QLocale::toCurrencyString(double value) const
+/*!
+ \since 4.8
+ \overload
+*/
+QString QLocale::toCurrencyString(double value, const QString &symbol) const
{
#ifndef QT_NO_SYSTEMLOCALE
if (d() == systemPrivate()) {
- QVariant res = systemLocale()->query(QSystemLocale::CurrencyToString, value);
+ QSystemLocale::CurrencyToStringArgument arg(value, symbol);
+ QVariant res = systemLocale()->query(QSystemLocale::CurrencyToString, QVariant::fromValue(arg));
if (!res.isNull())
return res.toString();
}
@@ -2948,11 +2958,11 @@ QString QLocale::toCurrencyString(double value) const
}
QString str = d->doubleToString(value, d->m_currency_digits,
QLocalePrivate::DFDecimal);
- QString symbol = currencySymbol();
- if (symbol.isEmpty())
- symbol = currencySymbol(QLocale::CurrencyIsoCode);
+ QString sym = symbol.isEmpty() ? currencySymbol() : symbol;
+ if (sym.isEmpty())
+ sym = currencySymbol(QLocale::CurrencyIsoCode);
QString format = getLocaleData(currency_format_data + idx, size);
- return format.arg(str, symbol);
+ return format.arg(str, sym);
}
/*!