stackedbarchartitem.cpp
84 lines
| 2.5 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) : | ||
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
|
r288 | qreal maxSum = mSeries->maxCategorySum(); | ||
sauimone
|
r674 | // Domain: | ||
if (mDomainMaxY > maxSum) { | ||||
maxSum = mDomainMaxY; | ||||
} | ||||
Michal Klocek
|
r679 | qreal height = geometry().height(); | ||
qreal width = geometry().width(); | ||||
qreal scale = (height / mSeries->maxCategorySum()); | ||||
qreal categotyCount = mSeries->categoryCount(); | ||||
qreal barWidth = width / (categotyCount *2); | ||||
qreal xStep = width/categotyCount; | ||||
qreal xPos = xStep/2 - barWidth/2; | ||||
sauimone
|
r473 | int itemIndex(0); | ||
Michal Klocek
|
r679 | for (int category = 0; category < categotyCount; category++) { | ||
qreal yPos = height; | ||||
sauimone
|
r366 | for (int set=0; set < mSeries->barsetCount(); set++) { | ||
sauimone
|
r288 | qreal barHeight = mSeries->valueAt(set, category) * scale; | ||
sauimone
|
r256 | Bar* bar = mBars.at(itemIndex); | ||
Tero Ahola
|
r661 | bar->setPen(mSeries->barsetAt(set)->pen()); | ||
sauimone
|
r357 | bar->setBrush(mSeries->barsetAt(set)->brush()); | ||
sauimone
|
r694 | QRectF rect(xPos,yPos-barHeight,barWidth,barHeight); | ||
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
|
r366 | for (int category=0; category < mSeries->categoryCount(); category++) { | ||
Michal Klocek
|
r679 | qreal yPos = height; | ||
sauimone
|
r366 | for (int set=0; set < mSeries->barsetCount(); set++) { | ||
sauimone
|
r288 | qreal barHeight = mSeries->valueAt(set,category) * scale; | ||
sauimone
|
r263 | BarValue* value = mFloatingValues.at(itemIndex); | ||
sauimone
|
r512 | QBarSet* barSet = mSeries->barsetAt(set); | ||
value->resize(100,50); // TODO: proper layout for this. | ||||
sauimone
|
r276 | value->setPos(xPos, yPos-barHeight/2); | ||
sauimone
|
r512 | value->setPen(barSet->floatingValuePen()); | ||
sauimone
|
r263 | |||
sauimone
|
r288 | if (mSeries->valueAt(set,category) != 0) { | ||
value->setValueString(QString::number(mSeries->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 | ||