summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-09-17 13:35:28 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-09-17 13:49:00 +0300
commit682630e62d588dace079a717e6cd4e43275a2db4 (patch)
treeabf36dd0c6663143e429f7872eaba998160ae875 /src
parentb421e87aa00a7a93dd0cbf88ad7ec5884c884f7c (diff)
Additional fixes to label localization
- The default bar/boxplot categories were not localized. - Might as well support "%i" format, as it is equivalent to "%d", and some of our own examples use it. - If precision is not specified in the label format, default to six instead of zero. Change-Id: I937b6a76128fc506d8db4b9974569e590d85ac5f Reviewed-by: Titta Heikkala <titta.heikkala@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/axis/chartaxiselement.cpp12
-rw-r--r--src/axis/valueaxis/qvalueaxis.cpp4
-rw-r--r--src/barchart/qabstractbarseries.cpp2
-rw-r--r--src/boxplotchart/qboxplotseries.cpp2
-rw-r--r--src/chartpresenter.cpp8
-rw-r--r--src/chartpresenter_p.h1
6 files changed, 20 insertions, 9 deletions
diff --git a/src/axis/chartaxiselement.cpp b/src/axis/chartaxiselement.cpp
index fb9be950..310555e7 100644
--- a/src/axis/chartaxiselement.cpp
+++ b/src/axis/chartaxiselement.cpp
@@ -29,7 +29,7 @@
QTCOMMERCIALCHART_BEGIN_NAMESPACE
static const char *labelFormatMatchString = "%[\\-\\+#\\s\\d\\.lhjztL]*([dicuoxfegXFEG])";
-static const char *labelFormatMatchLocalizedString = "^([^%]*)%\\.?(\\d)*([defgEG])(.*)$";
+static const char *labelFormatMatchLocalizedString = "^([^%]*)%\\.?(\\d)*([defgiEG])(.*)$";
static QRegExp *labelFormatMatcher = 0;
static QRegExp *labelFormatMatcherLocalized = 0;
class StaticLabelFormatMatcherDeleter
@@ -295,13 +295,14 @@ QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks,
QString formatSpec;
QString preStr;
QString postStr;
- int precision = 0;
+ int precision = 6; // Six is the default precision in Qt API
if (presenter()->localizeNumbers()) {
if (!labelFormatMatcherLocalized)
labelFormatMatcherLocalized = new QRegExp(labelFormatMatchLocalizedString);
if (labelFormatMatcherLocalized->indexIn(format, 0) != -1) {
preStr = labelFormatMatcherLocalized->cap(1);
- precision = labelFormatMatcherLocalized->cap(2).toInt();
+ if (!labelFormatMatcherLocalized->cap(2).isEmpty())
+ precision = labelFormatMatcherLocalized->cap(2).toInt();
formatSpec = labelFormatMatcherLocalized->cap(3);
postStr = labelFormatMatcherLocalized->cap(4);
}
@@ -348,13 +349,14 @@ QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal b
QString formatSpec;
QString preStr;
QString postStr;
- int precision = 0;
+ int precision = 6; // Six is the default precision in Qt API
if (presenter()->localizeNumbers()) {
if (!labelFormatMatcherLocalized)
labelFormatMatcherLocalized = new QRegExp(labelFormatMatchLocalizedString);
if (labelFormatMatcherLocalized->indexIn(format, 0) != -1) {
preStr = labelFormatMatcherLocalized->cap(1);
- precision = labelFormatMatcherLocalized->cap(2).toInt();
+ if (!labelFormatMatcherLocalized->cap(2).isEmpty())
+ precision = labelFormatMatcherLocalized->cap(2).toInt();
formatSpec = labelFormatMatcherLocalized->cap(3);
postStr = labelFormatMatcherLocalized->cap(4);
}
diff --git a/src/axis/valueaxis/qvalueaxis.cpp b/src/axis/valueaxis/qvalueaxis.cpp
index d76bb0fe..8656ebd4 100644
--- a/src/axis/valueaxis/qvalueaxis.cpp
+++ b/src/axis/valueaxis/qvalueaxis.cpp
@@ -110,7 +110,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE
See QString::sprintf() for additional details.
If the QChart::localizeNumbers is \c{true}, the supported specifiers are limited to: d, e, E, f,
- g, and G. Also, only the precision modifier is supported. The rest of the formatting comes from
+ g, G, and i. Also, only the precision modifier is supported. The rest of the formatting comes from
the default QLocale of the application.
*/
/*!
@@ -120,7 +120,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE
See QString::sprintf() for additional details.
If the ChartView::localizeNumbers is \c{true}, the supported specifiers are limited to: d, e, E, f,
- g, and G. Also, only the precision modifier is supported. The rest of the formatting comes from
+ g, G, and i. Also, only the precision modifier is supported. The rest of the formatting comes from
the default QLocale of the application.
*/
diff --git a/src/barchart/qabstractbarseries.cpp b/src/barchart/qabstractbarseries.cpp
index 6b40197e..564ee3a6 100644
--- a/src/barchart/qabstractbarseries.cpp
+++ b/src/barchart/qabstractbarseries.cpp
@@ -950,7 +950,7 @@ void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
QStringList categories;
if (axis->categories().isEmpty()) {
for (int i(1); i < categoryCount() + 1; i++)
- categories << QString::number(i);
+ categories << presenter()->numberToString(i);
axis->append(categories);
}
}
diff --git a/src/boxplotchart/qboxplotseries.cpp b/src/boxplotchart/qboxplotseries.cpp
index c645d864..4f562d79 100644
--- a/src/boxplotchart/qboxplotseries.cpp
+++ b/src/boxplotchart/qboxplotseries.cpp
@@ -418,7 +418,7 @@ void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
for (int i(1); i < m_boxSets.count() + 1; i++) {
QBoxSet *set = m_boxSets.at(i - 1);
if (set->label().isEmpty())
- categories << QString::number(i);
+ categories << presenter()->numberToString(i);
else
categories << set->label();
}
diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp
index 35b32bc2..619f400f 100644
--- a/src/chartpresenter.cpp
+++ b/src/chartpresenter.cpp
@@ -496,6 +496,14 @@ QString ChartPresenter::numberToString(double value, char f, int prec)
return QString::number(value, f, prec);
}
+QString ChartPresenter::numberToString(int value)
+{
+ if (m_localizeNumbers)
+ return m_locale.toString(value);
+ else
+ return QString::number(value);
+}
+
#include "moc_chartpresenter_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE
diff --git a/src/chartpresenter_p.h b/src/chartpresenter_p.h
index 8c9cffe4..c72a12d6 100644
--- a/src/chartpresenter_p.h
+++ b/src/chartpresenter_p.h
@@ -156,6 +156,7 @@ public:
inline static qreal textMargin() { return qreal(0.5); }
QString numberToString(double value, char f = 'g', int prec = 6);
+ QString numberToString(int value);
private:
void createBackgroundItem();