##// END OF EJS Templates
barchart visible property fix
sauimone -
r1322:5f7bdc0a2083
parent child
Show More
@@ -1,90 +1,92
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 "groupedbarchartitem_p.h"
22 22 #include "bar_p.h"
23 23 #include "qbarset_p.h"
24 24 #include "qbarseries_p.h"
25 25 #include "qbarset.h"
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 GroupedBarChartItem::GroupedBarChartItem(QBarSeries *series, ChartPresenter *presenter) :
30 30 BarChartItem(series, presenter)
31 31 {
32 32 }
33 33
34 34 QVector<QRectF> GroupedBarChartItem::calculateLayout()
35 35 {
36 36 QVector<QRectF> layout;
37 37
38 38 // Use temporary qreals for accuracy
39 39 qreal categoryCount = m_series->d_func()->categoryCount();
40 40 qreal setCount = m_series->barsetCount();
41 bool barsVisible = m_series->isVisible();
41 42
42 43 // Domain:
43 44 qreal width = geometry().width();
44 45 qreal height = geometry().height();
45 46 qreal rangeY = m_domainMaxY - m_domainMinY;
46 47 qreal rangeX = m_domainMaxX - m_domainMinX;
47 48 qreal scaleY = (height / rangeY);
48 49 qreal scaleX = (width / rangeX);
49 50 qreal categoryWidth = width / categoryCount;
50 51 qreal barWidth = categoryWidth / setCount - (categoryWidth / setCount) * m_series->d_func()->barMargin();
51 52
52 53 int itemIndex(0);
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 57 QBarSet* barSet = m_series->d_func()->barsetAt(set);
57 58
58 59 qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left();
59 60 xPos -= setCount*barWidth/2;
60 61 xPos += set*barWidth;
61 62 qreal barHeight = barSet->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 67 bar->setPen(barSet->pen());
67 68 bar->setBrush(barSet->brush());
69 bar->setVisible(barsVisible);
68 70
69 71 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
70 72
71 73 if (!qFuzzyIsNull(barSet->at(category).y())) {
72 74 label->setText(QString::number(barSet->at(category).y()));
73 75 } else {
74 76 label->setText(QString(""));
75 77 }
76 78
77 79 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
78 80 ,yPos - barHeight/2 - label->boundingRect().height()/2);
79 81 label->setFont(barSet->labelFont());
80 82 label->setBrush(barSet->labelBrush());
81 83
82 84 itemIndex++;
83 85 }
84 86 }
85 87 return layout;
86 88 }
87 89
88 90 #include "moc_groupedbarchartitem_p.cpp"
89 91
90 92 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,94 +1,98
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 "percentbarchartitem_p.h"
22 22 #include "bar_p.h"
23 23 #include "qbarseries_p.h"
24 24 #include "qbarset.h"
25 25 #include <QDebug>
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) :
30 30 BarChartItem(series, presenter)
31 31 {
32 32 }
33 33
34 34 QVector<QRectF> PercentBarChartItem::calculateLayout()
35 35 {
36 36 QVector<QRectF> layout;
37 37
38 38 // Use temporary qreals for accuracy
39 39 qreal categoryCount = m_series->d_func()->categoryCount();
40 40 qreal setCount = m_series->barsetCount();
41 bool barsVisible = m_series->isVisible();
41 42
42 43 // Domain:
43 44 qreal width = geometry().width();
44 45 qreal height = geometry().height();
45 46 qreal rangeY = m_domainMaxY - m_domainMinY;
46 47 qreal rangeX = m_domainMaxX - m_domainMinX;
47 48 qreal scaleY = (height / rangeY);
48 49 qreal scaleX = (width / rangeX);
49 50 qreal categoryWidth = width / categoryCount;
50 51 qreal barWidth = categoryWidth - categoryWidth * m_series->d_func()->barMargin();
51 52
52 53 int itemIndex(0);
53 54 for (int category = 0; category < categoryCount; category++) {
54 55 qreal colSum = m_series->d_func()->categorySum(category);
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 59 QBarSet* barSet = m_series->d_func()->barsetAt(set);
59 60
60 61 qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
61 62
62 63 qreal barHeight = barSet->at(category).y() * percentage * scaleY;
63 64 Bar* bar = m_bars.at(itemIndex);
64 65 bar->setPen(barSet->pen());
65 66 bar->setBrush(barSet->brush());
67 bar->setVisible(barsVisible);
68
66 69 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
67 70 layout.append(rect);
68 71
69 72 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
70 73
71 74 if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) {
72 75 int p = m_series->d_func()->percentageAt(set,category) * 100;
73 76 QString vString(QString::number(p));
74 77 vString.truncate(3);
75 78 vString.append("%");
76 79 label->setText(vString);
77 80 } else {
78 81 label->setText(QString(""));
79 82 }
80 83
81 84 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
82 85 ,yPos - barHeight/2 - label->boundingRect().height()/2);
83 86 label->setFont(barSet->labelFont());
84 87 label->setBrush(barSet->labelBrush());
88
85 89 itemIndex++;
86 90 yPos -= barHeight;
87 91 }
88 92 }
89 93 return layout;
90 94 }
91 95
92 96 #include "moc_percentbarchartitem_p.cpp"
93 97
94 98 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,88 +1,91
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 "stackedbarchartitem_p.h"
22 22 #include "bar_p.h"
23 23 #include "qbarset_p.h"
24 24 #include "qbarseries_p.h"
25 25 #include "qbarset.h"
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) :
30 30 BarChartItem(series, presenter)
31 31 {
32 32 }
33 33
34 34 QVector<QRectF> StackedBarChartItem::calculateLayout()
35 35 {
36 36 QVector<QRectF> layout;
37 37 // Use temporary qreals for accuracy
38 38 qreal categoryCount = m_series->d_func()->categoryCount();
39 39 qreal setCount = m_series->barsetCount();
40 bool barsVisible = m_series->isVisible();
40 41
41 42 // Domain:
42 43 qreal width = geometry().width();
43 44 qreal height = geometry().height();
44 45 qreal rangeY = m_domainMaxY - m_domainMinY;
45 46 qreal rangeX = m_domainMaxX - m_domainMinX;
46 47 qreal scaleY = (height / rangeY);
47 48 qreal scaleX = (width / rangeX);
48 49 qreal categoryWidth = width / categoryCount;
49 50 qreal barWidth = categoryWidth - categoryWidth * m_series->d_func()->barMargin();
50 51
51 52 int itemIndex(0);
52 53 for (int category = 0; category < categoryCount; category++) {
53 54 qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y();
54 55 for (int set=0; set < setCount; set++) {
55 56 QBarSet* barSet = m_series->d_func()->barsetAt(set);
56 57
57 58 qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
58 59
59 60 qreal barHeight = barSet->at(category).y() * scaleY;
60 61 Bar* bar = m_bars.at(itemIndex);
61 62 bar->setPen(barSet->pen());
62 63 bar->setBrush(barSet->brush());
64 bar->setVisible(barsVisible);
65
63 66 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
64 67 layout.append(rect);
65 68
66 69 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
67 70
68 71 if (!qFuzzyIsNull(barSet->at(category).y())) {
69 72 label->setText(QString::number(barSet->at(category).y()));
70 73 } else {
71 74 label->setText(QString(""));
72 75 }
73 76
74 77 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
75 78 ,yPos - barHeight/2 - label->boundingRect().height()/2);
76 79 label->setFont(barSet->labelFont());
77 80 label->setBrush(barSet->labelBrush());
78 81 itemIndex++;
79 82 yPos -= barHeight;
80 83 }
81 84 }
82 85
83 86 return layout;
84 87 }
85 88
86 89 #include "moc_stackedbarchartitem_p.cpp"
87 90
88 91 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now