##// END OF EJS Templates
added labels to series, intergrated with test app. minor hack to test app
added labels to series, intergrated with test app. minor hack to test app

File last commit:

r149:23a271e217e1
r167:023d2c8150a8
Show More
bar.cpp
62 lines | 1.2 KiB | text/x-c | CppLexer
#include "bar_p.h"
#include <QDebug>
#include <QPainter>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Bar::Bar(QGraphicsItem *parent)
: ChartItem(parent)
{
}
void Bar::setSize(const QSizeF& size)
{
mWidth = size.width();
mHeight = size.height();
}
void Bar::resize( qreal w, qreal h )
{
// qDebug() << "bar::resize" << w << h;
mWidth = w;
mHeight = h;
}
void Bar::setColor( QColor col )
{
mColor = col;
}
void Bar::setPos(qreal x, qreal y)
{
// qDebug() << "Bar::setpos" << x << y;
mXpos = x;
mYpos = y;
}
void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
if (0 == mHeight) {
return;
}
// TODO: accept brush instead of color
QBrush brush(mColor);
painter->setBrush(brush);
// This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1.
int x0 = mXpos;
int x1 = (mXpos + mWidth);
int w = x1-x0;
int y0 = mYpos;
int y1 = (mYpos + mHeight);
int h = y1-y0;
painter->drawRect(x0, y0 ,w ,h);
}
QRectF Bar::boundingRect() const
{
QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight);
return r;
}
QTCOMMERCIALCHART_END_NAMESPACE