areachartitem.cpp
121 lines
| 3.0 KiB
| text/x-c
|
CppLexer
Michal Klocek
|
r421 | #include "areachartitem_p.h" | ||
#include "qareaseries.h" | ||||
#include "qlineseries.h" | ||||
Michal Klocek
|
r564 | #include "chartpresenter_p.h" | ||
Michal Klocek
|
r421 | #include <QPainter> | ||
Michal Klocek
|
r571 | #include <QGraphicsSceneMouseEvent> | ||
Michal Klocek
|
r421 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
//TODO: optimize : remove points which are not visible | ||||
Tero Ahola
|
r761 | AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, ChartPresenter *presenter) | ||
: ChartItem(presenter), | ||||
sauimone
|
r743 | m_series(areaSeries), | ||
m_upper(0), | ||||
m_lower(0), | ||||
m_pointsVisible(false) | ||||
Michal Klocek
|
r421 | { | ||
Michal Klocek
|
r564 | setZValue(ChartPresenter::LineChartZValue); | ||
Michal Klocek
|
r690 | m_upper = new AreaBoundItem(this,m_series->upperSeries()); | ||
Tero Ahola
|
r761 | if (m_series->lowerSeries()) | ||
sauimone
|
r743 | m_lower = new AreaBoundItem(this,m_series->lowerSeries()); | ||
Michal Klocek
|
r421 | |||
sauimone
|
r743 | connect(areaSeries,SIGNAL(updated()),this,SLOT(handleUpdated())); | ||
connect(this,SIGNAL(clicked(const QPointF&)),areaSeries,SIGNAL(clicked(const QPointF&))); | ||||
Michal Klocek
|
r421 | |||
handleUpdated(); | ||||
} | ||||
AreaChartItem::~AreaChartItem() | ||||
{ | ||||
delete m_upper; | ||||
delete m_lower; | ||||
Tero Ahola
|
r761 | } | ||
Michal Klocek
|
r421 | |||
QRectF AreaChartItem::boundingRect() const | ||||
{ | ||||
return m_rect; | ||||
} | ||||
QPainterPath AreaChartItem::shape() const | ||||
{ | ||||
return m_path; | ||||
} | ||||
void AreaChartItem::updatePath() | ||||
{ | ||||
QPainterPath path; | ||||
Michal Klocek
|
r690 | path = m_upper->shape(); | ||
sauimone
|
r743 | if (m_lower) { | ||
path.connectPath(m_lower->shape().toReversed()); | ||||
} else { | ||||
Michal Klocek
|
r421 | 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(); | ||||
Tero Ahola
|
r761 | m_path = path; | ||
m_rect = path.boundingRect(); | ||||
Michal Klocek
|
r421 | update(); | ||
} | ||||
void AreaChartItem::handleUpdated() | ||||
{ | ||||
Michal Klocek
|
r563 | m_pointsVisible = m_series->pointsVisible(); | ||
m_linePen = m_series->pen(); | ||||
Michal Klocek
|
r557 | m_brush = m_series->brush(); | ||
Michal Klocek
|
r563 | m_pointPen = m_series->pen(); | ||
Tero Ahola
|
r761 | m_pointPen.setWidthF(2 * m_pointPen.width()); | ||
Michal Klocek
|
r563 | |||
Michal Klocek
|
r421 | update(); | ||
} | ||||
Michal Klocek
|
r439 | void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | ||
Michal Klocek
|
r421 | { | ||
Michal Klocek
|
r439 | m_upper->handleDomainChanged(minX,maxX,minY,maxY); | ||
sauimone
|
r743 | if (m_lower) | ||
m_lower->handleDomainChanged(minX,maxX,minY,maxY); | ||||
Michal Klocek
|
r421 | } | ||
sauimone
|
r743 | void AreaChartItem::handleGeometryChanged(const QRectF &rect) | ||
Michal Klocek
|
r421 | { | ||
m_clipRect=rect.translated(-rect.topLeft()); | ||||
setPos(rect.topLeft()); | ||||
m_upper->handleGeometryChanged(rect); | ||||
sauimone
|
r743 | if (m_lower) | ||
m_lower->handleGeometryChanged(rect); | ||||
Michal Klocek
|
r421 | } | ||
void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||||
{ | ||||
Tero Ahola
|
r611 | Q_UNUSED(widget) | ||
Q_UNUSED(option) | ||||
Michal Klocek
|
r421 | painter->save(); | ||
Michal Klocek
|
r690 | painter->setPen(m_linePen); | ||
painter->setBrush(m_brush); | ||||
Michal Klocek
|
r421 | painter->setClipRect(m_clipRect); | ||
painter->drawPath(m_path); | ||||
sauimone
|
r743 | if (m_pointsVisible) { | ||
Michal Klocek
|
r563 | painter->setPen(m_pointPen); | ||
painter->drawPoints(m_upper->points()); | ||||
sauimone
|
r743 | if (m_lower) | ||
painter->drawPoints(m_lower->points()); | ||||
Michal Klocek
|
r563 | } | ||
Michal Klocek
|
r421 | painter->restore(); | ||
} | ||||
sauimone
|
r743 | void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | ||
Michal Klocek
|
r571 | { | ||
emit clicked(m_upper->calculateDomainPoint(event->pos())); | ||||
} | ||||
Michal Klocek
|
r421 | #include "moc_areachartitem_p.cpp" | ||
QTCOMMERCIALCHART_END_NAMESPACE | ||||