diff --git a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml index 50ac53c..7609ca8 100644 --- a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml +++ b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml @@ -34,18 +34,18 @@ Rectangle { // For dynamic data you can use the ChartModel API. ChartModel { id: chartModel - ChartModelElement { values: [0, "Volkswagen", 13.5, 4.4] } - ChartModelElement { values: [0, "Toyota", 10.9, 4.2] } - ChartModelElement { values: [0, "Ford", 8.6, 3.0] } - ChartModelElement { values: [0, "Skoda", 8.2, 1.9] } - ChartModelElement { values: [0, "Volvo", 6.8, 1.5] } + ChartModelElement { values: ["Volkswagen", 13.5, 4.4] } + ChartModelElement { values: ["Toyota", 10.9, 4.2] } + ChartModelElement { values: ["Ford", 8.6, 3.0] } + ChartModelElement { values: ["Skoda", 8.2, 1.9] } + ChartModelElement { values: ["Volvo", 6.8, 1.5] } } LineSeries { name: "line" // TODO: the new mapper api -// XYModelMapperVertical { +// VXYModelMapper { // model: chartModel // xColumn: 0 // yColumn: 1 @@ -60,34 +60,24 @@ Rectangle { verticalPosition: 0.3 VPieModelMapper { - series: pieSeries // TODO model: chartModel - labelsColumn: 1 - valuesColumn: 2 + labelsColumn: 0 + valuesColumn: 1 } } - // TODO: the new mapper api -// PieModelMapperVertical { +// VPieModelMapper { // series: pieSeries // model: chartModel -// labelsColumn: 0 -// valuesColumn: 1 +// labelsColumn: 1 +// valuesColumn: 2 // } - AreaSeries { - name: "area" - upperSeries: LineSeries { -// model: chartModel -// modelMapper.mapX: 2 -// modelMapper.mapY: 2 - } - lowerSeries: LineSeries { -// model: chartModel -// modelMapper.mapX: 2 -// modelMapper.mapY: 0 - } - } +// AreaSeries { +// name: "area" +// upperSeries: LineSeries {} +// lowerSeries: LineSeries {} +// } // TODO: BarSeries with ChartModel base model API // BarSeries { diff --git a/plugins/declarative/declarativepieseries.cpp b/plugins/declarative/declarativepieseries.cpp index 627f36f..42c04cb 100644 --- a/plugins/declarative/declarativepieseries.cpp +++ b/plugins/declarative/declarativepieseries.cpp @@ -22,24 +22,14 @@ #include "declarativechart.h" #include "qchart.h" #include -#include "qpiemodelmapper.h" +#include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : QPieSeries(parent) { - // TODO: set default model on init? -// setModel(new DeclarativeTableModel()); - - // TODO: Set default mapper parameters to allow easy to use PieSeries api? -// QPieModelMapper *mapper = modelMapper();//new QPieModelMapper(); -// mapper->setMapLabels(0); -// mapper->setMapValues(1); -// mapper->setOrientation(Qt::Vertical); -// mapper->setFirst(0); -// mapper->setCount(-1); -// setModelMapper(mapper); } void DeclarativePieSeries::classBegin() @@ -51,13 +41,26 @@ void DeclarativePieSeries::componentComplete() foreach(QObject *child, children()) { if (qobject_cast(child)) { QPieSeries::append(qobject_cast(child)); + } else if(qobject_cast(child)) { + QVPieModelMapper *mapper = qobject_cast(child); + mapper->setSeries(this); + } else if(qobject_cast(child)) { + QHPieModelMapper *mapper = qobject_cast(child); + mapper->setSeries(this); } } } -QDeclarativeListProperty DeclarativePieSeries::initialSlices() +QDeclarativeListProperty DeclarativePieSeries::seriesChildren() +{ + return QDeclarativeListProperty(this, 0, &DeclarativePieSeries::appendSeriesChildren); +} + +void DeclarativePieSeries::appendSeriesChildren(QDeclarativeListProperty * list, QObject *element) { - return QDeclarativeListProperty(this, 0, &DeclarativePieSeries::appendInitialSlices); + // Empty implementation; the children are parsed in componentComplete instead + Q_UNUSED(list); + Q_UNUSED(element); } QPieSlice *DeclarativePieSeries::at(int index) diff --git a/plugins/declarative/declarativepieseries.h b/plugins/declarative/declarativepieseries.h index 4a5ef14..5c02821 100644 --- a/plugins/declarative/declarativepieseries.h +++ b/plugins/declarative/declarativepieseries.h @@ -27,7 +27,6 @@ #include #include #include -#include #include "declarativemodel.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -39,12 +38,12 @@ class DeclarativePieSeries : public QPieSeries, public QDeclarativeParserStatus Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(DeclarativeTableModel *model READ pieModel WRITE setPieModel) - Q_PROPERTY(QDeclarativeListProperty initialSlices READ initialSlices) - Q_CLASSINFO("DefaultProperty", "initialSlices") + Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) + Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativePieSeries(QObject *parent = 0); - QDeclarativeListProperty initialSlices(); + QDeclarativeListProperty seriesChildren(); DeclarativeTableModel *pieModel(); void setPieModel(DeclarativeTableModel *model); Q_INVOKABLE QPieSlice *at(int index); @@ -56,7 +55,7 @@ public: void componentComplete(); public Q_SLOTS: - static void appendInitialSlices(QDeclarativeListProperty * /*list*/, QPieSlice * /*element*/) {} + static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); }; QTCOMMERCIALCHART_END_NAMESPACE