##// END OF EJS Templates
QML area series to use models
Tero Ahola -
r1161:122f80368c30
parent child
Show More
@@ -26,7 +26,7 Rectangle {
26
26
27 ChartView {
27 ChartView {
28 id: chart
28 id: chart
29 title: "Car brand shares in Finland"
29 title: "Top-5 car brand shares in Finland"
30 anchors.top: parent.top
30 anchors.top: parent.top
31 anchors.bottom: button.top
31 anchors.bottom: button.top
32 anchors.left: parent.left
32 anchors.left: parent.left
@@ -33,99 +33,83 Rectangle {
33 "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"]
33 "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"]
34
34
35 AreaSeries {
35 AreaSeries {
36 name: "Swedish"
36 name: "Russian"
37 points: [
37 upperModel: russianModel
38 XyPoint { x: 0; y: 1 },
38 lowerModel: zerosModel
39 XyPoint { x: 1; y: 1 },
40 XyPoint { x: 2; y: 3 },
41 XyPoint { x: 3; y: 3 },
42 XyPoint { x: 4; y: 2 },
43 XyPoint { x: 5; y: 0 },
44 XyPoint { x: 6; y: 2 },
45 XyPoint { x: 7; y: 1 },
46 XyPoint { x: 8; y: 2 },
47 XyPoint { x: 9; y: 1 },
48 XyPoint { x: 10; y: 3 },
49 XyPoint { x: 11; y: 3 }
50 ]
51 lowerPoints: [
52 XyPoint { x: 0; y: 0 },
53 XyPoint { x: 1; y: 0 },
54 XyPoint { x: 2; y: 0 },
55 XyPoint { x: 3; y: 0 },
56 XyPoint { x: 4; y: 0 },
57 XyPoint { x: 5; y: 0 },
58 XyPoint { x: 6; y: 0 },
59 XyPoint { x: 7; y: 0 },
60 XyPoint { x: 8; y: 0 },
61 XyPoint { x: 9; y: 0 },
62 XyPoint { x: 10; y: 0 },
63 XyPoint { x: 11; y: 0 }
64 ]
65 }
39 }
66
67 AreaSeries {
40 AreaSeries {
68 name: "Russian"
41 name: "Swedish"
69 points: [
42 upperModel: swedishModel
70 XyPoint { x: 0; y: 1 },
43 lowerModel: zerosModel
71 XyPoint { x: 1; y: 1 },
72 XyPoint { x: 2; y: 1 },
73 XyPoint { x: 3; y: 1 },
74 XyPoint { x: 4; y: 1 },
75 XyPoint { x: 5; y: 0 },
76 XyPoint { x: 6; y: 1 },
77 XyPoint { x: 7; y: 1 },
78 XyPoint { x: 8; y: 4 },
79 XyPoint { x: 9; y: 3 },
80 XyPoint { x: 10; y: 2 },
81 XyPoint { x: 11; y: 1 }
82 ]
83 lowerPoints: [
84 XyPoint { x: 0; y: 0 },
85 XyPoint { x: 1; y: 0 },
86 XyPoint { x: 2; y: 0 },
87 XyPoint { x: 3; y: 0 },
88 XyPoint { x: 4; y: 0 },
89 XyPoint { x: 5; y: 0 },
90 XyPoint { x: 6; y: 0 },
91 XyPoint { x: 7; y: 0 },
92 XyPoint { x: 8; y: 0 },
93 XyPoint { x: 9; y: 0 },
94 XyPoint { x: 10; y: 0 },
95 XyPoint { x: 11; y: 0 }
96 ]
97 }
44 }
98
99 AreaSeries {
45 AreaSeries {
100 name: "Finnish"
46 name: "Finnish"
101 points: [
47 upperModel: finnishModel
102 XyPoint { x: 0; y: 0 },
48 lowerModel: zerosModel
103 XyPoint { x: 1; y: 0 },
104 XyPoint { x: 2; y: 0 },
105 XyPoint { x: 3; y: 0 },
106 XyPoint { x: 4; y: 0 },
107 XyPoint { x: 5; y: 0 },
108 XyPoint { x: 6; y: 1 },
109 XyPoint { x: 7; y: 0 },
110 XyPoint { x: 8; y: 0 },
111 XyPoint { x: 9; y: 0 },
112 XyPoint { x: 10; y: 0 },
113 XyPoint { x: 11; y: 1 }
114 ]
115 lowerPoints: [
116 XyPoint { x: 0; y: 0 },
117 XyPoint { x: 1; y: 0 },
118 XyPoint { x: 2; y: 0 },
119 XyPoint { x: 3; y: 0 },
120 XyPoint { x: 4; y: 0 },
121 XyPoint { x: 5; y: 0 },
122 XyPoint { x: 6; y: 0 },
123 XyPoint { x: 7; y: 0 },
124 XyPoint { x: 8; y: 0 },
125 XyPoint { x: 9; y: 0 },
126 XyPoint { x: 10; y: 0 },
127 XyPoint { x: 11; y: 0 }
128 ]
129 }
49 }
130 }
50 }
51
52 XYModel {
53 id: zerosModel
54 XyPoint { x: 0; y: 0 }
55 XyPoint { x: 1; y: 0 }
56 XyPoint { x: 2; y: 0 }
57 XyPoint { x: 3; y: 0 }
58 XyPoint { x: 4; y: 0 }
59 XyPoint { x: 5; y: 0 }
60 XyPoint { x: 6; y: 0 }
61 XyPoint { x: 7; y: 0 }
62 XyPoint { x: 8; y: 0 }
63 XyPoint { x: 9; y: 0 }
64 XyPoint { x: 10; y: 0 }
65 XyPoint { x: 11; y: 0 }
66 }
67
68 XYModel {
69 id: russianModel
70 XyPoint { x: 0; y: 1 }
71 XyPoint { x: 1; y: 1 }
72 XyPoint { x: 2; y: 1 }
73 XyPoint { x: 3; y: 1 }
74 XyPoint { x: 4; y: 1 }
75 XyPoint { x: 5; y: 0 }
76 XyPoint { x: 6; y: 1 }
77 XyPoint { x: 7; y: 1 }
78 XyPoint { x: 8; y: 4 }
79 XyPoint { x: 9; y: 3 }
80 XyPoint { x: 10; y: 2 }
81 XyPoint { x: 11; y: 1 }
82 }
83
84 XYModel {
85 id: swedishModel
86 XyPoint { x: 0; y: 1 }
87 XyPoint { x: 1; y: 1 }
88 XyPoint { x: 2; y: 3 }
89 XyPoint { x: 3; y: 3 }
90 XyPoint { x: 4; y: 2 }
91 XyPoint { x: 5; y: 0 }
92 XyPoint { x: 6; y: 2 }
93 XyPoint { x: 7; y: 1 }
94 XyPoint { x: 8; y: 2 }
95 XyPoint { x: 9; y: 1 }
96 XyPoint { x: 10; y: 3 }
97 XyPoint { x: 11; y: 3 }
98 }
99
100 XYModel {
101 id: finnishModel
102 XyPoint { x: 0; y: 0 }
103 XyPoint { x: 1; y: 0 }
104 XyPoint { x: 2; y: 0 }
105 XyPoint { x: 3; y: 0 }
106 XyPoint { x: 4; y: 0 }
107 XyPoint { x: 5; y: 0 }
108 XyPoint { x: 6; y: 1 }
109 XyPoint { x: 7; y: 0 }
110 XyPoint { x: 8; y: 0 }
111 XyPoint { x: 9; y: 0 }
112 XyPoint { x: 10; y: 0 }
113 XyPoint { x: 11; y: 1 }
114 }
131 }
115 }
@@ -21,7 +21,6
21 #include "declarativeareaseries.h"
21 #include "declarativeareaseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qlineseries.h"
25
24
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
26
@@ -30,34 +29,40 DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) :
30 {
29 {
31 }
30 }
32
31
33 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::points()
32 bool DeclarativeAreaSeries::setDeclarativeUpperModel(DeclarativeXyModel *model)
34 {
33 {
35 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendPoints);
34 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
35 bool value(false);
36 if (m) {
37 upperSeries()->setModel(m);
38 upperSeries()->setModelMapping(0, 1, Qt::Vertical);
39 } else {
40 qWarning("DeclarativeAreaSeries: Illegal model");
41 }
42 return value;
36 }
43 }
37
44
38 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::lowerPoints()
45 DeclarativeXyModel *DeclarativeAreaSeries::declarativeUpperModel()
39 {
46 {
40 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendLowerPoints);
47 return qobject_cast<DeclarativeXyModel *>(upperSeries()->model());
41 }
48 }
42
49
43 void DeclarativeAreaSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
50 bool DeclarativeAreaSeries::setDeclarativeLowerModel(DeclarativeXyModel *model)
44 DeclarativeXyPoint *element)
45 {
51 {
46 QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object);
52 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
47 if (series) {
53 bool value(false);
48 QLineSeries *upper = series->upperSeries();
54 if (m) {
49 upper->append(element->x(), element->y());
55 lowerSeries()->setModel(m);
56 lowerSeries()->setModelMapping(0, 1, Qt::Vertical);
57 } else {
58 qWarning("DeclarativeAreaSeries: Illegal model");
50 }
59 }
60 return value;
51 }
61 }
52
62
53 void DeclarativeAreaSeries::appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
63 DeclarativeXyModel *DeclarativeAreaSeries::declarativeLowerModel()
54 DeclarativeXyPoint *element)
55 {
64 {
56 QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object);
65 return qobject_cast<DeclarativeXyModel *>(lowerSeries()->model());
57 if (series) {
58 QLineSeries *lower = series->lowerSeries();
59 lower->append(element->x(), element->y());
60 }
61 }
66 }
62
67
63 #include "moc_declarativeareaseries.cpp"
68 #include "moc_declarativeareaseries.cpp"
@@ -23,6 +23,7
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qareaseries.h"
25 #include "qareaseries.h"
26 #include "declarativelineseries.h"
26 #include "declarativexyseries.h"
27 #include "declarativexyseries.h"
27
28
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -30,21 +31,17 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 class DeclarativeAreaSeries : public QAreaSeries, public DeclarativeXySeries
31 class DeclarativeAreaSeries : public QAreaSeries, public DeclarativeXySeries
31 {
32 {
32 Q_OBJECT
33 Q_OBJECT
33 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(DeclarativeXyModel *upperModel READ declarativeUpperModel WRITE setDeclarativeUpperModel)
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints READ lowerPoints)
35 Q_PROPERTY(DeclarativeXyModel *lowerModel READ declarativeLowerModel WRITE setDeclarativeLowerModel)
35
36
36 public:
37 public:
37 explicit DeclarativeAreaSeries(QObject *parent = 0);
38 explicit DeclarativeAreaSeries(QObject *parent = 0);
38
39
39 public:
40 public:
40 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 bool setDeclarativeUpperModel(DeclarativeXyModel *model);
41 QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints();
42 DeclarativeXyModel *declarativeUpperModel();
42
43 bool setDeclarativeLowerModel(DeclarativeXyModel *model);
43 public Q_SLOTS:
44 DeclarativeXyModel *declarativeLowerModel();
44 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
45 DeclarativeXyPoint *element);
46 static void appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
47 DeclarativeXyPoint *element);
48 };
45 };
49
46
50 QTCOMMERCIALCHART_END_NAMESPACE
47 QTCOMMERCIALCHART_END_NAMESPACE
@@ -91,19 +91,16 DeclarativePieModel::DeclarativePieModel(QObject *parent) :
91
91
92 void DeclarativePieModel::append(QPieSlice* slice)
92 void DeclarativePieModel::append(QPieSlice* slice)
93 {
93 {
94 qDebug() << "DeclarativePieModel::append:" << slice->label() << " " << slice->value();
94 // qDebug() << "DeclarativePieModel::append:" << slice->label() << " " << slice->value();
95 qDebug() << "rowCount:" << rowCount();
96 qDebug() << "coolCount:" << columnCount();
97 insertRow(rowCount());
95 insertRow(rowCount());
98 qDebug() << "new rowCount:" << rowCount();
99
96
100 qDebug() << setData(createIndex(rowCount() - 1, 0), slice->value());
97 setData(createIndex(rowCount() - 1, 0), slice->value());
101 qDebug() << setData(createIndex(rowCount() - 1, 1), slice->label());
98 setData(createIndex(rowCount() - 1, 1), slice->label());
102 }
99 }
103
100
104 void DeclarativePieModel::append(QVariantList slices)
101 void DeclarativePieModel::append(QVariantList slices)
105 {
102 {
106 qDebug() << "append:" << slices;
103 // qDebug() << "append:" << slices;
107 QString label = "";
104 QString label = "";
108 for (int i(0); i < slices.count(); i++) {
105 for (int i(0); i < slices.count(); i++) {
109 if (i % 2) {
106 if (i % 2) {
General Comments 0
You need to be logged in to leave comments. Login now