From e26d82d56bc95d0e2b06bf41813e885486a2ea6c Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 18 Sep 2014 14:50:03 +0300 Subject: Misc fixes - Default value for localizeNumbers is now false, as it would look weird if numbers were localized in otherwise unlocalized app. - Added locale property to qml ChartView. - Added registrations for latest revisions of all QML types for 2.0, since apparently this is necessary to make them visible when importing Charts 2.0 Change-Id: I46997b3af4458c6dbf6755a19e01115d5393013a Reviewed-by: Titta Heikkala --- plugins/declarative/declarativechart.cpp | 28 ++++++++++++++- plugins/declarative/declarativechart.h | 5 +++ plugins/declarative/plugin.cpp | 59 ++++++++++++++++++++++++++++++++ src/axis/chartaxiselement.cpp | 2 +- src/chartpresenter.cpp | 2 +- src/qchart.cpp | 2 +- 6 files changed, 94 insertions(+), 4 deletions(-) diff --git a/plugins/declarative/declarativechart.cpp b/plugins/declarative/declarativechart.cpp index b5b74c7c..fec441d5 100644 --- a/plugins/declarative/declarativechart.cpp +++ b/plugins/declarative/declarativechart.cpp @@ -180,7 +180,20 @@ 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{true}. + Defaults to \c{false}. + + \sa locale +*/ + +/*! + \qmlproperty locale ChartView::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 DateTimeAxis labels regardless of + localizeNumbers property. + Defaults to application default locale at the time the chart is constructed. + + \sa localizeNumbers */ /*! @@ -732,6 +745,19 @@ bool DeclarativeChart::localizeNumbers() const return m_chart->localizeNumbers(); } +void QtCommercialChart::DeclarativeChart::setLocale(const QLocale &locale) +{ + if (m_chart->locale() != locale) { + m_chart->setLocale(locale); + emit localeChanged(); + } +} + +QLocale QtCommercialChart::DeclarativeChart::locale() const +{ + return m_chart->locale(); +} + int DeclarativeChart::count() { return m_chart->series().count(); diff --git a/plugins/declarative/declarativechart.h b/plugins/declarative/declarativechart.h index 600dbf5c..a1b40d80 100644 --- a/plugins/declarative/declarativechart.h +++ b/plugins/declarative/declarativechart.h @@ -34,6 +34,7 @@ #endif #include "qchart.h" +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -68,6 +69,7 @@ class DeclarativeChart : public QDECLARATIVE_PAINTED_ITEM Q_PROPERTY(QDeclarativeListProperty axes READ axes REVISION 2) #endif Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers NOTIFY localizeNumbersChanged REVISION 4) + Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged REVISION 4) Q_ENUMS(Animation) Q_ENUMS(Theme) Q_ENUMS(SeriesType) @@ -145,6 +147,8 @@ public: Q_REVISION(3) QColor plotAreaColor(); Q_REVISION(4) void setLocalizeNumbers(bool localize); Q_REVISION(4) bool localizeNumbers() const; + Q_REVISION(4) void setLocale(const QLocale &locale); + Q_REVISION(4) QLocale locale() const; int count(); void setDropShadowEnabled(bool enabled); @@ -201,6 +205,7 @@ Q_SIGNALS: Q_REVISION(3) void plotAreaColorChanged(); Q_REVISION(3) void backgroundRoundnessChanged(qreal diameter); Q_REVISION(4) void localizeNumbersChanged(); + Q_REVISION(4) void localeChanged(); 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 6498456c..1dad0dc0 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -258,7 +258,66 @@ public: qmlRegisterType(uri, 2, 0, "VBoxPlotModelMapper"); qmlRegisterUncreatableType(uri, 2, 0, "BoxPlotModelMapper", QLatin1String("Trying to create uncreatable: BoxPlotModelMapper.")); + + // Re-register latest revisions for 2.0 qmlRegisterType(uri, 2, 0, "ChartView"); + qmlRegisterType(uri, 2, 0, "LineSeries"); + qmlRegisterType(uri, 2, 0, "ScatterSeries"); + qmlRegisterType(uri, 2, 0, "SplineSeries"); + qmlRegisterType(uri, 2, 0, "AreaSeries"); + qmlRegisterType(uri, 2, 0, "BarSeries"); + qmlRegisterType(uri, 2, 0, "StackedBarSeries"); + qmlRegisterType(uri, 2, 0, "PercentBarSeries"); + qmlRegisterType(uri, 2, 0, "HorizontalBarSeries"); + qmlRegisterType(uri, 2, 0, "HorizontalStackedBarSeries"); + qmlRegisterType(uri, 2, 0, "HorizontalPercentBarSeries"); + qmlRegisterType(uri, 2, 0, "BarSet"); + qmlRegisterType(uri, 2, 0, "BoxPlotSeries"); + qmlRegisterType(uri, 2, 0, "BoxSet"); + qmlRegisterType(uri, 2, 0, "PieSlice"); + qmlRegisterType(uri, 2, 0, "PieSeries"); + qmlRegisterType(uri, 2, 0, "XYPoint"); + qmlRegisterType(uri, 2, 0, "HXYModelMapper"); + qmlRegisterType(uri, 2, 0, "VXYModelMapper"); + qmlRegisterType(uri, 2, 0, "HPieModelMapper"); + qmlRegisterType(uri, 2, 0, "VPieModelMapper"); + qmlRegisterType(uri, 2, 0, "HBarModelMapper"); + qmlRegisterType(uri, 2, 0, "VBarModelMapper"); + qmlRegisterType(uri, 2, 0, "ValueAxis"); +#ifndef QT_ON_ARM + qmlRegisterType(uri, 2, 0, "DateTimeAxis"); +#endif + qmlRegisterType(uri, 2, 0, "CategoryAxis"); + qmlRegisterType(uri, 2, 0, "CategoryRange"); + qmlRegisterType(uri, 2, 0, "BarCategoryAxis"); + qmlRegisterUncreatableType(uri, 2, 0, "Legend", + QLatin1String("Trying to create uncreatable: Legend.")); + qmlRegisterUncreatableType(uri, 2, 0, "XYSeries", + QLatin1String("Trying to create uncreatable: XYSeries.")); + qmlRegisterUncreatableType(uri, 2, 0, "AbstractItemModel", + QLatin1String("Trying to create uncreatable: AbstractItemModel.")); + qmlRegisterUncreatableType(uri, 2, 0, "XYModelMapper", + QLatin1String("Trying to create uncreatable: XYModelMapper.")); + qmlRegisterUncreatableType(uri, 2, 0, "PieModelMapper", + QLatin1String("Trying to create uncreatable: PieModelMapper.")); + qmlRegisterUncreatableType(uri, 2, 0, "BarModelMapper", + QLatin1String("Trying to create uncreatable: BarModelMapper.")); + qmlRegisterUncreatableType(uri, 2, 0, "AbstractSeries", + QLatin1String("Trying to create uncreatable: AbstractSeries.")); + qmlRegisterUncreatableType(uri, 2, 0, "AbstractBarSeries", + QLatin1String("Trying to create uncreatable: AbstractBarSeries.")); + qmlRegisterUncreatableType(uri, 2, 0, "AbstractAxis", + QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead.")); + qmlRegisterUncreatableType(uri, 2, 0, "BarSetBase", + QLatin1String("Trying to create uncreatable: BarsetBase.")); + qmlRegisterUncreatableType(uri, 2, 0, "QPieSeries", + QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead.")); + qmlRegisterUncreatableType(uri, 2, 0, "DeclarativeAxes", + QLatin1String("Trying to create uncreatable: DeclarativeAxes.")); + qmlRegisterUncreatableType(uri, 2, 0, "Margins", + QLatin1String("Trying to create uncreatable: Margins.")); + qmlRegisterType(uri, 2, 0, "PolarChartView"); + qmlRegisterType(uri, 2, 0, "LogValueAxis"); } }; diff --git a/src/axis/chartaxiselement.cpp b/src/axis/chartaxiselement.cpp index 310555e7..c006b166 100644 --- a/src/axis/chartaxiselement.cpp +++ b/src/axis/chartaxiselement.cpp @@ -29,7 +29,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE static const char *labelFormatMatchString = "%[\\-\\+#\\s\\d\\.lhjztL]*([dicuoxfegXFEG])"; -static const char *labelFormatMatchLocalizedString = "^([^%]*)%\\.?(\\d)*([defgiEG])(.*)$"; +static const char *labelFormatMatchLocalizedString = "^([^%]*)%\\.(\\d+)([defgiEG])(.*)$"; static QRegExp *labelFormatMatcher = 0; static QRegExp *labelFormatMatcherLocalized = 0; class StaticLabelFormatMatcherDeleter diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 619f400f..e83a7fbc 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(true) + m_localizeNumbers(false) { if (type == QChart::ChartTypeCartesian) m_layout = new CartesianChartLayout(this); diff --git a/src/qchart.cpp b/src/qchart.cpp index b103ed9b..16391b9a 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -150,7 +150,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE When \c{true}, all generated numbers appearing in various series and axis labels will be localized using the QLocale set with the locale property. When \c{false}, the "C" locale is always used. - Defaults to \c{true}. + Defaults to \c{false}. \note This property doesn't affect QDateTimeAxis labels, which always use the QLocale set with the locale property. -- cgit v1.2.3