##// 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
bargroupbase.cpp
137 lines | 3.3 KiB | text/x-c | CppLexer
#include "bargroupbase.h"
#include "bar_p.h"
#include "barlabel_p.h"
#include "separator_p.h"
#include <QDebug>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
BarGroupBase::BarGroupBase(BarChartModel& model, QGraphicsItem *parent)
: ChartItem(parent)
,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
,mLayoutSet(false)
,mLayoutDirty(true)
,mSeparatorsVisible(true)
,mModel(model)
{
dataChanged();
}
void BarGroupBase::setSeparatorsVisible(bool visible)
{
mSeparatorsVisible = visible;
}
void BarGroupBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// qDebug() << "BarGroupBase::paint" << childItems().count();
if (!mLayoutSet) {
qDebug() << "BarGroupBase::paint called without layout set. Aborting.";
return;
}
// if (mLayoutDirty) {
// Layout or data has changed. Need to redraw.
foreach(QGraphicsItem* i, childItems()) {
i->paint(painter,option,widget);
}
// }
}
QRectF BarGroupBase::boundingRect() const
{
return QRectF(0,0,mWidth,mHeight);
}
void BarGroupBase::setBarWidth( int w )
{
mBarDefaultWidth = w;
}
/*
int BarGroupBase::addColor( QColor color )
{
// qDebug() << "BarGroupBase::addColor";
int colorIndex = mColors.count();
mColors.append(color);
return colorIndex;
}
*/
/*
void BarGroupBase::resetColors()
{
// qDebug() << "BarGroupBase::resetColors";
mColors.clear();
}
*/
void BarGroupBase::resetBrushes()
{
mBrushes.clear();
}
void BarGroupBase::addBrush(QBrush brush)
{
mBrushes.append(brush);
}
void BarGroupBase::dataChanged()
{
// TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them?
// Delete old bars
foreach (QGraphicsItem* item, childItems()) {
delete item;
}
// Create new graphic items for bars
int totalItems = mModel.countTotalItems();
for (int i=0; i<totalItems; i++) {
Bar *bar = new Bar(this);
childItems().append(bar);
}
int count = mModel.countCategories();
for (int i=0; i<count; i++) {
BarLabel* label = new BarLabel(this);
label->set(mModel.label(i));
childItems().append(label);
}
count = mModel.countCategories() - 1; // There is one less separator than columns
for (int i=0; i<count; i++) {
Separator* sep = new Separator(this);
sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme
childItems().append(sep);
}
// TODO: if (autolayout) { layoutChanged() } or something
mLayoutDirty = true;
}
//handlers
void BarGroupBase::handleModelChanged(int index)
{
// qDebug() << "BarGroupBase::handleModelChanged" << index;
dataChanged();
}
void BarGroupBase::handleDomainChanged(const Domain& domain)
{
// qDebug() << "BarGroupBase::handleDomainChanged";
// TODO: Figure out the use case for this.
// Affects the size of visible item, so layout is changed.
// layoutChanged();
}
void BarGroupBase::handleGeometryChanged(const QRectF& rect)
{
mWidth = rect.width();
mHeight = rect.height();
layoutChanged();
mLayoutSet = true;
setPos(rect.topLeft());
}
#include "moc_bargroupbase.cpp"
QTCOMMERCIALCHART_END_NAMESPACE