@@ -6,7 +6,6 CURRENTLY_BUILDING_COMPONENTS = "examples" | |||
|
6 | 6 | TEMPLATE = subdirs |
|
7 | 7 | SUBDIRS += \ |
|
8 | 8 | areachart \ |
|
9 | barchart \ | |
|
10 | 9 | #customchart \ |
|
11 | 10 | linechart \ |
|
12 | 11 | percentbarchart \ |
@@ -25,7 +25,7 | |||
|
25 | 25 | #include <QLabel> |
|
26 | 26 | #include <QDebug> |
|
27 | 27 | #include <QBarSet> |
|
28 | #include <QBarSeries> | |
|
28 | #include <QGroupedBarSeries> | |
|
29 | 29 | #include <QLegend> |
|
30 | 30 | #include <QFormLayout> |
|
31 | 31 | |
@@ -118,7 +118,7 MainWidget::MainWidget(QWidget *parent) : | |||
|
118 | 118 | |
|
119 | 119 | void MainWidget::createSeries() |
|
120 | 120 | { |
|
121 | m_series = new QBarSeries(); | |
|
121 | m_series = new QGroupedBarSeries(); | |
|
122 | 122 | addBarset(); |
|
123 | 123 | addBarset(); |
|
124 | 124 | addBarset(); |
@@ -196,7 +196,7 void MainWidget::addBarset() | |||
|
196 | 196 | { |
|
197 | 197 | QBarSet *barSet = new QBarSet(QString("set ") + QString::number(m_series->count())); |
|
198 | 198 | qreal delta = m_series->count() * 0.1; |
|
199 | *barSet << QPointF(0.0 + delta, 1 + delta) << QPointF(1.0 + delta, 2 + delta) << QPointF(2.0 + delta, 3 + delta) << QPointF(3.0 + delta, 4 + delta); | |
|
199 | *barSet << 1 + delta << 2 + delta << 3 + delta << 4 + delta; | |
|
200 | 200 | m_series->append(barSet); |
|
201 | 201 | } |
|
202 | 202 |
@@ -30,7 +30,7 | |||
|
30 | 30 | #include <QGraphicsGridLayout> |
|
31 | 31 | #include <QDoubleSpinBox> |
|
32 | 32 | #include <QGroupBox> |
|
33 | #include <QBarSeries> | |
|
33 | #include <QGroupedBarSeries> | |
|
34 | 34 | |
|
35 | 35 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
36 | 36 | |
@@ -66,7 +66,7 public slots: | |||
|
66 | 66 | private: |
|
67 | 67 | |
|
68 | 68 | QChart *m_chart; |
|
69 | QBarSeries *m_series; | |
|
69 | QGroupedBarSeries *m_series; | |
|
70 | 70 | |
|
71 | 71 | QChartView *m_chartView; |
|
72 | 72 | QGridLayout *m_mainLayout; |
@@ -57,8 +57,6 void DeclarativeBarSet::setValues(QVariantList values) | |||
|
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 | else if (values.at(i).canConvert(QVariant::PointF)) | |
|
61 | QBarSet::append(values[i].toPointF()); | |
|
62 | 60 | } |
|
63 | 61 | } |
|
64 | 62 |
@@ -47,11 +47,9 public: | |||
|
47 | 47 | |
|
48 | 48 | public: // From QBarSet |
|
49 | 49 | Q_INVOKABLE void append(qreal value) { QBarSet::append(value); } |
|
50 | Q_INVOKABLE void append(qreal x, qreal y) { QBarSet::append(QPointF(x, y)); } | |
|
51 | 50 | Q_INVOKABLE void remove(const int index, const int count = 1) { QBarSet::remove(index, count); } |
|
52 | 51 | Q_INVOKABLE void replace(int index, qreal value) { QBarSet::replace(index, value); } |
|
53 |
Q_INVOKABLE |
|
|
54 | Q_INVOKABLE QPointF at(int index) { return QBarSet::at(index); } | |
|
52 | Q_INVOKABLE qreal at(int index) { return QBarSet::at(index); } | |
|
55 | 53 | |
|
56 | 54 | Q_SIGNALS: |
|
57 | 55 | void countChanged(int count); |
@@ -83,30 +83,30 QVector<QRectF> BarChartItem::calculateLayout() | |||
|
83 | 83 | for (int category = 0; category < categoryCount; category++) { |
|
84 | 84 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
85 | 85 | for (int set = 0; set < setCount; set++) { |
|
86 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
|
87 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
|
88 | qreal barHeight = barSet->at(category).y() * scaleY; | |
|
86 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
|
87 | qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
|
88 | qreal barHeight = barSet->m_values.at(category).y() * scaleY; | |
|
89 | 89 | |
|
90 | 90 | Bar* bar = m_bars.at(itemIndex); |
|
91 | 91 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
92 | 92 | |
|
93 | 93 | layout.append(rect); |
|
94 |
bar->setPen(barSet->pen |
|
|
95 |
bar->setBrush(barSet->brush |
|
|
94 | bar->setPen(barSet->m_pen); | |
|
95 | bar->setBrush(barSet->m_brush); | |
|
96 | 96 | bar->setVisible(barsVisible); |
|
97 | 97 | |
|
98 | 98 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
99 | 99 | |
|
100 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
|
101 | label->setText(QString::number(barSet->at(category).y())); | |
|
100 | if (!qFuzzyIsNull(barSet->m_values.at(category).y())) { | |
|
101 | label->setText(QString::number(barSet->m_values.at(category).y())); | |
|
102 | 102 | } else { |
|
103 | 103 | label->setText(QString("")); |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
107 | 107 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
108 |
label->setFont(barSet->labelFont |
|
|
109 |
label->setBrush(barSet->labelBrush |
|
|
108 | label->setFont(barSet->m_labelFont); | |
|
109 | label->setBrush(barSet->m_labelBrush); | |
|
110 | 110 | |
|
111 | 111 | itemIndex++; |
|
112 | 112 | } |
@@ -23,6 +23,7 | |||
|
23 | 23 | #include "qbarset_p.h" |
|
24 | 24 | #include "qbarseries_p.h" |
|
25 | 25 | #include "qbarset.h" |
|
26 | #include "qbarset_p.h" | |
|
26 | 27 | |
|
27 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 29 | |
@@ -53,32 +54,32 QVector<QRectF> GroupedBarChartItem::calculateLayout() | |||
|
53 | 54 | for (int category = 0; category < categoryCount; category++) { |
|
54 | 55 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
55 | 56 | for (int set = 0; set < setCount; set++) { |
|
56 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
|
57 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
|
57 | 58 | |
|
58 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left(); | |
|
59 | qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left(); | |
|
59 | 60 | xPos -= setCount*barWidth/2; |
|
60 | 61 | xPos += set*barWidth; |
|
61 | qreal barHeight = barSet->at(category).y() * scaleY; | |
|
62 | qreal barHeight = barSet->m_values.at(category).y() * scaleY; | |
|
62 | 63 | Bar* bar = m_bars.at(itemIndex); |
|
63 | 64 | |
|
64 | 65 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
65 | 66 | layout.append(rect); |
|
66 |
bar->setPen(barSet->pen |
|
|
67 |
bar->setBrush(barSet->brush |
|
|
67 | bar->setPen(barSet->m_pen); | |
|
68 | bar->setBrush(barSet->m_brush); | |
|
68 | 69 | bar->setVisible(barsVisible); |
|
69 | 70 | |
|
70 | 71 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
71 | 72 | |
|
72 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
|
73 | label->setText(QString::number(barSet->at(category).y())); | |
|
73 | if (!qFuzzyIsNull(barSet->m_values.at(category).y())) { | |
|
74 | label->setText(QString::number(barSet->m_values.at(category).y())); | |
|
74 | 75 | } else { |
|
75 | 76 | label->setText(QString("")); |
|
76 | 77 | } |
|
77 | 78 | |
|
78 | 79 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
79 | 80 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
80 |
label->setFont(barSet->labelFont |
|
|
81 |
label->setBrush(barSet->labelBrush |
|
|
81 | label->setFont(barSet->m_labelFont); | |
|
82 | label->setBrush(barSet->m_labelBrush); | |
|
82 | 83 | |
|
83 | 84 | itemIndex++; |
|
84 | 85 | } |
@@ -23,6 +23,7 | |||
|
23 | 23 | #include "qbarseries_p.h" |
|
24 | 24 | #include "qbarset.h" |
|
25 | 25 | #include "chartanimator_p.h" |
|
26 | #include "qbarset_p.h" | |
|
26 | 27 | |
|
27 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 29 | |
@@ -55,14 +56,14 QVector<QRectF> PercentBarChartItem::calculateLayout() | |||
|
55 | 56 | qreal percentage = (100 / colSum); |
|
56 | 57 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
57 | 58 | for (int set=0; set < setCount; set++) { |
|
58 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
|
59 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
|
59 | 60 | |
|
60 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
|
61 | qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
|
61 | 62 | |
|
62 | qreal barHeight = barSet->at(category).y() * percentage * scaleY; | |
|
63 | qreal barHeight = barSet->m_values.at(category).y() * percentage * scaleY; | |
|
63 | 64 | Bar* bar = m_bars.at(itemIndex); |
|
64 |
bar->setPen(barSet->pen |
|
|
65 |
bar->setBrush(barSet->brush |
|
|
65 | bar->setPen(barSet->m_pen); | |
|
66 | bar->setBrush(barSet->m_brush); | |
|
66 | 67 | bar->setVisible(barsVisible); |
|
67 | 68 | |
|
68 | 69 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
@@ -82,8 +83,8 QVector<QRectF> PercentBarChartItem::calculateLayout() | |||
|
82 | 83 | |
|
83 | 84 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
84 | 85 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
85 |
label->setFont(barSet->labelFont |
|
|
86 |
label->setBrush(barSet->labelBrush |
|
|
86 | label->setFont(barSet->m_labelFont); | |
|
87 | label->setBrush(barSet->m_labelBrush); | |
|
87 | 88 | |
|
88 | 89 | itemIndex++; |
|
89 | 90 | yPos -= barHeight; |
@@ -416,7 +416,7 void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets) | |||
|
416 | 416 | for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) { |
|
417 | 417 | m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label()); |
|
418 | 418 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++) |
|
419 |
m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j) |
|
|
419 | m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j)); | |
|
420 | 420 | } |
|
421 | 421 | blockModelSignals(false); |
|
422 | 422 | initializeBarFromModel(); |
@@ -465,7 +465,7 void QBarModelMapperPrivate::valuesAdded(int index, int count) | |||
|
465 | 465 | m_model->insertColumns(index + m_first, count); |
|
466 | 466 | |
|
467 | 467 | for (int j = index; j < index + count; j++) |
|
468 |
m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j) |
|
|
468 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j)); | |
|
469 | 469 | |
|
470 | 470 | blockModelSignals(false); |
|
471 | 471 | initializeBarFromModel(); |
@@ -510,7 +510,7 void QBarModelMapperPrivate::barValueChanged(int index) | |||
|
510 | 510 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
511 | 511 | |
|
512 | 512 | blockModelSignals(); |
|
513 |
m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index) |
|
|
513 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index)); | |
|
514 | 514 | blockModelSignals(false); |
|
515 | 515 | initializeBarFromModel(); |
|
516 | 516 | } |
@@ -432,7 +432,7 qreal QBarSeriesPrivate::min() | |||
|
432 | 432 | for (int i = 0; i < m_barSets.count(); i++) { |
|
433 | 433 | int categoryCount = m_barSets.at(i)->count(); |
|
434 | 434 | for (int j = 0; j < categoryCount; j++) { |
|
435 |
qreal temp = m_barSets.at(i)->at(j) |
|
|
435 | qreal temp = m_barSets.at(i)->at(j); | |
|
436 | 436 | if (temp < min) |
|
437 | 437 | min = temp; |
|
438 | 438 | } |
@@ -450,7 +450,7 qreal QBarSeriesPrivate::max() | |||
|
450 | 450 | for (int i = 0; i < m_barSets.count(); i++) { |
|
451 | 451 | int categoryCount = m_barSets.at(i)->count(); |
|
452 | 452 | for (int j = 0; j < categoryCount; j++) { |
|
453 |
qreal temp = m_barSets.at(i)->at(j) |
|
|
453 | qreal temp = m_barSets.at(i)->at(j); | |
|
454 | 454 | if (temp > max) |
|
455 | 455 | max = temp; |
|
456 | 456 | } |
@@ -469,7 +469,7 qreal QBarSeriesPrivate::valueAt(int set, int category) | |||
|
469 | 469 | return 0; |
|
470 | 470 | } |
|
471 | 471 | |
|
472 |
return m_barSets.at(set)->at(category) |
|
|
472 | return m_barSets.at(set)->at(category); | |
|
473 | 473 | } |
|
474 | 474 | |
|
475 | 475 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
@@ -482,7 +482,7 qreal QBarSeriesPrivate::percentageAt(int set, int category) | |||
|
482 | 482 | return 0; |
|
483 | 483 | } |
|
484 | 484 | |
|
485 |
qreal value = m_barSets.at(set)->at(category) |
|
|
485 | qreal value = m_barSets.at(set)->at(category); | |
|
486 | 486 | qreal sum = categorySum(category); |
|
487 | 487 | if ( qFuzzyIsNull(sum) ) { |
|
488 | 488 | return 0; |
@@ -497,7 +497,7 qreal QBarSeriesPrivate::categorySum(int category) | |||
|
497 | 497 | int count = m_barSets.count(); // Count sets |
|
498 | 498 | for (int set = 0; set < count; set++) { |
|
499 | 499 | if (category < m_barSets.at(set)->count()) |
|
500 |
sum += m_barSets.at(set)->at(category) |
|
|
500 | sum += m_barSets.at(set)->at(category); | |
|
501 | 501 | } |
|
502 | 502 | return sum; |
|
503 | 503 | } |
@@ -508,7 +508,7 qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |||
|
508 | 508 | int count = m_barSets.count(); // Count sets |
|
509 | 509 | for (int set = 0; set < count; set++) { |
|
510 | 510 | if (category < m_barSets.at(set)->count()) |
|
511 |
sum += qAbs(m_barSets.at(set)->at(category) |
|
|
511 | sum += qAbs(m_barSets.at(set)->at(category)); | |
|
512 | 512 | } |
|
513 | 513 | return sum; |
|
514 | 514 | } |
@@ -535,7 +535,7 qreal QBarSeriesPrivate::minX() | |||
|
535 | 535 | for (int i = 0; i < m_barSets.count(); i++) { |
|
536 | 536 | int categoryCount = m_barSets.at(i)->count(); |
|
537 | 537 | for (int j = 0; j < categoryCount; j++) { |
|
538 | qreal temp = m_barSets.at(i)->at(j).x(); | |
|
538 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
|
539 | 539 | if (temp < min) |
|
540 | 540 | min = temp; |
|
541 | 541 | } |
@@ -553,7 +553,7 qreal QBarSeriesPrivate::maxX() | |||
|
553 | 553 | for (int i = 0; i < m_barSets.count(); i++) { |
|
554 | 554 | int categoryCount = m_barSets.at(i)->count(); |
|
555 | 555 | for (int j = 0; j < categoryCount; j++) { |
|
556 | qreal temp = m_barSets.at(i)->at(j).x(); | |
|
556 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
|
557 | 557 | if (temp > max) |
|
558 | 558 | max = temp; |
|
559 | 559 | } |
@@ -276,42 +276,17 QString QBarSet::label() const | |||
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | /*! |
|
279 | Appends a point to set. Parameter \a value x coordinate defines the | |
|
280 | position in x-axis and y coordinate defines the height of bar. | |
|
281 | Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries) | |
|
282 | the x values are used or ignored. | |
|
283 | */ | |
|
284 | void QBarSet::append(const QPointF value) | |
|
285 | { | |
|
286 | int index = d_ptr->m_values.count(); | |
|
287 | d_ptr->append(value); | |
|
288 | emit valuesAdded(index, 1); | |
|
289 | } | |
|
290 | ||
|
291 | /*! | |
|
292 | Appends a list of \a values to set. Works like append with single point. | |
|
293 | \sa append() | |
|
294 | */ | |
|
295 | void QBarSet::append(const QList<QPointF> &values) | |
|
296 | { | |
|
297 | int index = d_ptr->m_values.count(); | |
|
298 | d_ptr->append(values); | |
|
299 | emit valuesAdded(index, values.count()); | |
|
300 | } | |
|
301 | ||
|
302 | /*! | |
|
303 | Appends new value \a value to the end of set. Internally the value is converted to QPointF, | |
|
304 | with x coordinate being the index of appended value and y coordinate is the value. | |
|
279 | Appends new value \a value to the end of set. | |
|
305 | 280 | */ |
|
306 | 281 | void QBarSet::append(const qreal value) |
|
307 | 282 | { |
|
308 | // Convert to QPointF and use other append(QPointF) method. | |
|
309 | append(QPointF(d_ptr->m_values.count(), value)); | |
|
283 | // Convert to QPointF | |
|
284 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | |
|
310 | 285 | } |
|
311 | 286 | |
|
312 | 287 | /*! |
|
313 | 288 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
314 | are converted to QPointF, where x coordinate is the index of point and y coordinate is the value. | |
|
289 | are appended to end of barset | |
|
315 | 290 | \sa append() |
|
316 | 291 | */ |
|
317 | 292 | void QBarSet::append(const QList<qreal> &values) |
@@ -327,17 +302,8 void QBarSet::append(const QList<qreal> &values) | |||
|
327 | 302 | */ |
|
328 | 303 | QBarSet& QBarSet::operator << (const qreal &value) |
|
329 | 304 | { |
|
330 | append(value); | |
|
331 | return *this; | |
|
332 | } | |
|
333 | ||
|
334 | /*! | |
|
335 | Convinience operator. Same as append, with QPointF \a value. | |
|
336 | \sa append() | |
|
337 | */ | |
|
338 | QBarSet& QBarSet::operator << (const QPointF &value) | |
|
339 | { | |
|
340 | append(value); | |
|
305 | // append(value); | |
|
306 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | |
|
341 | 307 | return *this; |
|
342 | 308 | } |
|
343 | 309 | |
@@ -353,17 +319,6 void QBarSet::insert(const int index, const qreal value) | |||
|
353 | 319 | } |
|
354 | 320 | |
|
355 | 321 | /*! |
|
356 | Inserts new \a value on the \a index position. | |
|
357 | The value that is currently at this postion is moved to postion index + 1 | |
|
358 | \sa remove() | |
|
359 | */ | |
|
360 | void QBarSet::insert(const int index, const QPointF value) | |
|
361 | { | |
|
362 | d_ptr->insert(index,value); | |
|
363 | emit valuesAdded(index,1); | |
|
364 | } | |
|
365 | ||
|
366 | /*! | |
|
367 | 322 | Removes \a count number of values from the set starting at \a index. |
|
368 | 323 | \sa insert() |
|
369 | 324 | */ |
@@ -387,40 +342,27 void QBarSet::replace(const int index, const qreal value) | |||
|
387 | 342 | } |
|
388 | 343 | } |
|
389 | 344 | |
|
390 | /*! | |
|
391 | Sets a new value \a value to set, indexed by \a index | |
|
392 | */ | |
|
393 | void QBarSet::replace(const int index, const QPointF value) | |
|
394 | { | |
|
395 | if (index >= 0 && index < d_ptr->m_values.count()) { | |
|
396 | d_ptr->replace(index,value); | |
|
397 | emit valueChanged(index); | |
|
398 | } | |
|
399 | } | |
|
400 | 345 | |
|
401 | 346 | /*! |
|
402 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF. | |
|
403 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value | |
|
404 | of the QPointF (if appended with QPointF append). | |
|
405 | If the index is out of bounds QPointF(0, 0.0) is returned. | |
|
347 | Returns value of set indexed by \a index. | |
|
348 | If the index is out of bounds 0.0 is returned. | |
|
406 | 349 | */ |
|
407 |
|
|
|
350 | qreal QBarSet::at(const int index) const | |
|
408 | 351 | { |
|
409 | 352 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
410 |
return |
|
|
353 | return 0; | |
|
411 | 354 | } |
|
412 | 355 | |
|
413 | return d_ptr->m_values.at(index); | |
|
356 | return d_ptr->m_values.at(index).y(); | |
|
414 | 357 | } |
|
415 | 358 | |
|
416 | 359 | /*! |
|
417 | Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF. | |
|
418 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value | |
|
419 | of the QPointF (if appended with QPointF append). | |
|
360 | Returns value of set indexed by \a index. | |
|
361 | If the index is out of bounds 0.0 is returned. | |
|
420 | 362 | */ |
|
421 |
|
|
|
363 | qreal QBarSet::operator [](const int index) const | |
|
422 | 364 | { |
|
423 |
return |
|
|
365 | return at(index); | |
|
424 | 366 | } |
|
425 | 367 | |
|
426 | 368 | /*! |
@@ -432,13 +374,12 int QBarSet::count() const | |||
|
432 | 374 | } |
|
433 | 375 | |
|
434 | 376 | /*! |
|
435 | Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation. | |
|
377 | Returns sum of all values in barset. | |
|
436 | 378 | */ |
|
437 | 379 | qreal QBarSet::sum() const |
|
438 | 380 | { |
|
439 | 381 | qreal total(0); |
|
440 | 382 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
441 | //total += d_ptr->m_values.at(i); | |
|
442 | 383 | total += d_ptr->m_values.at(i).y(); |
|
443 | 384 | } |
|
444 | 385 | return total; |
@@ -48,21 +48,16 public: | |||
|
48 | 48 | void setLabel(const QString label); |
|
49 | 49 | QString label() const; |
|
50 | 50 | |
|
51 | void append(const QPointF value); | |
|
52 | void append(const QList<QPointF> &values); | |
|
53 | 51 | void append(const qreal value); |
|
54 | 52 | void append(const QList<qreal> &values); |
|
55 | 53 | |
|
56 | 54 | QBarSet& operator << (const qreal &value); |
|
57 | QBarSet& operator << (const QPointF &value); | |
|
58 | 55 | |
|
59 | 56 | void insert(const int index, const qreal value); |
|
60 | void insert(const int index, const QPointF value); | |
|
61 | 57 | void remove(const int index, const int count = 1); |
|
62 | 58 | void replace(const int index, const qreal value); |
|
63 |
|
|
|
64 |
|
|
|
65 | QPointF operator [] (const int index) const; | |
|
59 | qreal at(const int index) const; | |
|
60 | qreal operator [] (const int index) const; | |
|
66 | 61 | int count() const; |
|
67 | 62 | qreal sum() const; |
|
68 | 63 | |
@@ -110,6 +105,9 private: | |||
|
110 | 105 | friend class BarLegendMarker; |
|
111 | 106 | friend class BarChartItem; |
|
112 | 107 | friend class QBarSeriesPrivate; |
|
108 | friend class StackedBarChartItem; | |
|
109 | friend class PercentBarChartItem; | |
|
110 | friend class GroupedBarChartItem; | |
|
113 | 111 | }; |
|
114 | 112 | |
|
115 | 113 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -53,14 +53,14 QVector<QRectF> StackedBarChartItem::calculateLayout() | |||
|
53 | 53 | for (int category = 0; category < categoryCount; category++) { |
|
54 | 54 | qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y(); |
|
55 | 55 | for (int set=0; set < setCount; set++) { |
|
56 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
|
56 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
|
57 | 57 | |
|
58 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
|
58 | qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
|
59 | 59 | |
|
60 | qreal barHeight = barSet->at(category).y() * scaleY; | |
|
60 | qreal barHeight = barSet->m_values.at(category).y() * scaleY; | |
|
61 | 61 | Bar* bar = m_bars.at(itemIndex); |
|
62 |
bar->setPen(barSet->pen |
|
|
63 |
bar->setBrush(barSet->brush |
|
|
62 | bar->setPen(barSet->m_pen); | |
|
63 | bar->setBrush(barSet->m_brush); | |
|
64 | 64 | bar->setVisible(barsVisible); |
|
65 | 65 | |
|
66 | 66 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
@@ -68,16 +68,16 QVector<QRectF> StackedBarChartItem::calculateLayout() | |||
|
68 | 68 | |
|
69 | 69 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
70 | 70 | |
|
71 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
|
72 | label->setText(QString::number(barSet->at(category).y())); | |
|
71 | if (!qFuzzyIsNull(barSet->m_values.at(category).y())) { | |
|
72 | label->setText(QString::number(barSet->m_values.at(category).y())); | |
|
73 | 73 | } else { |
|
74 | 74 | label->setText(QString("")); |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | 77 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
78 | 78 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
79 |
label->setFont(barSet->labelFont |
|
|
80 |
label->setBrush(barSet->labelBrush |
|
|
79 | label->setFont(barSet->m_labelFont); | |
|
80 | label->setBrush(barSet->m_labelBrush); | |
|
81 | 81 | itemIndex++; |
|
82 | 82 | yPos -= barHeight; |
|
83 | 83 | } |
@@ -605,7 +605,7 void tst_qbarmodelmapper::modelUpdateCell() | |||
|
605 | 605 | createVerticalMapper(); |
|
606 | 606 | |
|
607 | 607 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); |
|
608 |
QCOMPARE(m_series->barSets().at(0)->at(1) |
|
|
608 | QCOMPARE(m_series->barSets().at(0)->at(1), 44.0); | |
|
609 | 609 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); |
|
610 | 610 | } |
|
611 | 611 |
@@ -319,11 +319,13 void tst_QBarSeries::mouseclicked() | |||
|
319 | 319 | QBarSeries* series = new QBarSeries(); |
|
320 | 320 | |
|
321 | 321 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
322 | *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
|
322 | // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
|
323 | *set1 << 10 << 10 << 10; | |
|
323 | 324 | series->append(set1); |
|
324 | 325 | |
|
325 | 326 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
326 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
|
327 | // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
|
328 | *set2 << 10 << 10 << 10; | |
|
327 | 329 | series->append(set2); |
|
328 | 330 | |
|
329 | 331 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*))); |
@@ -455,11 +457,13 void tst_QBarSeries::mousehovered() | |||
|
455 | 457 | QBarSeries* series = new QBarSeries(); |
|
456 | 458 | |
|
457 | 459 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
458 | *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
|
460 | // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
|
461 | *set1 << 10 << 10 << 10; | |
|
459 | 462 | series->append(set1); |
|
460 | 463 | |
|
461 | 464 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
462 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
|
465 | // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
|
466 | *set2 << 10 << 10 << 10; | |
|
463 | 467 | series->append(set2); |
|
464 | 468 | |
|
465 | 469 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*))); |
@@ -549,11 +553,13 void tst_QBarSeries::clearWithAnimations() | |||
|
549 | 553 | QBarSeries* series = new QBarSeries(); |
|
550 | 554 | |
|
551 | 555 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
552 | *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
|
556 | // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
|
557 | *set1 << 10 << 10 << 10; | |
|
553 | 558 | series->append(set1); |
|
554 | 559 | |
|
555 | 560 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
556 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
|
561 | // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
|
562 | *set2 << 10 << 10 << 10; | |
|
557 | 563 | series->append(set2); |
|
558 | 564 | |
|
559 | 565 | QChartView view(new QChart()); |
@@ -137,7 +137,7 void tst_QBarSet::append() | |||
|
137 | 137 | |
|
138 | 138 | for (int i=0; i<count; i++) { |
|
139 | 139 | m_barset->append(value); |
|
140 |
QCOMPARE(m_barset->at(i) |
|
|
140 | QCOMPARE(m_barset->at(i), value); | |
|
141 | 141 | sum += value; |
|
142 | 142 | value += 1.0; |
|
143 | 143 | } |
@@ -167,7 +167,7 void tst_QBarSet::appendOperator() | |||
|
167 | 167 | |
|
168 | 168 | for (int i=0; i<count; i++) { |
|
169 | 169 | *m_barset << value; |
|
170 |
QCOMPARE(m_barset->at(i) |
|
|
170 | QCOMPARE(m_barset->at(i), value); | |
|
171 | 171 | sum += value; |
|
172 | 172 | value += 1.0; |
|
173 | 173 | } |
@@ -188,20 +188,20 void tst_QBarSet::insert() | |||
|
188 | 188 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); |
|
189 | 189 | |
|
190 | 190 | m_barset->insert(0, 1.0); // 1.0 |
|
191 |
QCOMPARE(m_barset->at(0) |
|
|
191 | QCOMPARE(m_barset->at(0), 1.0); | |
|
192 | 192 | QCOMPARE(m_barset->count(), 1); |
|
193 | 193 | QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0)); |
|
194 | 194 | |
|
195 | 195 | m_barset->insert(0, 2.0); // 2.0 1.0 |
|
196 |
QCOMPARE(m_barset->at(0) |
|
|
197 |
QCOMPARE(m_barset->at(1) |
|
|
196 | QCOMPARE(m_barset->at(0), 2.0); | |
|
197 | QCOMPARE(m_barset->at(1), 1.0); | |
|
198 | 198 | QCOMPARE(m_barset->count(), 2); |
|
199 | 199 | QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0)); |
|
200 | 200 | |
|
201 | 201 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 |
|
202 |
QCOMPARE(m_barset->at(1) |
|
|
203 |
QCOMPARE(m_barset->at(0) |
|
|
204 |
QCOMPARE(m_barset->at(2) |
|
|
202 | QCOMPARE(m_barset->at(1), 3.0); | |
|
203 | QCOMPARE(m_barset->at(0), 2.0); | |
|
204 | QCOMPARE(m_barset->at(2), 1.0); | |
|
205 | 205 | QCOMPARE(m_barset->count(), 3); |
|
206 | 206 | QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0)); |
|
207 | 207 | QCOMPARE(valueSpy.count(), 3); |
@@ -228,9 +228,9 void tst_QBarSet::remove() | |||
|
228 | 228 | |
|
229 | 229 | // Remove middle |
|
230 | 230 | m_barset->remove(2); // 1.0 2.0 4.0 |
|
231 |
QCOMPARE(m_barset->at(0) |
|
|
232 |
QCOMPARE(m_barset->at(1) |
|
|
233 |
QCOMPARE(m_barset->at(2) |
|
|
231 | QCOMPARE(m_barset->at(0), 1.0); | |
|
232 | QCOMPARE(m_barset->at(1), 2.0); | |
|
233 | QCOMPARE(m_barset->at(2), 4.0); | |
|
234 | 234 | QCOMPARE(m_barset->count(), 3); |
|
235 | 235 | QCOMPARE(m_barset->sum(), 7.0); |
|
236 | 236 | QCOMPARE(valueSpy.count(), 1); |
@@ -245,8 +245,8 void tst_QBarSet::remove() | |||
|
245 | 245 | |
|
246 | 246 | // Remove first |
|
247 | 247 | m_barset->remove(0); // 2.0 4.0 |
|
248 |
QCOMPARE(m_barset->at(0) |
|
|
249 |
QCOMPARE(m_barset->at(1) |
|
|
248 | QCOMPARE(m_barset->at(0), 2.0); | |
|
249 | QCOMPARE(m_barset->at(1), 4.0); | |
|
250 | 250 | QCOMPARE(m_barset->count(), 2); |
|
251 | 251 | QCOMPARE(m_barset->sum(), 6.0); |
|
252 | 252 | |
@@ -310,16 +310,16 void tst_QBarSet::replace() | |||
|
310 | 310 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 |
|
311 | 311 | QCOMPARE(m_barset->count(), 4); |
|
312 | 312 | QCOMPARE(m_barset->sum(), 14.0); |
|
313 |
QCOMPARE(m_barset->at(0) |
|
|
313 | QCOMPARE(m_barset->at(0), 5.0); | |
|
314 | 314 | |
|
315 | 315 | // Replace last |
|
316 | 316 | m_barset->replace(3, 6.0); |
|
317 | 317 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
318 | 318 | QCOMPARE(m_barset->sum(), 16.0); |
|
319 |
QCOMPARE(m_barset->at(0) |
|
|
320 |
QCOMPARE(m_barset->at(1) |
|
|
321 |
QCOMPARE(m_barset->at(2) |
|
|
322 |
QCOMPARE(m_barset->at(3) |
|
|
319 | QCOMPARE(m_barset->at(0), 5.0); | |
|
320 | QCOMPARE(m_barset->at(1), 2.0); | |
|
321 | QCOMPARE(m_barset->at(2), 3.0); | |
|
322 | QCOMPARE(m_barset->at(3), 6.0); | |
|
323 | 323 | |
|
324 | 324 | // Illegal indexes |
|
325 | 325 | m_barset->replace(4, 6.0); |
@@ -328,10 +328,10 void tst_QBarSet::replace() | |||
|
328 | 328 | m_barset->replace(-1, 6.0); |
|
329 | 329 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
330 | 330 | QCOMPARE(m_barset->sum(), 16.0); |
|
331 |
m_barset->replace(4, |
|
|
331 | m_barset->replace(4, 1.0); | |
|
332 | 332 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
333 | 333 | QCOMPARE(m_barset->sum(), 16.0); |
|
334 |
m_barset->replace(-1, |
|
|
334 | m_barset->replace(-1, 1.0); | |
|
335 | 335 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
336 | 336 | QCOMPARE(m_barset->sum(), 16.0); |
|
337 | 337 | |
@@ -353,10 +353,10 void tst_QBarSet::at() | |||
|
353 | 353 | m_barset->append(3.0); |
|
354 | 354 | m_barset->append(4.0); |
|
355 | 355 | |
|
356 |
QCOMPARE(m_barset->at(0) |
|
|
357 |
QCOMPARE(m_barset->at(1) |
|
|
358 |
QCOMPARE(m_barset->at(2) |
|
|
359 |
QCOMPARE(m_barset->at(3) |
|
|
356 | QCOMPARE(m_barset->at(0), 1.0); | |
|
357 | QCOMPARE(m_barset->at(1), 2.0); | |
|
358 | QCOMPARE(m_barset->at(2), 3.0); | |
|
359 | QCOMPARE(m_barset->at(3), 4.0); | |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | void tst_QBarSet::atOperator_data() |
@@ -374,10 +374,10 void tst_QBarSet::atOperator() | |||
|
374 | 374 | m_barset->append(3.0); |
|
375 | 375 | m_barset->append(4.0); |
|
376 | 376 | |
|
377 |
QCOMPARE(m_barset->operator [](0) |
|
|
378 |
QCOMPARE(m_barset->operator [](1) |
|
|
379 |
QCOMPARE(m_barset->operator [](2) |
|
|
380 |
QCOMPARE(m_barset->operator [](3) |
|
|
377 | QCOMPARE(m_barset->operator [](0), 1.0); | |
|
378 | QCOMPARE(m_barset->operator [](1), 2.0); | |
|
379 | QCOMPARE(m_barset->operator [](2), 3.0); | |
|
380 | QCOMPARE(m_barset->operator [](3), 4.0); | |
|
381 | 381 | } |
|
382 | 382 | |
|
383 | 383 | void tst_QBarSet::count_data() |
General Comments 0
You need to be logged in to leave comments.
Login now