diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2011-02-25 15:08:57 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2011-02-25 17:51:26 (GMT) |
commit | 0c2ec3cef9f0a91b08d5103ac0bafd173f2a20df (patch) | |
tree | 76f7d93f5babfaae6fbeef8f62f26866c8b4108f /tests | |
parent | 08868df5e94a5b89d9f8ce904e97b43a48313fc1 (diff) | |
download | Qt-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 'tests')
-rw-r--r-- | tests/auto/qlocale/tst_qlocale.cpp | 6 | ||||
-rw-r--r-- | tests/manual/qlocale/currency.cpp | 29 | ||||
-rw-r--r-- | tests/manual/qlocale/currency.h | 4 |
3 files changed, 29 insertions, 10 deletions
diff --git a/tests/auto/qlocale/tst_qlocale.cpp b/tests/auto/qlocale/tst_qlocale.cpp index d1b7193..7a3e339 100644 --- a/tests/auto/qlocale/tst_qlocale.cpp +++ b/tests/auto/qlocale/tst_qlocale.cpp @@ -2159,9 +2159,15 @@ void tst_QLocale::currency() const QLocale de_DE("de_DE"); QCOMPARE(de_DE.toCurrencyString(qulonglong(1234)), QString::fromUtf8("1234\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(qulonglong(1234), QLatin1String("BAZ")), QString::fromUtf8("1234\xc2\xa0" "BAZ")); QCOMPARE(de_DE.toCurrencyString(qlonglong(-1234)), QString::fromUtf8("-1234\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(qlonglong(-1234), QLatin1String("BAZ")), QString::fromUtf8("-1234\xc2\xa0" "BAZ")); QCOMPARE(de_DE.toCurrencyString(double(1234.56)), QString::fromUtf8("1234,56\xc2\xa0\xe2\x82\xac")); QCOMPARE(de_DE.toCurrencyString(double(-1234.56)), QString::fromUtf8("-1234,56\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(double(-1234.56), QLatin1String("BAZ")), QString::fromUtf8("-1234,56\xc2\xa0" "BAZ")); + + const QLocale system = QLocale::system(); + QVERIFY(system.toCurrencyString(1, QLatin1String("FOO")).contains(QLatin1String("FOO"))); } void tst_QLocale::quoteString() diff --git a/tests/manual/qlocale/currency.cpp b/tests/manual/qlocale/currency.cpp index c55df3d..4ef157c 100644 --- a/tests/manual/qlocale/currency.cpp +++ b/tests/manual/qlocale/currency.cpp @@ -52,37 +52,48 @@ CurrencyWidget::CurrencyWidget() currencyName = new QLineEdit; currencyFormattingLabel = new QLabel("Currency formatting:"); currencyFormattingValue = new QLineEdit(QString::number(1234.56, 'f', 2)); + currencyFormattingSymbolLabel = new QLabel("currency:"); + currencyFormattingSymbol = new QLineEdit; currencyFormatting = new QLineEdit; + currencyFormattingValue->setFixedWidth(150); + currencyFormattingSymbol->setFixedWidth(50); + l->addWidget(currencySymbolLabel, 0, 0); - l->addWidget(currencySymbol, 0, 1, 1, 2); + l->addWidget(currencySymbol, 0, 1, 1, 4); l->addWidget(currencyISOLabel, 1, 0); - l->addWidget(currencyISO, 1, 1, 1, 2); + l->addWidget(currencyISO, 1, 1, 1, 4); l->addWidget(currencyNameLabel, 2, 0); - l->addWidget(currencyName, 2, 1, 1, 2); + l->addWidget(currencyName, 2, 1, 1, 4); l->addWidget(currencyFormattingLabel, 3, 0); l->addWidget(currencyFormattingValue, 3, 1); - l->addWidget(currencyFormatting, 3, 2); + l->addWidget(currencyFormattingSymbolLabel, 3, 2); + l->addWidget(currencyFormattingSymbol, 3, 3); + l->addWidget(currencyFormatting, 3, 4); QVBoxLayout *v = new QVBoxLayout(this); v->addLayout(l); v->addStretch(); + connect(currencyFormattingSymbol, SIGNAL(textChanged(QString)), + this, SLOT(updateCurrencyFormatting())); connect(currencyFormattingValue, SIGNAL(textChanged(QString)), - this, SLOT(updateCurrencyFormatting(QString))); + this, SLOT(updateCurrencyFormatting())); } -void CurrencyWidget::updateCurrencyFormatting(QString value) +void CurrencyWidget::updateCurrencyFormatting() { QString result; bool ok; + QString symbol = currencyFormattingSymbol->text(); + QString value = currencyFormattingValue->text(); int i = value.toInt(&ok); if (ok) { - result = locale().toCurrencyString(i); + result = locale().toCurrencyString(i, symbol); } else { double d = value.toDouble(&ok); if (ok) - result = locale().toCurrencyString(d); + result = locale().toCurrencyString(d, symbol); } currencyFormatting->setText(result); } @@ -93,6 +104,6 @@ void CurrencyWidget::localeChanged(QLocale locale) currencySymbol->setText(locale.currencySymbol()); currencyISO->setText(locale.currencySymbol(QLocale::CurrencyIsoCode)); currencyName->setText(locale.currencySymbol(QLocale::CurrencyDisplayName)); - updateCurrencyFormatting(currencyFormattingValue->text()); + updateCurrencyFormatting(); } diff --git a/tests/manual/qlocale/currency.h b/tests/manual/qlocale/currency.h index 5e43689..3a12553 100644 --- a/tests/manual/qlocale/currency.h +++ b/tests/manual/qlocale/currency.h @@ -58,11 +58,13 @@ private: QLineEdit *currencyName; QLabel *currencyFormattingLabel; QLineEdit *currencyFormattingValue; + QLabel *currencyFormattingSymbolLabel; + QLineEdit *currencyFormattingSymbol; QLineEdit *currencyFormatting; private slots: void localeChanged(QLocale locale); - void updateCurrencyFormatting(QString); + void updateCurrencyFormatting(); }; #endif |