summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-09-17 12:44:36 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-09-17 13:35:01 +0300
commitb421e87aa00a7a93dd0cbf88ad7ec5884c884f7c (patch)
tree5dccfce1a09fac9610d1e1526f4a9f4b8d7e012d
parentef2ab40bd1b9233ef398d0e6207d8537d2cd3b1a (diff)
Added QChart::locale property
This locale is used for localizing the numbers on various labels when localizeNumbers is set to true. It is also the locale that QDateTimeAxis labels use for month and day names. Task-number: QTRD-3179 Change-Id: Ib9a9cad770c5a6890311fe45a1d4cabd5f40aff4 Reviewed-by: Mika Salmela <mika.salmela@digia.com>
-rw-r--r--plugins/declarative/declarativechart.cpp2
-rw-r--r--plugins/declarative/declarativechart.h2
-rw-r--r--src/axis/chartaxiselement.cpp2
-rw-r--r--src/axis/datetimeaxis/qdatetimeaxis.cpp2
-rw-r--r--src/chartpresenter.cpp8
-rw-r--r--src/chartpresenter_p.h5
-rw-r--r--src/qchart.cpp29
-rw-r--r--src/qchart.h3
8 files changed, 42 insertions, 11 deletions
diff --git a/plugins/declarative/declarativechart.cpp b/plugins/declarative/declarativechart.cpp
index 3a9b8de3..b5b74c7c 100644
--- a/plugins/declarative/declarativechart.cpp
+++ b/plugins/declarative/declarativechart.cpp
@@ -180,7 +180,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE
When \c{true}, all generated numbers appearing in various series and axis labels will be
localized using the default QLocale of the application, which defaults to the system locale.
When \c{false}, the "C" locale is always used.
- Defaults to \c{false}.
+ Defaults to \c{true}.
*/
/*!
diff --git a/plugins/declarative/declarativechart.h b/plugins/declarative/declarativechart.h
index 58f19f40..600dbf5c 100644
--- a/plugins/declarative/declarativechart.h
+++ b/plugins/declarative/declarativechart.h
@@ -200,7 +200,7 @@ Q_SIGNALS:
void seriesRemoved(QAbstractSeries *series);
Q_REVISION(3) void plotAreaColorChanged();
Q_REVISION(3) void backgroundRoundnessChanged(qreal diameter);
- Q_REVISION(4) bool localizeNumbersChanged();
+ Q_REVISION(4) void localizeNumbersChanged();
private Q_SLOTS:
void changeMinimumMargins(int top, int bottom, int left, int right);
diff --git a/src/axis/chartaxiselement.cpp b/src/axis/chartaxiselement.cpp
index 95fbd062..fb9be950 100644
--- a/src/axis/chartaxiselement.cpp
+++ b/src/axis/chartaxiselement.cpp
@@ -385,7 +385,7 @@ QStringList ChartAxisElement::createDateTimeLabels(qreal min, qreal max,int tick
n++;
for (int i = 0; i < ticks; i++) {
qreal value = min + (i * (max - min) / (ticks - 1));
- labels << QDateTime::fromMSecsSinceEpoch(value).toString(format);
+ labels << presenter()->locale().toString(QDateTime::fromMSecsSinceEpoch(value), format);
}
return labels;
}
diff --git a/src/axis/datetimeaxis/qdatetimeaxis.cpp b/src/axis/datetimeaxis/qdatetimeaxis.cpp
index ebc40ecd..83c09fbb 100644
--- a/src/axis/datetimeaxis/qdatetimeaxis.cpp
+++ b/src/axis/datetimeaxis/qdatetimeaxis.cpp
@@ -149,6 +149,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE
\property QDateTimeAxis::format
The format string that is used when creating label for the axis out of a QDateTime object.
Check QDateTime documentation for information on how the string should be defined.
+
+ \sa QChart::locale
*/
/*!
\qmlproperty string DateTimeAxis::format
diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp
index c5c1b34f..35b32bc2 100644
--- a/src/chartpresenter.cpp
+++ b/src/chartpresenter.cpp
@@ -45,7 +45,7 @@ ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type)
m_background(0),
m_plotAreaBackground(0),
m_title(0),
- m_localizeNumbers(false)
+ m_localizeNumbers(true)
{
if (type == QChart::ChartTypeCartesian)
m_layout = new CartesianChartLayout(this);
@@ -352,12 +352,12 @@ void ChartPresenter::setLocalizeNumbers(bool localize)
m_layout->invalidate();
}
-bool ChartPresenter::localizeNumbers() const
+void ChartPresenter::setLocale(const QLocale &locale)
{
- return m_localizeNumbers;
+ m_locale = locale;
+ m_layout->invalidate();
}
-
AbstractChartLayout *ChartPresenter::layout()
{
return m_layout;
diff --git a/src/chartpresenter_p.h b/src/chartpresenter_p.h
index d75d450e..8c9cffe4 100644
--- a/src/chartpresenter_p.h
+++ b/src/chartpresenter_p.h
@@ -131,7 +131,9 @@ public:
bool isBackgroundDropShadowEnabled() const;
void setLocalizeNumbers(bool localize);
- bool localizeNumbers() const;
+ inline bool localizeNumbers() const { return m_localizeNumbers; }
+ void setLocale(const QLocale &locale);
+ inline const QLocale &locale() const { return m_locale; }
void setVisible(bool visible);
@@ -154,7 +156,6 @@ public:
inline static qreal textMargin() { return qreal(0.5); }
QString numberToString(double value, char f = 'g', int prec = 6);
- inline const QLocale &locale() const { return m_locale; }
private:
void createBackgroundItem();
diff --git a/src/qchart.cpp b/src/qchart.cpp
index fba3669f..b103ed9b 100644
--- a/src/qchart.cpp
+++ b/src/qchart.cpp
@@ -148,9 +148,24 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE
\property QChart::localizeNumbers
\since QtCharts 2.0
When \c{true}, all generated numbers appearing in various series and axis labels will be
- localized using the default QLocale of the application, which defaults to the system locale.
+ localized using the QLocale set with the locale property.
When \c{false}, the "C" locale is always used.
- Defaults to \c{false}.
+ Defaults to \c{true}.
+ \note This property doesn't affect QDateTimeAxis labels, which always use the QLocale set with
+ the locale property.
+
+ \sa locale
+*/
+
+/*!
+ \property QChart::locale
+ \since QtCharts 2.0
+ Sets the locale used to format various chart labels when localizeNumbers is \c{true}.
+ This also determines the locale used to format QDateTimeAxis labels regardless of
+ localizeNumbers property.
+ Defaults to application default locale at the time the chart is constructed.
+
+ \sa localizeNumbers
*/
/*!
@@ -580,6 +595,16 @@ bool QChart::localizeNumbers() const
return d_ptr->m_presenter->localizeNumbers();
}
+void QChart::setLocale(const QLocale &locale)
+{
+ d_ptr->m_presenter->setLocale(locale);
+}
+
+QLocale QChart::locale() const
+{
+ return d_ptr->m_presenter->locale();
+}
+
void QChart::setAnimationOptions(AnimationOptions options)
{
d_ptr->m_presenter->setAnimationOptions(options);
diff --git a/src/qchart.h b/src/qchart.h
index 02233ca5..337ad33a 100644
--- a/src/qchart.h
+++ b/src/qchart.h
@@ -50,6 +50,7 @@ class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
Q_PROPERTY(QChart::ChartType chartType READ chartType)
Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible)
Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers)
+ Q_PROPERTY(QLocale locale READ locale WRITE setLocale)
Q_ENUMS(ChartTheme)
Q_ENUMS(AnimationOption)
Q_ENUMS(ChartType)
@@ -154,6 +155,8 @@ public:
bool isPlotAreaBackgroundVisible() const;
void setLocalizeNumbers(bool localize);
bool localizeNumbers() const;
+ void setLocale(const QLocale &locale);
+ QLocale locale() const;
QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0);
QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0);