stackedbarchartitem.cpp
101 lines
| 2.9 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) : | ||
BarChartItem(series,presenter) | ||||
|
r96 | { | ||
} | ||||
|
r666 | StackedBarChartItem::~StackedBarChartItem() | ||
|
r438 | { | ||
} | ||||
|
r666 | void StackedBarChartItem::layoutChanged() | ||
|
r96 | { | ||
// Scale bars to new layout | ||||
// Layout for bars: | ||||
|
r366 | if (mSeries->barsetCount() <= 0) { | ||
|
r173 | qDebug() << "No sets in model!"; | ||
|
r96 | // Nothing to do. | ||
return; | ||||
} | ||||
|
r366 | if (mSeries->categoryCount() == 0) { | ||
|
r173 | qDebug() << "No categories in model!"; | ||
|
r119 | // Nothing to do | ||
return; | ||||
} | ||||
|
r165 | if (childItems().count() == 0) { | ||
|
r666 | qDebug() << "WARNING: StackedBarChartItem::layoutChanged called before graphics items are created!"; | ||
|
r165 | return; | ||
} | ||||
|
r473 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | ||
|
r679 | |||
|
r288 | qreal maxSum = mSeries->maxCategorySum(); | ||
|
r674 | // Domain: | ||
if (mDomainMaxY > maxSum) { | ||||
maxSum = mDomainMaxY; | ||||
} | ||||
|
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; | ||||
|
r98 | |||
|
r473 | int itemIndex(0); | ||
|
r679 | for (int category = 0; category < categotyCount; category++) { | ||
qreal yPos = height; | ||||
|
r366 | for (int set=0; set < mSeries->barsetCount(); set++) { | ||
|
r288 | qreal barHeight = mSeries->valueAt(set, category) * scale; | ||
|
r256 | Bar* bar = mBars.at(itemIndex); | ||
|
r661 | bar->setPen(mSeries->barsetAt(set)->pen()); | ||
|
r357 | bar->setBrush(mSeries->barsetAt(set)->brush()); | ||
|
r679 | bar->setRect(xPos, yPos-barHeight,barWidth, barHeight); | ||
|
r96 | itemIndex++; | ||
|
r97 | yPos -= barHeight; | ||
|
r96 | } | ||
|
r98 | xPos += xStep; | ||
|
r96 | } | ||
|
r654 | |||
|
r263 | // Position floating values | ||
itemIndex = 0; | ||||
|
r679 | xPos = (width/categotyCount); | ||
|
r366 | for (int category=0; category < mSeries->categoryCount(); category++) { | ||
|
r679 | qreal yPos = height; | ||
|
r366 | for (int set=0; set < mSeries->barsetCount(); set++) { | ||
|
r288 | qreal barHeight = mSeries->valueAt(set,category) * scale; | ||
|
r263 | BarValue* value = mFloatingValues.at(itemIndex); | ||
|
r512 | QBarSet* barSet = mSeries->barsetAt(set); | ||
value->resize(100,50); // TODO: proper layout for this. | ||||
|
r276 | value->setPos(xPos, yPos-barHeight/2); | ||
|
r512 | value->setPen(barSet->floatingValuePen()); | ||
|
r263 | |||
|
r288 | if (mSeries->valueAt(set,category) != 0) { | ||
value->setValueString(QString::number(mSeries->valueAt(set,category))); | ||||
|
r276 | } else { | ||
value->setValueString(QString("")); | ||||
} | ||||
|
r263 | |||
itemIndex++; | ||||
yPos -= barHeight; | ||||
} | ||||
xPos += xStep; | ||||
|
r119 | } | ||
|
r96 | } | ||
|
r666 | #include "moc_stackedbarchartitem_p.cpp" | ||
|
r288 | |||
|
r96 | QTCOMMERCIALCHART_END_NAMESPACE | ||