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