#include "barpresenterbase.h" #include "bar_p.h" #include "barvalue_p.h" #include "barlabel_p.h" #include "separator_p.h" #include "qbarset.h" #include QTCOMMERCIALCHART_BEGIN_NAMESPACE BarPresenterBase::BarPresenterBase(BarChartModel& model, QGraphicsItem *parent) : ChartItem(parent) ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready ,mLayoutSet(false) ,mLayoutDirty(true) ,mSeparatorsVisible(false) ,mModel(model) { dataChanged(); } void BarPresenterBase::setSeparatorsVisible(bool visible) { mSeparatorsVisible = visible; } void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { if (!mLayoutSet) { qDebug() << "BarPresenterBase::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 BarPresenterBase::boundingRect() const { return QRectF(0,0,mWidth,mHeight); } void BarPresenterBase::setBarWidth( int w ) { mBarDefaultWidth = w; } void BarPresenterBase::dataChanged() { // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? qDebug() << "datachanged"; // Delete old bars foreach (QGraphicsItem* item, childItems()) { delete item; } mBars.clear(); mLabels.clear(); mSeparators.clear(); mFloatingValues.clear(); // Create new graphic items for bars for (int s=0; sset(mModel.label(i)); childItems().append(label); mLabels.append(label); } // Create separators count = mModel.countCategories() - 1; // There is one less separator than columns for (int i=0; isetColor(QColor(255,0,0,255)); // TODO: color for separations from theme childItems().append(sep); mSeparators.append(sep); } // Create floating values for (int s=0; s