##// END OF EJS Templates
Fixed issue with multiple QML charts...
Fixed issue with multiple QML charts If you had a QML chart with line series and another QML chart with some other series, the latter was not drawn.

File last commit:

r183:45734e367adb
r213:d6e1b3166f68
Show More
bargroup.cpp
73 lines | 2.2 KiB | text/x-c | CppLexer
#include "bargroup.h"
#include "bar_p.h"
#include "barlabel_p.h"
#include <QDebug>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
BarGroup::BarGroup(BarChartModel& model, QGraphicsItem *parent) :
BarGroupBase(model,parent)
{
mBarDefaultWidth = 5;
}
void BarGroup::layoutChanged()
{
// qDebug() << "BarGroup::layoutChanged";
// Scale bars to new layout
// Layout for bars:
if (mModel.countSets() <= 0) {
qDebug() << "No sets in model!";
return;
}
if (childItems().count() == 0) {
qDebug() << "WARNING: BarGroup::layoutChanged called before graphics items are created!";
return;
}
// TODO: better way to auto-layout?
// Use reals for accurancy (we might get some compiler warnings... :)
int itemCount = mModel.countCategories();
int setCount = mModel.countSets();
qreal tW = mWidth;
qreal tH = mHeight;
qreal tM = mModel.max();
qreal scale = (tH/tM);
qreal tC = itemCount+1;
qreal xStepPerSet = (tW/tC);
// Scaling.
int itemIndex(0);
int labelIndex = itemCount * setCount;
for (int item=0; item < itemCount; item++) {
qreal xPos = xStepPerSet * item + ((tW + mBarDefaultWidth*setCount)/(itemCount*2));
qreal yPos = mHeight;
for (int set = 0; set < setCount; set++) {
qreal barHeight = mModel.valueAt(set, item) * scale;
Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
// TODO: width settable per bar?
bar->resize(mBarDefaultWidth, barHeight);
bar->setBrush(mBrushes.at(set));
// bar->setPen(mModel.barSet(set).pen());
// bar->setColor(mColors.at(set));
// bar->setPen();
bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + set * mBarDefaultWidth, mHeight);
itemIndex++;
xPos += mBarDefaultWidth;
}
// TODO: Layout for labels, remove magic number
xPos = xStepPerSet * item + ((tW + mBarDefaultWidth*setCount)/(itemCount*2));
BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex));
label->setPos(xPos, mHeight + 20);
labelIndex++;
}
mLayoutDirty = true;
}
QTCOMMERCIALCHART_END_NAMESPACE