barpresenter.cpp
96 lines
| 3.0 KiB
| text/x-c
|
CppLexer
sauimone
|
r381 | #include "barpresenter_p.h" | ||
sauimone
|
r118 | #include "bar_p.h" | ||
sauimone
|
r263 | #include "barvalue_p.h" | ||
sauimone
|
r505 | #include "separator_p.h" | ||
sauimone
|
r214 | #include "qbarset.h" | ||
sauimone
|
r56 | #include <QDebug> | ||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
sauimone
|
r487 | BarPresenter::BarPresenter(QBarSeries *series, QChart *parent) : | ||
sauimone
|
r288 | BarPresenterBase(series, parent) | ||
sauimone
|
r56 | { | ||
} | ||||
sauimone
|
r216 | void BarPresenter::layoutChanged() | ||
sauimone
|
r56 | { | ||
// Scale bars to new layout | ||||
// Layout for bars: | ||||
sauimone
|
r366 | if (mSeries->barsetCount() <= 0) { | ||
sauimone
|
r173 | qDebug() << "No sets in model!"; | ||
sauimone
|
r159 | return; | ||
} | ||||
sauimone
|
r56 | |||
sauimone
|
r165 | if (childItems().count() == 0) { | ||
sauimone
|
r256 | qDebug() << "WARNING: BarPresenter::layoutChanged called before graphics items are created!"; | ||
sauimone
|
r165 | return; | ||
} | ||||
sauimone
|
r473 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | ||
sauimone
|
r366 | int categoryCount = mSeries->categoryCount(); | ||
int setCount = mSeries->barsetCount(); | ||||
sauimone
|
r56 | |||
sauimone
|
r99 | qreal tW = mWidth; | ||
qreal tH = mHeight; | ||||
sauimone
|
r288 | qreal tM = mSeries->max(); | ||
sauimone
|
r99 | qreal scale = (tH/tM); | ||
sauimone
|
r473 | qreal tC = categoryCount + 1; | ||
sauimone
|
r505 | qreal categoryWidth = tW/tC; | ||
mBarWidth = categoryWidth / (setCount+1); | ||||
sauimone
|
r99 | |||
sauimone
|
r71 | int itemIndex(0); | ||
sauimone
|
r263 | for (int category=0; category < categoryCount; category++) { | ||
sauimone
|
r570 | qreal xPos = categoryWidth * category + categoryWidth /2 + mBarWidth/2; | ||
sauimone
|
r113 | qreal yPos = mHeight; | ||
sauimone
|
r183 | for (int set = 0; set < setCount; set++) { | ||
sauimone
|
r288 | qreal barHeight = mSeries->valueAt(set,category) * scale; | ||
sauimone
|
r256 | Bar* bar = mBars.at(itemIndex); | ||
sauimone
|
r99 | |||
// TODO: width settable per bar? | ||||
sauimone
|
r473 | bar->resize(mBarWidth, barHeight); | ||
sauimone
|
r357 | bar->setBrush(mSeries->barsetAt(set)->brush()); | ||
sauimone
|
r288 | bar->setPos(xPos, yPos-barHeight); | ||
sauimone
|
r99 | itemIndex++; | ||
sauimone
|
r473 | xPos += mBarWidth; | ||
sauimone
|
r99 | } | ||
} | ||||
sauimone
|
r592 | /* | ||
sauimone
|
r505 | // Position separators | ||
sauimone
|
r570 | qreal xPos = categoryWidth + categoryWidth/2; | ||
sauimone
|
r505 | for (int s=0; s < mSeparators.count(); s++) { | ||
Separator* sep = mSeparators.at(s); | ||||
sep->setPos(xPos,0); | ||||
sep->setSize(QSizeF(1,mHeight)); | ||||
sauimone
|
r512 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme | ||
sauimone
|
r505 | xPos += categoryWidth; | ||
} | ||||
sauimone
|
r592 | */ | ||
sauimone
|
r263 | // Position floating values | ||
itemIndex = 0; | ||||
sauimone
|
r366 | for (int category=0; category < mSeries->categoryCount(); category++) { | ||
sauimone
|
r570 | qreal xPos = categoryWidth * category + categoryWidth/2 + mBarWidth; | ||
sauimone
|
r263 | qreal yPos = mHeight; | ||
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++; | ||||
sauimone
|
r473 | xPos += mBarWidth; | ||
sauimone
|
r263 | } | ||
} | ||||
sauimone
|
r56 | } | ||
sauimone
|
r381 | #include "moc_barpresenter_p.cpp" | ||
sauimone
|
r288 | |||
sauimone
|
r56 | QTCOMMERCIALCHART_END_NAMESPACE | ||