@@ -1,433 +1,433 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativebarseries.h" |
|
21 | #include "declarativebarseries.h" | |
22 | #include "qbarset.h" |
|
22 | #include "qbarset.h" | |
23 | #include "qvbarmodelmapper.h" |
|
23 | #include "qvbarmodelmapper.h" | |
24 | #include "qhbarmodelmapper.h" |
|
24 | #include "qhbarmodelmapper.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : |
|
28 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : | |
29 | QBarSet("", parent) |
|
29 | QBarSet("", parent) | |
30 | { |
|
30 | { | |
31 |
connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, |
|
31 | connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int,int))); | |
32 |
connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, |
|
32 | connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int,int))); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | void DeclarativeBarSet::handleCountChanged(int index, int count) |
|
35 | void DeclarativeBarSet::handleCountChanged(int index, int count) | |
36 | { |
|
36 | { | |
37 | Q_UNUSED(index) |
|
37 | Q_UNUSED(index) | |
38 | Q_UNUSED(count) |
|
38 | Q_UNUSED(count) | |
39 | emit countChanged(QBarSet::count()); |
|
39 | emit countChanged(QBarSet::count()); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | qreal DeclarativeBarSet::borderWidth() const |
|
42 | qreal DeclarativeBarSet::borderWidth() const | |
43 | { |
|
43 | { | |
44 | return pen().widthF(); |
|
44 | return pen().widthF(); | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void DeclarativeBarSet::setBorderWidth(qreal width) |
|
47 | void DeclarativeBarSet::setBorderWidth(qreal width) | |
48 | { |
|
48 | { | |
49 | if (width != pen().widthF()) { |
|
49 | if (width != pen().widthF()) { | |
50 | QPen p = pen(); |
|
50 | QPen p = pen(); | |
51 | p.setWidthF(width); |
|
51 | p.setWidthF(width); | |
52 | setPen(p); |
|
52 | setPen(p); | |
53 | emit borderWidthChanged(width); |
|
53 | emit borderWidthChanged(width); | |
54 | } |
|
54 | } | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | QVariantList DeclarativeBarSet::values() |
|
57 | QVariantList DeclarativeBarSet::values() | |
58 | { |
|
58 | { | |
59 | QVariantList values; |
|
59 | QVariantList values; | |
60 | for (int i(0); i < count(); i++) |
|
60 | for (int i(0); i < count(); i++) | |
61 | values.append(QVariant(QBarSet::at(i))); |
|
61 | values.append(QVariant(QBarSet::at(i))); | |
62 | return values; |
|
62 | return values; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | void DeclarativeBarSet::setValues(QVariantList values) |
|
65 | void DeclarativeBarSet::setValues(QVariantList values) | |
66 | { |
|
66 | { | |
67 | while (count()) |
|
67 | while (count()) | |
68 | remove(count() - 1); |
|
68 | remove(count() - 1); | |
69 |
|
69 | |||
70 | for (int i(0); i < values.count(); i++) { |
|
70 | for (int i(0); i < values.count(); i++) { | |
71 | if (values.at(i).canConvert(QVariant::Double)) |
|
71 | if (values.at(i).canConvert(QVariant::Double)) | |
72 | QBarSet::append(values[i].toDouble()); |
|
72 | QBarSet::append(values[i].toDouble()); | |
73 | } |
|
73 | } | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | // Declarative bar series ====================================================================================== |
|
76 | // Declarative bar series ====================================================================================== | |
77 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : |
|
77 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : | |
78 | QBarSeries(parent), |
|
78 | QBarSeries(parent), | |
79 | m_axisX(0), |
|
79 | m_axisX(0), | |
80 | m_axisY(0) |
|
80 | m_axisY(0) | |
81 | { |
|
81 | { | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | void DeclarativeBarSeries::classBegin() |
|
84 | void DeclarativeBarSeries::classBegin() | |
85 | { |
|
85 | { | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | void DeclarativeBarSeries::componentComplete() |
|
88 | void DeclarativeBarSeries::componentComplete() | |
89 | { |
|
89 | { | |
90 | foreach(QObject *child, children()) { |
|
90 | foreach(QObject *child, children()) { | |
91 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
91 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
92 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
92 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
93 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
93 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
94 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
94 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
95 | mapper->setSeries(this); |
|
95 | mapper->setSeries(this); | |
96 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
96 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
97 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
97 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
98 | mapper->setSeries(this); |
|
98 | mapper->setSeries(this); | |
99 | } |
|
99 | } | |
100 | } |
|
100 | } | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren() |
|
103 | QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren() | |
104 | { |
|
104 | { | |
105 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); |
|
105 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
108 | void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
109 | { |
|
109 | { | |
110 | // Empty implementation; the children are parsed in componentComplete instead |
|
110 | // Empty implementation; the children are parsed in componentComplete instead | |
111 | Q_UNUSED(list); |
|
111 | Q_UNUSED(list); | |
112 | Q_UNUSED(element); |
|
112 | Q_UNUSED(element); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | DeclarativeBarSet *DeclarativeBarSeries::at(int index) |
|
115 | DeclarativeBarSet *DeclarativeBarSeries::at(int index) | |
116 | { |
|
116 | { | |
117 | QList<QBarSet*> setList = barSets(); |
|
117 | QList<QBarSet*> setList = barSets(); | |
118 | if (index >= 0 && index < setList.count()) |
|
118 | if (index >= 0 && index < setList.count()) | |
119 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
119 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
120 |
|
120 | |||
121 | return 0; |
|
121 | return 0; | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values) |
|
124 | DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values) | |
125 | { |
|
125 | { | |
126 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
126 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); | |
127 | barset->setLabel(label); |
|
127 | barset->setLabel(label); | |
128 | barset->setValues(values); |
|
128 | barset->setValues(values); | |
129 | if (QBarSeries::insert(index, barset)) |
|
129 | if (QBarSeries::insert(index, barset)) | |
130 | return barset; |
|
130 | return barset; | |
131 | delete barset; |
|
131 | delete barset; | |
132 | return 0; |
|
132 | return 0; | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | // Declarative stacked bar series ============================================================================== |
|
135 | // Declarative stacked bar series ============================================================================== | |
136 | DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) : |
|
136 | DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) : | |
137 | QStackedBarSeries(parent), |
|
137 | QStackedBarSeries(parent), | |
138 | m_axisX(0), |
|
138 | m_axisX(0), | |
139 | m_axisY(0) |
|
139 | m_axisY(0) | |
140 | { |
|
140 | { | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | void DeclarativeStackedBarSeries::classBegin() |
|
143 | void DeclarativeStackedBarSeries::classBegin() | |
144 | { |
|
144 | { | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | void DeclarativeStackedBarSeries::componentComplete() |
|
147 | void DeclarativeStackedBarSeries::componentComplete() | |
148 | { |
|
148 | { | |
149 | foreach(QObject *child, children()) { |
|
149 | foreach(QObject *child, children()) { | |
150 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
150 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
151 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
151 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
152 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
152 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
153 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
153 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
154 | mapper->setSeries(this); |
|
154 | mapper->setSeries(this); | |
155 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
155 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
156 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
156 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
157 | mapper->setSeries(this); |
|
157 | mapper->setSeries(this); | |
158 | } |
|
158 | } | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 |
|
162 | |||
163 | QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren() |
|
163 | QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren() | |
164 | { |
|
164 | { | |
165 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); |
|
165 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
168 | void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
169 | { |
|
169 | { | |
170 | // Empty implementation; the children are parsed in componentComplete instead |
|
170 | // Empty implementation; the children are parsed in componentComplete instead | |
171 | Q_UNUSED(list); |
|
171 | Q_UNUSED(list); | |
172 | Q_UNUSED(element); |
|
172 | Q_UNUSED(element); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index) |
|
175 | DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index) | |
176 | { |
|
176 | { | |
177 | QList<QBarSet*> setList = barSets(); |
|
177 | QList<QBarSet*> setList = barSets(); | |
178 | if (index >= 0 && index < setList.count()) |
|
178 | if (index >= 0 && index < setList.count()) | |
179 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
179 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
180 |
|
180 | |||
181 | return 0; |
|
181 | return 0; | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values) |
|
184 | DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values) | |
185 | { |
|
185 | { | |
186 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
186 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); | |
187 | barset->setLabel(label); |
|
187 | barset->setLabel(label); | |
188 | barset->setValues(values); |
|
188 | barset->setValues(values); | |
189 | if (QStackedBarSeries::insert(index, barset)) |
|
189 | if (QStackedBarSeries::insert(index, barset)) | |
190 | return barset; |
|
190 | return barset; | |
191 | delete barset; |
|
191 | delete barset; | |
192 | return 0; |
|
192 | return 0; | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | // Declarative percent bar series ============================================================================== |
|
195 | // Declarative percent bar series ============================================================================== | |
196 | DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) : |
|
196 | DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) : | |
197 | QPercentBarSeries(parent), |
|
197 | QPercentBarSeries(parent), | |
198 | m_axisX(0), |
|
198 | m_axisX(0), | |
199 | m_axisY(0) |
|
199 | m_axisY(0) | |
200 | { |
|
200 | { | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | void DeclarativePercentBarSeries::classBegin() |
|
203 | void DeclarativePercentBarSeries::classBegin() | |
204 | { |
|
204 | { | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | void DeclarativePercentBarSeries::componentComplete() |
|
207 | void DeclarativePercentBarSeries::componentComplete() | |
208 | { |
|
208 | { | |
209 | foreach(QObject *child, children()) { |
|
209 | foreach(QObject *child, children()) { | |
210 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
210 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
211 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
211 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
212 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
212 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
213 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
213 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
214 | mapper->setSeries(this); |
|
214 | mapper->setSeries(this); | |
215 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
215 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
216 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
216 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
217 | mapper->setSeries(this); |
|
217 | mapper->setSeries(this); | |
218 | } |
|
218 | } | |
219 | } |
|
219 | } | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren() |
|
222 | QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren() | |
223 | { |
|
223 | { | |
224 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); |
|
224 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
227 | void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
228 | { |
|
228 | { | |
229 | // Empty implementation; the children are parsed in componentComplete instead |
|
229 | // Empty implementation; the children are parsed in componentComplete instead | |
230 | Q_UNUSED(list); |
|
230 | Q_UNUSED(list); | |
231 | Q_UNUSED(element); |
|
231 | Q_UNUSED(element); | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | DeclarativeBarSet *DeclarativePercentBarSeries::at(int index) |
|
234 | DeclarativeBarSet *DeclarativePercentBarSeries::at(int index) | |
235 | { |
|
235 | { | |
236 | QList<QBarSet*> setList = barSets(); |
|
236 | QList<QBarSet*> setList = barSets(); | |
237 | if (index >= 0 && index < setList.count()) |
|
237 | if (index >= 0 && index < setList.count()) | |
238 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
238 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
239 |
|
239 | |||
240 | return 0; |
|
240 | return 0; | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values) |
|
243 | DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values) | |
244 | { |
|
244 | { | |
245 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
245 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); | |
246 | barset->setLabel(label); |
|
246 | barset->setLabel(label); | |
247 | barset->setValues(values); |
|
247 | barset->setValues(values); | |
248 | if (QPercentBarSeries::insert(index, barset)) |
|
248 | if (QPercentBarSeries::insert(index, barset)) | |
249 | return barset; |
|
249 | return barset; | |
250 | delete barset; |
|
250 | delete barset; | |
251 | return 0; |
|
251 | return 0; | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | // Declarative horizontal bar series =========================================================================== |
|
254 | // Declarative horizontal bar series =========================================================================== | |
255 | DeclarativeHorizontalBarSeries::DeclarativeHorizontalBarSeries(QDeclarativeItem *parent) : |
|
255 | DeclarativeHorizontalBarSeries::DeclarativeHorizontalBarSeries(QDeclarativeItem *parent) : | |
256 | QHorizontalBarSeries(parent), |
|
256 | QHorizontalBarSeries(parent), | |
257 | m_axisX(0), |
|
257 | m_axisX(0), | |
258 | m_axisY(0) |
|
258 | m_axisY(0) | |
259 | { |
|
259 | { | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | void DeclarativeHorizontalBarSeries::classBegin() |
|
262 | void DeclarativeHorizontalBarSeries::classBegin() | |
263 | { |
|
263 | { | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | void DeclarativeHorizontalBarSeries::componentComplete() |
|
266 | void DeclarativeHorizontalBarSeries::componentComplete() | |
267 | { |
|
267 | { | |
268 | foreach(QObject *child, children()) { |
|
268 | foreach(QObject *child, children()) { | |
269 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
269 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
270 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
270 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
271 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
271 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
272 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
272 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
273 | mapper->setSeries(this); |
|
273 | mapper->setSeries(this); | |
274 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
274 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
275 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
275 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
276 | mapper->setSeries(this); |
|
276 | mapper->setSeries(this); | |
277 | } |
|
277 | } | |
278 | } |
|
278 | } | |
279 | } |
|
279 | } | |
280 |
|
280 | |||
281 | QDeclarativeListProperty<QObject> DeclarativeHorizontalBarSeries::seriesChildren() |
|
281 | QDeclarativeListProperty<QObject> DeclarativeHorizontalBarSeries::seriesChildren() | |
282 | { |
|
282 | { | |
283 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeHorizontalBarSeries::appendSeriesChildren); |
|
283 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeHorizontalBarSeries::appendSeriesChildren); | |
284 | } |
|
284 | } | |
285 |
|
285 | |||
286 | void DeclarativeHorizontalBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
286 | void DeclarativeHorizontalBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
287 | { |
|
287 | { | |
288 | // Empty implementation; the children are parsed in componentComplete instead |
|
288 | // Empty implementation; the children are parsed in componentComplete instead | |
289 | Q_UNUSED(list); |
|
289 | Q_UNUSED(list); | |
290 | Q_UNUSED(element); |
|
290 | Q_UNUSED(element); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | DeclarativeBarSet *DeclarativeHorizontalBarSeries::at(int index) |
|
293 | DeclarativeBarSet *DeclarativeHorizontalBarSeries::at(int index) | |
294 | { |
|
294 | { | |
295 | QList<QBarSet*> setList = barSets(); |
|
295 | QList<QBarSet*> setList = barSets(); | |
296 | if (index >= 0 && index < setList.count()) |
|
296 | if (index >= 0 && index < setList.count()) | |
297 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
297 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
298 |
|
298 | |||
299 | return 0; |
|
299 | return 0; | |
300 | } |
|
300 | } | |
301 |
|
301 | |||
302 | DeclarativeBarSet *DeclarativeHorizontalBarSeries::insert(int index, QString label, QVariantList values) |
|
302 | DeclarativeBarSet *DeclarativeHorizontalBarSeries::insert(int index, QString label, QVariantList values) | |
303 | { |
|
303 | { | |
304 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
304 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); | |
305 | barset->setLabel(label); |
|
305 | barset->setLabel(label); | |
306 | barset->setValues(values); |
|
306 | barset->setValues(values); | |
307 | if (QHorizontalBarSeries::insert(index, barset)) |
|
307 | if (QHorizontalBarSeries::insert(index, barset)) | |
308 | return barset; |
|
308 | return barset; | |
309 | delete barset; |
|
309 | delete barset; | |
310 | return 0; |
|
310 | return 0; | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | // Declarative horizontal stacked bar series =================================================================== |
|
313 | // Declarative horizontal stacked bar series =================================================================== | |
314 | DeclarativeHorizontalStackedBarSeries::DeclarativeHorizontalStackedBarSeries(QDeclarativeItem *parent) : |
|
314 | DeclarativeHorizontalStackedBarSeries::DeclarativeHorizontalStackedBarSeries(QDeclarativeItem *parent) : | |
315 | QHorizontalStackedBarSeries(parent), |
|
315 | QHorizontalStackedBarSeries(parent), | |
316 | m_axisX(0), |
|
316 | m_axisX(0), | |
317 | m_axisY(0) |
|
317 | m_axisY(0) | |
318 | { |
|
318 | { | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 | void DeclarativeHorizontalStackedBarSeries::classBegin() |
|
321 | void DeclarativeHorizontalStackedBarSeries::classBegin() | |
322 | { |
|
322 | { | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | void DeclarativeHorizontalStackedBarSeries::componentComplete() |
|
325 | void DeclarativeHorizontalStackedBarSeries::componentComplete() | |
326 | { |
|
326 | { | |
327 | foreach(QObject *child, children()) { |
|
327 | foreach(QObject *child, children()) { | |
328 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
328 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
329 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
329 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
330 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
330 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
331 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
331 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
332 | mapper->setSeries(this); |
|
332 | mapper->setSeries(this); | |
333 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
333 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
334 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
334 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
335 | mapper->setSeries(this); |
|
335 | mapper->setSeries(this); | |
336 | } |
|
336 | } | |
337 | } |
|
337 | } | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | QDeclarativeListProperty<QObject> DeclarativeHorizontalStackedBarSeries::seriesChildren() |
|
340 | QDeclarativeListProperty<QObject> DeclarativeHorizontalStackedBarSeries::seriesChildren() | |
341 | { |
|
341 | { | |
342 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeHorizontalStackedBarSeries::appendSeriesChildren); |
|
342 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeHorizontalStackedBarSeries::appendSeriesChildren); | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | void DeclarativeHorizontalStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
345 | void DeclarativeHorizontalStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
346 | { |
|
346 | { | |
347 | // Empty implementation; the children are parsed in componentComplete instead |
|
347 | // Empty implementation; the children are parsed in componentComplete instead | |
348 | Q_UNUSED(list); |
|
348 | Q_UNUSED(list); | |
349 | Q_UNUSED(element); |
|
349 | Q_UNUSED(element); | |
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::at(int index) |
|
352 | DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::at(int index) | |
353 | { |
|
353 | { | |
354 | QList<QBarSet*> setList = barSets(); |
|
354 | QList<QBarSet*> setList = barSets(); | |
355 | if (index >= 0 && index < setList.count()) |
|
355 | if (index >= 0 && index < setList.count()) | |
356 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
356 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
357 |
|
357 | |||
358 | return 0; |
|
358 | return 0; | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::insert(int index, QString label, QVariantList values) |
|
361 | DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::insert(int index, QString label, QVariantList values) | |
362 | { |
|
362 | { | |
363 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
363 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); | |
364 | barset->setLabel(label); |
|
364 | barset->setLabel(label); | |
365 | barset->setValues(values); |
|
365 | barset->setValues(values); | |
366 | if (QHorizontalStackedBarSeries::insert(index, barset)) |
|
366 | if (QHorizontalStackedBarSeries::insert(index, barset)) | |
367 | return barset; |
|
367 | return barset; | |
368 | delete barset; |
|
368 | delete barset; | |
369 | return 0; |
|
369 | return 0; | |
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | // Declarative horizontal percent bar series =================================================================== |
|
372 | // Declarative horizontal percent bar series =================================================================== | |
373 | DeclarativeHorizontalPercentBarSeries::DeclarativeHorizontalPercentBarSeries(QDeclarativeItem *parent) : |
|
373 | DeclarativeHorizontalPercentBarSeries::DeclarativeHorizontalPercentBarSeries(QDeclarativeItem *parent) : | |
374 | QHorizontalPercentBarSeries(parent), |
|
374 | QHorizontalPercentBarSeries(parent), | |
375 | m_axisX(0), |
|
375 | m_axisX(0), | |
376 | m_axisY(0) |
|
376 | m_axisY(0) | |
377 | { |
|
377 | { | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | void DeclarativeHorizontalPercentBarSeries::classBegin() |
|
380 | void DeclarativeHorizontalPercentBarSeries::classBegin() | |
381 | { |
|
381 | { | |
382 | } |
|
382 | } | |
383 |
|
383 | |||
384 | void DeclarativeHorizontalPercentBarSeries::componentComplete() |
|
384 | void DeclarativeHorizontalPercentBarSeries::componentComplete() | |
385 | { |
|
385 | { | |
386 | foreach(QObject *child, children()) { |
|
386 | foreach(QObject *child, children()) { | |
387 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
387 | if (qobject_cast<DeclarativeBarSet *>(child)) { | |
388 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
388 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | |
389 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
389 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
390 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
390 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
391 | mapper->setSeries(this); |
|
391 | mapper->setSeries(this); | |
392 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
392 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
393 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
393 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
394 | mapper->setSeries(this); |
|
394 | mapper->setSeries(this); | |
395 | } |
|
395 | } | |
396 | } |
|
396 | } | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | QDeclarativeListProperty<QObject> DeclarativeHorizontalPercentBarSeries::seriesChildren() |
|
399 | QDeclarativeListProperty<QObject> DeclarativeHorizontalPercentBarSeries::seriesChildren() | |
400 | { |
|
400 | { | |
401 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeHorizontalPercentBarSeries::appendSeriesChildren); |
|
401 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeHorizontalPercentBarSeries::appendSeriesChildren); | |
402 | } |
|
402 | } | |
403 |
|
403 | |||
404 | void DeclarativeHorizontalPercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
404 | void DeclarativeHorizontalPercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
405 | { |
|
405 | { | |
406 | // Empty implementation; the children are parsed in componentComplete instead |
|
406 | // Empty implementation; the children are parsed in componentComplete instead | |
407 | Q_UNUSED(list); |
|
407 | Q_UNUSED(list); | |
408 | Q_UNUSED(element); |
|
408 | Q_UNUSED(element); | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | DeclarativeBarSet *DeclarativeHorizontalPercentBarSeries::at(int index) |
|
411 | DeclarativeBarSet *DeclarativeHorizontalPercentBarSeries::at(int index) | |
412 | { |
|
412 | { | |
413 | QList<QBarSet*> setList = barSets(); |
|
413 | QList<QBarSet*> setList = barSets(); | |
414 | if (index >= 0 && index < setList.count()) |
|
414 | if (index >= 0 && index < setList.count()) | |
415 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
415 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | |
416 |
|
416 | |||
417 | return 0; |
|
417 | return 0; | |
418 | } |
|
418 | } | |
419 |
|
419 | |||
420 | DeclarativeBarSet *DeclarativeHorizontalPercentBarSeries::insert(int index, QString label, QVariantList values) |
|
420 | DeclarativeBarSet *DeclarativeHorizontalPercentBarSeries::insert(int index, QString label, QVariantList values) | |
421 | { |
|
421 | { | |
422 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
422 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); | |
423 | barset->setLabel(label); |
|
423 | barset->setLabel(label); | |
424 | barset->setValues(values); |
|
424 | barset->setValues(values); | |
425 | if (QHorizontalPercentBarSeries::insert(index, barset)) |
|
425 | if (QHorizontalPercentBarSeries::insert(index, barset)) | |
426 | return barset; |
|
426 | return barset; | |
427 | delete barset; |
|
427 | delete barset; | |
428 | return 0; |
|
428 | return 0; | |
429 | } |
|
429 | } | |
430 |
|
430 | |||
431 | #include "moc_declarativebarseries.cpp" |
|
431 | #include "moc_declarativebarseries.cpp" | |
432 |
|
432 | |||
433 | QTCOMMERCIALCHART_END_NAMESPACE |
|
433 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,689 +1,689 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativechart.h" |
|
21 | #include "declarativechart.h" | |
22 | #include <QPainter> |
|
22 | #include <QPainter> | |
23 | #include <QDeclarativeEngine> |
|
23 | #include <QDeclarativeEngine> | |
24 | #include "declarativelineseries.h" |
|
24 | #include "declarativelineseries.h" | |
25 | #include "declarativeareaseries.h" |
|
25 | #include "declarativeareaseries.h" | |
26 | #include "declarativebarseries.h" |
|
26 | #include "declarativebarseries.h" | |
27 | #include "declarativepieseries.h" |
|
27 | #include "declarativepieseries.h" | |
28 | #include "declarativesplineseries.h" |
|
28 | #include "declarativesplineseries.h" | |
29 | #include "declarativescatterseries.h" |
|
29 | #include "declarativescatterseries.h" | |
30 | #include "qbarcategoryaxis.h" |
|
30 | #include "qbarcategoryaxis.h" | |
31 | #include "qvalueaxis.h" |
|
31 | #include "qvalueaxis.h" | |
32 | #include "qcategoryaxis.h" |
|
32 | #include "qcategoryaxis.h" | |
33 | #include "qabstractseries_p.h" |
|
33 | #include "qabstractseries_p.h" | |
34 | #include "declarativemargins.h" |
|
34 | #include "declarativemargins.h" | |
35 |
|
35 | |||
36 | #ifndef QT_ON_ARM |
|
36 | #ifndef QT_ON_ARM | |
37 | #include "qdatetimeaxis.h" |
|
37 | #include "qdatetimeaxis.h" | |
38 | #endif |
|
38 | #endif | |
39 |
|
39 | |||
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \qmlclass ChartView DeclarativeChart |
|
43 | \qmlclass ChartView DeclarativeChart | |
44 |
|
44 | |||
45 | ChartView element is the parent that is responsible for showing different chart series types. |
|
45 | ChartView element is the parent that is responsible for showing different chart series types. | |
46 |
|
46 | |||
47 | The following QML shows how to create a simple chart with one pie series: |
|
47 | The following QML shows how to create a simple chart with one pie series: | |
48 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
48 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 | |
49 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
49 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 | |
50 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
50 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 | |
51 |
|
51 | |||
52 | \beginfloatleft |
|
52 | \beginfloatleft | |
53 | \image examples_qmlpiechart.png |
|
53 | \image examples_qmlpiechart.png | |
54 | \endfloat |
|
54 | \endfloat | |
55 | \clearfloat |
|
55 | \clearfloat | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \qmlproperty Theme ChartView::theme |
|
59 | \qmlproperty Theme ChartView::theme | |
60 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
60 | Theme defines the visual appearance of the chart, including for example colors, fonts, line | |
61 | widths and chart background. |
|
61 | widths and chart background. | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | \qmlproperty Animation ChartView::animation |
|
65 | \qmlproperty Animation ChartView::animation | |
66 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
66 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, | |
67 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
67 | ChartView.SeriesAnimations or ChartView.AllAnimations. | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | \qmlproperty Font ChartView::titleFont |
|
71 | \qmlproperty Font ChartView::titleFont | |
72 | The title font of the chart |
|
72 | The title font of the chart | |
73 |
|
73 | |||
74 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
74 | See the \l {Font} {QML Font Element} for detailed documentation. | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \qmlproperty string ChartView::title |
|
78 | \qmlproperty string ChartView::title | |
79 | The title of the chart, shown on top of the chart. |
|
79 | The title of the chart, shown on top of the chart. | |
80 | \sa ChartView::titleColor |
|
80 | \sa ChartView::titleColor | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \qmlproperty string ChartView::titleColor |
|
84 | \qmlproperty string ChartView::titleColor | |
85 | The color of the title text. |
|
85 | The color of the title text. | |
86 | */ |
|
86 | */ | |
87 |
|
87 | |||
88 | /*! |
|
88 | /*! | |
89 | \qmlproperty Axis ChartView::axisX |
|
89 | \qmlproperty Axis ChartView::axisX | |
90 | The x-axis of the chart. |
|
90 | The x-axis of the chart. | |
91 | */ |
|
91 | */ | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | \qmlproperty Axis ChartView::axisY |
|
94 | \qmlproperty Axis ChartView::axisY | |
95 | The default y-axis of the chart. |
|
95 | The default y-axis of the chart. | |
96 | */ |
|
96 | */ | |
97 |
|
97 | |||
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty Legend ChartView::legend |
|
99 | \qmlproperty Legend ChartView::legend | |
100 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
100 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \qmlproperty int ChartView::count |
|
104 | \qmlproperty int ChartView::count | |
105 | The count of series added to the chart. |
|
105 | The count of series added to the chart. | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | \qmlproperty color ChartView::backgroundColor |
|
109 | \qmlproperty color ChartView::backgroundColor | |
110 | The color of the chart's background. By default background color is defined by chart theme. |
|
110 | The color of the chart's background. By default background color is defined by chart theme. | |
111 | \sa ChartView::theme |
|
111 | \sa ChartView::theme | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | \qmlproperty bool ChartView::dropShadowEnabled |
|
115 | \qmlproperty bool ChartView::dropShadowEnabled | |
116 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
116 | The chart's border drop shadow. Set to true to enable drop shadow. | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \qmlproperty real ChartView::topMargin |
|
120 | \qmlproperty real ChartView::topMargin | |
121 | Deprecated. Use minimumMargins and plotArea instead. |
|
121 | Deprecated. Use minimumMargins and plotArea instead. | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \qmlproperty real ChartView::bottomMargin |
|
125 | \qmlproperty real ChartView::bottomMargin | |
126 | Deprecated. Use minimumMargins and plotArea instead. |
|
126 | Deprecated. Use minimumMargins and plotArea instead. | |
127 | */ |
|
127 | */ | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \qmlproperty real ChartView::leftMargin |
|
130 | \qmlproperty real ChartView::leftMargin | |
131 | Deprecated. Use minimumMargins and plotArea instead. |
|
131 | Deprecated. Use minimumMargins and plotArea instead. | |
132 | */ |
|
132 | */ | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | \qmlproperty real ChartView::rightMargin |
|
135 | \qmlproperty real ChartView::rightMargin | |
136 | Deprecated. Use minimumMargins and plotArea instead. |
|
136 | Deprecated. Use minimumMargins and plotArea instead. | |
137 | */ |
|
137 | */ | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | \qmlproperty Margins ChartView::minimumMargins |
|
140 | \qmlproperty Margins ChartView::minimumMargins | |
141 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
141 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins | |
142 | area of ChartView is used for drawing title, axes and legend. Please note that setting the |
|
142 | area of ChartView is used for drawing title, axes and legend. Please note that setting the | |
143 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView |
|
143 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView | |
144 | properties that affect it's layout. If you need to know the actual plotting area used at any |
|
144 | properties that affect it's layout. If you need to know the actual plotting area used at any | |
145 | given time, you can check ChartView::plotArea instead. |
|
145 | given time, you can check ChartView::plotArea instead. | |
146 | */ |
|
146 | */ | |
147 |
|
147 | |||
148 | /*! |
|
148 | /*! | |
149 | \qmlproperty rect ChartView::plotArea |
|
149 | \qmlproperty rect ChartView::plotArea | |
150 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the |
|
150 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the | |
151 | margins. |
|
151 | margins. | |
152 | \sa ChartView::minimumMargins |
|
152 | \sa ChartView::minimumMargins | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
156 | \qmlmethod AbstractSeries ChartView::series(int index) | |
157 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
157 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with | |
158 | the count property of the chart. |
|
158 | the count property of the chart. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
162 | \qmlmethod AbstractSeries ChartView::series(string name) | |
163 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
163 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. | |
164 | */ |
|
164 | */ | |
165 |
|
165 | |||
166 | /*! |
|
166 | /*! | |
167 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name) |
|
167 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name) | |
168 | Creates a series object of \a type to the chart. For example: |
|
168 | Creates a series object of \a type to the chart. For example: | |
169 | \code |
|
169 | \code | |
170 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series"); |
|
170 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series"); | |
171 | scatter.markerSize = 22; |
|
171 | scatter.markerSize = 22; | |
172 | scatter.append(1.1, 2.0); |
|
172 | scatter.append(1.1, 2.0); | |
173 | \endcode |
|
173 | \endcode | |
174 | */ |
|
174 | */ | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) |
|
177 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) | |
178 | The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported. |
|
178 | The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported. | |
179 | */ |
|
179 | */ | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | \qmlmethod ChartView::zoomY(real factor) |
|
182 | \qmlmethod ChartView::zoomY(real factor) | |
183 | Zooms in by \a factor on the center of the chart. |
|
183 | Zooms in by \a factor on the center of the chart. | |
184 | */ |
|
184 | */ | |
185 |
|
185 | |||
186 | /*! |
|
186 | /*! | |
187 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
187 | \qmlmethod ChartView::scrollLeft(real pixels) | |
188 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
188 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. | |
189 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
189 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
190 | */ |
|
190 | */ | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | \qmlmethod ChartView::scrollRight(real pixels) |
|
193 | \qmlmethod ChartView::scrollRight(real pixels) | |
194 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
194 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. | |
195 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
195 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
196 | */ |
|
196 | */ | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | \qmlmethod ChartView::scrollUp(real pixels) |
|
199 | \qmlmethod ChartView::scrollUp(real pixels) | |
200 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
200 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. | |
201 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
201 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
202 | */ |
|
202 | */ | |
203 |
|
203 | |||
204 | /*! |
|
204 | /*! | |
205 | \qmlmethod ChartView::scrollDown(real pixels) |
|
205 | \qmlmethod ChartView::scrollDown(real pixels) | |
206 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
206 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. | |
207 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
207 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
208 | */ |
|
208 | */ | |
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | \qmlsignal ChartView::onTopMarginChanged(real margin) |
|
211 | \qmlsignal ChartView::onTopMarginChanged(real margin) | |
212 | The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
212 | The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
213 | related properties of the legend or chart title. |
|
213 | related properties of the legend or chart title. | |
214 | */ |
|
214 | */ | |
215 |
|
215 | |||
216 | /*! |
|
216 | /*! | |
217 | \qmlsignal ChartView::onBottomMarginChanged(real margin) |
|
217 | \qmlsignal ChartView::onBottomMarginChanged(real margin) | |
218 | The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
218 | The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
219 | related properties of the legend or chart title. |
|
219 | related properties of the legend or chart title. | |
220 | */ |
|
220 | */ | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | \qmlsignal ChartView::onLeftMarginChanged(real margin) |
|
223 | \qmlsignal ChartView::onLeftMarginChanged(real margin) | |
224 | The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
224 | The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
225 | related properties of the legend or chart title. |
|
225 | related properties of the legend or chart title. | |
226 | */ |
|
226 | */ | |
227 |
|
227 | |||
228 | /*! |
|
228 | /*! | |
229 | \qmlsignal ChartView::onRightMarginChanged(real margin) |
|
229 | \qmlsignal ChartView::onRightMarginChanged(real margin) | |
230 | The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
230 | The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
231 | related properties of the legend or chart title. |
|
231 | related properties of the legend or chart title. | |
232 | */ |
|
232 | */ | |
233 |
|
233 | |||
234 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
234 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |
235 | : QDeclarativeItem(parent), |
|
235 | : QDeclarativeItem(parent), | |
236 | m_chart(new QChart(this)) |
|
236 | m_chart(new QChart(this)) | |
237 | { |
|
237 | { | |
238 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
238 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
239 | m_minMargins = new DeclarativeMargins(this); |
|
239 | m_minMargins = new DeclarativeMargins(this); | |
240 |
connect(m_minMargins, SIGNAL(topChanged(int, |
|
240 | connect(m_minMargins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
241 |
connect(m_minMargins, SIGNAL(bottomChanged(int, |
|
241 | connect(m_minMargins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
242 |
connect(m_minMargins, SIGNAL(leftChanged(int, |
|
242 | connect(m_minMargins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
243 |
connect(m_minMargins, SIGNAL(rightChanged(int, |
|
243 | connect(m_minMargins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
244 | // TODO: connect to plotAreaChanged signal from m_chart |
|
244 | // TODO: connect to plotAreaChanged signal from m_chart | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) |
|
247 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) | |
248 | { |
|
248 | { | |
249 | m_chart->setMinimumMargins(QMargins(left, top, right, bottom)); |
|
249 | m_chart->setMinimumMargins(QMargins(left, top, right, bottom)); | |
250 | plotAreaChanged(m_chart->plotArea()); |
|
250 | plotAreaChanged(m_chart->plotArea()); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | DeclarativeChart::~DeclarativeChart() |
|
253 | DeclarativeChart::~DeclarativeChart() | |
254 | { |
|
254 | { | |
255 | delete m_chart; |
|
255 | delete m_chart; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
258 | void DeclarativeChart::childEvent(QChildEvent *event) | |
259 | { |
|
259 | { | |
260 | if (event->type() == QEvent::ChildAdded) { |
|
260 | if (event->type() == QEvent::ChildAdded) { | |
261 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
261 | if (qobject_cast<QAbstractSeries *>(event->child())) { | |
262 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
262 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); | |
263 | } |
|
263 | } | |
264 | } |
|
264 | } | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | void DeclarativeChart::componentComplete() |
|
267 | void DeclarativeChart::componentComplete() | |
268 | { |
|
268 | { | |
269 | foreach(QObject *child, children()) { |
|
269 | foreach(QObject *child, children()) { | |
270 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
270 | if (qobject_cast<QAbstractSeries *>(child)) { | |
271 | // Add series to the chart |
|
271 | // Add series to the chart | |
272 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); |
|
272 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); | |
273 | m_chart->addSeries(series); |
|
273 | m_chart->addSeries(series); | |
274 |
|
274 | |||
275 | // Set optional user defined axes and connect axis related signals |
|
275 | // Set optional user defined axes and connect axis related signals | |
276 | if (qobject_cast<DeclarativeLineSeries *>(child)) { |
|
276 | if (qobject_cast<DeclarativeLineSeries *>(child)) { | |
277 | DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child); |
|
277 | DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child); | |
278 |
connect(s, SIGNAL(axisXChanged(QAbstractAxis |
|
278 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
279 |
connect(s, SIGNAL(axisYChanged(QAbstractAxis |
|
279 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
280 | setAxisX(s->axisX(), s); |
|
280 | setAxisX(s->axisX(), s); | |
281 | setAxisY(s->axisY(), s); |
|
281 | setAxisY(s->axisY(), s); | |
282 | } else if (qobject_cast<DeclarativeSplineSeries *>(child)) { |
|
282 | } else if (qobject_cast<DeclarativeSplineSeries *>(child)) { | |
283 | DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child); |
|
283 | DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child); | |
284 |
connect(s, SIGNAL(axisXChanged(QAbstractAxis |
|
284 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
285 |
connect(s, SIGNAL(axisYChanged(QAbstractAxis |
|
285 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
286 | setAxisX(s->axisX(), s); |
|
286 | setAxisX(s->axisX(), s); | |
287 | setAxisY(s->axisY(), s); |
|
287 | setAxisY(s->axisY(), s); | |
288 | } else if (qobject_cast<DeclarativeScatterSeries *>(child)) { |
|
288 | } else if (qobject_cast<DeclarativeScatterSeries *>(child)) { | |
289 | DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child); |
|
289 | DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child); | |
290 |
connect(s, SIGNAL(axisXChanged(QAbstractAxis |
|
290 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
291 |
connect(s, SIGNAL(axisYChanged(QAbstractAxis |
|
291 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
292 | setAxisX(s->axisX(), s); |
|
292 | setAxisX(s->axisX(), s); | |
293 | setAxisY(s->axisY(), s); |
|
293 | setAxisY(s->axisY(), s); | |
294 | } else if (qobject_cast<DeclarativeAreaSeries *>(child)) { |
|
294 | } else if (qobject_cast<DeclarativeAreaSeries *>(child)) { | |
295 | DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child); |
|
295 | DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child); | |
296 |
connect(s, SIGNAL(axisXChanged(QAbstractAxis |
|
296 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
297 |
connect(s, SIGNAL(axisYChanged(QAbstractAxis |
|
297 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
298 | setAxisX(s->axisX(), s); |
|
298 | setAxisX(s->axisX(), s); | |
299 | setAxisY(s->axisY(), s); |
|
299 | setAxisY(s->axisY(), s); | |
300 | } else if (qobject_cast<DeclarativeBarSeries *>(child)) { |
|
300 | } else if (qobject_cast<DeclarativeBarSeries *>(child)) { | |
301 | DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child); |
|
301 | DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child); | |
302 |
connect(s, SIGNAL(axisXChanged(QAbstractAxis |
|
302 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
303 |
connect(s, SIGNAL(axisYChanged(QAbstractAxis |
|
303 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
304 | setAxisX(s->axisX(), s); |
|
304 | setAxisX(s->axisX(), s); | |
305 | setAxisY(s->axisY(), s); |
|
305 | setAxisY(s->axisY(), s); | |
306 | } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) { |
|
306 | } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) { | |
307 | DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child); |
|
307 | DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child); | |
308 |
connect(s, SIGNAL(axisXChanged(QAbstractAxis |
|
308 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
309 |
connect(s, SIGNAL(axisYChanged(QAbstractAxis |
|
309 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
310 | setAxisX(s->axisX(), s); |
|
310 | setAxisX(s->axisX(), s); | |
311 | setAxisY(s->axisY(), s); |
|
311 | setAxisY(s->axisY(), s); | |
312 | } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) { |
|
312 | } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) { | |
313 | DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child); |
|
313 | DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child); | |
314 |
connect(s, SIGNAL(axisXChanged(QAbstractAxis |
|
314 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
315 |
connect(s, SIGNAL(axisYChanged(QAbstractAxis |
|
315 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
316 | setAxisX(s->axisX(), s); |
|
316 | setAxisX(s->axisX(), s); | |
317 | setAxisY(s->axisY(), s); |
|
317 | setAxisY(s->axisY(), s); | |
318 | } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) { |
|
318 | } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) { | |
319 | DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child); |
|
319 | DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child); | |
320 |
connect(s, SIGNAL(axisXChanged(QAbstractAxis |
|
320 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
321 |
connect(s, SIGNAL(axisYChanged(QAbstractAxis |
|
321 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
322 | setAxisX(s->axisX(), s); |
|
322 | setAxisX(s->axisX(), s); | |
323 | setAxisY(s->axisY(), s); |
|
323 | setAxisY(s->axisY(), s); | |
324 | } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) { |
|
324 | } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) { | |
325 | DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child); |
|
325 | DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child); | |
326 |
connect(s, SIGNAL(axisXChanged(QAbstractAxis |
|
326 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
327 |
connect(s, SIGNAL(axisYChanged(QAbstractAxis |
|
327 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
328 | setAxisX(s->axisX(), s); |
|
328 | setAxisX(s->axisX(), s); | |
329 | setAxisY(s->axisY(), s); |
|
329 | setAxisY(s->axisY(), s); | |
330 | } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) { |
|
330 | } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) { | |
331 | DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child); |
|
331 | DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child); | |
332 |
connect(s, SIGNAL(axisXChanged(QAbstractAxis |
|
332 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
333 |
connect(s, SIGNAL(axisYChanged(QAbstractAxis |
|
333 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
334 | setAxisX(s->axisX(), s); |
|
334 | setAxisX(s->axisX(), s); | |
335 | setAxisY(s->axisY(), s); |
|
335 | setAxisY(s->axisY(), s); | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | // Create the missing axes for the series that cannot be painted without axes |
|
338 | // Create the missing axes for the series that cannot be painted without axes | |
339 | createDefaultAxes(series); |
|
339 | createDefaultAxes(series); | |
340 | } else if(qobject_cast<QAbstractAxis *>(child)) { |
|
340 | } else if(qobject_cast<QAbstractAxis *>(child)) { | |
341 | // Do nothing, axes are set for the chart in the context of series |
|
341 | // Do nothing, axes are set for the chart in the context of series | |
342 | } |
|
342 | } | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | QDeclarativeItem::componentComplete(); |
|
345 | QDeclarativeItem::componentComplete(); | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | void DeclarativeChart::handleAxisXSet(QAbstractAxis* axis) |
|
348 | void DeclarativeChart::handleAxisXSet(QAbstractAxis* axis) | |
349 | { |
|
349 | { | |
350 | // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis; |
|
350 | // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis; | |
351 | if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) { |
|
351 | if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) { | |
352 | m_chart->setAxisX(axis, qobject_cast<DeclarativeLineSeries *>(sender())); |
|
352 | m_chart->setAxisX(axis, qobject_cast<DeclarativeLineSeries *>(sender())); | |
353 | } |
|
353 | } | |
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | void DeclarativeChart::handleAxisYSet(QAbstractAxis* axis) |
|
356 | void DeclarativeChart::handleAxisYSet(QAbstractAxis* axis) | |
357 | { |
|
357 | { | |
358 | // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis; |
|
358 | // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis; | |
359 | if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) { |
|
359 | if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) { | |
360 | m_chart->setAxisY(axis, qobject_cast<DeclarativeLineSeries *>(sender())); |
|
360 | m_chart->setAxisY(axis, qobject_cast<DeclarativeLineSeries *>(sender())); | |
361 | } |
|
361 | } | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
364 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
365 | { |
|
365 | { | |
366 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
366 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); | |
367 | if (newGeometry.isValid()) { |
|
367 | if (newGeometry.isValid()) { | |
368 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
368 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
369 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
369 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
370 | } |
|
370 | } | |
371 | } |
|
371 | } | |
372 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
372 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); | |
373 | } |
|
373 | } | |
374 |
|
374 | |||
375 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
375 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) | |
376 | { |
|
376 | { | |
377 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
377 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; | |
378 | if (chartTheme != m_chart->theme()) |
|
378 | if (chartTheme != m_chart->theme()) | |
379 | m_chart->setTheme(chartTheme); |
|
379 | m_chart->setTheme(chartTheme); | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
382 | DeclarativeChart::Theme DeclarativeChart::theme() | |
383 | { |
|
383 | { | |
384 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
384 | return (DeclarativeChart::Theme) m_chart->theme(); | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
387 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) | |
388 | { |
|
388 | { | |
389 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
389 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; | |
390 | if (animationOptions != m_chart->animationOptions()) |
|
390 | if (animationOptions != m_chart->animationOptions()) | |
391 | m_chart->setAnimationOptions(animationOptions); |
|
391 | m_chart->setAnimationOptions(animationOptions); | |
392 | } |
|
392 | } | |
393 |
|
393 | |||
394 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
394 | DeclarativeChart::Animation DeclarativeChart::animationOptions() | |
395 | { |
|
395 | { | |
396 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
396 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) | |
397 | return DeclarativeChart::AllAnimations; |
|
397 | return DeclarativeChart::AllAnimations; | |
398 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
398 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) | |
399 | return DeclarativeChart::GridAxisAnimations; |
|
399 | return DeclarativeChart::GridAxisAnimations; | |
400 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
400 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) | |
401 | return DeclarativeChart::SeriesAnimations; |
|
401 | return DeclarativeChart::SeriesAnimations; | |
402 | else |
|
402 | else | |
403 | return DeclarativeChart::NoAnimation; |
|
403 | return DeclarativeChart::NoAnimation; | |
404 | } |
|
404 | } | |
405 |
|
405 | |||
406 | void DeclarativeChart::setTitle(QString title) |
|
406 | void DeclarativeChart::setTitle(QString title) | |
407 | { |
|
407 | { | |
408 | if (title != m_chart->title()) |
|
408 | if (title != m_chart->title()) | |
409 | m_chart->setTitle(title); |
|
409 | m_chart->setTitle(title); | |
410 | } |
|
410 | } | |
411 | QString DeclarativeChart::title() |
|
411 | QString DeclarativeChart::title() | |
412 | { |
|
412 | { | |
413 | return m_chart->title(); |
|
413 | return m_chart->title(); | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
416 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) | |
417 | { |
|
417 | { | |
418 | return m_chart->axisX(series); |
|
418 | return m_chart->axisX(series); | |
419 | } |
|
419 | } | |
420 |
|
420 | |||
421 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
421 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) | |
422 | { |
|
422 | { | |
423 | return m_chart->axisY(series); |
|
423 | return m_chart->axisY(series); | |
424 | } |
|
424 | } | |
425 |
|
425 | |||
426 | QLegend *DeclarativeChart::legend() |
|
426 | QLegend *DeclarativeChart::legend() | |
427 | { |
|
427 | { | |
428 | return m_chart->legend(); |
|
428 | return m_chart->legend(); | |
429 | } |
|
429 | } | |
430 |
|
430 | |||
431 | void DeclarativeChart::setTitleColor(QColor color) |
|
431 | void DeclarativeChart::setTitleColor(QColor color) | |
432 | { |
|
432 | { | |
433 | QBrush b = m_chart->titleBrush(); |
|
433 | QBrush b = m_chart->titleBrush(); | |
434 | if (color != b.color()) { |
|
434 | if (color != b.color()) { | |
435 | b.setColor(color); |
|
435 | b.setColor(color); | |
436 | m_chart->setTitleBrush(b); |
|
436 | m_chart->setTitleBrush(b); | |
437 | emit titleColorChanged(color); |
|
437 | emit titleColorChanged(color); | |
438 | } |
|
438 | } | |
439 | } |
|
439 | } | |
440 |
|
440 | |||
441 | QFont DeclarativeChart::titleFont() const |
|
441 | QFont DeclarativeChart::titleFont() const | |
442 | { |
|
442 | { | |
443 | return m_chart->titleFont(); |
|
443 | return m_chart->titleFont(); | |
444 | } |
|
444 | } | |
445 |
|
445 | |||
446 | void DeclarativeChart::setTitleFont(const QFont& font) |
|
446 | void DeclarativeChart::setTitleFont(const QFont& font) | |
447 | { |
|
447 | { | |
448 | m_chart->setTitleFont(font); |
|
448 | m_chart->setTitleFont(font); | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | QColor DeclarativeChart::titleColor() |
|
451 | QColor DeclarativeChart::titleColor() | |
452 | { |
|
452 | { | |
453 | return m_chart->titleBrush().color(); |
|
453 | return m_chart->titleBrush().color(); | |
454 | } |
|
454 | } | |
455 |
|
455 | |||
456 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
456 | void DeclarativeChart::setBackgroundColor(QColor color) | |
457 | { |
|
457 | { | |
458 | QBrush b = m_chart->backgroundBrush(); |
|
458 | QBrush b = m_chart->backgroundBrush(); | |
459 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
459 | if (b.style() != Qt::SolidPattern || color != b.color()) { | |
460 | b.setStyle(Qt::SolidPattern); |
|
460 | b.setStyle(Qt::SolidPattern); | |
461 | b.setColor(color); |
|
461 | b.setColor(color); | |
462 | m_chart->setBackgroundBrush(b); |
|
462 | m_chart->setBackgroundBrush(b); | |
463 | emit backgroundColorChanged(); |
|
463 | emit backgroundColorChanged(); | |
464 | } |
|
464 | } | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | QColor DeclarativeChart::backgroundColor() |
|
467 | QColor DeclarativeChart::backgroundColor() | |
468 | { |
|
468 | { | |
469 | return m_chart->backgroundBrush().color(); |
|
469 | return m_chart->backgroundBrush().color(); | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | int DeclarativeChart::count() |
|
472 | int DeclarativeChart::count() | |
473 | { |
|
473 | { | |
474 | return m_chart->series().count(); |
|
474 | return m_chart->series().count(); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
477 | void DeclarativeChart::setDropShadowEnabled(bool enabled) | |
478 | { |
|
478 | { | |
479 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
479 | if (enabled != m_chart->isDropShadowEnabled()) { | |
480 | m_chart->setDropShadowEnabled(enabled); |
|
480 | m_chart->setDropShadowEnabled(enabled); | |
481 | dropShadowEnabledChanged(enabled); |
|
481 | dropShadowEnabledChanged(enabled); | |
482 | } |
|
482 | } | |
483 | } |
|
483 | } | |
484 |
|
484 | |||
485 | bool DeclarativeChart::dropShadowEnabled() |
|
485 | bool DeclarativeChart::dropShadowEnabled() | |
486 | { |
|
486 | { | |
487 | return m_chart->isDropShadowEnabled(); |
|
487 | return m_chart->isDropShadowEnabled(); | |
488 | } |
|
488 | } | |
489 |
|
489 | |||
490 | qreal DeclarativeChart::topMargin() |
|
490 | qreal DeclarativeChart::topMargin() | |
491 | { |
|
491 | { | |
492 | qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
492 | qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead."; | |
493 | return m_chart->plotArea().top(); |
|
493 | return m_chart->plotArea().top(); | |
494 | } |
|
494 | } | |
495 |
|
495 | |||
496 | qreal DeclarativeChart::bottomMargin() |
|
496 | qreal DeclarativeChart::bottomMargin() | |
497 | { |
|
497 | { | |
498 | qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
498 | qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead."; | |
499 | return m_chart->plotArea().bottom(); |
|
499 | return m_chart->plotArea().bottom(); | |
500 | } |
|
500 | } | |
501 |
|
501 | |||
502 | qreal DeclarativeChart::leftMargin() |
|
502 | qreal DeclarativeChart::leftMargin() | |
503 | { |
|
503 | { | |
504 | qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
504 | qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead."; | |
505 | return m_chart->plotArea().left(); |
|
505 | return m_chart->plotArea().left(); | |
506 | } |
|
506 | } | |
507 |
|
507 | |||
508 | qreal DeclarativeChart::rightMargin() |
|
508 | qreal DeclarativeChart::rightMargin() | |
509 | { |
|
509 | { | |
510 | qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
510 | qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead."; | |
511 | return m_chart->plotArea().right(); |
|
511 | return m_chart->plotArea().right(); | |
512 | } |
|
512 | } | |
513 |
|
513 | |||
514 | void DeclarativeChart::zoom(qreal factor) |
|
514 | void DeclarativeChart::zoom(qreal factor) | |
515 | { |
|
515 | { | |
516 | m_chart->zoom(factor); |
|
516 | m_chart->zoom(factor); | |
517 | } |
|
517 | } | |
518 |
|
518 | |||
519 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
519 | void DeclarativeChart::scrollLeft(qreal pixels) | |
520 | { |
|
520 | { | |
521 | m_chart->scroll(pixels, 0); |
|
521 | m_chart->scroll(pixels, 0); | |
522 | } |
|
522 | } | |
523 |
|
523 | |||
524 | void DeclarativeChart::scrollRight(qreal pixels) |
|
524 | void DeclarativeChart::scrollRight(qreal pixels) | |
525 | { |
|
525 | { | |
526 | m_chart->scroll(-pixels, 0); |
|
526 | m_chart->scroll(-pixels, 0); | |
527 | } |
|
527 | } | |
528 |
|
528 | |||
529 | void DeclarativeChart::scrollUp(qreal pixels) |
|
529 | void DeclarativeChart::scrollUp(qreal pixels) | |
530 | { |
|
530 | { | |
531 | m_chart->scroll(0, pixels); |
|
531 | m_chart->scroll(0, pixels); | |
532 | } |
|
532 | } | |
533 |
|
533 | |||
534 | void DeclarativeChart::scrollDown(qreal pixels) |
|
534 | void DeclarativeChart::scrollDown(qreal pixels) | |
535 | { |
|
535 | { | |
536 | m_chart->scroll(0, -pixels); |
|
536 | m_chart->scroll(0, -pixels); | |
537 | } |
|
537 | } | |
538 |
|
538 | |||
539 | QAbstractSeries *DeclarativeChart::series(int index) |
|
539 | QAbstractSeries *DeclarativeChart::series(int index) | |
540 | { |
|
540 | { | |
541 | if (index < m_chart->series().count()) { |
|
541 | if (index < m_chart->series().count()) { | |
542 | return m_chart->series().at(index); |
|
542 | return m_chart->series().at(index); | |
543 | } |
|
543 | } | |
544 | return 0; |
|
544 | return 0; | |
545 | } |
|
545 | } | |
546 |
|
546 | |||
547 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
547 | QAbstractSeries *DeclarativeChart::series(QString seriesName) | |
548 | { |
|
548 | { | |
549 | foreach(QAbstractSeries *series, m_chart->series()) { |
|
549 | foreach(QAbstractSeries *series, m_chart->series()) { | |
550 | if (series->name() == seriesName) |
|
550 | if (series->name() == seriesName) | |
551 | return series; |
|
551 | return series; | |
552 | } |
|
552 | } | |
553 | return 0; |
|
553 | return 0; | |
554 | } |
|
554 | } | |
555 |
|
555 | |||
556 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
556 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) | |
557 | { |
|
557 | { | |
558 | QAbstractSeries *series = 0; |
|
558 | QAbstractSeries *series = 0; | |
559 |
|
559 | |||
560 | switch (type) { |
|
560 | switch (type) { | |
561 | case DeclarativeChart::SeriesTypeLine: |
|
561 | case DeclarativeChart::SeriesTypeLine: | |
562 | series = new DeclarativeLineSeries(); |
|
562 | series = new DeclarativeLineSeries(); | |
563 | break; |
|
563 | break; | |
564 | case DeclarativeChart::SeriesTypeArea: |
|
564 | case DeclarativeChart::SeriesTypeArea: | |
565 | series = new DeclarativeAreaSeries(); |
|
565 | series = new DeclarativeAreaSeries(); | |
566 | break; |
|
566 | break; | |
567 | case DeclarativeChart::SeriesTypeStackedBar: |
|
567 | case DeclarativeChart::SeriesTypeStackedBar: | |
568 | series = new DeclarativeStackedBarSeries(); |
|
568 | series = new DeclarativeStackedBarSeries(); | |
569 | break; |
|
569 | break; | |
570 | case DeclarativeChart::SeriesTypePercentBar: |
|
570 | case DeclarativeChart::SeriesTypePercentBar: | |
571 | series = new DeclarativePercentBarSeries(); |
|
571 | series = new DeclarativePercentBarSeries(); | |
572 | break; |
|
572 | break; | |
573 | case DeclarativeChart::SeriesTypeBar: |
|
573 | case DeclarativeChart::SeriesTypeBar: | |
574 | series = new DeclarativeBarSeries(); |
|
574 | series = new DeclarativeBarSeries(); | |
575 | break; |
|
575 | break; | |
576 | case DeclarativeChart::SeriesTypeHorizontalBar: |
|
576 | case DeclarativeChart::SeriesTypeHorizontalBar: | |
577 | series = new DeclarativeHorizontalBarSeries(); |
|
577 | series = new DeclarativeHorizontalBarSeries(); | |
578 | break; |
|
578 | break; | |
579 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: |
|
579 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: | |
580 | series = new DeclarativeHorizontalPercentBarSeries(); |
|
580 | series = new DeclarativeHorizontalPercentBarSeries(); | |
581 | break; |
|
581 | break; | |
582 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: |
|
582 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: | |
583 | series = new DeclarativeHorizontalStackedBarSeries(); |
|
583 | series = new DeclarativeHorizontalStackedBarSeries(); | |
584 | break; |
|
584 | break; | |
585 | case DeclarativeChart::SeriesTypePie: |
|
585 | case DeclarativeChart::SeriesTypePie: | |
586 | series = new DeclarativePieSeries(); |
|
586 | series = new DeclarativePieSeries(); | |
587 | break; |
|
587 | break; | |
588 | case DeclarativeChart::SeriesTypeScatter: |
|
588 | case DeclarativeChart::SeriesTypeScatter: | |
589 | series = new DeclarativeScatterSeries(); |
|
589 | series = new DeclarativeScatterSeries(); | |
590 | break; |
|
590 | break; | |
591 | case DeclarativeChart::SeriesTypeSpline: |
|
591 | case DeclarativeChart::SeriesTypeSpline: | |
592 | series = new DeclarativeSplineSeries(); |
|
592 | series = new DeclarativeSplineSeries(); | |
593 | break; |
|
593 | break; | |
594 | default: |
|
594 | default: | |
595 | qWarning() << "Illegal series type"; |
|
595 | qWarning() << "Illegal series type"; | |
596 | } |
|
596 | } | |
597 |
|
597 | |||
598 | if (series) { |
|
598 | if (series) { | |
599 | series->setName(name); |
|
599 | series->setName(name); | |
600 | m_chart->addSeries(series); |
|
600 | m_chart->addSeries(series); | |
601 | createDefaultAxes(series); |
|
601 | createDefaultAxes(series); | |
602 | } |
|
602 | } | |
603 |
|
603 | |||
604 | return series; |
|
604 | return series; | |
605 | } |
|
605 | } | |
606 |
|
606 | |||
607 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
607 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) | |
608 | { |
|
608 | { | |
609 | if (axis) |
|
609 | if (axis) | |
610 | m_chart->setAxisX(axis, series); |
|
610 | m_chart->setAxisX(axis, series); | |
611 | } |
|
611 | } | |
612 |
|
612 | |||
613 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
613 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) | |
614 | { |
|
614 | { | |
615 | if (axis) |
|
615 | if (axis) | |
616 | m_chart->setAxisY(axis, series); |
|
616 | m_chart->setAxisY(axis, series); | |
617 | } |
|
617 | } | |
618 |
|
618 | |||
619 | void DeclarativeChart::createDefaultAxes() |
|
619 | void DeclarativeChart::createDefaultAxes() | |
620 | { |
|
620 | { | |
621 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; |
|
621 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; | |
622 | } |
|
622 | } | |
623 |
|
623 | |||
624 | void DeclarativeChart::createDefaultAxes(QAbstractSeries* series) |
|
624 | void DeclarativeChart::createDefaultAxes(QAbstractSeries* series) | |
625 | { |
|
625 | { | |
626 | foreach (QAbstractSeries *s, m_chart->series()) { |
|
626 | foreach (QAbstractSeries *s, m_chart->series()) { | |
627 | // If there is already an x axis of the correct type, re-use it |
|
627 | // If there is already an x axis of the correct type, re-use it | |
628 | if (!m_chart->axisX(series) && s != series && m_chart->axisX(s) |
|
628 | if (!m_chart->axisX(series) && s != series && m_chart->axisX(s) | |
629 | && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal)) |
|
629 | && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal)) | |
630 | m_chart->setAxisX(m_chart->axisX(s), series); |
|
630 | m_chart->setAxisX(m_chart->axisX(s), series); | |
631 |
|
631 | |||
632 | // If there is already a y axis of the correct type, re-use it |
|
632 | // If there is already a y axis of the correct type, re-use it | |
633 | if (!m_chart->axisY(series) && s != series && m_chart->axisY(s) |
|
633 | if (!m_chart->axisY(series) && s != series && m_chart->axisY(s) | |
634 | && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical)) |
|
634 | && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical)) | |
635 | m_chart->setAxisY(m_chart->axisY(s), series); |
|
635 | m_chart->setAxisY(m_chart->axisY(s), series); | |
636 | } |
|
636 | } | |
637 |
|
637 | |||
638 | // If no x axis of correct type was found, create a new x axis based of default axis type |
|
638 | // If no x axis of correct type was found, create a new x axis based of default axis type | |
639 | if (!m_chart->axisX(series)) { |
|
639 | if (!m_chart->axisX(series)) { | |
640 | switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) { |
|
640 | switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) { | |
641 | case QAbstractAxis::AxisTypeValue: |
|
641 | case QAbstractAxis::AxisTypeValue: | |
642 | m_chart->setAxisX(new QValueAxis(this), series); |
|
642 | m_chart->setAxisX(new QValueAxis(this), series); | |
643 | break; |
|
643 | break; | |
644 | case QAbstractAxis::AxisTypeBarCategory: |
|
644 | case QAbstractAxis::AxisTypeBarCategory: | |
645 | m_chart->setAxisX(new QBarCategoryAxis(this), series); |
|
645 | m_chart->setAxisX(new QBarCategoryAxis(this), series); | |
646 | break; |
|
646 | break; | |
647 | case QAbstractAxis::AxisTypeCategory: |
|
647 | case QAbstractAxis::AxisTypeCategory: | |
648 | m_chart->setAxisX(new QCategoryAxis(this), series); |
|
648 | m_chart->setAxisX(new QCategoryAxis(this), series); | |
649 | break; |
|
649 | break; | |
650 | #ifndef QT_ON_ARM |
|
650 | #ifndef QT_ON_ARM | |
651 | case QAbstractAxis::AxisTypeDateTime: |
|
651 | case QAbstractAxis::AxisTypeDateTime: | |
652 | m_chart->setAxisX(new QDateTimeAxis(this), series); |
|
652 | m_chart->setAxisX(new QDateTimeAxis(this), series); | |
653 | break; |
|
653 | break; | |
654 | #endif |
|
654 | #endif | |
655 | default: |
|
655 | default: | |
656 | // Do nothing, assume AxisTypeNoAxis |
|
656 | // Do nothing, assume AxisTypeNoAxis | |
657 | break; |
|
657 | break; | |
658 | } |
|
658 | } | |
659 | } |
|
659 | } | |
660 |
|
660 | |||
661 | // If no y axis of correct type was found, create a new y axis based of default axis type |
|
661 | // If no y axis of correct type was found, create a new y axis based of default axis type | |
662 | if (!m_chart->axisY(series)) { |
|
662 | if (!m_chart->axisY(series)) { | |
663 | switch (series->d_ptr->defaultAxisType(Qt::Vertical)) { |
|
663 | switch (series->d_ptr->defaultAxisType(Qt::Vertical)) { | |
664 | case QAbstractAxis::AxisTypeValue: |
|
664 | case QAbstractAxis::AxisTypeValue: | |
665 | m_chart->setAxisY(new QValueAxis(this), series); |
|
665 | m_chart->setAxisY(new QValueAxis(this), series); | |
666 | break; |
|
666 | break; | |
667 | case QAbstractAxis::AxisTypeBarCategory: |
|
667 | case QAbstractAxis::AxisTypeBarCategory: | |
668 | m_chart->setAxisY(new QBarCategoryAxis(this), series); |
|
668 | m_chart->setAxisY(new QBarCategoryAxis(this), series); | |
669 | break; |
|
669 | break; | |
670 | case QAbstractAxis::AxisTypeCategory: |
|
670 | case QAbstractAxis::AxisTypeCategory: | |
671 | m_chart->setAxisY(new QCategoryAxis(this), series); |
|
671 | m_chart->setAxisY(new QCategoryAxis(this), series); | |
672 | break; |
|
672 | break; | |
673 | #ifndef QT_ON_ARM |
|
673 | #ifndef QT_ON_ARM | |
674 | case QAbstractAxis::AxisTypeDateTime: |
|
674 | case QAbstractAxis::AxisTypeDateTime: | |
675 | m_chart->setAxisY(new QDateTimeAxis(this), series); |
|
675 | m_chart->setAxisY(new QDateTimeAxis(this), series); | |
676 | break; |
|
676 | break; | |
677 | #endif |
|
677 | #endif | |
678 | default: |
|
678 | default: | |
679 | // Do nothing, assume AxisTypeNoAxis |
|
679 | // Do nothing, assume AxisTypeNoAxis | |
680 | break; |
|
680 | break; | |
681 | } |
|
681 | } | |
682 | } |
|
682 | } | |
683 |
|
683 | |||
684 | //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series); |
|
684 | //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series); | |
685 | } |
|
685 | } | |
686 |
|
686 | |||
687 | #include "moc_declarativechart.cpp" |
|
687 | #include "moc_declarativechart.cpp" | |
688 |
|
688 | |||
689 | QTCOMMERCIALCHART_END_NAMESPACE |
|
689 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now