stackedbarchartitem.cpp
83 lines
| 2.6 KiB
| text/x-c
|
CppLexer
sauimone
|
r666 | #include "stackedbarchartitem_p.h" | ||
sauimone
|
r118 | #include "bar_p.h" | ||
sauimone
|
r263 | #include "barvalue_p.h" | ||
sauimone
|
r214 | #include "qbarset.h" | ||
sauimone
|
r96 | #include <QDebug> | ||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Michal Klocek
|
r677 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | ||
Tero Ahola
|
r737 | BarChartItem(series, presenter) | ||
sauimone
|
r96 | { | ||
} | ||||
sauimone
|
r666 | StackedBarChartItem::~StackedBarChartItem() | ||
sauimone
|
r438 | { | ||
} | ||||
sauimone
|
r694 | QVector<QRectF> StackedBarChartItem::calculateLayout() | ||
sauimone
|
r96 | { | ||
sauimone
|
r694 | QVector<QRectF> layout; | ||
sauimone
|
r473 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | ||
Michal Klocek
|
r679 | |||
sauimone
|
r763 | qreal maxSum = m_series->maxCategorySum(); | ||
sauimone
|
r674 | // Domain: | ||
sauimone
|
r763 | if (m_domainMaxY > maxSum) { | ||
maxSum = m_domainMaxY; | ||||
sauimone
|
r674 | } | ||
Michal Klocek
|
r679 | qreal height = geometry().height(); | ||
qreal width = geometry().width(); | ||||
sauimone
|
r763 | qreal scale = (height / m_series->maxCategorySum()); | ||
qreal categotyCount = m_series->categoryCount(); | ||||
Tero Ahola
|
r737 | qreal barWidth = width / (categotyCount * 2); | ||
qreal xStep = width / categotyCount; | ||||
qreal xPos = xStep / 2 - barWidth / 2; | ||||
Michal Klocek
|
r679 | |||
sauimone
|
r473 | int itemIndex(0); | ||
Michal Klocek
|
r679 | for (int category = 0; category < categotyCount; category++) { | ||
qreal yPos = height; | ||||
sauimone
|
r763 | for (int set=0; set < m_series->barsetCount(); set++) { | ||
qreal barHeight = m_series->valueAt(set, category) * scale; | ||||
Bar* bar = m_bars.at(itemIndex); | ||||
bar->setPen(m_series->barsetAt(set)->pen()); | ||||
bar->setBrush(m_series->barsetAt(set)->brush()); | ||||
Tero Ahola
|
r737 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | ||
sauimone
|
r694 | layout.append(rect); | ||
sauimone
|
r96 | itemIndex++; | ||
sauimone
|
r97 | yPos -= barHeight; | ||
sauimone
|
r96 | } | ||
sauimone
|
r98 | xPos += xStep; | ||
sauimone
|
r96 | } | ||
sauimone
|
r654 | |||
sauimone
|
r263 | // Position floating values | ||
itemIndex = 0; | ||||
Michal Klocek
|
r679 | xPos = (width/categotyCount); | ||
sauimone
|
r763 | for (int category=0; category < m_series->categoryCount(); category++) { | ||
Michal Klocek
|
r679 | qreal yPos = height; | ||
sauimone
|
r763 | for (int set=0; set < m_series->barsetCount(); set++) { | ||
qreal barHeight = m_series->valueAt(set, category) * scale; | ||||
BarValue* value = m_floatingValues.at(itemIndex); | ||||
sauimone
|
r263 | |||
sauimone
|
r763 | QBarSet* barSet = m_series->barsetAt(set); | ||
Tero Ahola
|
r737 | value->resize(100, 50); // TODO: proper layout for this. | ||
value->setPos(xPos, yPos-barHeight / 2); | ||||
sauimone
|
r512 | value->setPen(barSet->floatingValuePen()); | ||
sauimone
|
r263 | |||
sauimone
|
r763 | if (m_series->valueAt(set, category) != 0) { | ||
value->setValueString(QString::number(m_series->valueAt(set,category))); | ||||
sauimone
|
r276 | } else { | ||
value->setValueString(QString("")); | ||||
} | ||||
sauimone
|
r263 | |||
itemIndex++; | ||||
yPos -= barHeight; | ||||
} | ||||
xPos += xStep; | ||||
sauimone
|
r119 | } | ||
sauimone
|
r694 | return layout; | ||
sauimone
|
r96 | } | ||
sauimone
|
r666 | #include "moc_stackedbarchartitem_p.cpp" | ||
sauimone
|
r288 | |||
sauimone
|
r96 | QTCOMMERCIALCHART_END_NAMESPACE | ||