@@ -1,510 +1,510 | |||
|
1 | 1 | /****************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
|
4 | 4 | ** Contact: http://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:COMM$ |
|
9 | 9 | ** |
|
10 | 10 | ** Commercial License Usage |
|
11 | 11 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
12 | 12 | ** accordance with the commercial license agreement provided with the |
|
13 | 13 | ** Software or, alternatively, in accordance with the terms contained in |
|
14 | 14 | ** a written agreement between you and The Qt Company. For licensing terms |
|
15 | 15 | ** and conditions see http://www.qt.io/terms-conditions. For further |
|
16 | 16 | ** information use the contact form at http://www.qt.io/contact-us. |
|
17 | 17 | ** |
|
18 | 18 | ** $QT_END_LICENSE$ |
|
19 | 19 | ** |
|
20 | 20 | ******************************************************************************/ |
|
21 | 21 | |
|
22 | 22 | #include "declarativebarseries.h" |
|
23 | 23 | #include <QtCharts/QBarSet> |
|
24 | 24 | #include <QtCharts/QVBarModelMapper> |
|
25 | 25 | #include <QtCharts/QHBarModelMapper> |
|
26 | 26 | |
|
27 | 27 | QT_CHARTS_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) |
|
30 | 30 | : QBarSet("", parent) |
|
31 | 31 | { |
|
32 | 32 | connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int,int))); |
|
33 | 33 | connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int,int))); |
|
34 | 34 | connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged())); |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | void DeclarativeBarSet::handleCountChanged(int index, int count) |
|
38 | 38 | { |
|
39 | 39 | Q_UNUSED(index) |
|
40 | 40 | Q_UNUSED(count) |
|
41 | 41 | emit countChanged(QBarSet::count()); |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | qreal DeclarativeBarSet::borderWidth() const |
|
45 | 45 | { |
|
46 | 46 | return pen().widthF(); |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | void DeclarativeBarSet::setBorderWidth(qreal width) |
|
50 | 50 | { |
|
51 | 51 | if (width != pen().widthF()) { |
|
52 | 52 | QPen p = pen(); |
|
53 | 53 | p.setWidthF(width); |
|
54 | 54 | setPen(p); |
|
55 | 55 | emit borderWidthChanged(width); |
|
56 | 56 | } |
|
57 | 57 | } |
|
58 | 58 | |
|
59 | 59 | QVariantList DeclarativeBarSet::values() |
|
60 | 60 | { |
|
61 | 61 | QVariantList values; |
|
62 | 62 | for (int i(0); i < count(); i++) |
|
63 | 63 | values.append(QVariant(QBarSet::at(i))); |
|
64 | 64 | return values; |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | void DeclarativeBarSet::setValues(QVariantList values) |
|
68 | 68 | { |
|
69 | 69 | while (count()) |
|
70 | 70 | remove(count() - 1); |
|
71 | 71 | |
|
72 | if (values.at(0).canConvert(QVariant::Point)) { | |
|
72 | if (values.count() > 0 && values.at(0).canConvert(QVariant::Point)) { | |
|
73 | 73 | // Create list of values for appending if the first item is Qt.point |
|
74 | 74 | int maxValue = 0; |
|
75 | 75 | for (int i = 0; i < values.count(); i++) { |
|
76 | 76 | if (values.at(i).canConvert(QVariant::Point) && |
|
77 | 77 | values.at(i).toPoint().x() > maxValue) { |
|
78 | 78 | maxValue = values.at(i).toPoint().x(); |
|
79 | 79 | } |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | QVector<int> indexValueList; |
|
83 | 83 | indexValueList.resize(maxValue + 1); |
|
84 | 84 | |
|
85 | 85 | for (int i = 0; i < values.count(); i++) { |
|
86 | 86 | if (values.at(i).canConvert(QVariant::Point)) { |
|
87 | 87 | indexValueList.replace(values.at(i).toPoint().x(), values.at(i).toPoint().y()); |
|
88 | 88 | } |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | for (int i = 0; i < indexValueList.count(); i++) |
|
92 | 92 | QBarSet::append(indexValueList.at(i)); |
|
93 | 93 | |
|
94 | 94 | } else { |
|
95 | 95 | for (int i(0); i < values.count(); i++) { |
|
96 | 96 | if (values.at(i).canConvert(QVariant::Double)) |
|
97 | 97 | QBarSet::append(values[i].toDouble()); |
|
98 | 98 | } |
|
99 | 99 | } |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | QString DeclarativeBarSet::brushFilename() const |
|
103 | 103 | { |
|
104 | 104 | return m_brushFilename; |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | void DeclarativeBarSet::setBrushFilename(const QString &brushFilename) |
|
108 | 108 | { |
|
109 | 109 | QImage brushImage(brushFilename); |
|
110 | 110 | if (QBarSet::brush().textureImage() != brushImage) { |
|
111 | 111 | QBrush brush = QBarSet::brush(); |
|
112 | 112 | brush.setTextureImage(brushImage); |
|
113 | 113 | QBarSet::setBrush(brush); |
|
114 | 114 | m_brushFilename = brushFilename; |
|
115 | 115 | m_brushImage = brushImage; |
|
116 | 116 | emit brushFilenameChanged(brushFilename); |
|
117 | 117 | } |
|
118 | 118 | } |
|
119 | 119 | |
|
120 | 120 | void DeclarativeBarSet::handleBrushChanged() |
|
121 | 121 | { |
|
122 | 122 | // If the texture image of the brush has changed along the brush |
|
123 | 123 | // the brush file name needs to be cleared. |
|
124 | 124 | if (!m_brushFilename.isEmpty() && QBarSet::brush().textureImage() != m_brushImage) { |
|
125 | 125 | m_brushFilename.clear(); |
|
126 | 126 | emit brushFilenameChanged(QString("")); |
|
127 | 127 | } |
|
128 | 128 | } |
|
129 | 129 | |
|
130 | 130 | // Declarative bar series ====================================================================================== |
|
131 | 131 | DeclarativeBarSeries::DeclarativeBarSeries(QQuickItem *parent) : |
|
132 | 132 | QBarSeries(parent), |
|
133 | 133 | m_axes(new DeclarativeAxes(this)) |
|
134 | 134 | { |
|
135 | 135 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
136 | 136 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
137 | 137 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
138 | 138 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
139 | 139 | } |
|
140 | 140 | |
|
141 | 141 | void DeclarativeBarSeries::classBegin() |
|
142 | 142 | { |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | void DeclarativeBarSeries::componentComplete() |
|
146 | 146 | { |
|
147 | 147 | foreach (QObject *child, children()) { |
|
148 | 148 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
149 | 149 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
150 | 150 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
151 | 151 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
152 | 152 | mapper->setSeries(this); |
|
153 | 153 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
154 | 154 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
155 | 155 | mapper->setSeries(this); |
|
156 | 156 | } |
|
157 | 157 | } |
|
158 | 158 | } |
|
159 | 159 | |
|
160 | 160 | QQmlListProperty<QObject> DeclarativeBarSeries::seriesChildren() |
|
161 | 161 | { |
|
162 | 162 | return QQmlListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren ,0,0,0); |
|
163 | 163 | } |
|
164 | 164 | |
|
165 | 165 | void DeclarativeBarSeries::appendSeriesChildren(QQmlListProperty<QObject> *list, QObject *element) |
|
166 | 166 | { |
|
167 | 167 | // Empty implementation; the children are parsed in componentComplete instead |
|
168 | 168 | Q_UNUSED(list); |
|
169 | 169 | Q_UNUSED(element); |
|
170 | 170 | } |
|
171 | 171 | |
|
172 | 172 | DeclarativeBarSet *DeclarativeBarSeries::at(int index) |
|
173 | 173 | { |
|
174 | 174 | QList<QBarSet *> setList = barSets(); |
|
175 | 175 | if (index >= 0 && index < setList.count()) |
|
176 | 176 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
177 | 177 | |
|
178 | 178 | return 0; |
|
179 | 179 | } |
|
180 | 180 | |
|
181 | 181 | DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values) |
|
182 | 182 | { |
|
183 | 183 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
184 | 184 | barset->setLabel(label); |
|
185 | 185 | barset->setValues(values); |
|
186 | 186 | if (QBarSeries::insert(index, barset)) |
|
187 | 187 | return barset; |
|
188 | 188 | delete barset; |
|
189 | 189 | return 0; |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | 192 | // Declarative stacked bar series ============================================================================== |
|
193 | 193 | DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QQuickItem *parent) : |
|
194 | 194 | QStackedBarSeries(parent), |
|
195 | 195 | m_axes(0) |
|
196 | 196 | { |
|
197 | 197 | m_axes = new DeclarativeAxes(this); |
|
198 | 198 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
199 | 199 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
200 | 200 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
201 | 201 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | void DeclarativeStackedBarSeries::classBegin() |
|
205 | 205 | { |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | void DeclarativeStackedBarSeries::componentComplete() |
|
209 | 209 | { |
|
210 | 210 | foreach (QObject *child, children()) { |
|
211 | 211 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
212 | 212 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
213 | 213 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
214 | 214 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
215 | 215 | mapper->setSeries(this); |
|
216 | 216 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
217 | 217 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
218 | 218 | mapper->setSeries(this); |
|
219 | 219 | } |
|
220 | 220 | } |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | |
|
224 | 224 | QQmlListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren() |
|
225 | 225 | { |
|
226 | 226 | return QQmlListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren ,0,0,0); |
|
227 | 227 | } |
|
228 | 228 | |
|
229 | 229 | void DeclarativeStackedBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
|
230 | 230 | { |
|
231 | 231 | // Empty implementation; the children are parsed in componentComplete instead |
|
232 | 232 | Q_UNUSED(list); |
|
233 | 233 | Q_UNUSED(element); |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index) |
|
237 | 237 | { |
|
238 | 238 | QList<QBarSet *> setList = barSets(); |
|
239 | 239 | if (index >= 0 && index < setList.count()) |
|
240 | 240 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
241 | 241 | |
|
242 | 242 | return 0; |
|
243 | 243 | } |
|
244 | 244 | |
|
245 | 245 | DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values) |
|
246 | 246 | { |
|
247 | 247 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
248 | 248 | barset->setLabel(label); |
|
249 | 249 | barset->setValues(values); |
|
250 | 250 | if (QStackedBarSeries::insert(index, barset)) |
|
251 | 251 | return barset; |
|
252 | 252 | delete barset; |
|
253 | 253 | return 0; |
|
254 | 254 | } |
|
255 | 255 | |
|
256 | 256 | // Declarative percent bar series ============================================================================== |
|
257 | 257 | DeclarativePercentBarSeries::DeclarativePercentBarSeries(QQuickItem *parent) : |
|
258 | 258 | QPercentBarSeries(parent), |
|
259 | 259 | m_axes(0) |
|
260 | 260 | { |
|
261 | 261 | m_axes = new DeclarativeAxes(this); |
|
262 | 262 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
263 | 263 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
264 | 264 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
265 | 265 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
266 | 266 | } |
|
267 | 267 | |
|
268 | 268 | void DeclarativePercentBarSeries::classBegin() |
|
269 | 269 | { |
|
270 | 270 | } |
|
271 | 271 | |
|
272 | 272 | void DeclarativePercentBarSeries::componentComplete() |
|
273 | 273 | { |
|
274 | 274 | foreach (QObject *child, children()) { |
|
275 | 275 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
276 | 276 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
277 | 277 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
278 | 278 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
279 | 279 | mapper->setSeries(this); |
|
280 | 280 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
281 | 281 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
282 | 282 | mapper->setSeries(this); |
|
283 | 283 | } |
|
284 | 284 | } |
|
285 | 285 | } |
|
286 | 286 | |
|
287 | 287 | QQmlListProperty<QObject> DeclarativePercentBarSeries::seriesChildren() |
|
288 | 288 | { |
|
289 | 289 | return QQmlListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren ,0,0,0); |
|
290 | 290 | } |
|
291 | 291 | |
|
292 | 292 | void DeclarativePercentBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
|
293 | 293 | { |
|
294 | 294 | // Empty implementation; the children are parsed in componentComplete instead |
|
295 | 295 | Q_UNUSED(list); |
|
296 | 296 | Q_UNUSED(element); |
|
297 | 297 | } |
|
298 | 298 | |
|
299 | 299 | DeclarativeBarSet *DeclarativePercentBarSeries::at(int index) |
|
300 | 300 | { |
|
301 | 301 | QList<QBarSet *> setList = barSets(); |
|
302 | 302 | if (index >= 0 && index < setList.count()) |
|
303 | 303 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
304 | 304 | |
|
305 | 305 | return 0; |
|
306 | 306 | } |
|
307 | 307 | |
|
308 | 308 | DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values) |
|
309 | 309 | { |
|
310 | 310 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
311 | 311 | barset->setLabel(label); |
|
312 | 312 | barset->setValues(values); |
|
313 | 313 | if (QPercentBarSeries::insert(index, barset)) |
|
314 | 314 | return barset; |
|
315 | 315 | delete barset; |
|
316 | 316 | return 0; |
|
317 | 317 | } |
|
318 | 318 | |
|
319 | 319 | // Declarative horizontal bar series =========================================================================== |
|
320 | 320 | DeclarativeHorizontalBarSeries::DeclarativeHorizontalBarSeries(QQuickItem *parent) : |
|
321 | 321 | QHorizontalBarSeries(parent), |
|
322 | 322 | m_axes(0) |
|
323 | 323 | { |
|
324 | 324 | m_axes = new DeclarativeAxes(this); |
|
325 | 325 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
326 | 326 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
327 | 327 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
328 | 328 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
329 | 329 | } |
|
330 | 330 | |
|
331 | 331 | void DeclarativeHorizontalBarSeries::classBegin() |
|
332 | 332 | { |
|
333 | 333 | } |
|
334 | 334 | |
|
335 | 335 | void DeclarativeHorizontalBarSeries::componentComplete() |
|
336 | 336 | { |
|
337 | 337 | foreach (QObject *child, children()) { |
|
338 | 338 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
339 | 339 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
340 | 340 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
341 | 341 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
342 | 342 | mapper->setSeries(this); |
|
343 | 343 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
344 | 344 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
345 | 345 | mapper->setSeries(this); |
|
346 | 346 | } |
|
347 | 347 | } |
|
348 | 348 | } |
|
349 | 349 | |
|
350 | 350 | QQmlListProperty<QObject> DeclarativeHorizontalBarSeries::seriesChildren() |
|
351 | 351 | { |
|
352 | 352 | return QQmlListProperty<QObject>(this, 0, &DeclarativeHorizontalBarSeries::appendSeriesChildren ,0,0,0); |
|
353 | 353 | } |
|
354 | 354 | |
|
355 | 355 | void DeclarativeHorizontalBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
|
356 | 356 | { |
|
357 | 357 | // Empty implementation; the children are parsed in componentComplete instead |
|
358 | 358 | Q_UNUSED(list); |
|
359 | 359 | Q_UNUSED(element); |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | DeclarativeBarSet *DeclarativeHorizontalBarSeries::at(int index) |
|
363 | 363 | { |
|
364 | 364 | QList<QBarSet *> setList = barSets(); |
|
365 | 365 | if (index >= 0 && index < setList.count()) |
|
366 | 366 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
367 | 367 | |
|
368 | 368 | return 0; |
|
369 | 369 | } |
|
370 | 370 | |
|
371 | 371 | DeclarativeBarSet *DeclarativeHorizontalBarSeries::insert(int index, QString label, QVariantList values) |
|
372 | 372 | { |
|
373 | 373 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
374 | 374 | barset->setLabel(label); |
|
375 | 375 | barset->setValues(values); |
|
376 | 376 | if (QHorizontalBarSeries::insert(index, barset)) |
|
377 | 377 | return barset; |
|
378 | 378 | delete barset; |
|
379 | 379 | return 0; |
|
380 | 380 | } |
|
381 | 381 | |
|
382 | 382 | // Declarative horizontal stacked bar series =================================================================== |
|
383 | 383 | DeclarativeHorizontalStackedBarSeries::DeclarativeHorizontalStackedBarSeries(QQuickItem *parent) : |
|
384 | 384 | QHorizontalStackedBarSeries(parent), |
|
385 | 385 | m_axes(0) |
|
386 | 386 | { |
|
387 | 387 | m_axes = new DeclarativeAxes(this); |
|
388 | 388 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
389 | 389 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
390 | 390 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
391 | 391 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
392 | 392 | } |
|
393 | 393 | |
|
394 | 394 | void DeclarativeHorizontalStackedBarSeries::classBegin() |
|
395 | 395 | { |
|
396 | 396 | } |
|
397 | 397 | |
|
398 | 398 | void DeclarativeHorizontalStackedBarSeries::componentComplete() |
|
399 | 399 | { |
|
400 | 400 | foreach (QObject *child, children()) { |
|
401 | 401 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
402 | 402 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
403 | 403 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
404 | 404 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
405 | 405 | mapper->setSeries(this); |
|
406 | 406 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
407 | 407 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
408 | 408 | mapper->setSeries(this); |
|
409 | 409 | } |
|
410 | 410 | } |
|
411 | 411 | } |
|
412 | 412 | |
|
413 | 413 | QQmlListProperty<QObject> DeclarativeHorizontalStackedBarSeries::seriesChildren() |
|
414 | 414 | { |
|
415 | 415 | return QQmlListProperty<QObject>(this, 0, &DeclarativeHorizontalStackedBarSeries::appendSeriesChildren ,0,0,0); |
|
416 | 416 | } |
|
417 | 417 | |
|
418 | 418 | void DeclarativeHorizontalStackedBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
|
419 | 419 | { |
|
420 | 420 | // Empty implementation; the children are parsed in componentComplete instead |
|
421 | 421 | Q_UNUSED(list); |
|
422 | 422 | Q_UNUSED(element); |
|
423 | 423 | } |
|
424 | 424 | |
|
425 | 425 | DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::at(int index) |
|
426 | 426 | { |
|
427 | 427 | QList<QBarSet *> setList = barSets(); |
|
428 | 428 | if (index >= 0 && index < setList.count()) |
|
429 | 429 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
430 | 430 | |
|
431 | 431 | return 0; |
|
432 | 432 | } |
|
433 | 433 | |
|
434 | 434 | DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::insert(int index, QString label, QVariantList values) |
|
435 | 435 | { |
|
436 | 436 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
437 | 437 | barset->setLabel(label); |
|
438 | 438 | barset->setValues(values); |
|
439 | 439 | if (QHorizontalStackedBarSeries::insert(index, barset)) |
|
440 | 440 | return barset; |
|
441 | 441 | delete barset; |
|
442 | 442 | return 0; |
|
443 | 443 | } |
|
444 | 444 | |
|
445 | 445 | // Declarative horizontal percent bar series =================================================================== |
|
446 | 446 | DeclarativeHorizontalPercentBarSeries::DeclarativeHorizontalPercentBarSeries(QQuickItem *parent) : |
|
447 | 447 | QHorizontalPercentBarSeries(parent), |
|
448 | 448 | m_axes(0) |
|
449 | 449 | { |
|
450 | 450 | m_axes = new DeclarativeAxes(this); |
|
451 | 451 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
452 | 452 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
453 | 453 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
454 | 454 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
455 | 455 | } |
|
456 | 456 | |
|
457 | 457 | void DeclarativeHorizontalPercentBarSeries::classBegin() |
|
458 | 458 | { |
|
459 | 459 | } |
|
460 | 460 | |
|
461 | 461 | void DeclarativeHorizontalPercentBarSeries::componentComplete() |
|
462 | 462 | { |
|
463 | 463 | foreach (QObject *child, children()) { |
|
464 | 464 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
465 | 465 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
466 | 466 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
467 | 467 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
468 | 468 | mapper->setSeries(this); |
|
469 | 469 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
470 | 470 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
471 | 471 | mapper->setSeries(this); |
|
472 | 472 | } |
|
473 | 473 | } |
|
474 | 474 | } |
|
475 | 475 | |
|
476 | 476 | QQmlListProperty<QObject> DeclarativeHorizontalPercentBarSeries::seriesChildren() |
|
477 | 477 | { |
|
478 | 478 | return QQmlListProperty<QObject>(this, 0, &DeclarativeHorizontalPercentBarSeries::appendSeriesChildren ,0,0,0); |
|
479 | 479 | } |
|
480 | 480 | |
|
481 | 481 | void DeclarativeHorizontalPercentBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
|
482 | 482 | { |
|
483 | 483 | // Empty implementation; the children are parsed in componentComplete instead |
|
484 | 484 | Q_UNUSED(list); |
|
485 | 485 | Q_UNUSED(element); |
|
486 | 486 | } |
|
487 | 487 | |
|
488 | 488 | DeclarativeBarSet *DeclarativeHorizontalPercentBarSeries::at(int index) |
|
489 | 489 | { |
|
490 | 490 | QList<QBarSet *> setList = barSets(); |
|
491 | 491 | if (index >= 0 && index < setList.count()) |
|
492 | 492 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
493 | 493 | |
|
494 | 494 | return 0; |
|
495 | 495 | } |
|
496 | 496 | |
|
497 | 497 | DeclarativeBarSet *DeclarativeHorizontalPercentBarSeries::insert(int index, QString label, QVariantList values) |
|
498 | 498 | { |
|
499 | 499 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
500 | 500 | barset->setLabel(label); |
|
501 | 501 | barset->setValues(values); |
|
502 | 502 | if (QHorizontalPercentBarSeries::insert(index, barset)) |
|
503 | 503 | return barset; |
|
504 | 504 | delete barset; |
|
505 | 505 | return 0; |
|
506 | 506 | } |
|
507 | 507 | |
|
508 | 508 | #include "moc_declarativebarseries.cpp" |
|
509 | 509 | |
|
510 | 510 | QT_CHARTS_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now