diff --git a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml index 31b32a4..ebe6369 100644 --- a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml +++ b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml @@ -31,8 +31,10 @@ Rectangle { title: "Custom model example" anchors.fill: parent theme: ChartView.ChartThemeLight - axisX.max: 20 + axisX.max: 10 + axisX.min: 0 axisY.max: 20 + axisY.min: 0 // For dynamic data we use a custom data model derived from QAbstractiItemModel CustomModel { @@ -68,7 +70,7 @@ Rectangle { PieSeries { id: pieSeries size: 0.4 - horizontalPosition: 0.2 + horizontalPosition: 0.7 verticalPosition: 0.3 } @@ -92,10 +94,16 @@ Rectangle { } } -// BarSeries { -// model: customModel -// modelMapper.first: 0 -// } + GroupedBarSeries { + name: "Skoda and Volvo" + barCategories: [ "1", "2", "3", "4", "5", "6" ] + HBarModelMapper { + model: customModel + firstBarSetRow: 4 + lastBarSetRow: 5 + first: 2 + } + } } diff --git a/plugins/declarative/declarativebarseries.cpp b/plugins/declarative/declarativebarseries.cpp index d4e2ab6..17194fb 100644 --- a/plugins/declarative/declarativebarseries.cpp +++ b/plugins/declarative/declarativebarseries.cpp @@ -21,6 +21,8 @@ #include "declarativebarseries.h" #include "declarativechart.h" #include +#include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -98,13 +100,26 @@ void DeclarativeBarSeries::componentComplete() foreach(QObject *child, children()) { if (qobject_cast(child)) { QBarSeries::append(qobject_cast(child)); + } else if(qobject_cast(child)) { + QVBarModelMapper *mapper = qobject_cast(child); + mapper->setSeries(this); + } else if(qobject_cast(child)) { + QHBarModelMapper *mapper = qobject_cast(child); + mapper->setSeries(this); } } } -QDeclarativeListProperty DeclarativeBarSeries::initialBarSets() +QDeclarativeListProperty DeclarativeBarSeries::seriesChildren() { - return QDeclarativeListProperty(this, 0, &DeclarativeBarSeries::appendInitialBarSets); + return QDeclarativeListProperty(this, 0, &DeclarativeBarSeries::appendSeriesChildren); +} + +void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty * list, QObject *element) +{ + // Empty implementation; the children are parsed in componentComplete instead + Q_UNUSED(list); + Q_UNUSED(element); } void DeclarativeBarSeries::setBarCategories(QStringList categories) @@ -140,13 +155,26 @@ void DeclarativeGroupedBarSeries::componentComplete() foreach(QObject *child, children()) { if (qobject_cast(child)) { QBarSeries::append(qobject_cast(child)); + } else if(qobject_cast(child)) { + QVBarModelMapper *mapper = qobject_cast(child); + mapper->setSeries(this); + } else if(qobject_cast(child)) { + QHBarModelMapper *mapper = qobject_cast(child); + mapper->setSeries(this); } } } -QDeclarativeListProperty DeclarativeGroupedBarSeries::initialBarSets() +QDeclarativeListProperty DeclarativeGroupedBarSeries::seriesChildren() +{ + return QDeclarativeListProperty(this, 0, &DeclarativeBarSeries::appendSeriesChildren); +} + +void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty * list, QObject *element) { - return QDeclarativeListProperty(this, 0, &DeclarativeGroupedBarSeries::appendInitialBarSets); + // Empty implementation; the children are parsed in componentComplete instead + Q_UNUSED(list); + Q_UNUSED(element); } void DeclarativeGroupedBarSeries::setBarCategories(QStringList categories) diff --git a/plugins/declarative/declarativebarseries.h b/plugins/declarative/declarativebarseries.h index 05ba199..011b05c 100644 --- a/plugins/declarative/declarativebarseries.h +++ b/plugins/declarative/declarativebarseries.h @@ -60,12 +60,12 @@ class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories) - Q_PROPERTY(QDeclarativeListProperty initialBarSets READ initialBarSets) - Q_CLASSINFO("DefaultProperty", "initialBarSets") + Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) + Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); - QDeclarativeListProperty initialBarSets(); + QDeclarativeListProperty seriesChildren(); void setBarCategories(QStringList categories); QStringList barCategories(); @@ -77,7 +77,7 @@ public: // from QDeclarativeParserStatus void componentComplete(); public Q_SLOTS: - static void appendInitialBarSets(QDeclarativeListProperty * /*list*/, DeclarativeBarSet * /*element*/) {} + static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); }; class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus @@ -85,12 +85,12 @@ class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativ Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories) - Q_PROPERTY(QDeclarativeListProperty initialBarSets READ initialBarSets) - Q_CLASSINFO("DefaultProperty", "initialBarSets") + Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) + Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0); - QDeclarativeListProperty initialBarSets(); + QDeclarativeListProperty seriesChildren(); void setBarCategories(QStringList categories); QStringList barCategories(); @@ -102,7 +102,7 @@ public: // from QDeclarativeParserStatus void componentComplete(); public Q_SLOTS: - static void appendInitialBarSets(QDeclarativeListProperty * /*list*/, DeclarativeBarSet * /*element*/) {} + static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/plugin.cpp b/plugins/declarative/plugin.cpp index 5c93250..f1c8081 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -34,6 +34,8 @@ #include #include #include +#include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -60,6 +62,8 @@ public: qmlRegisterType(uri, 1, 0, "VXYModelMapper"); qmlRegisterType(uri, 1, 0, "HPieModelMapper"); qmlRegisterType(uri, 1, 0, "VPieModelMapper"); + qmlRegisterType(uri, 1, 0, "HBarModelMapper"); + qmlRegisterType(uri, 1, 0, "VBarModelMapper"); qmlRegisterUncreatableType(uri, 1, 0, "QScatterSeries", @@ -72,6 +76,8 @@ public: QLatin1String("Trying to create uncreatable: XYModelMapper.")); qmlRegisterUncreatableType(uri, 1, 0, "PieModelMapper", QLatin1String("Trying to create uncreatable: PieModelMapper.")); + qmlRegisterUncreatableType(uri, 1, 0, "BarModelMapper", + QLatin1String("Trying to create uncreatable: BarModelMapper.")); qmlRegisterUncreatableType(uri, 1, 0, "AbstractSeries", QLatin1String("Trying to create uncreatable: AbstractSeries.")); qmlRegisterUncreatableType(uri, 1, 0, "Axis", diff --git a/src/barchart/qhbarmodelmapper.h b/src/barchart/qhbarmodelmapper.h index 3db52d4..df54b84 100644 --- a/src/barchart/qhbarmodelmapper.h +++ b/src/barchart/qhbarmodelmapper.h @@ -10,6 +10,7 @@ class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper Q_OBJECT Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow) Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow) + Q_PROPERTY(int categoriesRow READ categoriesRow WRITE setCategoriesRow) public: explicit QHBarModelMapper(QObject *parent = 0); diff --git a/src/barchart/qvbarmodelmapper.h b/src/barchart/qvbarmodelmapper.h index 4b3c4fe..f44df66 100644 --- a/src/barchart/qvbarmodelmapper.h +++ b/src/barchart/qvbarmodelmapper.h @@ -10,6 +10,7 @@ class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper Q_OBJECT Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn) Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn) + Q_PROPERTY(int categoriesColumn READ categoriesColumn WRITE setCategoriesColumn) public: explicit QVBarModelMapper(QObject *parent = 0); diff --git a/tests/tablemodelchart/tablewidget.cpp b/tests/tablemodelchart/tablewidget.cpp index 94361b8..c3cdac1 100644 --- a/tests/tablemodelchart/tablewidget.cpp +++ b/tests/tablemodelchart/tablewidget.cpp @@ -488,8 +488,8 @@ void TableWidget::updateChartType(bool toggle) // int count = 4; QVBarModelMapper *mapper = new QVBarModelMapper; mapper->setCategoriesSection(5); - mapper->setFirstBarSection(2); - mapper->setLastBarSection(4); + mapper->setFirstBarSetSection(2); + mapper->setLastBarSetSection(4); mapper->setFirst(first); // mapper->setCount(count); mapper->setSeries(barSeries);