##// END OF EJS Templates
Colors of the light theme
Colors of the light theme

File last commit:

r571:0bb609016fcc
r607:32d18e1badc3
Show More
areachartitem.cpp
120 lines | 2.9 KiB | text/x-c | CppLexer
Michal Klocek
Adds area chart...
r421 #include "areachartitem_p.h"
#include "qareaseries.h"
#include "qlineseries.h"
Michal Klocek
Fixes missing chart area z value intialization
r564 #include "chartpresenter_p.h"
Michal Klocek
Adds area chart...
r421 #include <QPainter>
Michal Klocek
Refactors click signal to line,area,spline,scatter charts
r571 #include <QGraphicsSceneMouseEvent>
Michal Klocek
Adds area chart...
r421
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),
Michal Klocek
Adds visiblePoints handling to area chart
r563 m_lower(0),
m_pointsVisible(false)
Michal Klocek
Adds area chart...
r421 {
Michal Klocek
Fixes missing chart area z value intialization
r564 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()));
Michal Klocek
Refactors click signal to line,area,spline,scatter charts
r571 QObject::connect(this,SIGNAL(clicked(const QPointF&)),areaSeries,SIGNAL(clicked(const QPointF&)));
Michal Klocek
Adds area chart...
r421
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::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()
{
Michal Klocek
Adds visiblePoints handling to area chart
r563 m_pointsVisible = m_series->pointsVisible();
m_linePen = m_series->pen();
Michal Klocek
Unify naming setGeometry -> setLayout
r557 m_brush = m_series->brush();
Michal Klocek
Adds visiblePoints handling to area chart
r563 m_pointPen = m_series->pen();
m_pointPen.setWidthF(2*m_pointPen.width());
Michal Klocek
Adds area chart...
r421 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();
Michal Klocek
Adds visiblePoints handling to area chart
r563 painter->setPen(m_linePen);
Michal Klocek
Adds area chart...
r421 painter->setBrush(m_brush);
painter->setClipRect(m_clipRect);
painter->drawPath(m_path);
Michal Klocek
Adds visiblePoints handling to area chart
r563 if(m_pointsVisible){
painter->setPen(m_pointPen);
painter->drawPoints(m_upper->points());
if(m_lower) painter->drawPoints(m_lower->points());
}
Michal Klocek
Adds area chart...
r421 painter->restore();
}
Michal Klocek
Refactors click signal to line,area,spline,scatter charts
r571 void AreaChartItem::mousePressEvent( QGraphicsSceneMouseEvent * event )
{
emit clicked(m_upper->calculateDomainPoint(event->pos()));
}
Michal Klocek
Adds area chart...
r421 #include "moc_areachartitem_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE