##// END OF EJS Templates
fixed moc name in declarative barseries
sauimone -
r1592:6c904515388c
parent child
Show More
@@ -1,393 +1,393
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "declarativebarseries.h"
22 22 #include "declarativechart.h"
23 23 #include <QBarSet>
24 24 #include <QVBarModelMapper>
25 25 #include <QHBarModelMapper>
26 26 #include <QAbstractAxis>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 DeclarativeBarSet::DeclarativeBarSet(QObject *parent) :
31 31 QBarSet("", parent)
32 32 {
33 33 connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int)));
34 34 connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int)));
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 QVariantList DeclarativeBarSet::values()
45 45 {
46 46 QVariantList values;
47 47 for (int i(0); i < count(); i++)
48 48 values.append(QVariant(QBarSet::at(i)));
49 49 return values;
50 50 }
51 51
52 52 void DeclarativeBarSet::setValues(QVariantList values)
53 53 {
54 54 while (count())
55 55 remove(count() - 1);
56 56
57 57 for (int i(0); i < values.count(); i++) {
58 58 if (values.at(i).canConvert(QVariant::Double))
59 59 QBarSet::append(values[i].toDouble());
60 60 }
61 61 }
62 62
63 63 DeclarativeAbstractBarSeries::DeclarativeAbstractBarSeries(QDeclarativeItem *parent) :
64 64 QAbstractBarSeries(parent)
65 65 {
66 66 connect(this, SIGNAL(barsetsAdded(QList<QBarSet*>)), this, SLOT(handleAdded(QList<QBarSet*>)));
67 67 connect(this, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleRemoved(QList<QBarSet*>)));
68 68 }
69 69
70 70 void DeclarativeAbstractBarSeries::handleAdded(QList<QBarSet* > barsets)
71 71 {
72 72 foreach(QBarSet *b, barsets) {
73 73 DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b);
74 74 emit added(barset);
75 75 }
76 76 }
77 77
78 78 void DeclarativeAbstractBarSeries::handleRemoved(QList<QBarSet* > barsets)
79 79 {
80 80 foreach(QBarSet *b, barsets) {
81 81 DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b);
82 82 emit removed(barset);
83 83 }
84 84 }
85 85
86 86 void DeclarativeAbstractBarSeries::classBegin()
87 87 {
88 88 }
89 89
90 90 void DeclarativeAbstractBarSeries::componentComplete()
91 91 {
92 92 foreach(QObject *child, children()) {
93 93 if (qobject_cast<DeclarativeBarSet *>(child)) {
94 94 QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
95 95 } else if (qobject_cast<QVBarModelMapper *>(child)) {
96 96 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
97 97 mapper->setSeries(this);
98 98 } else if (qobject_cast<QHBarModelMapper *>(child)) {
99 99 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
100 100 mapper->setSeries(this);
101 101 }
102 102 }
103 103 }
104 104
105 105 void DeclarativeAbstractBarSeries::setAxisX(QAbstractAxis *axis)
106 106 {
107 107 chart()->setAxisX(axis, this);
108 108 }
109 109
110 110 QAbstractAxis *DeclarativeAbstractBarSeries::axisX()
111 111 {
112 112 return chart()->axisX(this);
113 113 }
114 114
115 115 void DeclarativeAbstractBarSeries::setAxisY(QAbstractAxis *axis)
116 116 {
117 117 chart()->setAxisY(axis, this);
118 118 }
119 119
120 120 QAbstractAxis *DeclarativeAbstractBarSeries::axisY()
121 121 {
122 122 return chart()->axisY(this);
123 123 }
124 124
125 125 QDeclarativeListProperty<QObject> DeclarativeAbstractBarSeries::seriesChildren()
126 126 {
127 127 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren);
128 128 }
129 129
130 130 void DeclarativeAbstractBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
131 131 {
132 132 // Empty implementation; the children are parsed in componentComplete instead
133 133 Q_UNUSED(list);
134 134 Q_UNUSED(element);
135 135 }
136 136
137 137 DeclarativeBarSet *DeclarativeAbstractBarSeries::at(int index)
138 138 {
139 139 QList<QBarSet*> setList = barSets();
140 140 if (index >= 0 && index < setList.count())
141 141 return qobject_cast<DeclarativeBarSet *>(setList[index]);
142 142
143 143 return 0;
144 144 }
145 145
146 146 DeclarativeBarSet *DeclarativeAbstractBarSeries::insert(int index, QString label, QVariantList values)
147 147 {
148 148 int insertIndex = index;
149 149 if (insertIndex < 0)
150 150 insertIndex = 0;
151 151 else if (insertIndex > count())
152 152 insertIndex = count();
153 153
154 154 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
155 155 barset->setLabel(label);
156 156 barset->setValues(values);
157 157 if (QAbstractBarSeries::insert(insertIndex, barset))
158 158 return barset;
159 159 delete barset;
160 160 return 0;
161 161 }
162 162
163 163 DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) :
164 164 QGroupedBarSeries(parent)
165 165 {
166 166 }
167 167
168 168 void DeclarativeGroupedBarSeries::classBegin()
169 169 {
170 170 }
171 171
172 172 void DeclarativeGroupedBarSeries::componentComplete()
173 173 {
174 174 foreach(QObject *child, children()) {
175 175 if (qobject_cast<DeclarativeBarSet *>(child)) {
176 176 QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
177 177 } else if(qobject_cast<QVBarModelMapper *>(child)) {
178 178 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
179 179 mapper->setSeries(this);
180 180 } else if(qobject_cast<QHBarModelMapper *>(child)) {
181 181 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
182 182 mapper->setSeries(this);
183 183 }
184 184 }
185 185 }
186 186
187 187 void DeclarativeGroupedBarSeries::setAxisX(QAbstractAxis *axis)
188 188 {
189 189 chart()->setAxisX(axis, this);
190 190 }
191 191
192 192 QAbstractAxis *DeclarativeGroupedBarSeries::axisX()
193 193 {
194 194 return chart()->axisX(this);
195 195 }
196 196
197 197 void DeclarativeGroupedBarSeries::setAxisY(QAbstractAxis *axis)
198 198 {
199 199 chart()->setAxisY(axis, this);
200 200 }
201 201
202 202 QAbstractAxis *DeclarativeGroupedBarSeries::axisY()
203 203 {
204 204 return chart()->axisY(this);
205 205 }
206 206
207 207 QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren()
208 208 {
209 209 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren);
210 210 }
211 211
212 212 void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
213 213 {
214 214 // Empty implementation; the children are parsed in componentComplete instead
215 215 Q_UNUSED(list);
216 216 Q_UNUSED(element);
217 217 }
218 218
219 219 DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index)
220 220 {
221 221 QList<QBarSet*> setList = barSets();
222 222 if (index >= 0 && index < setList.count())
223 223 return qobject_cast<DeclarativeBarSet *>(setList[index]);
224 224
225 225 return 0;
226 226 }
227 227
228 228 DeclarativeBarSet *DeclarativeGroupedBarSeries::insert(int index, QString label, QVariantList values)
229 229 {
230 230 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
231 231 barset->setLabel(label);
232 232 barset->setValues(values);
233 233 if (QGroupedBarSeries::insert(index, barset))
234 234 return barset;
235 235 delete barset;
236 236 return 0;
237 237 }
238 238
239 239 DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) :
240 240 QStackedBarSeries(parent)
241 241 {
242 242 }
243 243
244 244 void DeclarativeStackedBarSeries::classBegin()
245 245 {
246 246 }
247 247
248 248 void DeclarativeStackedBarSeries::componentComplete()
249 249 {
250 250 foreach(QObject *child, children()) {
251 251 if (qobject_cast<DeclarativeBarSet *>(child)) {
252 252 QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
253 253 } else if(qobject_cast<QVBarModelMapper *>(child)) {
254 254 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
255 255 mapper->setSeries(this);
256 256 } else if(qobject_cast<QHBarModelMapper *>(child)) {
257 257 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
258 258 mapper->setSeries(this);
259 259 }
260 260 }
261 261 }
262 262
263 263 void DeclarativeStackedBarSeries::setAxisX(QAbstractAxis *axis)
264 264 {
265 265 chart()->setAxisX(axis, this);
266 266 }
267 267
268 268 QAbstractAxis *DeclarativeStackedBarSeries::axisX()
269 269 {
270 270 return chart()->axisX(this);
271 271 }
272 272
273 273 void DeclarativeStackedBarSeries::setAxisY(QAbstractAxis *axis)
274 274 {
275 275 chart()->setAxisY(axis, this);
276 276 }
277 277
278 278 QAbstractAxis *DeclarativeStackedBarSeries::axisY()
279 279 {
280 280 return chart()->axisY(this);
281 281 }
282 282
283 283 QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren()
284 284 {
285 285 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren);
286 286 }
287 287
288 288 void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
289 289 {
290 290 // Empty implementation; the children are parsed in componentComplete instead
291 291 Q_UNUSED(list);
292 292 Q_UNUSED(element);
293 293 }
294 294
295 295 DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index)
296 296 {
297 297 QList<QBarSet*> setList = barSets();
298 298 if (index >= 0 && index < setList.count())
299 299 return qobject_cast<DeclarativeBarSet *>(setList[index]);
300 300
301 301 return 0;
302 302 }
303 303
304 304 DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values)
305 305 {
306 306 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
307 307 barset->setLabel(label);
308 308 barset->setValues(values);
309 309 if (QStackedBarSeries::insert(index, barset))
310 310 return barset;
311 311 delete barset;
312 312 return 0;
313 313 }
314 314
315 315 DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) :
316 316 QPercentBarSeries(parent)
317 317 {
318 318 }
319 319
320 320 void DeclarativePercentBarSeries::classBegin()
321 321 {
322 322 }
323 323
324 324 void DeclarativePercentBarSeries::componentComplete()
325 325 {
326 326 foreach(QObject *child, children()) {
327 327 if (qobject_cast<DeclarativeBarSet *>(child)) {
328 328 QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
329 329 } else if(qobject_cast<QVBarModelMapper *>(child)) {
330 330 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
331 331 mapper->setSeries(this);
332 332 } else if(qobject_cast<QHBarModelMapper *>(child)) {
333 333 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
334 334 mapper->setSeries(this);
335 335 }
336 336 }
337 337 }
338 338
339 339 void DeclarativePercentBarSeries::setAxisX(QAbstractAxis *axis)
340 340 {
341 341 chart()->setAxisX(axis, this);
342 342 }
343 343
344 344 QAbstractAxis *DeclarativePercentBarSeries::axisX()
345 345 {
346 346 return chart()->axisX(this);
347 347 }
348 348
349 349 void DeclarativePercentBarSeries::setAxisY(QAbstractAxis *axis)
350 350 {
351 351 chart()->setAxisY(axis, this);
352 352 }
353 353
354 354 QAbstractAxis *DeclarativePercentBarSeries::axisY()
355 355 {
356 356 return chart()->axisY(this);
357 357 }
358 358
359 359 QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren()
360 360 {
361 361 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren);
362 362 }
363 363
364 364 void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
365 365 {
366 366 // Empty implementation; the children are parsed in componentComplete instead
367 367 Q_UNUSED(list);
368 368 Q_UNUSED(element);
369 369 }
370 370
371 371 DeclarativeBarSet *DeclarativePercentBarSeries::at(int index)
372 372 {
373 373 QList<QBarSet*> setList = barSets();
374 374 if (index >= 0 && index < setList.count())
375 375 return qobject_cast<DeclarativeBarSet *>(setList[index]);
376 376
377 377 return 0;
378 378 }
379 379
380 380 DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values)
381 381 {
382 382 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
383 383 barset->setLabel(label);
384 384 barset->setValues(values);
385 385 if (QPercentBarSeries::insert(index, barset))
386 386 return barset;
387 387 delete barset;
388 388 return 0;
389 389 }
390 390
391 #include "moc_declarativeabstractbarseries.cpp"
391 #include "moc_declarativebarseries.cpp"
392 392
393 393 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now