##// END OF EJS Templates
First version of legend. Simple markers and serie names. Using drilldown as example for now.
First version of legend. Simple markers and serie names. Using drilldown as example for now.

File last commit:

r439:86afa1b4ff5f
r529:73dc1554f5c7
Show More
areachartitem.cpp
112 lines | 2.4 KiB | text/x-c | CppLexer
Michal Klocek
Adds area chart...
r421 #include "areachartitem_p.h"
#include "qareaseries.h"
#include "qlineseries.h"
#include <QPainter>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
//TODO: optimize : remove points which are not visible
Michal Klocek
Refactor domain model...
r439 AreaChartItem::AreaChartItem(QAreaSeries* areaSeries,QGraphicsItem *parent):ChartItem(parent),
Michal Klocek
Adds area chart...
r421 m_series(areaSeries),
m_upper(0),
m_lower(0)
{
//m_items.setZValue(ChartPresenter::LineChartZValue);
Michal Klocek
Refactor domain model...
r439 m_upper = new AreaBoundItem(this,m_series->upperSeries());
Michal Klocek
Adds area chart...
r421 if(m_series->lowerSeries()){
Michal Klocek
Refactor domain model...
r439 m_lower = new AreaBoundItem(this,m_series->lowerSeries());
Michal Klocek
Adds area chart...
r421 }
QObject::connect(areaSeries,SIGNAL(updated()),this,SLOT(handleUpdated()));
handleUpdated();
}
AreaChartItem::~AreaChartItem()
{
delete m_upper;
delete m_lower;
};
QRectF AreaChartItem::boundingRect() const
{
return m_rect;
}
QPainterPath AreaChartItem::shape() const
{
return m_path;
}
void AreaChartItem::setPen(const QPen& pen)
{
m_pen = pen;
}
void AreaChartItem::setBrush(const QBrush& brush)
{
m_brush = brush;
}
void AreaChartItem::updatePath()
{
QPainterPath path;
path.connectPath(m_upper->shape());
if(m_lower){
path.connectPath(m_lower->shape().toReversed());
}
else{
QPointF first = path.pointAtPercent(0);
QPointF last = path.pointAtPercent(1);
path.lineTo(last.x(),m_clipRect.bottom());
path.lineTo(first.x(),m_clipRect.bottom());
}
path.closeSubpath();
prepareGeometryChange();
m_path=path;
m_rect=path.boundingRect();
update();
}
void AreaChartItem::handleUpdated()
{
setPen(m_series->pen());
setBrush(m_series->brush());
update();
}
Michal Klocek
Refactor domain model...
r439 void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
Michal Klocek
Adds area chart...
r421 {
Michal Klocek
Refactor domain model...
r439 m_upper->handleDomainChanged(minX,maxX,minY,maxY);
Michal Klocek
Adds area chart...
r421 if(m_lower)
Michal Klocek
Refactor domain model...
r439 m_lower->handleDomainChanged(minX,maxX,minY,maxY);
Michal Klocek
Adds area chart...
r421 }
void AreaChartItem::handleGeometryChanged(const QRectF& rect)
{
m_clipRect=rect.translated(-rect.topLeft());
setPos(rect.topLeft());
m_upper->handleGeometryChanged(rect);
if(m_lower)
m_lower->handleGeometryChanged(rect);
}
//painter
void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
Q_UNUSED(option);
painter->save();
painter->setPen(m_pen);
painter->setBrush(m_brush);
painter->setClipRect(m_clipRect);
painter->drawPath(m_path);
painter->restore();
}
#include "moc_areachartitem_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE