@@ -34,18 +34,18 Rectangle { | |||||
34 | // For dynamic data you can use the ChartModel API. |
|
34 | // For dynamic data you can use the ChartModel API. | |
35 | ChartModel { |
|
35 | ChartModel { | |
36 | id: chartModel |
|
36 | id: chartModel | |
37 |
ChartModelElement { values: [ |
|
37 | ChartModelElement { values: ["Volkswagen", 13.5, 4.4] } | |
38 |
ChartModelElement { values: [ |
|
38 | ChartModelElement { values: ["Toyota", 10.9, 4.2] } | |
39 |
ChartModelElement { values: [ |
|
39 | ChartModelElement { values: ["Ford", 8.6, 3.0] } | |
40 |
ChartModelElement { values: [ |
|
40 | ChartModelElement { values: ["Skoda", 8.2, 1.9] } | |
41 |
ChartModelElement { values: [ |
|
41 | ChartModelElement { values: ["Volvo", 6.8, 1.5] } | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | LineSeries { |
|
44 | LineSeries { | |
45 | name: "line" |
|
45 | name: "line" | |
46 |
|
46 | |||
47 | // TODO: the new mapper api |
|
47 | // TODO: the new mapper api | |
48 |
// XYModelMapper |
|
48 | // VXYModelMapper { | |
49 | // model: chartModel |
|
49 | // model: chartModel | |
50 | // xColumn: 0 |
|
50 | // xColumn: 0 | |
51 | // yColumn: 1 |
|
51 | // yColumn: 1 | |
@@ -60,34 +60,24 Rectangle { | |||||
60 | verticalPosition: 0.3 |
|
60 | verticalPosition: 0.3 | |
61 |
|
61 | |||
62 | VPieModelMapper { |
|
62 | VPieModelMapper { | |
63 | series: pieSeries // TODO |
|
|||
64 |
|
|
63 | model: chartModel | |
65 |
labelsColumn: |
|
64 | labelsColumn: 0 | |
66 |
valuesColumn: |
|
65 | valuesColumn: 1 | |
67 | } |
|
66 | } | |
68 | } |
|
67 | } | |
69 |
|
68 | |||
70 | // TODO: the new mapper api |
|
69 | // VPieModelMapper { | |
71 | // PieModelMapperVertical { |
|
|||
72 | // series: pieSeries |
|
70 | // series: pieSeries | |
73 | // model: chartModel |
|
71 | // model: chartModel | |
74 |
// labelsColumn: |
|
72 | // labelsColumn: 1 | |
75 |
// valuesColumn: |
|
73 | // valuesColumn: 2 | |
76 | // } |
|
74 | // } | |
77 |
|
75 | |||
78 |
|
|
76 | // AreaSeries { | |
79 |
|
|
77 | // name: "area" | |
80 |
|
|
78 | // upperSeries: LineSeries {} | |
81 | // model: chartModel |
|
79 | // lowerSeries: LineSeries {} | |
82 | // modelMapper.mapX: 2 |
|
80 | // } | |
83 | // modelMapper.mapY: 2 |
|
|||
84 | } |
|
|||
85 | lowerSeries: LineSeries { |
|
|||
86 | // model: chartModel |
|
|||
87 | // modelMapper.mapX: 2 |
|
|||
88 | // modelMapper.mapY: 0 |
|
|||
89 | } |
|
|||
90 | } |
|
|||
91 |
|
81 | |||
92 | // TODO: BarSeries with ChartModel base model API |
|
82 | // TODO: BarSeries with ChartModel base model API | |
93 |
|
|
83 | // BarSeries { |
@@ -22,24 +22,14 | |||||
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 | #include <qdeclarativelist.h> |
|
24 | #include <qdeclarativelist.h> | |
25 |
#include |
|
25 | #include <QVPieModelMapper> | |
|
26 | #include <QHPieModelMapper> | |||
26 |
|
27 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
29 | |||
29 | DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : |
|
30 | DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : | |
30 | QPieSeries(parent) |
|
31 | QPieSeries(parent) | |
31 | { |
|
32 | { | |
32 | // TODO: set default model on init? |
|
|||
33 | // setModel(new DeclarativeTableModel()); |
|
|||
34 |
|
||||
35 | // TODO: Set default mapper parameters to allow easy to use PieSeries api? |
|
|||
36 | // QPieModelMapper *mapper = modelMapper();//new QPieModelMapper(); |
|
|||
37 | // mapper->setMapLabels(0); |
|
|||
38 | // mapper->setMapValues(1); |
|
|||
39 | // mapper->setOrientation(Qt::Vertical); |
|
|||
40 | // mapper->setFirst(0); |
|
|||
41 | // mapper->setCount(-1); |
|
|||
42 | // setModelMapper(mapper); |
|
|||
43 | } |
|
33 | } | |
44 |
|
34 | |||
45 | void DeclarativePieSeries::classBegin() |
|
35 | void DeclarativePieSeries::classBegin() | |
@@ -51,13 +41,26 void DeclarativePieSeries::componentComplete() | |||||
51 | foreach(QObject *child, children()) { |
|
41 | foreach(QObject *child, children()) { | |
52 | if (qobject_cast<QPieSlice *>(child)) { |
|
42 | if (qobject_cast<QPieSlice *>(child)) { | |
53 | QPieSeries::append(qobject_cast<QPieSlice *>(child)); |
|
43 | QPieSeries::append(qobject_cast<QPieSlice *>(child)); | |
|
44 | } else if(qobject_cast<QVPieModelMapper *>(child)) { | |||
|
45 | QVPieModelMapper *mapper = qobject_cast<QVPieModelMapper *>(child); | |||
|
46 | mapper->setSeries(this); | |||
|
47 | } else if(qobject_cast<QHPieModelMapper *>(child)) { | |||
|
48 | QHPieModelMapper *mapper = qobject_cast<QHPieModelMapper *>(child); | |||
|
49 | mapper->setSeries(this); | |||
|
50 | } | |||
54 |
|
|
51 | } | |
55 | } |
|
52 | } | |
|
53 | ||||
|
54 | QDeclarativeListProperty<QObject> DeclarativePieSeries::seriesChildren() | |||
|
55 | { | |||
|
56 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativePieSeries::appendSeriesChildren); | |||
56 | } |
|
57 | } | |
57 |
|
58 | |||
58 | QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::initialSlices() |
|
59 | void DeclarativePieSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
59 | { |
|
60 | { | |
60 | return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendInitialSlices); |
|
61 | // Empty implementation; the children are parsed in componentComplete instead | |
|
62 | Q_UNUSED(list); | |||
|
63 | Q_UNUSED(element); | |||
61 | } |
|
64 | } | |
62 |
|
65 | |||
63 | QPieSlice *DeclarativePieSeries::at(int index) |
|
66 | QPieSlice *DeclarativePieSeries::at(int index) |
@@ -27,7 +27,6 | |||||
27 | #include <QDeclarativeParserStatus> |
|
27 | #include <QDeclarativeParserStatus> | |
28 | #include <QDeclarativeListProperty> |
|
28 | #include <QDeclarativeListProperty> | |
29 | #include <QAbstractItemModel> |
|
29 | #include <QAbstractItemModel> | |
30 | #include <QVariant> |
|
|||
31 | #include "declarativemodel.h" |
|
30 | #include "declarativemodel.h" | |
32 |
|
31 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
@@ -39,12 +38,12 class DeclarativePieSeries : public QPieSeries, public QDeclarativeParserStatus | |||||
39 | Q_OBJECT |
|
38 | Q_OBJECT | |
40 | Q_INTERFACES(QDeclarativeParserStatus) |
|
39 | Q_INTERFACES(QDeclarativeParserStatus) | |
41 | Q_PROPERTY(DeclarativeTableModel *model READ pieModel WRITE setPieModel) |
|
40 | Q_PROPERTY(DeclarativeTableModel *model READ pieModel WRITE setPieModel) | |
42 |
Q_PROPERTY(QDeclarativeListProperty<Q |
|
41 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) | |
43 |
Q_CLASSINFO("DefaultProperty", " |
|
42 | Q_CLASSINFO("DefaultProperty", "seriesChildren") | |
44 |
|
43 | |||
45 | public: |
|
44 | public: | |
46 | explicit DeclarativePieSeries(QObject *parent = 0); |
|
45 | explicit DeclarativePieSeries(QObject *parent = 0); | |
47 |
QDeclarativeListProperty<Q |
|
46 | QDeclarativeListProperty<QObject> seriesChildren(); | |
48 | DeclarativeTableModel *pieModel(); |
|
47 | DeclarativeTableModel *pieModel(); | |
49 | void setPieModel(DeclarativeTableModel *model); |
|
48 | void setPieModel(DeclarativeTableModel *model); | |
50 | Q_INVOKABLE QPieSlice *at(int index); |
|
49 | Q_INVOKABLE QPieSlice *at(int index); | |
@@ -56,7 +55,7 public: | |||||
56 | void componentComplete(); |
|
55 | void componentComplete(); | |
57 |
|
56 | |||
58 | public Q_SLOTS: |
|
57 | public Q_SLOTS: | |
59 |
static void append |
|
58 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
60 | }; |
|
59 | }; | |
61 |
|
60 | |||
62 | QTCOMMERCIALCHART_END_NAMESPACE |
|
61 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now