From 98e0c04fe78da9735c2943524bd36648b2654f98 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 18 Sep 2014 13:49:23 +0300 Subject: Added possibility to change graph's locale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Locale affects how axis labels are formatted. Default locale is still the "C". Task-number: QTRD-3229 Change-Id: I6126ce676906f4bbc91ae0abd18775bc1d564118 Reviewed-by: Mika Salmela Reviewed-by: Tomi Korpipää --- .../axis/qvalue3daxisformatter.cpp | 40 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src/datavisualization/axis/qvalue3daxisformatter.cpp') diff --git a/src/datavisualization/axis/qvalue3daxisformatter.cpp b/src/datavisualization/axis/qvalue3daxisformatter.cpp index 56ca3b0f..f6b705a9 100644 --- a/src/datavisualization/axis/qvalue3daxisformatter.cpp +++ b/src/datavisualization/axis/qvalue3daxisformatter.cpp @@ -270,6 +270,28 @@ QStringList &QValue3DAxisFormatter::labelStrings() const return d_ptr->m_labelStrings; } +/*! + * Sets the \a locale that this formatter uses. + * The graph automatically sets the formatter's locale to a graph's locale whenever the parent axis + * is set as an active axis of the graph, the axis formatter is set to an axis attached to + * the graph, or the graph's locale changes. + * + * \sa locale(), QAbstract3DGraph::locale + */ +void QValue3DAxisFormatter::setLocale(const QLocale &locale) +{ + d_ptr->m_cLocaleInUse = (locale == QLocale::c()); + d_ptr->m_locale = locale; + markDirty(true); +} +/*! + * \return the current locale this formatter is using. + */ +QLocale QValue3DAxisFormatter::locale() const +{ + return d_ptr->m_locale; +} + // QValue3DAxisFormatterPrivate QValue3DAxisFormatterPrivate::QValue3DAxisFormatterPrivate(QValue3DAxisFormatter *q) : QObject(0), @@ -281,7 +303,10 @@ QValue3DAxisFormatterPrivate::QValue3DAxisFormatterPrivate(QValue3DAxisFormatter m_axis(0), m_preparsedParamType(Utils::ParamTypeUnknown), m_allowNegatives(true), - m_allowZero(true) + m_allowZero(true), + m_formatPrecision(6), // 6 and 'g' are defaults in Qt API for format precision and spec + m_formatSpec('g'), + m_cLocaleInUse(true) { } @@ -363,12 +388,19 @@ QString QValue3DAxisFormatterPrivate::stringForValue(qreal value, const QString { if (m_previousLabelFormat.compare(format)) { // Format string different than the previous one used, reparse it - m_previousLabelFormat = format; - m_preparsedParamType = Utils::findFormatParamType(format); m_labelFormatArray = format.toUtf8(); + m_previousLabelFormat = format; + m_preparsedParamType = Utils::preParseFormat(format, m_formatPreStr, m_formatPostStr, + m_formatPrecision, m_formatSpec); } - return Utils::formatLabel(m_labelFormatArray, m_preparsedParamType, value); + if (m_cLocaleInUse) { + return Utils::formatLabelSprintf(m_labelFormatArray, m_preparsedParamType, value); + } else { + return Utils::formatLabelLocalized(m_preparsedParamType, value, m_locale, m_formatPreStr, + m_formatPostStr, m_formatPrecision, m_formatSpec, + m_labelFormatArray); + } } float QValue3DAxisFormatterPrivate::positionAt(float value) const -- cgit v1.2.3