##// END OF EJS Templates
barchart mvp model integrating
barchart mvp model integrating

File last commit:

r159:e1dfbbf1ecba
r160:f044c4ee95db
Show More
bargroupbase.cpp
133 lines | 3.2 KiB | text/x-c | CppLexer
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 #include "bargroupbase.h"
#include "bar_p.h"
#include "barlabel_p.h"
#include "separator_p.h"
#include "barchartseriesbase.h"
#include <QDebug>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
BarGroupBase::BarGroupBase(BarChartSeriesBase& series, QGraphicsItem *parent)
: ChartItem(parent)
sauimone
model prototyping for bar chart
r159 // ,mSeries(series)
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
,mLayoutSet(false)
,mLayoutDirty(true)
,mTheme(0)
,mSeparatorsVisible(true)
{
sauimone
model prototyping for bar chart
r159 mModel.addSeries(series);
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 dataChanged();
}
void BarGroupBase::setSeparatorsVisible(bool visible)
{
mSeparatorsVisible = visible;
}
void BarGroupBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
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::themeChanged(ChartTheme *theme)
{
mTheme = theme;
}
void BarGroupBase::setBarWidth( int w )
{
mBarDefaultWidth = w;
}
int BarGroupBase::addColor( QColor color )
{
int colorIndex = mColors.count();
mColors.append(color);
return colorIndex;
}
void BarGroupBase::resetColors()
{
mColors.clear();
}
void BarGroupBase::dataChanged()
{
qDebug() << "BarGroupBase::dataChanged";
sauimone
model prototyping for bar chart
r159 // Find out maximum and minimum of all series.
// TODO: is this actually needed?
// mMax = mModel.max();
// mMin = mModel.min();
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126
// Delete old bars
foreach (QGraphicsItem* item, childItems()) {
delete item;
}
// Create new graphic items for bars
sauimone
model prototyping for bar chart
r159 int totalItems = mModel.countTotalItems(); // mSeries.countTotalItems();
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 for (int i=0; i<totalItems; i++) {
Bar *bar = new Bar(this);
childItems().append(bar);
}
// TODO: labels from series. This creates just some example labels
sauimone
model prototyping for bar chart
r159 int count = mModel.countItemsInSeries(); // mSeries.countColumns();
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 for (int i=0; i<count; i++) {
BarLabel* label = new BarLabel(this);
QString text("Label " + QString::number(i));
label->set(text);
childItems().append(label);
}
sauimone
model prototyping for bar chart
r159 count = mModel.countItemsInSeries() - 1; // mSeries.countColumns() - 1; // There is one less separator than columns
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 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;
}
Michal Klocek
Refactored for MVP...
r139 //handlers
void BarGroupBase::handleModelChanged(int index)
{
qDebug() << "BarGroupBase::handleModelChanged";
}
void BarGroupBase::handleDomainChanged(const Domain& domain)
{
qDebug() << "BarGroupBase::handleModelChanged";
}
void BarGroupBase::handleGeometryChanged(const QRectF& rect)
{
mWidth = rect.width();
mHeight = rect.height();
layoutChanged();
mLayoutSet = true;
setPos(rect.topLeft());
}
#include "moc_bargroupbase.cpp"
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 QTCOMMERCIALCHART_END_NAMESPACE