summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/axis
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-09-18 13:49:23 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-09-19 09:14:13 +0300
commit98e0c04fe78da9735c2943524bd36648b2654f98 (patch)
tree3c711ff622e0fb43b358982fb815065e12d49af0 /src/datavisualization/axis
parent0c11550bed204807b8b366fd07862a5da9cd2251 (diff)
Added possibility to change graph's locale
Locale affects how axis labels are formatted. Default locale is still the "C". Task-number: QTRD-3229 Change-Id: I6126ce676906f4bbc91ae0abd18775bc1d564118 Reviewed-by: Mika Salmela <mika.salmela@digia.com> Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/axis')
-rw-r--r--src/datavisualization/axis/qvalue3daxis.cpp24
-rw-r--r--src/datavisualization/axis/qvalue3daxisformatter.cpp40
-rw-r--r--src/datavisualization/axis/qvalue3daxisformatter.h4
-rw-r--r--src/datavisualization/axis/qvalue3daxisformatter_p.h8
4 files changed, 70 insertions, 6 deletions
diff --git a/src/datavisualization/axis/qvalue3daxis.cpp b/src/datavisualization/axis/qvalue3daxis.cpp
index 8207174f..3b9c9e3d 100644
--- a/src/datavisualization/axis/qvalue3daxis.cpp
+++ b/src/datavisualization/axis/qvalue3daxis.cpp
@@ -18,6 +18,7 @@
#include "qvalue3daxis_p.h"
#include "qvalue3daxisformatter_p.h"
+#include "abstract3dcontroller_p.h"
QT_BEGIN_NAMESPACE_DATAVISUALIZATION
@@ -68,8 +69,16 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
/*!
* \qmlproperty string ValueAxis3D::labelFormat
*
- * Defines the label format to be used for the labels on this axis. Supported specifiers are:
+ * Defines the label format to be used for the labels on this axis. How the format is interpreted
+ * depends on the axis formatter and the locale in use. Using the default formatter and default
+ * locale (\c{"C"}), the formatting uses QString::sprintf(). Supported specifiers are:
* \c {d, i, o, x, X, f, F, e, E, g, G, c}. See QString::sprintf() for additional details.
+ * For other locales, the default formatter uses reduced set of printf format specifiers:
+ * \c {d, i, f, F, e, E, g, G}. In these cases, the only supported modifier is the precision
+ * modifier for the floating point and exponential formats. The decimal point and other locale
+ * dependent formatting is done according to the graph locale.
+ *
+ * \sa AbstractGraph3D::locale
*/
/*!
@@ -164,12 +173,20 @@ int QValue3DAxis::subSegmentCount() const
/*!
* \property QValue3DAxis::labelFormat
*
- * Defines the label \a format to be used for the labels on this axis. Supported specifiers are:
+ * Defines the label format to be used for the labels on this axis. How the format is interpreted
+ * depends on the axis formatter and the locale in use. Using the default formatter and default
+ * locale (\c{"C"}), the formatting uses QString::sprintf(). Supported specifiers are:
* \c {d, i, o, x, X, f, F, e, E, g, G, c}. See QString::sprintf() for additional details.
+ * For other locales, the default formatter uses reduced set of printf format specifiers:
+ * \c {d, i, f, F, e, E, g, G}. In these cases, the only supported modifier is the precision
+ * modifier for the floating point and exponential formats. The decimal point and other locale
+ * dependent formatting is done according to the graph locale.
*
* Usage example:
*
* \c {axis->setLabelFormat("%.2f mm");}
+ *
+ * \sa formatter, QAbstract3DGraph::locale
*/
void QValue3DAxis::setLabelFormat(const QString &format)
{
@@ -201,6 +218,9 @@ void QValue3DAxis::setFormatter(QValue3DAxisFormatter *formatter)
dptr()->m_formatter = formatter;
formatter->setParent(this);
formatter->d_ptr->setAxis(this);
+ Abstract3DController *controller = qobject_cast<Abstract3DController *>(parent());
+ if (controller)
+ formatter->setLocale(controller->locale());
emit formatterChanged(formatter);
emit dptr()->formatterDirty();
}
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
diff --git a/src/datavisualization/axis/qvalue3daxisformatter.h b/src/datavisualization/axis/qvalue3daxisformatter.h
index c7b0bac5..82e49f21 100644
--- a/src/datavisualization/axis/qvalue3daxisformatter.h
+++ b/src/datavisualization/axis/qvalue3daxisformatter.h
@@ -24,6 +24,7 @@
#include <QtCore/QScopedPointer>
#include <QtCore/QVector>
#include <QtCore/QStringList>
+#include <QtCore/QLocale>
QT_BEGIN_NAMESPACE_DATAVISUALIZATION
@@ -60,6 +61,9 @@ protected:
QVector<float> &labelPositions() const;
QStringList &labelStrings() const;
+ void setLocale(const QLocale &locale);
+ QLocale locale() const;
+
QScopedPointer<QValue3DAxisFormatterPrivate> d_ptr;
private:
diff --git a/src/datavisualization/axis/qvalue3daxisformatter_p.h b/src/datavisualization/axis/qvalue3daxisformatter_p.h
index 2d1dc920..9571d001 100644
--- a/src/datavisualization/axis/qvalue3daxisformatter_p.h
+++ b/src/datavisualization/axis/qvalue3daxisformatter_p.h
@@ -32,6 +32,7 @@
#include "datavisualizationglobal_p.h"
#include "qvalue3daxisformatter.h"
#include "utils_p.h"
+#include <QtCore/QLocale>
QT_BEGIN_NAMESPACE_DATAVISUALIZATION
@@ -83,6 +84,13 @@ protected:
bool m_allowNegatives;
bool m_allowZero;
+ QLocale m_locale;
+ QString m_formatPreStr;
+ QString m_formatPostStr;
+ int m_formatPrecision;
+ char m_formatSpec;
+ bool m_cLocaleInUse;
+
friend class QValue3DAxisFormatter;
};