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