diff --git a/plugins/declarative/declarativechart.cpp b/plugins/declarative/declarativechart.cpp index a903708..3a9b8de 100644 --- a/plugins/declarative/declarativechart.cpp +++ b/plugins/declarative/declarativechart.cpp @@ -175,6 +175,15 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \qmlproperty bool ChartView::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. + When \c{false}, the "C" locale is always used. + Defaults to \c{false}. +*/ + +/*! \qmlmethod AbstractSeries ChartView::series(int index) Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with the count property of the chart. @@ -710,6 +719,19 @@ QColor QtCommercialChart::DeclarativeChart::plotAreaColor() return m_chart->plotAreaBackgroundBrush().color(); } +void DeclarativeChart::setLocalizeNumbers(bool localize) +{ + if (m_chart->localizeNumbers() != localize) { + m_chart->setLocalizeNumbers(localize); + emit localizeNumbersChanged(); + } +} + +bool DeclarativeChart::localizeNumbers() const +{ + return m_chart->localizeNumbers(); +} + int DeclarativeChart::count() { return m_chart->series().count(); diff --git a/plugins/declarative/declarativechart.h b/plugins/declarative/declarativechart.h index dee1855..58f19f4 100644 --- a/plugins/declarative/declarativechart.h +++ b/plugins/declarative/declarativechart.h @@ -67,6 +67,7 @@ class DeclarativeChart : public QDECLARATIVE_PAINTED_ITEM #else Q_PROPERTY(QDeclarativeListProperty axes READ axes REVISION 2) #endif + Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers NOTIFY localizeNumbersChanged REVISION 4) Q_ENUMS(Animation) Q_ENUMS(Theme) Q_ENUMS(SeriesType) @@ -142,6 +143,9 @@ public: QColor backgroundColor(); Q_REVISION(3) void setPlotAreaColor(QColor color); Q_REVISION(3) QColor plotAreaColor(); + Q_REVISION(4) void setLocalizeNumbers(bool localize); + Q_REVISION(4) bool localizeNumbers() const; + int count(); void setDropShadowEnabled(bool enabled); bool dropShadowEnabled(); @@ -196,6 +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(); private Q_SLOTS: void changeMinimumMargins(int top, int bottom, int left, int right); diff --git a/plugins/declarative/plugin.cpp b/plugins/declarative/plugin.cpp index 9fc4760..6498456 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -258,6 +258,7 @@ public: qmlRegisterType(uri, 2, 0, "VBoxPlotModelMapper"); qmlRegisterUncreatableType(uri, 2, 0, "BoxPlotModelMapper", QLatin1String("Trying to create uncreatable: BoxPlotModelMapper.")); + qmlRegisterType(uri, 2, 0, "ChartView"); } }; diff --git a/src/areachart/areachartitem.cpp b/src/areachart/areachartitem.cpp index 8b07db2..eec37e8 100644 --- a/src/areachart/areachartitem.cpp +++ b/src/areachart/areachartitem.cpp @@ -201,8 +201,10 @@ void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt if (m_series->upperSeries()) { for (int i(0); i < m_series->upperSeries()->count(); i++) { - pointLabel.replace(xPointTag, QString::number(m_series->upperSeries()->at(i).x())); - pointLabel.replace(yPointTag, QString::number(m_series->upperSeries()->at(i).y())); + pointLabel.replace(xPointTag, + presenter()->numberToString(m_series->upperSeries()->at(i).x())); + pointLabel.replace(yPointTag, + presenter()->numberToString(m_series->upperSeries()->at(i).y())); // Position text in relation to the point int pointLabelWidth = fm.width(pointLabel); @@ -216,8 +218,10 @@ void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt if (m_series->lowerSeries()) { for (int i(0); i < m_series->lowerSeries()->count(); i++) { - pointLabel.replace(xPointTag, QString::number(m_series->lowerSeries()->at(i).x())); - pointLabel.replace(yPointTag, QString::number(m_series->lowerSeries()->at(i).y())); + pointLabel.replace(xPointTag, + presenter()->numberToString(m_series->lowerSeries()->at(i).x())); + pointLabel.replace(yPointTag, + presenter()->numberToString(m_series->lowerSeries()->at(i).y())); // Position text in relation to the point int pointLabelWidth = fm.width(pointLabel); diff --git a/src/axis/chartaxiselement.cpp b/src/axis/chartaxiselement.cpp index 6657cfe..95fbd06 100644 --- a/src/axis/chartaxiselement.cpp +++ b/src/axis/chartaxiselement.cpp @@ -29,12 +29,17 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE static const char *labelFormatMatchString = "%[\\-\\+#\\s\\d\\.lhjztL]*([dicuoxfegXFEG])"; +static const char *labelFormatMatchLocalizedString = "^([^%]*)%\\.?(\\d)*([defgEG])(.*)$"; static QRegExp *labelFormatMatcher = 0; +static QRegExp *labelFormatMatcherLocalized = 0; class StaticLabelFormatMatcherDeleter { public: StaticLabelFormatMatcherDeleter() {} - ~StaticLabelFormatMatcherDeleter() { delete labelFormatMatcher; } + ~StaticLabelFormatMatcherDeleter() { + delete labelFormatMatcher; + delete labelFormatMatcherLocalized; + } }; static StaticLabelFormatMatcherDeleter staticLabelFormatMatcherDeleter; @@ -233,75 +238,96 @@ qreal ChartAxisElement::max() const return m_axis->d_ptr->max(); } -static void appendFormattedLabel(const QString &capStr, const QByteArray &array, - QStringList &labels, qreal value) +QString ChartAxisElement::formatLabel(const QString &formatSpec, const QByteArray &array, + qreal value, int precision, const QString &preStr, + const QString &postStr) const { - if (capStr.isEmpty()) { - labels << QString(); - } else if (capStr.at(0) == QLatin1Char('d') - || capStr.at(0) == QLatin1Char('i') - || capStr.at(0) == QLatin1Char('c')) { - labels << QString().sprintf(array, (qint64)value); - } else if (capStr.at(0) == QLatin1Char('u') - || capStr.at(0) == QLatin1Char('o') - || capStr.at(0) == QLatin1Char('x') - || capStr.at(0) == QLatin1Char('X')) { - labels << QString().sprintf(array, (quint64)value); - } else if (capStr.at(0) == QLatin1Char('f') - || capStr.at(0) == QLatin1Char('F') - || capStr.at(0) == QLatin1Char('e') - || capStr.at(0) == QLatin1Char('E') - || capStr.at(0) == QLatin1Char('g') - || capStr.at(0) == QLatin1Char('G')) { - labels << QString().sprintf(array, value); - } else { - labels << QString(); + QString retVal; + if (!formatSpec.isEmpty()) { + if (formatSpec.at(0) == QLatin1Char('d') + || formatSpec.at(0) == QLatin1Char('i') + || formatSpec.at(0) == QLatin1Char('c')) { + if (presenter()->localizeNumbers()) + retVal = preStr + presenter()->locale().toString(qint64(value)) + postStr; + else + retVal = QString().sprintf(array, qint64(value)); + } else if (formatSpec.at(0) == QLatin1Char('u') + || formatSpec.at(0) == QLatin1Char('o') + || formatSpec.at(0) == QLatin1Char('x') + || formatSpec.at(0) == QLatin1Char('X')) { + // These formats are not supported by localized numbers + retVal = QString().sprintf(array, quint64(value)); + } else if (formatSpec.at(0) == QLatin1Char('f') + || formatSpec.at(0) == QLatin1Char('F') + || formatSpec.at(0) == QLatin1Char('e') + || formatSpec.at(0) == QLatin1Char('E') + || formatSpec.at(0) == QLatin1Char('g') + || formatSpec.at(0) == QLatin1Char('G')) { + if (presenter()->localizeNumbers()) { + retVal = preStr + + presenter()->locale().toString(value, formatSpec.at(0).toLatin1(), + precision) + + postStr; + } else { + retVal = QString().sprintf(array, value); + } + } } + return retVal; } -QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, const QString &format) +QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, + const QString &format) const { QStringList labels; if (max <= min || ticks < 1) return labels; - int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); - n++; - if (format.isNull()) { + int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0) + 1; for (int i = 0; i < ticks; i++) { qreal value = min + (i * (max - min) / (ticks - 1)); - labels << QString::number(value, 'f', n); + labels << presenter()->numberToString(value, 'f', n); } } else { QByteArray array = format.toLatin1(); - QString capStr; - if (!labelFormatMatcher) - labelFormatMatcher = new QRegExp(labelFormatMatchString); - if (labelFormatMatcher->indexIn(format, 0) != -1) - capStr = labelFormatMatcher->cap(1); + QString formatSpec; + QString preStr; + QString postStr; + int precision = 0; + if (presenter()->localizeNumbers()) { + if (!labelFormatMatcherLocalized) + labelFormatMatcherLocalized = new QRegExp(labelFormatMatchLocalizedString); + if (labelFormatMatcherLocalized->indexIn(format, 0) != -1) { + preStr = labelFormatMatcherLocalized->cap(1); + precision = labelFormatMatcherLocalized->cap(2).toInt(); + formatSpec = labelFormatMatcherLocalized->cap(3); + postStr = labelFormatMatcherLocalized->cap(4); + } + } else { + if (!labelFormatMatcher) + labelFormatMatcher = new QRegExp(labelFormatMatchString); + if (labelFormatMatcher->indexIn(format, 0) != -1) + formatSpec = labelFormatMatcher->cap(1); + } for (int i = 0; i < ticks; i++) { qreal value = min + (i * (max - min) / (ticks - 1)); - appendFormattedLabel(capStr, array, labels, value); + labels << formatLabel(formatSpec, array, value, precision, preStr, postStr); } } return labels; } -QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format) +QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, + const QString &format) const { QStringList labels; if (max <= min || ticks < 1) return labels; - int n = 0; - if (ticks > 1) - n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); - n++; - int firstTick; if (base > 1) firstTick = ceil(log10(min) / log10(base)); @@ -309,27 +335,46 @@ QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal b firstTick = ceil(log10(max) / log10(base)); if (format.isNull()) { + int n = 0; + if (ticks > 1) + n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); + n++; for (int i = firstTick; i < ticks + firstTick; i++) { qreal value = qPow(base, i); - labels << QString::number(value, 'f', n); + labels << presenter()->numberToString(value, 'f', n); } } else { QByteArray array = format.toLatin1(); - QString capStr; - if (!labelFormatMatcher) - labelFormatMatcher = new QRegExp(labelFormatMatchString); - if (labelFormatMatcher->indexIn(format, 0) != -1) - capStr = labelFormatMatcher->cap(1); + QString formatSpec; + QString preStr; + QString postStr; + int precision = 0; + if (presenter()->localizeNumbers()) { + if (!labelFormatMatcherLocalized) + labelFormatMatcherLocalized = new QRegExp(labelFormatMatchLocalizedString); + if (labelFormatMatcherLocalized->indexIn(format, 0) != -1) { + preStr = labelFormatMatcherLocalized->cap(1); + precision = labelFormatMatcherLocalized->cap(2).toInt(); + formatSpec = labelFormatMatcherLocalized->cap(3); + postStr = labelFormatMatcherLocalized->cap(4); + } + } else { + if (!labelFormatMatcher) + labelFormatMatcher = new QRegExp(labelFormatMatchString); + if (labelFormatMatcher->indexIn(format, 0) != -1) + formatSpec = labelFormatMatcher->cap(1); + } for (int i = firstTick; i < ticks + firstTick; i++) { qreal value = qPow(base, i); - appendFormattedLabel(capStr, array, labels, value); + labels << formatLabel(formatSpec, array, value, precision, preStr, postStr); } } return labels; } -QStringList ChartAxisElement::createDateTimeLabels(qreal min, qreal max,int ticks,const QString &format) +QStringList ChartAxisElement::createDateTimeLabels(qreal min, qreal max,int ticks, + const QString &format) const { QStringList labels; diff --git a/src/axis/chartaxiselement_p.h b/src/axis/chartaxiselement_p.h index ff3ff49..c561d9d 100644 --- a/src/axis/chartaxiselement_p.h +++ b/src/axis/chartaxiselement_p.h @@ -77,9 +77,10 @@ public: //this flag indicates that axis is used to show intervals it means labels are in between ticks bool intervalAxis() const { return m_intervalAxis; } - static QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format); - static QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format); - static QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format); + QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format) const; + QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, + const QString &format) const; + QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format) const; // from QGraphicsLayoutItem QRectF boundingRect() const @@ -132,6 +133,9 @@ Q_SIGNALS: private: void connectSlots(); + QString formatLabel(const QString &formatSpec, const QByteArray &array, + qreal value, int precision, const QString &preStr, + const QString &postStr) const; QAbstractAxis *m_axis; AxisAnimation *m_animation; diff --git a/src/axis/valueaxis/qvalueaxis.cpp b/src/axis/valueaxis/qvalueaxis.cpp index 3a22a98..d76bb0f 100644 --- a/src/axis/valueaxis/qvalueaxis.cpp +++ b/src/axis/valueaxis/qvalueaxis.cpp @@ -106,14 +106,22 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE /*! \property QValueAxis::labelFormat Defines the label format of the axis. - Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c + Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, and c. 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 + the default QLocale of the application. */ /*! \qmlproperty real ValueAxis::labelFormat Defines the label format of the axis. - Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c + Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, and c. 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 + the default QLocale of the application. */ /*! diff --git a/src/barchart/abstractbarchartitem.cpp b/src/barchart/abstractbarchartitem.cpp index 8dbc318..23874bf 100644 --- a/src/barchart/abstractbarchartitem.cpp +++ b/src/barchart/abstractbarchartitem.cpp @@ -217,11 +217,14 @@ void AbstractBarChartItem::handleUpdatedBars() QGraphicsTextItem *label = m_labels.at(itemIndex); QString valueLabel; - if (m_series->labelsFormat().isEmpty()) { - valueLabel = QString("%1").arg(barSet->value(category)); - } else { - valueLabel = m_series->labelsFormat(); - valueLabel.replace(valueTag, QString::number(barSet->value(category))); + if (presenter()) { // At startup presenter is not yet set, yet somehow update comes + if (m_series->labelsFormat().isEmpty()) { + valueLabel = presenter()->numberToString(barSet->value(category)); + } else { + valueLabel = m_series->labelsFormat(); + valueLabel.replace(valueTag, + presenter()->numberToString(barSet->value(category))); + } } label->setHtml(valueLabel); label->setFont(barSet->m_labelFont); diff --git a/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp b/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp index 3508366..9dd875d 100644 --- a/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp +++ b/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp @@ -115,16 +115,15 @@ void HorizontalPercentBarChartItem::handleUpdatedBars() bar->update(); QGraphicsTextItem *label = m_labels.at(itemIndex); - int p = m_series->d_func()->percentageAt(set, category) * 100; - QString vString(QString::number(p)); - vString.truncate(3); - vString.append("%"); + qreal p = m_series->d_func()->percentageAt(set, category) * 100.0; + QString vString(presenter()->numberToString(p, 'f', 0)); QString valueLabel; if (m_series->labelsFormat().isEmpty()) { + vString.append("%"); valueLabel = vString; } else { valueLabel = m_series->labelsFormat(); - valueLabel.replace(valueTag, QString::number(barSet->value(category))); + valueLabel.replace(valueTag, vString); } label->setHtml(valueLabel); label->setFont(barSet->m_labelFont); diff --git a/src/barchart/vertical/percent/percentbarchartitem.cpp b/src/barchart/vertical/percent/percentbarchartitem.cpp index b4c6283..d5a8430 100644 --- a/src/barchart/vertical/percent/percentbarchartitem.cpp +++ b/src/barchart/vertical/percent/percentbarchartitem.cpp @@ -120,16 +120,15 @@ void PercentBarChartItem::handleUpdatedBars() bar->update(); QGraphicsTextItem *label = m_labels.at(itemIndex); - int p = m_series->d_func()->percentageAt(set, category) * 100; - QString vString(QString::number(p)); - vString.truncate(3); - vString.append("%"); + qreal p = m_series->d_func()->percentageAt(set, category) * 100.0; + QString vString(presenter()->numberToString(p, 'f', 0)); QString valueLabel; if (m_series->labelsFormat().isEmpty()) { + vString.append("%"); valueLabel = vString; } else { valueLabel = m_series->labelsFormat(); - valueLabel.replace(valueTag, QString::number(barSet->value(category))); + valueLabel.replace(valueTag, vString); } label->setHtml(valueLabel); label->setFont(barSet->m_labelFont); diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index e91fd08..c5c1b34 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -44,7 +44,8 @@ ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type) m_state(ShowState), m_background(0), m_plotAreaBackground(0), - m_title(0) + m_title(0), + m_localizeNumbers(false) { if (type == QChart::ChartTypeCartesian) m_layout = new CartesianChartLayout(this); @@ -102,6 +103,7 @@ void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) { series->d_ptr->initializeGraphics(rootItem()); series->d_ptr->initializeAnimations(m_options); + series->d_ptr->setPresenter(this); ChartItem *chart = series->d_ptr->chartItem(); chart->setPresenter(this); chart->setThemeManager(m_chart->d_ptr->m_themeManager); @@ -344,6 +346,17 @@ bool ChartPresenter::isBackgroundDropShadowEnabled() const return m_background->isDropShadowEnabled(); } +void ChartPresenter::setLocalizeNumbers(bool localize) +{ + m_localizeNumbers = localize; + m_layout->invalidate(); +} + +bool ChartPresenter::localizeNumbers() const +{ + return m_localizeNumbers; +} + AbstractChartLayout *ChartPresenter::layout() { @@ -475,6 +488,14 @@ QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qr return truncatedString; } +QString ChartPresenter::numberToString(double value, char f, int prec) +{ + if (m_localizeNumbers) + return m_locale.toString(value, f, prec); + else + return QString::number(value, f, prec); +} + #include "moc_chartpresenter_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/chartpresenter_p.h b/src/chartpresenter_p.h index e99360a..d75d450 100644 --- a/src/chartpresenter_p.h +++ b/src/chartpresenter_p.h @@ -34,6 +34,7 @@ #include "qchart.h" //because of QChart::ChartThemeId #include #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -129,6 +130,9 @@ public: void setBackgroundDropShadowEnabled(bool enabled); bool isBackgroundDropShadowEnabled() const; + void setLocalizeNumbers(bool localize); + bool localizeNumbers() const; + void setVisible(bool visible); void setAnimationOptions(QChart::AnimationOptions options); @@ -148,6 +152,10 @@ public: static QString truncatedText(const QFont &font, const QString &text, qreal angle, qreal maxWidth, qreal maxHeight, QRectF &boundingRect); 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(); void createPlotAreaBackgroundItem(); @@ -173,6 +181,8 @@ private: QAbstractGraphicsShapeItem *m_plotAreaBackground; ChartTitle *m_title; QRectF m_rect; + bool m_localizeNumbers; + QLocale m_locale; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/qabstractseries.cpp b/src/qabstractseries.cpp index 4f0e32c..f88d2cf 100644 --- a/src/qabstractseries.cpp +++ b/src/qabstractseries.cpp @@ -303,6 +303,16 @@ void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain) } } +void QAbstractSeriesPrivate::setPresenter(ChartPresenter *presenter) +{ + m_presenter = presenter; +} + +ChartPresenter *QAbstractSeriesPrivate::presenter() const +{ + return m_presenter; +} + void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent) { Q_ASSERT(!m_item.isNull()); diff --git a/src/qabstractseries_p.h b/src/qabstractseries_p.h index b9745d9..2838fea 100644 --- a/src/qabstractseries_p.h +++ b/src/qabstractseries_p.h @@ -73,6 +73,9 @@ public: virtual void setDomain(AbstractDomain* domain); AbstractDomain* domain() { return m_domain.data(); } + virtual void setPresenter(ChartPresenter *presenter); + ChartPresenter *presenter() const; + QChart* chart() { return m_chart; } Q_SIGNALS: @@ -88,6 +91,7 @@ private: QString m_name; bool m_visible; qreal m_opacity; + ChartPresenter *m_presenter; friend class QAbstractSeries; friend class ChartDataSet; diff --git a/src/qchart.cpp b/src/qchart.cpp index 0cc8b89..fba3669 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -145,6 +145,15 @@ 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. + When \c{false}, the "C" locale is always used. + Defaults to \c{false}. +*/ + +/*! \internal Constructs a chart object of \a type which is a child of a \a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. @@ -561,6 +570,16 @@ bool QChart::isPlotAreaBackgroundVisible() const return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); } +void QChart::setLocalizeNumbers(bool localize) +{ + d_ptr->m_presenter->setLocalizeNumbers(localize); +} + +bool QChart::localizeNumbers() const +{ + return d_ptr->m_presenter->localizeNumbers(); +} + void QChart::setAnimationOptions(AnimationOptions options) { d_ptr->m_presenter->setAnimationOptions(options); diff --git a/src/qchart.h b/src/qchart.h index b5f6772..02233ca 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -49,6 +49,7 @@ class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget Q_PROPERTY(QMargins margins READ margins WRITE setMargins) Q_PROPERTY(QChart::ChartType chartType READ chartType) Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible) + Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers) Q_ENUMS(ChartTheme) Q_ENUMS(AnimationOption) Q_ENUMS(ChartType) @@ -151,6 +152,8 @@ public: QPen plotAreaBackgroundPen() const; void setPlotAreaBackgroundVisible(bool visible = true); bool isPlotAreaBackgroundVisible() const; + void setLocalizeNumbers(bool localize); + bool localizeNumbers() const; QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0); QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0); diff --git a/src/xychart/qxyseries.cpp b/src/xychart/qxyseries.cpp index 448e383..b573d7a 100644 --- a/src/xychart/qxyseries.cpp +++ b/src/xychart/qxyseries.cpp @@ -785,8 +785,8 @@ void QXYSeriesPrivate::drawSeriesPointLabels(QPainter *painter, const QVectornumberToString(m_points.at(i).x())); + pointLabel.replace(yPointTag, presenter()->numberToString(m_points.at(i).y())); // Position text in relation to the point int pointLabelWidth = fm.width(pointLabel);