@@ -26,7 +26,7 Rectangle { | |||||
26 |
|
26 | |||
27 | ChartView { |
|
27 | ChartView { | |
28 | id: chart |
|
28 | id: chart | |
29 |
title: " |
|
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: "Russian" | |||
|
37 | upperModel: russianModel | |||
|
38 | lowerModel: zerosModel | |||
|
39 | } | |||
|
40 | AreaSeries { | |||
36 | name: "Swedish" |
|
41 | name: "Swedish" | |
37 | points: [ |
|
42 | upperModel: swedishModel | |
38 | XyPoint { x: 0; y: 1 }, |
|
43 | 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 | } |
|
44 | } | |
66 |
|
||||
67 | AreaSeries { |
|
45 | AreaSeries { | |
68 |
name: " |
|
46 | name: "Finnish" | |
69 | points: [ |
|
47 | upperModel: finnishModel | |
70 | XyPoint { x: 0; y: 1 }, |
|
48 | lowerModel: zerosModel | |
71 | XyPoint { x: 1; y: 1 }, |
|
49 | } | |
72 | XyPoint { x: 2; y: 1 }, |
|
50 | } | |
73 | XyPoint { x: 3; y: 1 }, |
|
51 | ||
74 | XyPoint { x: 4; y: 1 }, |
|
52 | XYModel { | |
75 | XyPoint { x: 5; y: 0 }, |
|
53 | id: zerosModel | |
76 |
|
|
54 | XyPoint { x: 0; y: 0 } | |
77 |
|
|
55 | XyPoint { x: 1; y: 0 } | |
78 |
|
|
56 | XyPoint { x: 2; y: 0 } | |
79 |
|
|
57 | XyPoint { x: 3; y: 0 } | |
80 |
|
|
58 | XyPoint { x: 4; y: 0 } | |
81 |
|
|
59 | XyPoint { x: 5; y: 0 } | |
82 | ] |
|
60 | XyPoint { x: 6; y: 0 } | |
83 | lowerPoints: [ |
|
61 | XyPoint { x: 7; y: 0 } | |
84 |
|
|
62 | XyPoint { x: 8; y: 0 } | |
85 |
|
|
63 | XyPoint { x: 9; y: 0 } | |
86 |
|
|
64 | XyPoint { x: 10; 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 |
|
|
65 | XyPoint { x: 11; y: 0 } | |
96 | ] |
|
|||
97 |
|
|
66 | } | |
98 |
|
67 | |||
99 | AreaSeries { |
|
68 | XYModel { | |
100 | name: "Finnish" |
|
69 | id: russianModel | |
101 | points: [ |
|
70 | XyPoint { x: 0; y: 1 } | |
102 |
|
|
71 | XyPoint { x: 1; y: 1 } | |
103 |
|
|
72 | XyPoint { x: 2; y: 1 } | |
104 |
|
|
73 | XyPoint { x: 3; y: 1 } | |
105 |
|
|
74 | XyPoint { x: 4; y: 1 } | |
106 |
|
|
75 | XyPoint { x: 5; y: 0 } | |
107 |
|
|
76 | XyPoint { x: 6; y: 1 } | |
108 |
|
|
77 | XyPoint { x: 7; y: 1 } | |
109 |
|
|
78 | XyPoint { x: 8; y: 4 } | |
110 |
|
|
79 | XyPoint { x: 9; y: 3 } | |
111 |
|
|
80 | XyPoint { x: 10; y: 2 } | |
112 | XyPoint { x: 10; y: 0 }, |
|
|||
113 |
|
|
81 | 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 |
|
|
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 } | |||
130 | } |
|
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 |
|
|
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 |
|
|
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 |
|
|
97 | setData(createIndex(rowCount() - 1, 0), slice->value()); | |
101 |
|
|
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