##// END OF EJS Templates
Removed gdpbarchart from demos docs
Marek Rosa -
r947:8669b640bdbc
parent child
Show More
@@ -1,24 +1,23
1 1 /*!
2 2 \page demos.html
3 3 \title Demos
4 4 \keyword Demos
5 5
6 6 \raw HTML
7 7 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
8 8 <tr>
9 9 <th class="titleheader" width="33%">
10 10 List of demos
11 11 </th>
12 12 </tr>
13 13 <tr>
14 14 <td valign="top">
15 15 <ul>
16 16 <li><a href="demos-chartthemes.html">Chart themes</a></li>
17 <li><a href="demos-gdpbarchart.html">GDP bar chart</a></li>
18 17 <li><a href="demos-piechartcustomization.html">Pie chart customization</a></li>
19 18 </ul>
20 19 </td>
21 20 </tr>
22 21 </table>
23 22 \endraw
24 23 */
@@ -1,811 +1,811
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 "qbarseries.h"
22 22 #include "qbarseries_p.h"
23 23 #include "qbarset.h"
24 24 #include "qbarset_p.h"
25 25 #include "barchartmodel_p.h"
26 26 #include "domain_p.h"
27 27 #include "chartdataset_p.h"
28 28 #include "charttheme_p.h"
29 29 #include "chartanimator_p.h"
30 30
31 31 #include <QAbstractItemModel>
32 32 #include <QModelIndex>
33 33
34 34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 35
36 36 /*!
37 37 \class QBarSeries
38 38 \brief part of QtCommercial chart API.
39 39
40 40 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible
41 41 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
42 42 by QStringList.
43 43
44 44 \mainclass
45 45
46 46 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
47 47 */
48 48
49 49 /*!
50 50 \fn virtual QSeriesType QBarSeries::type() const
51 51 \brief Returns type of series.
52 52 \sa QSeries, QSeriesType
53 53 */
54 54
55 55 /*!
56 56 \fn void QBarSeries::showToolTip(QPoint pos, QString tip)
57 57 \brief \internal \a pos \a tip
58 58 */
59 59
60 60 /*!
61 61 Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
62 62 QBarSeries is QObject which is a child of a \a parent.
63 63 */
64 64
65 65 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(*new QBarSeriesPrivate(categories, this),parent)
66 66 {
67 67
68 68 }
69 69
70 70 QBarSeries::QBarSeries(QBarSeriesPrivate &d,QObject *parent) : QSeries(d,parent)
71 71 {
72 72
73 73 }
74 74
75 75 QSeries::QSeriesType QBarSeries::type() const
76 76 {
77 77 return QSeries::SeriesTypeBar;
78 78 }
79 79
80 80 /*!
81 81 Adds a set of bars to series. Takes ownership of \a set.
82 82 Connects the clicked(QString, Qt::MouseButtons) signal
83 83 of \a set to this series
84 84 */
85 85 void QBarSeries::appendBarSet(QBarSet *set)
86 86 {
87 87 Q_D(QBarSeries);
88 88 d->m_internalModel->appendBarSet(set);
89 89 QObject::connect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons)));
90 90 QObject::connect(set->d_ptr.data(), SIGNAL(valueChanged()), d, SLOT(barsetChanged()));
91 91 emit d->restructuredBars();
92 92 }
93 93
94 94 /*!
95 95 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
96 96 Disconnects the clicked(QString, Qt::MouseButtons) signal
97 97 of \a set from this series
98 98 */
99 99 void QBarSeries::removeBarSet(QBarSet *set)
100 100 {
101 101 Q_D(QBarSeries);
102 102 QObject::disconnect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons)));
103 103 d->m_internalModel->removeBarSet(set);
104 104 emit d->restructuredBars();
105 105 }
106 106
107 107 /*!
108 108 Adds a list of barsets to series. Takes ownership of \a sets.
109 109 Connects the clicked(QString, Qt::MouseButtons) signals
110 110 of \a sets to this series
111 111 */
112 112 void QBarSeries::appendBarSets(QList<QBarSet* > sets)
113 113 {
114 114 Q_D(QBarSeries);
115 115 foreach (QBarSet* barset, sets) {
116 116 d->m_internalModel->appendBarSet(barset);
117 117 QObject::connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
118 118 QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
119 119 }
120 120 emit d->restructuredBars();
121 121
122 122 }
123 123
124 124 /*!
125 125 Removes a list of barsets from series. Releases ownership of \a sets. Doesnt delete \a sets.
126 126 Disconnects the clicked(QString, Qt::MouseButtons) signal
127 127 of \a sets from this series
128 128 */
129 129 void QBarSeries::removeBarSets(QList<QBarSet* > sets)
130 130 {
131 131 Q_D(QBarSeries);
132 132
133 133 foreach (QBarSet* barset, sets) {
134 134 QObject::disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
135 135 d->m_internalModel->removeBarSet(barset);
136 136 }
137 137 emit d->restructuredBars();
138 138 }
139 139
140 140 /*!
141 141 Inserts new \a set on the \a i position.
142 142 The barset that is currently at this postion is moved to postion i + 1
143 143 */
144 144 void QBarSeries::insertBarSet(int i, QBarSet *set)
145 145 {
146 146 Q_D(QBarSeries);
147 147 d->m_internalModel->insertBarSet(i, set);
148 148 emit d->barsetChanged();
149 149 }
150 150
151 151 /*!
152 152 Inserts new \a category on the \a i position.
153 153 The category that is currently at this postion is moved to postion i + 1
154 154 \sa removeCategory()
155 155 */
156 156 void QBarSeries::insertCategory(int i, QString category)
157 157 {
158 158 Q_D(QBarSeries);
159 159 d->m_internalModel->insertCategory(i, category);
160 160 }
161 161
162 162 /*!
163 163 Removes the category specified by \a i
164 164 \sa insertCategory()
165 165 */
166 166 void QBarSeries::removeCategory(int i)
167 167 {
168 168 Q_D(QBarSeries);
169 169 d->m_internalModel->removeCategory(i);
170 170 }
171 171
172 172 /*!
173 173 Returns number of sets in series.
174 174 */
175 175 int QBarSeries::barsetCount() const
176 176 {
177 177 Q_D(const QBarSeries);
178 178 /*
179 179 // if(m_model)
180 180 // return m_mapBarTop - m_mapBarBottom;
181 181 // else
182 182
183 183 */
184 184 return d->m_internalModel->barsetCount();
185 185 }
186 186
187 187 /*!
188 188 Returns number of categories in series
189 189 */
190 190 int QBarSeries::categoryCount() const
191 191 {
192 192 Q_D(const QBarSeries);
193 193 return d->m_internalModel->categoryCount();
194 194 }
195 195
196 196 /*!
197 197 Returns a list of sets in series. Keeps ownership of sets.
198 198 */
199 199 QList<QBarSet*> QBarSeries::barSets() const
200 200 {
201 201 Q_D(const QBarSeries);
202 202 return d->m_internalModel->barSets();
203 203 }
204 204
205 205 /*!
206 206 \internal \a index
207 207 */
208 208 QBarSet* QBarSeries::barsetAt(int index)
209 209 {
210 210 Q_D(QBarSeries);
211 211 return d->barsetAt(index);
212 212 // return m_internalModel->barsetAt(index);
213 213 }
214 214
215 215 /*!
216 216 \internal \a category
217 217 */
218 218 QString QBarSeries::categoryName(int category)
219 219 {
220 220 Q_D(QBarSeries);
221 221 return d->categoryName(category);
222 222 // return m_internalModel->categoryName(category);
223 223 }
224 224
225 225 /*!
226 226 Enables or disables tooltip depending on parameter \a enabled.
227 227 Tooltip shows the name of set, when mouse is hovering on top of bar.
228 228 Calling without parameter \a enabled, enables the tooltip
229 229 */
230 230 void QBarSeries::setToolTipEnabled(bool enabled)
231 231 {
232 232 Q_D(QBarSeries);
233 233 d->setToolTipEnabled(enabled);
234 234 /*
235 235 // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
236 236 if (enabled) {
237 237 for (int i=0; i<m_internalModel->barsetCount(); i++) {
238 238 QBarSet *set = m_internalModel->barsetAt(i);
239 239 connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
240 240 }
241 241 } else {
242 242 for (int i=0; i<m_internalModel->barsetCount(); i++) {
243 243 QBarSet *set = m_internalModel->barsetAt(i);
244 244 disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
245 245 }
246 246 }
247 247 */
248 248 }
249 249
250 250
251 251 /*!
252 252 \internal \a category
253 253 */
254 254 void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button)
255 255 {
256 256 Q_D(QBarSeries);
257 257 d->barsetClicked(category,button);
258 258 // emit clicked(qobject_cast<QBarSet*>(sender()), category, button);
259 259 }
260 260
261 261 /*!
262 262 \internal
263 263 */
264 264 qreal QBarSeries::min()
265 265 {
266 266 Q_D(QBarSeries);
267 267 return d->min();
268 268 //return m_internalModel->min();
269 269 }
270 270
271 271 /*!
272 272 \internal
273 273 */
274 274 qreal QBarSeries::max()
275 275 {
276 276 Q_D(QBarSeries);
277 277 return d->max();
278 278 // return m_internalModel->max();
279 279 }
280 280
281 281 /*!
282 282 \internal \a set \a category
283 283 */
284 284 qreal QBarSeries::valueAt(int set, int category)
285 285 {
286 286 Q_D(QBarSeries);
287 287 return d->valueAt(set,category);
288 288 // return m_internalModel->valueAt(set, category);
289 289 }
290 290
291 291 /*!
292 292 \internal \a set \a category
293 293 */
294 294 qreal QBarSeries::percentageAt(int set, int category)
295 295 {
296 296 Q_D(QBarSeries);
297 297 return d->percentageAt(set,category);
298 298 // return m_internalModel->percentageAt(set, category);
299 299 }
300 300
301 301 /*!
302 302 \internal \a category
303 303 */
304 304 qreal QBarSeries::categorySum(int category)
305 305 {
306 306 Q_D(QBarSeries);
307 307 return d->categorySum(category);
308 308 // return m_internalModel->categorySum(category);
309 309 }
310 310
311 311 /*!
312 312 \internal \a category
313 313 */
314 314 qreal QBarSeries::absoluteCategorySum(int category)
315 315 {
316 316 Q_D(QBarSeries);
317 317 return d->absoluteCategorySum(category);
318 318 // return m_internalModel->absoluteCategorySum(category);
319 319 }
320 320
321 321 /*!
322 322 \internal
323 323 */
324 324 qreal QBarSeries::maxCategorySum()
325 325 {
326 326 Q_D(QBarSeries);
327 327 return d->maxCategorySum();
328 328 // return m_internalModel->maxCategorySum();
329 329 }
330 330
331 331 /*!
332 332 \internal
333 333 */
334 334 BarChartModel& QBarSeries::modelInternal()
335 335 {
336 336 Q_D(QBarSeries);
337 337 return d->modelInternal();
338 338 // return *m_internalModel;
339 339 }
340 340
341 341 /*!
342 342 \fn bool QBarSeries::setModel(QAbstractItemModel *model)
343 343 Sets the \a model to be used as a data source
344 344 */
345 345 bool QBarSeries::setModel(QAbstractItemModel *model)
346 346 {
347 347 Q_D(QBarSeries);
348 348 return d->setModel(model);
349 349 /*
350 350 // disconnect signals from old model
351 351 if(m_model)
352 352 {
353 353 disconnect(m_model, 0, this, 0);
354 354 m_mapCategories = -1;
355 355 m_mapBarBottom = -1;
356 356 m_mapBarTop = -1;
357 357 m_mapFirst = 0;
358 358 m_mapCount = 0;
359 359 m_mapOrientation = Qt::Vertical;
360 360 }
361 361
362 362 // set new model
363 363 if(model)
364 364 {
365 365 m_model = model;
366 366 return true;
367 367 }
368 368 else
369 369 {
370 370 m_model = 0;
371 371 return false;
372 372 }
373 373 */
374 374 }
375 375
376 376 /*!
377 377 \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
378 378 Sets column/row specified by \a categories to be used as a list of bar series categories.
379 379 Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model.
380 380 Parameter \a topBoundry indicates the column/row where the last bar set is located in the model.
381 381 All the columns/rows inbetween those two values are also used as data for bar sets.
382 382 The \a orientation paramater specifies whether the data is in columns or in rows.
383 383 */
384 384 void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation)
385 385 {
386 386 Q_D(QBarSeries);
387 387 d->setModelMapping(categories,bottomBoundary,topBoundary,orientation);
388 388 /*
389 389 if (!m_model)
390 390 return;
391 391
392 392 m_mapCategories = categories;
393 393 m_mapBarBottom = bottomBoundry;
394 394 m_mapBarTop = topBoundry;
395 395 // m_mapFirst = 1;
396 396 m_mapOrientation = orientation;
397 397
398 398 // connect the signals
399 399 if (m_mapOrientation == Qt::Vertical) {
400 400 m_mapCount = m_model->rowCount() - m_mapFirst;
401 401 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
402 402 this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
403 403 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)),
404 404 this, SLOT(modelDataAdded(QModelIndex,int,int)));
405 405 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)),
406 406 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
407 407 } else {
408 408 m_mapCount = m_model->columnCount() - m_mapFirst;
409 409 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
410 410 this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
411 411 connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)),
412 412 this, SLOT(modelDataAdded(QModelIndex,int,int)));
413 413 connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)),
414 414 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
415 415 }
416 416
417 417 // create the initial bars
418 418 delete m_internalModel;
419 419 if (m_mapOrientation == Qt::Vertical) {
420 420 QStringList categories;
421 421 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
422 422 categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
423 423 m_internalModel = new BarChartModel(categories, this);
424 424
425 425 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
426 426 QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
427 427 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
428 428 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
429 429 appendBarSet(barSet);
430 430 }
431 431 } else {
432 432 QStringList categories;
433 433 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
434 434 categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
435 435 m_internalModel = new BarChartModel(categories, this);
436 436
437 437 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
438 438 QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
439 439 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
440 440 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
441 441 appendBarSet(barSet);
442 442 }
443 443 }
444 444 */
445 445 }
446 446
447 447 /*!
448 448 \internal
449 449 */
450 450 void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
451 451 {
452 452 Q_D(QBarSeries);
453 453 d->modelUpdated(topLeft,bottomRight);
454 454 /*
455 455 Q_UNUSED(bottomRight)
456 456
457 457 if (m_mapOrientation == Qt::Vertical)
458 458 {
459 459 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
460 460 if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount)
461 461 barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
462 462 }
463 463 else
464 464 {
465 465 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
466 466 if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount)
467 467 barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
468 468 }
469 469 */
470 470 }
471 471
472 472 /*!
473 473 \internal
474 474 */
475 475 void QBarSeries::modelDataAdded(QModelIndex parent, int start, int end)
476 476 {
477 477 Q_D(QBarSeries);
478 478 d->modelDataAdded(parent,start,end);
479 479 /*
480 480 if (m_mapOrientation == Qt::Vertical) {
481 481 insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1));
482 482 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
483 483 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble());
484 484 }
485 485 } else {
486 486 insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1));
487 487 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
488 488 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble());
489 489 }
490 490 }
491 491 emit restructuredBars();
492 492 */
493 493 }
494 494
495 495 /*!
496 496 \internal
497 497 */
498 498 void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end)
499 499 {
500 500 Q_D(QBarSeries);
501 501 d->modelDataRemoved(parent,start,end);
502 502 /*
503 503 Q_UNUSED(parent)
504 504 Q_UNUSED(end)
505 505
506 506 removeCategory(start - m_mapFirst);
507 507 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++)
508 508 {
509 509 barsetAt(i)->removeValue(start - m_mapFirst);
510 510 }
511 511 emit restructuredBars();
512 512 */
513 513 }
514 514
515 515 void QBarSeries::barsetChanged()
516 516 {
517 517 Q_D(QBarSeries);
518 518 d->barsetChanged();
519 519 // emit updatedBars();
520 520 }
521 521
522 522 QBarCategories QBarSeries::categories() const
523 523 {
524 524 Q_D(const QBarSeries);
525 525
526 526 QBarCategories categories;
527 527 int count = d->m_internalModel->categoryCount();
528 528 for (int i=1; i <= count; i++) {
529 529 categories.insert(i, d->m_internalModel->categoryName(i - 1));
530 530 }
531 531 return categories;
532 532
533 533 }
534 534
535 535 /*!
536 536 Sets the visibility of labels in series to \a visible
537 537 */
538 538 void QBarSeries::setLabelsVisible(bool visible)
539 539 {
540 540 foreach (QBarSet* s, barSets()) {
541 541 s->setLabelsVisible(visible);
542 542 }
543 543 }
544 544
545 545 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
546 546
547 547 QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : QSeriesPrivate(q),
548 548 m_internalModel(new BarChartModel(categories,this)),
549 549 m_model(0),
550 550 m_mapCategories(-1),
551 551 m_mapBarBottom(-1),
552 552 m_mapBarTop(-1),
553 553 m_mapFirst(0),
554 554 m_mapCount(0),
555 555 m_mapOrientation(Qt::Vertical)
556 556 {
557 557 }
558 558
559 559 QBarSet* QBarSeriesPrivate::barsetAt(int index)
560 560 {
561 561 return m_internalModel->barsetAt(index);
562 562 }
563 563
564 564 QString QBarSeriesPrivate::categoryName(int category)
565 565 {
566 566 return m_internalModel->categoryName(category);
567 567 }
568 568
569 569 void QBarSeriesPrivate::setToolTipEnabled(bool enabled)
570 570 {
571 571 // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
572 572 if (enabled) {
573 573 for (int i=0; i<m_internalModel->barsetCount(); i++) {
574 574 QBarSet *set = m_internalModel->barsetAt(i);
575 575 connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
576 576 }
577 577 } else {
578 578 for (int i=0; i<m_internalModel->barsetCount(); i++) {
579 579 QBarSet *set = m_internalModel->barsetAt(i);
580 580 disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
581 581 }
582 582 }
583 583 }
584 584
585 585 void QBarSeriesPrivate::barsetClicked(QString category, Qt::MouseButtons button)
586 586 {
587 587 emit clicked(qobject_cast<QBarSet*>(sender()), category, button);
588 588 }
589 589
590 590 qreal QBarSeriesPrivate::min()
591 591 {
592 592 return m_internalModel->min();
593 593 }
594 594
595 595 qreal QBarSeriesPrivate::max()
596 596 {
597 597 return m_internalModel->max();
598 598 }
599 599
600 600 qreal QBarSeriesPrivate::valueAt(int set, int category)
601 601 {
602 602 return m_internalModel->valueAt(set, category);
603 603 }
604 604
605 605 qreal QBarSeriesPrivate::percentageAt(int set, int category)
606 606 {
607 607 return m_internalModel->percentageAt(set, category);
608 608 }
609 609
610 610 qreal QBarSeriesPrivate::categorySum(int category)
611 611 {
612 612 return m_internalModel->categorySum(category);
613 613 }
614 614
615 615 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
616 616 {
617 617 return m_internalModel->absoluteCategorySum(category);
618 618 }
619 619
620 620 qreal QBarSeriesPrivate::maxCategorySum()
621 621 {
622 622 return m_internalModel->maxCategorySum();
623 623 }
624 624
625 625 BarChartModel& QBarSeriesPrivate::modelInternal()
626 626 {
627 627 return *m_internalModel;
628 628 }
629 629
630 630 bool QBarSeriesPrivate::setModel(QAbstractItemModel *model)
631 631 {
632 632 // disconnect signals from old model
633 633 if(m_model)
634 634 {
635 635 disconnect(m_model, 0, this, 0);
636 636 m_mapCategories = -1;
637 637 m_mapBarBottom = -1;
638 638 m_mapBarTop = -1;
639 639 m_mapFirst = 0;
640 640 m_mapCount = 0;
641 641 m_mapOrientation = Qt::Vertical;
642 642 }
643 643
644 644 // set new model
645 645 if(model)
646 646 {
647 647 m_model = model;
648 648 return true;
649 649 }
650 650 else
651 651 {
652 652 m_model = 0;
653 653 return false;
654 654 }
655 655 }
656 656
657 657 void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
658 658 {
659 659 Q_Q(QBarSeries);
660 660
661 if (!m_model)
661 if (m_model == 0)
662 662 return;
663 663
664 664 m_mapCategories = categories;
665 665 m_mapBarBottom = bottomBoundry;
666 666 m_mapBarTop = topBoundry;
667 667 // m_mapFirst = 1;
668 668 m_mapOrientation = orientation;
669 669
670 670 // connect the signals
671 671 if (m_mapOrientation == Qt::Vertical) {
672 672 m_mapCount = m_model->rowCount() - m_mapFirst;
673 673 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
674 674 this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
675 675 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)),
676 676 this, SLOT(modelDataAdded(QModelIndex,int,int)));
677 677 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)),
678 678 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
679 679 } else {
680 680 m_mapCount = m_model->columnCount() - m_mapFirst;
681 681 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
682 682 this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
683 683 connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)),
684 684 this, SLOT(modelDataAdded(QModelIndex,int,int)));
685 685 connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)),
686 686 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
687 687 }
688 688
689 689 // create the initial bars
690 690 delete m_internalModel;
691 691 if (m_mapOrientation == Qt::Vertical) {
692 692 QStringList categories;
693 693 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
694 694 categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
695 695 m_internalModel = new BarChartModel(categories, this);
696 696
697 697 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
698 698 QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
699 699 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
700 700 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
701 701 q->appendBarSet(barSet);
702 702 }
703 703 } else {
704 704 QStringList categories;
705 705 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
706 706 categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
707 707 m_internalModel = new BarChartModel(categories, this);
708 708
709 709 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
710 710 QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
711 711 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
712 712 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
713 713 q->appendBarSet(barSet);
714 714 }
715 715 }
716 716 }
717 717
718 718 void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
719 719 {
720 720 Q_UNUSED(bottomRight)
721 721
722 722 if (m_mapOrientation == Qt::Vertical)
723 723 {
724 724 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
725 725 if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount)
726 726 barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
727 727 }
728 728 else
729 729 {
730 730 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
731 731 if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount)
732 732 barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
733 733 }
734 734 }
735 735
736 736 void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/)
737 737 {
738 738 Q_Q(QBarSeries);
739 739
740 740 if (m_mapOrientation == Qt::Vertical) {
741 741 q->insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1));
742 742 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
743 743 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble());
744 744 }
745 745 } else {
746 746 q->insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1));
747 747 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
748 748 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble());
749 749 }
750 750 }
751 751 emit restructuredBars();
752 752 }
753 753
754 754 void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
755 755 {
756 756 Q_Q(QBarSeries);
757 757 Q_UNUSED(parent)
758 758 Q_UNUSED(end)
759 759
760 760 q->removeCategory(start - m_mapFirst);
761 761 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++)
762 762 {
763 763 barsetAt(i)->removeValue(start - m_mapFirst);
764 764 }
765 765 emit restructuredBars();
766 766 }
767 767
768 768 void QBarSeriesPrivate::barsetChanged()
769 769 {
770 770 emit updatedBars();
771 771 }
772 772
773 773 void QBarSeriesPrivate::scaleDomain(Domain& domain)
774 774 {
775 775 Q_Q(QBarSeries);
776 776 qreal minX(domain.minX());
777 777 qreal minY(domain.minY());
778 778 qreal maxX(domain.maxX());
779 779 qreal maxY(domain.maxY());
780 780 int tickXCount(domain.tickXCount());
781 781 int tickYCount(domain.tickYCount());
782 782
783 783 qreal x = q->categoryCount();
784 784 qreal y = q->max();
785 785 minX = qMin(minX, x);
786 786 minY = qMin(minY, y);
787 787 maxX = qMax(maxX, x);
788 788 maxY = qMax(maxY, y);
789 789 tickXCount = x+1;
790 790
791 791 domain.setRangeX(minX,maxX,tickXCount);
792 792 domain.setRangeY(minY,maxY,tickYCount);
793 793 }
794 794
795 795 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
796 796 {
797 797 Q_Q(QBarSeries);
798 798
799 799 BarChartItem* bar = new BarChartItem(q,presenter);
800 800 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
801 801 presenter->animator()->addAnimation(bar);
802 802 }
803 803 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
804 804 return bar;
805 805
806 806 }
807 807
808 808 #include "moc_qbarseries.cpp"
809 809 #include "moc_qbarseries_p.cpp"
810 810
811 811 QTCOMMERCIALCHART_END_NAMESPACE
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now