##// END OF EJS Templates
updated barchart examples
updated barchart examples

File last commit:

r167:023d2c8150a8
r170:ff886517a70e
Show More
bargroupbase.cpp
131 lines | 3.4 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)
,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
,mLayoutSet(false)
,mLayoutDirty(true)
,mSeparatorsVisible(true)
sauimone
model delegate for bar series. updated examples
r161 ,mModel(series.model())
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167 ,mSeries(series)
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 {
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167 dataChanged();
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 }
void BarGroupBase::setSeparatorsVisible(bool visible)
{
mSeparatorsVisible = visible;
}
void BarGroupBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarGroupBase::paint" << childItems().count();
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 if (!mLayoutSet) {
qDebug() << "BarGroupBase::paint called without layout set. Aborting.";
return;
}
sauimone
model delegate for bar series. updated examples
r161 // if (mLayoutDirty) {
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 // Layout or data has changed. Need to redraw.
foreach(QGraphicsItem* i, childItems()) {
i->paint(painter,option,widget);
}
sauimone
model delegate for bar series. updated examples
r161 // }
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 }
QRectF BarGroupBase::boundingRect() const
{
return QRectF(0,0,mWidth,mHeight);
}
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 void BarGroupBase::setBarWidth( int w )
{
mBarDefaultWidth = w;
}
int BarGroupBase::addColor( QColor color )
{
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarGroupBase::addColor";
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 int colorIndex = mColors.count();
mColors.append(color);
return colorIndex;
}
void BarGroupBase::resetColors()
{
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarGroupBase::resetColors";
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 mColors.clear();
}
void BarGroupBase::dataChanged()
{
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarGroupBase::dataChanged";
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 delegate for bar series. updated examples
r161 int count = mModel.countColumns(); // 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);
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167 // QString text("Label " + QString::number(i));
label->set(mSeries.label(i));
sauimone
refactored barcharts. layout to derived classess other funtionality to base class
r126 childItems().append(label);
}
sauimone
model delegate for bar series. updated examples
r161 count = mModel.countColumns() - 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)
{
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167 qDebug() << "BarGroupBase::handleModelChanged" << index;
sauimone
model delegate for bar series. updated examples
r161 dataChanged();
Michal Klocek
Refactored for MVP...
r139 }
void BarGroupBase::handleDomainChanged(const Domain& domain)
{
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarGroupBase::handleDomainChanged";
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167
// TODO: Figure out the use case for this.
// Affects the size of visible item, so layout is changed.
// layoutChanged();
Michal Klocek
Refactored for MVP...
r139 }
void BarGroupBase::handleGeometryChanged(const QRectF& rect)
{
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165 // qDebug() << "BarGroupBase::handleGeometryChanged";
Michal Klocek
Refactored for MVP...
r139 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