##// END OF EJS Templates
barchart: doc update for hover signals
sauimone -
r980:29373936de0b
parent child
Show More
@@ -1,513 +1,532
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 "legendmarker_p.h"
28 28 #include "chartdataset_p.h"
29 29 #include "charttheme_p.h"
30 30 #include "chartanimator_p.h"
31 31
32 32 #include <QAbstractItemModel>
33 33 #include <QModelIndex>
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 /*!
38 38 \class QBarSeries
39 39 \brief part of QtCommercial chart API.
40 40
41 41 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple
42 42 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
43 43 by QStringList.
44 44
45 45 \mainclass
46 46
47 47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 48 */
49 49
50 50 /*!
51 51 \fn virtual QSeriesType QBarSeries::type() const
52 52 \brief Returns type of series.
53 53 \sa QSeries, QSeriesType
54 54 */
55 55
56 56 /*!
57 57 \fn void QBarSeries::clicked(QBarSet *barset, QString category, Qt::MouseButtons button)
58 58
59 59 The signal is emitted if the user clicks with a mouse \a button on top of QBarSet \a barset of category \a category
60 60 contained by the series.
61 61 */
62 62
63 63 /*!
64 64 \fn void QBarSeries::selected()
65 65
66 66 The signal is emitted if the user selects/deselects the series. The logic for storing selections should be
67 67 implemented by the user of QBarSeries API.
68 68 */
69 69
70 70 /*!
71 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
72
73 The signal is emitted if mouse is hovered on top of series.
74 Parameter \a barset is the pointer of barset, where hover happened.
75 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
76 */
77
78 /*!
71 79 Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
72 80 QBarSeries is QObject which is a child of a \a parent.
73 81 */
74 82 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) :
75 83 QSeries(*new QBarSeriesPrivate(categories, this),parent)
76 84 {
77 85 }
78 86
79 87 /*!
88 Destructs barseries and owned barsets.
89 */
90 QBarSeries::~QBarSeries()
91 {
92 // NOTE: d_ptr destroyed by QObject
93 }
94
95 /*!
80 96 \internal
81 97 */
82 98 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
83 99 QSeries(d,parent)
84 100 {
85 101 }
86 102
103 /*!
104 Returns the type of series. Derived classes override this.
105 */
87 106 QSeries::QSeriesType QBarSeries::type() const
88 107 {
89 108 return QSeries::SeriesTypeBar;
90 109 }
91 110
92 111 /*!
93 112 Adds a set of bars to series. Takes ownership of \a set.
94 113 Connects the clicked(QString, Qt::MouseButtons) signal
95 114 of \a set to this series
96 115 */
97 116 void QBarSeries::appendBarSet(QBarSet *set)
98 117 {
99 118 Q_D(QBarSeries);
100 119 d->m_internalModel->appendBarSet(set);
101 120 QObject::connect(set->d_ptr.data(), SIGNAL(valueChanged()), d, SLOT(barsetChanged()));
102 121 emit d->restructuredBars();
103 122 }
104 123
105 124 /*!
106 125 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
107 126 Disconnects the clicked(QString, Qt::MouseButtons) signal
108 127 of \a set from this series
109 128 */
110 129 void QBarSeries::removeBarSet(QBarSet *set)
111 130 {
112 131 Q_D(QBarSeries);
113 132 d->m_internalModel->removeBarSet(set);
114 133 emit d->restructuredBars();
115 134 }
116 135
117 136 /*!
118 137 Adds a list of barsets to series. Takes ownership of \a sets.
119 138 Connects the clicked(QString, Qt::MouseButtons) signals
120 139 of \a sets to this series
121 140 */
122 141 void QBarSeries::appendBarSets(QList<QBarSet* > sets)
123 142 {
124 143 Q_D(QBarSeries);
125 144 foreach (QBarSet* barset, sets) {
126 145 d->m_internalModel->appendBarSet(barset);
127 146 QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
128 147 }
129 148 emit d->restructuredBars();
130 149
131 150 }
132 151
133 152 /*!
134 153 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
135 154 Disconnects the clicked(QString, Qt::MouseButtons) signal
136 155 of \a sets from this series
137 156 */
138 157 void QBarSeries::removeBarSets(QList<QBarSet* > sets)
139 158 {
140 159 Q_D(QBarSeries);
141 160
142 161 foreach (QBarSet* barset, sets) {
143 162 d->m_internalModel->removeBarSet(barset);
144 163 }
145 164 emit d->restructuredBars();
146 165 }
147 166
148 167 /*!
149 168 Inserts new \a set on the \a i position.
150 169 The barset that is currently at this postion is moved to postion i + 1
151 170 */
152 171 void QBarSeries::insertBarSet(int i, QBarSet *set)
153 172 {
154 173 Q_D(QBarSeries);
155 174 d->m_internalModel->insertBarSet(i, set);
156 175 emit d->barsetChanged();
157 176 }
158 177
159 178 /*!
160 179 Inserts new \a category on the \a i position.
161 180 The category that is currently at this postion is moved to postion i + 1
162 181 \sa removeCategory()
163 182 */
164 183 void QBarSeries::insertCategory(int i, QString category)
165 184 {
166 185 Q_D(QBarSeries);
167 186 d->m_internalModel->insertCategory(i, category);
168 187 }
169 188
170 189 /*!
171 190 Removes the category specified by \a i
172 191 \sa insertCategory()
173 192 */
174 193 void QBarSeries::removeCategory(int i)
175 194 {
176 195 Q_D(QBarSeries);
177 196 d->m_internalModel->removeCategory(i);
178 197 }
179 198
180 199 /*!
181 200 Returns number of sets in series.
182 201 */
183 202 int QBarSeries::barsetCount() const
184 203 {
185 204 Q_D(const QBarSeries);
186 205 return d->m_internalModel->barsetCount();
187 206 }
188 207
189 208 /*!
190 209 Returns number of categories in series
191 210 */
192 211 int QBarSeries::categoryCount() const
193 212 {
194 213 Q_D(const QBarSeries);
195 214 return d->m_internalModel->categoryCount();
196 215 }
197 216
198 217 /*!
199 218 Returns a list of sets in series. Keeps ownership of sets.
200 219 */
201 220 QList<QBarSet*> QBarSeries::barSets() const
202 221 {
203 222 Q_D(const QBarSeries);
204 223 return d->m_internalModel->barSets();
205 224 }
206 225
207 226 /*!
208 227 \fn bool QBarSeries::setModel(QAbstractItemModel *model)
209 228 Sets the \a model to be used as a data source
210 229 */
211 230 bool QBarSeries::setModel(QAbstractItemModel *model)
212 231 {
213 232 Q_D(QBarSeries);
214 233 return d->setModel(model);
215 234 }
216 235
217 236 /*!
218 237 \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
219 238 Sets column/row specified by \a categories to be used as a list of bar series categories.
220 239 Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model.
221 240 Parameter \a topBoundry indicates the column/row where the last bar set is located in the model.
222 241 All the columns/rows inbetween those two values are also used as data for bar sets.
223 242 The \a orientation parameter specifies whether the data is in columns or in rows.
224 243 */
225 244 void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation)
226 245 {
227 246 Q_D(QBarSeries);
228 247 d->setModelMapping(categories,bottomBoundary,topBoundary,orientation);
229 248 }
230 249
231 250 /*!
232 251 Returns the bar categories of the series.
233 252 */
234 253 QBarCategories QBarSeries::categories() const
235 254 {
236 255 Q_D(const QBarSeries);
237 256
238 257 QBarCategories categories;
239 258 int count = d->m_internalModel->categoryCount();
240 259 for (int i=1; i <= count; i++) {
241 260 categories.insert(i, d->m_internalModel->categoryName(i - 1));
242 261 }
243 262 return categories;
244 263
245 264 }
246 265
247 266 /*!
248 267 Sets the visibility of labels in series to \a visible
249 268 */
250 269 void QBarSeries::setLabelsVisible(bool visible)
251 270 {
252 271 foreach (QBarSet* s, barSets()) {
253 272 s->setLabelsVisible(visible);
254 273 }
255 274 }
256 275
257 276 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
258 277
259 278 QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : QSeriesPrivate(q),
260 279 m_internalModel(new BarChartModel(categories,this)),
261 280 m_model(0),
262 281 m_mapCategories(-1),
263 282 m_mapBarBottom(-1),
264 283 m_mapBarTop(-1),
265 284 m_mapFirst(0),
266 285 m_mapCount(0),
267 286 m_mapOrientation(Qt::Vertical)
268 287 {
269 288 }
270 289
271 290 QBarSet* QBarSeriesPrivate::barsetAt(int index)
272 291 {
273 292 return m_internalModel->barsetAt(index);
274 293 }
275 294
276 295 QString QBarSeriesPrivate::categoryName(int category)
277 296 {
278 297 return m_internalModel->categoryName(category);
279 298 }
280 299
281 300 qreal QBarSeriesPrivate::min()
282 301 {
283 302 return m_internalModel->min();
284 303 }
285 304
286 305 qreal QBarSeriesPrivate::max()
287 306 {
288 307 return m_internalModel->max();
289 308 }
290 309
291 310 qreal QBarSeriesPrivate::valueAt(int set, int category)
292 311 {
293 312 return m_internalModel->valueAt(set, category);
294 313 }
295 314
296 315 qreal QBarSeriesPrivate::percentageAt(int set, int category)
297 316 {
298 317 return m_internalModel->percentageAt(set, category);
299 318 }
300 319
301 320 qreal QBarSeriesPrivate::categorySum(int category)
302 321 {
303 322 return m_internalModel->categorySum(category);
304 323 }
305 324
306 325 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
307 326 {
308 327 return m_internalModel->absoluteCategorySum(category);
309 328 }
310 329
311 330 qreal QBarSeriesPrivate::maxCategorySum()
312 331 {
313 332 return m_internalModel->maxCategorySum();
314 333 }
315 334
316 335 BarChartModel& QBarSeriesPrivate::modelInternal()
317 336 {
318 337 return *m_internalModel;
319 338 }
320 339
321 340 bool QBarSeriesPrivate::setModel(QAbstractItemModel *model)
322 341 {
323 342 // disconnect signals from old model
324 343 if(m_model)
325 344 {
326 345 disconnect(m_model, 0, this, 0);
327 346 m_mapCategories = -1;
328 347 m_mapBarBottom = -1;
329 348 m_mapBarTop = -1;
330 349 m_mapFirst = 0;
331 350 m_mapCount = 0;
332 351 m_mapOrientation = Qt::Vertical;
333 352 }
334 353
335 354 // set new model
336 355 if(model)
337 356 {
338 357 m_model = model;
339 358 return true;
340 359 }
341 360 else
342 361 {
343 362 m_model = 0;
344 363 return false;
345 364 }
346 365 }
347 366
348 367 void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
349 368 {
350 369 Q_Q(QBarSeries);
351 370
352 371 if (m_model == 0)
353 372 return;
354 373
355 374 m_mapCategories = categories;
356 375 m_mapBarBottom = bottomBoundry;
357 376 m_mapBarTop = topBoundry;
358 377 // m_mapFirst = 1;
359 378 m_mapOrientation = orientation;
360 379
361 380 // connect the signals
362 381 if (m_mapOrientation == Qt::Vertical) {
363 382 m_mapCount = m_model->rowCount() - m_mapFirst;
364 383 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
365 384 this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
366 385 connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)),
367 386 this, SLOT(modelDataAdded(QModelIndex,int,int)));
368 387 connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
369 388 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
370 389 } else {
371 390 m_mapCount = m_model->columnCount() - m_mapFirst;
372 391 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
373 392 this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
374 393 connect(m_model,SIGNAL(columnsInserted(QModelIndex,int,int)),
375 394 this, SLOT(modelDataAdded(QModelIndex,int,int)));
376 395 connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
377 396 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
378 397 }
379 398
380 399 // create the initial bars
381 400 delete m_internalModel;
382 401 if (m_mapOrientation == Qt::Vertical) {
383 402 QStringList categories;
384 403 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
385 404 categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
386 405 m_internalModel = new BarChartModel(categories, this);
387 406
388 407 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
389 408 QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
390 409 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
391 410 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
392 411 q->appendBarSet(barSet);
393 412 }
394 413 } else {
395 414 QStringList categories;
396 415 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
397 416 categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
398 417 m_internalModel = new BarChartModel(categories, this);
399 418
400 419 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
401 420 QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
402 421 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
403 422 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
404 423 q->appendBarSet(barSet);
405 424 }
406 425 }
407 426 }
408 427
409 428 void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
410 429 {
411 430 Q_UNUSED(bottomRight)
412 431
413 432 if (m_mapOrientation == Qt::Vertical)
414 433 {
415 434 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
416 435 if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount)
417 436 barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
418 437 }
419 438 else
420 439 {
421 440 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
422 441 if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount)
423 442 barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
424 443 }
425 444 }
426 445
427 446 void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/)
428 447 {
429 448 Q_Q(QBarSeries);
430 449
431 450 if (m_mapOrientation == Qt::Vertical) {
432 451 q->insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1));
433 452 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
434 453 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble());
435 454 }
436 455 } else {
437 456 q->insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1));
438 457 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
439 458 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble());
440 459 }
441 460 }
442 461 emit restructuredBars();
443 462 }
444 463
445 464 void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
446 465 {
447 466 Q_Q(QBarSeries);
448 467 Q_UNUSED(parent)
449 468 Q_UNUSED(end)
450 469
451 470 q->removeCategory(start - m_mapFirst);
452 471 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++)
453 472 {
454 473 barsetAt(i)->removeValue(start - m_mapFirst);
455 474 }
456 475 emit restructuredBars();
457 476 }
458 477
459 478 void QBarSeriesPrivate::barsetChanged()
460 479 {
461 480 emit updatedBars();
462 481 }
463 482
464 483 void QBarSeriesPrivate::scaleDomain(Domain& domain)
465 484 {
466 485 qreal minX(domain.minX());
467 486 qreal minY(domain.minY());
468 487 qreal maxX(domain.maxX());
469 488 qreal maxY(domain.maxY());
470 489 int tickXCount(domain.tickXCount());
471 490 int tickYCount(domain.tickYCount());
472 491
473 492 qreal x = m_internalModel->categoryCount();
474 493 qreal y = max();
475 494 minX = qMin(minX, x);
476 495 minY = qMin(minY, y);
477 496 maxX = qMax(maxX, x);
478 497 maxY = qMax(maxY, y);
479 498 tickXCount = x+1;
480 499
481 500 domain.setRangeX(minX,maxX,tickXCount);
482 501 domain.setRangeY(minY,maxY,tickYCount);
483 502 }
484 503
485 504 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
486 505 {
487 506 Q_Q(QBarSeries);
488 507
489 508 BarChartItem* bar = new BarChartItem(q,presenter);
490 509 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
491 510 presenter->animator()->addAnimation(bar);
492 511 }
493 512 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
494 513 return bar;
495 514
496 515 }
497 516
498 517 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
499 518 {
500 519 Q_Q(QBarSeries);
501 520 QList<LegendMarker*> markers;
502 521 foreach(QBarSet* set, q->barSets()) {
503 522 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
504 523 markers << marker;
505 524 }
506 525
507 526 return markers;
508 527 }
509 528
510 529 #include "moc_qbarseries.cpp"
511 530 #include "moc_qbarseries_p.cpp"
512 531
513 532 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,81 +1,82
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 #ifndef BARSERIES_H
22 22 #define BARSERIES_H
23 23
24 24 #include <qseries.h>
25 25 #include <QStringList>
26 26
27 27 class QModelIndex;
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 typedef QStringList QBarCategories;
32 32
33 33 class QBarSet;
34 34 class BarChartModel;
35 35 class BarCategory;
36 36 class QBarSeriesPrivate;
37 37
38 38 // Container for series
39 39 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries
40 40 {
41 41 Q_OBJECT
42 42 public:
43 43 explicit QBarSeries(QBarCategories categories, QObject *parent = 0);
44 virtual ~QBarSeries();
44 45
45 46 QSeries::QSeriesType type() const;
46 47
47 48 void appendBarSet(QBarSet *set); // Takes ownership of set
48 49 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
49 50 void appendBarSets(QList<QBarSet* > sets);
50 51 void removeBarSets(QList<QBarSet* > sets);
51 52 void insertBarSet(int i, QBarSet *set);
52 53 void insertCategory(int i, QString category);
53 54 void removeCategory(int i);
54 55 int barsetCount() const;
55 56 int categoryCount() const;
56 57 QList<QBarSet*> barSets() const;
57 58 QBarCategories categories() const;
58 59
59 60 void setLabelsVisible(bool visible = true);
60 61
61 62 bool setModel(QAbstractItemModel *model);
62 63 void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
63 64
64 65 protected:
65 66 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
66 67
67 68 Q_SIGNALS:
68 69 void clicked(QBarSet *barset, QString category, Qt::MouseButtons button);
69 70 void selected();
70 71 void hovered(QBarSet* barset, bool status);
71 72
72 73 protected:
73 74 Q_DECLARE_PRIVATE(QBarSeries)
74 75 friend class BarChartItem;
75 76 friend class PercentBarChartItem;
76 77 friend class StackedBarChartItem;
77 78 };
78 79
79 80 QTCOMMERCIALCHART_END_NAMESPACE
80 81
81 82 #endif // BARSERIES_H
@@ -1,281 +1,292
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 "qbarset.h"
22 22 #include "qbarset_p.h"
23 23
24 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25
26 26 /*!
27 27 \class QBarSet
28 28 \brief part of QtCommercial chart API.
29 29
30 30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
31 31 First value of set is assumed to belong to first category, second to second category and so on.
32 32 If set has fewer values than there are categories, then the missing values are assumed to be
33 33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
34 34
35 35 \mainclass
36 36
37 37 \sa QBarSeries, QStackedBarSeries, QPercentBarSeries
38 38 */
39 39
40 40 /*!
41 41 \fn void QBarSet::clicked(QString category, Qt::MouseButtons button)
42 42 \brief signals that set has been clicked
43 43 Parameter \a category describes on which category was clicked
44 44 Parameter \a button mouse button
45 45 */
46 46
47 47 /*!
48 \fn void QBarSet::selected()
49 \brief signals that set has been selected
50 */
51
52 /*!
48 53 \fn void QBarSet::hovered(bool status)
49 54 \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left.
55
56 The signal is emitted if mouse is hovered on top of set
57 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
50 58 */
51 59
52 60 /*!
53 61 Constructs QBarSet with a name of \a name and with parent of \a parent
54 62 */
55 63 QBarSet::QBarSet(QString name, QObject *parent)
56 64 : QObject(parent)
57 65 ,d_ptr(new QBarSetPrivate(name,this))
58 66 {
59 67 }
60 68
69 /*!
70 Destroys the barset
71 */
61 72 QBarSet::~QBarSet()
62 73 {
63
74 // NOTE: d_ptr destroyed by QObject
64 75 }
65 76
66 77 /*!
67 78 Sets new \a name for set.
68 79 */
69 80 void QBarSet::setName(QString name)
70 81 {
71 82 d_ptr->m_name = name;
72 83 }
73 84
74 85 /*!
75 86 Returns name of the set.
76 87 */
77 88 QString QBarSet::name() const
78 89 {
79 90 return d_ptr->m_name;
80 91 }
81 92
82 93 /*!
83 94 Appends new value \a value to the end of set.
84 95 */
85 96 QBarSet& QBarSet::operator << (const qreal &value)
86 97 {
87 98 d_ptr->m_values.append(value);
88 99 emit d_ptr->structureChanged();
89 100 return *this;
90 101 }
91 102
92 103 /*!
93 104 Inserts new \a value on the \a i position.
94 105 The value that is currently at this postion is moved to postion i + 1
95 106 \sa removeValue()
96 107 */
97 108 void QBarSet::insertValue(int i, qreal value)
98 109 {
99 110 d_ptr->m_values.insert(i, value);
100 111 }
101 112
102 113 /*!
103 114 Removes the value specified by \a i
104 115 \sa insertValue()
105 116 */
106 117 void QBarSet::removeValue(int i)
107 118 {
108 119 d_ptr->m_values.removeAt(i);
109 120 }
110 121
111 122 /*!
112 123 Returns count of values in set.
113 124 */
114 125 int QBarSet::count() const
115 126 {
116 127 return d_ptr->m_values.count();
117 128 }
118 129
119 130 /*!
120 131 Returns value of set indexed by \a index
121 132 */
122 133 qreal QBarSet::valueAt(int index) const
123 134 {
124 135 return d_ptr->m_values.at(index);
125 136 }
126 137
127 138 /*!
128 139 Sets a new value \a value to set, indexed by \a index
129 140 */
130 141 void QBarSet::setValue(int index, qreal value)
131 142 {
132 143 d_ptr->m_values.replace(index,value);
133 144 emit d_ptr->valueChanged();
134 145 }
135 146
136 147 /*!
137 148 Returns sum of all values in barset.
138 149 */
139 150 qreal QBarSet::sum() const
140 151 {
141 152 qreal total(0);
142 153 for (int i=0; i < d_ptr->m_values.count(); i++) {
143 154 total += d_ptr->m_values.at(i);
144 155 }
145 156 return total;
146 157 }
147 158
148 159 /*!
149 160 Sets pen for set. Bars of this set are drawn using \a pen
150 161 */
151 162 void QBarSet::setPen(const QPen &pen)
152 163 {
153 164 if(d_ptr->m_pen!=pen){
154 165 d_ptr->m_pen = pen;
155 166 emit d_ptr->valueChanged();
156 167 }
157 168 }
158 169
159 170 /*!
160 171 Returns pen of the set.
161 172 */
162 173 QPen QBarSet::pen() const
163 174 {
164 175 return d_ptr->m_pen;
165 176 }
166 177
167 178 /*!
168 179 Sets brush for the set. Bars of this set are drawn using \a brush
169 180 */
170 181 void QBarSet::setBrush(const QBrush &brush)
171 182 {
172 183 if(d_ptr->m_brush!=brush){
173 184 d_ptr->m_brush = brush;
174 185 emit d_ptr->valueChanged();
175 186 }
176 187 }
177 188
178 189 /*!
179 190 Returns brush of the set.
180 191 */
181 192 QBrush QBarSet::brush() const
182 193 {
183 194 return d_ptr->m_brush;
184 195 }
185 196
186 197 /*!
187 198 Sets \a pen of the values that are drawn on top of this barset
188 199 */
189 200 void QBarSet::setLabelPen(const QPen &pen)
190 201 {
191 202 if(d_ptr->m_labelPen!=pen){
192 203 d_ptr->m_labelPen = pen;
193 204 emit d_ptr->valueChanged();
194 205 }
195 206 }
196 207
197 208 /*!
198 209 Returns pen of the values that are drawn on top of this barset
199 210 */
200 211 QPen QBarSet::labelPen() const
201 212 {
202 213 return d_ptr->m_labelPen;
203 214 }
204 215
205 216 /*!
206 217 Sets \a brush of the values that are drawn on top of this barset
207 218 */
208 219 void QBarSet::setLabelBrush(const QBrush &brush)
209 220 {
210 221 if(d_ptr->m_labelBrush!=brush){
211 222 d_ptr->m_labelBrush = brush;
212 223 emit d_ptr->valueChanged();
213 224 }
214 225 }
215 226
216 227 /*!
217 228 Returns brush of the values that are drawn on top of this barset
218 229 */
219 230 QBrush QBarSet::labelBrush() const
220 231 {
221 232 return d_ptr->m_labelBrush;
222 233 }
223 234
224 235 /*!
225 236 Sets the \a font for values that are drawn on top of this barset
226 237 */
227 238 void QBarSet::setLabelFont(const QFont &font)
228 239 {
229 240 if(d_ptr->m_labelFont!=font) {
230 241 d_ptr->m_labelFont = font;
231 242 emit d_ptr->valueChanged();
232 243 }
233 244
234 245 }
235 246
236 247 /*!
237 248 Returns the pen for values that are drawn on top of this set
238 249 */
239 250 QFont QBarSet::labelFont() const
240 251 {
241 252 return d_ptr->m_labelFont;
242 253 }
243 254
244 255 /*!
245 256 Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets.
246 257 */
247 258
248 259 void QBarSet::setLabelsVisible(bool visible)
249 260 {
250 261 if(d_ptr->m_labelsVisible!=visible) {
251 262 d_ptr->m_labelsVisible = visible;
252 263 emit d_ptr->labelsVisibleChanged(visible);
253 264 }
254 265 }
255 266
256 267 /*!
257 268 Returns the visibility of values
258 269 */
259 270 bool QBarSet::labelsVisible() const
260 271 {
261 272 return d_ptr->m_labelsVisible;
262 273 }
263 274
264 275 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
265 276
266 277 QBarSetPrivate::QBarSetPrivate(QString name, QBarSet *parent) : QObject(parent),
267 278 q_ptr(parent),
268 279 m_name(name),
269 280 m_labelsVisible(false)
270 281 {
271 282
272 283 }
273 284
274 285 QBarSetPrivate::~QBarSetPrivate()
275 286 {
276 287
277 288 }
278 289 #include "moc_qbarset.cpp"
279 290 #include "moc_qbarset_p.cpp"
280 291
281 292 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,84 +1,84
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 #ifndef QBARSET_H
22 22 #define QBARSET_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <QPen>
26 26 #include <QBrush>
27 27 #include <QFont>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30 class QBarSetPrivate;
31 31
32 32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
33 33 {
34 34 Q_OBJECT
35 35
36 36 public:
37 37 explicit QBarSet(QString name, QObject *parent = 0);
38 ~QBarSet();
38 virtual ~QBarSet();
39 39
40 40 void setName(QString name);
41 41 QString name() const;
42 42 QBarSet& operator << (const qreal &value); // appends new value to set
43 43 void insertValue(int i, qreal value);
44 44 void removeValue(int i);
45 45 int count() const; // count of values in set
46 46 qreal valueAt(int index) const; // for modifying individual values
47 47 void setValue(int index, qreal value); // setter for individual value
48 48 qreal sum() const; // sum of all values in the set
49 49
50 50 void setPen(const QPen &pen);
51 51 QPen pen() const;
52 52
53 53 void setBrush(const QBrush &brush);
54 54 QBrush brush() const;
55 55
56 56 void setLabelPen(const QPen &pen);
57 57 QPen labelPen() const;
58 58
59 59 void setLabelBrush(const QBrush &brush);
60 60 QBrush labelBrush() const;
61 61
62 62 void setLabelFont(const QFont &font);
63 63 QFont labelFont() const;
64 64
65 65 void setLabelsVisible(bool visible = true);
66 66 bool labelsVisible() const;
67 67
68 68 Q_SIGNALS:
69 69 void clicked(QString category, Qt::MouseButtons button);
70 70 void selected();
71 71 void hovered(bool status);
72 72
73 73 private:
74 74 QScopedPointer<QBarSetPrivate> d_ptr;
75 75 Q_DISABLE_COPY(QBarSet)
76 76 friend class QBarSeries;
77 77 friend class BarLegendMarker;
78 78 friend class BarChartItem;
79 79 friend class QBarSeriesPrivate;
80 80 };
81 81
82 82 QTCOMMERCIALCHART_END_NAMESPACE
83 83
84 84 #endif // QBARSET_H
General Comments 0
You need to be logged in to leave comments. Login now