##// END OF EJS Templates
barchart: layout calculation fix
sauimone -
r976:727d6e49349d
parent child
Show More
@@ -60,7 +60,7 void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
60
60
61 QRectF BarChartItem::boundingRect() const
61 QRectF BarChartItem::boundingRect() const
62 {
62 {
63 return m_rect.translated(-m_rect.topLeft());
63 return m_rect;
64 }
64 }
65
65
66 void BarChartItem::dataChanged()
66 void BarChartItem::dataChanged()
@@ -117,8 +117,8 QVector<QRectF> BarChartItem::calculateLayout()
117
117
118 int itemIndex(0);
118 int itemIndex(0);
119 for (int category = 0; category < categoryCount; category++) {
119 for (int category = 0; category < categoryCount; category++) {
120 qreal xPos = categoryWidth * category + barWidth / 2;
120 qreal xPos = categoryWidth * category + barWidth / 2 + geometry().topLeft().x();
121 qreal yPos = height + scale * m_domainMinY;
121 qreal yPos = height + scale * m_domainMinY + geometry().topLeft().y();
122 for (int set = 0; set < setCount; set++) {
122 for (int set = 0; set < setCount; set++) {
123 QBarSet* barSet = m_series->d_func()->barsetAt(set);
123 QBarSet* barSet = m_series->d_func()->barsetAt(set);
124
124
@@ -185,11 +185,9 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal
185 void BarChartItem::handleGeometryChanged(const QRectF &rect)
185 void BarChartItem::handleGeometryChanged(const QRectF &rect)
186 {
186 {
187 prepareGeometryChange();
187 prepareGeometryChange();
188 m_clipRect = rect.translated(-rect.topLeft());
189 m_rect = rect;
188 m_rect = rect;
190 handleLayoutChanged();
189 handleLayoutChanged();
191 m_layoutSet = true;
190 m_layoutSet = true;
192 setPos(rect.topLeft());
193 }
191 }
194
192
195 void BarChartItem::handleLayoutChanged()
193 void BarChartItem::handleLayoutChanged()
@@ -72,7 +72,6 protected:
72 qreal m_domainMaxY;
72 qreal m_domainMaxY;
73
73
74 QRectF m_rect;
74 QRectF m_rect;
75 QRectF m_clipRect;
76 bool m_layoutSet; // True, if component has been laid out.
75 bool m_layoutSet; // True, if component has been laid out.
77 QVector<QRectF> m_layout;
76 QVector<QRectF> m_layout;
78
77
@@ -43,7 +43,7 QVector<QRectF> PercentBarChartItem::calculateLayout()
43 qreal categoryCount = m_series->categoryCount();
43 qreal categoryCount = m_series->categoryCount();
44 qreal barWidth = width / (m_series->categoryCount() * 2);
44 qreal barWidth = width / (m_series->categoryCount() * 2);
45 qreal xStep = width / categoryCount;
45 qreal xStep = width / categoryCount;
46 qreal xPos = xStep / 2 - barWidth / 2;
46 qreal xPos = xStep / 2 - barWidth / 2 + geometry().topLeft().x();
47
47
48 qreal range = m_domainMaxY - m_domainMinY;
48 qreal range = m_domainMaxY - m_domainMinY;
49 qreal domainScale = (height / range);
49 qreal domainScale = (height / range);
@@ -52,7 +52,7 QVector<QRectF> PercentBarChartItem::calculateLayout()
52 for (int category = 0; category < categoryCount; category++) {
52 for (int category = 0; category < categoryCount; category++) {
53 qreal colSum = m_series->d_func()->categorySum(category);
53 qreal colSum = m_series->d_func()->categorySum(category);
54 qreal percentage = (100 / colSum);
54 qreal percentage = (100 / colSum);
55 qreal yPos = height + domainScale * m_domainMinY;
55 qreal yPos = height + domainScale * m_domainMinY + geometry().topLeft().y();
56 for (int set=0; set < m_series->barsetCount(); set++) {
56 for (int set=0; set < m_series->barsetCount(); set++) {
57 QBarSet* barSet = m_series->d_func()->barsetAt(set);
57 QBarSet* barSet = m_series->d_func()->barsetAt(set);
58 qreal barHeight = barSet->valueAt(category) * percentage * domainScale;
58 qreal barHeight = barSet->valueAt(category) * percentage * domainScale;
@@ -45,11 +45,11 QVector<QRectF> StackedBarChartItem::calculateLayout()
45 qreal categotyCount = m_series->categoryCount();
45 qreal categotyCount = m_series->categoryCount();
46 qreal barWidth = width / (categotyCount * 2);
46 qreal barWidth = width / (categotyCount * 2);
47 qreal xStep = width / categotyCount;
47 qreal xStep = width / categotyCount;
48 qreal xPos = xStep / 2 - barWidth / 2;
48 qreal xPos = xStep / 2 - barWidth / 2 + geometry().topLeft().x();
49
49
50 int itemIndex(0);
50 int itemIndex(0);
51 for (int category = 0; category < categotyCount; category++) {
51 for (int category = 0; category < categotyCount; category++) {
52 qreal yPos = height + scale * m_domainMinY;
52 qreal yPos = height + scale * m_domainMinY + geometry().topLeft().y();
53 for (int set=0; set < m_series->barsetCount(); set++) {
53 for (int set=0; set < m_series->barsetCount(); set++) {
54 QBarSet* barSet = m_series->d_func()->barsetAt(set);
54 QBarSet* barSet = m_series->d_func()->barsetAt(set);
55
55
General Comments 0
You need to be logged in to leave comments. Login now