diff --git a/plugins/declarative/declarativechart.cpp b/plugins/declarative/declarativechart.cpp index 3a9b8de..b5b74c7 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 58f19f4..600dbf5 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 95fbd06..fb9be95 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 ebc40ec..83c09fb 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 c5c1b34..35b32bc 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 d75d450..8c9cffe 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 fba3669..b103ed9 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 02233ca..337ad33 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);