linechartitem.cpp
81 lines
| 1.7 KiB
| text/x-c
|
CppLexer
Michal Klocek
|
r144 | #include "linechartitem_p.h" | ||
Michal Klocek
|
r349 | #include "qlineseries.h" | ||
Michal Klocek
|
r131 | #include "chartpresenter_p.h" | ||
Michal Klocek
|
r21 | #include <QPainter> | ||
Michal Klocek
|
r144 | |||
Michal Klocek
|
r21 | |||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
Michal Klocek
|
r21 | |||
Michal Klocek
|
r391 | //TODO: optimize : remove points which are not visible | ||
Michal Klocek
|
r150 | |||
Michal Klocek
|
r465 | LineChartItem::LineChartItem(QLineSeries* series,QGraphicsItem *parent):XYChartItem(series,parent), | ||
Michal Klocek
|
r391 | m_series(series), | ||
Michal Klocek
|
r544 | m_pointsVisible(false) | ||
Michal Klocek
|
r21 | { | ||
Michal Klocek
|
r262 | setZValue(ChartPresenter::LineChartZValue); | ||
Michal Klocek
|
r421 | QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated())); | ||
Michal Klocek
|
r439 | handleUpdated(); | ||
Michal Klocek
|
r21 | } | ||
Michal Klocek
|
r144 | QRectF LineChartItem::boundingRect() const | ||
Tero Ahola
|
r103 | { | ||
Michal Klocek
|
r131 | return m_rect; | ||
Tero Ahola
|
r103 | } | ||
Michal Klocek
|
r85 | |||
Michal Klocek
|
r144 | QPainterPath LineChartItem::shape() const | ||
Michal Klocek
|
r67 | { | ||
Michal Klocek
|
r131 | return m_path; | ||
} | ||||
Michal Klocek
|
r85 | |||
Michal Klocek
|
r557 | void LineChartItem::setLayout(QVector<QPointF>& points) | ||
Michal Klocek
|
r131 | { | ||
Marek Rosa
|
r545 | if(points.size()==0) | ||
{ | ||||
Michal Klocek
|
r557 | XYChartItem::setLayout(points); | ||
Marek Rosa
|
r545 | return; | ||
} | ||||
Michal Klocek
|
r464 | |||
Michal Klocek
|
r465 | QList<QGraphicsItem*> items = m_items.childItems(); | ||
Michal Klocek
|
r464 | |||
Michal Klocek
|
r544 | QPainterPath linePath(points.at(0)); | ||
Michal Klocek
|
r464 | |||
Michal Klocek
|
r465 | for(int i=1; i< points.size();i++) { | ||
Michal Klocek
|
r544 | linePath.lineTo(points.at(i)); | ||
Michal Klocek
|
r465 | } | ||
Michal Klocek
|
r464 | |||
Michal Klocek
|
r465 | prepareGeometryChange(); | ||
Michal Klocek
|
r544 | m_path = linePath; | ||
m_rect = linePath.boundingRect(); | ||||
Michal Klocek
|
r131 | |||
Michal Klocek
|
r557 | XYChartItem::setLayout(points); | ||
Michal Klocek
|
r21 | } | ||
Michal Klocek
|
r392 | void LineChartItem::handleUpdated() | ||
Michal Klocek
|
r389 | { | ||
Michal Klocek
|
r544 | m_pointsVisible = m_series->pointsVisible(); | ||
m_linePen = m_series->pen(); | ||||
m_pointPen = m_series->pen(); | ||||
m_pointPen.setWidthF(2*m_pointPen.width()); | ||||
Michal Klocek
|
r139 | update(); | ||
} | ||||
Michal Klocek
|
r391 | //painter | ||
void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||||
{ | ||||
Q_UNUSED(widget); | ||||
Q_UNUSED(option); | ||||
painter->save(); | ||||
Michal Klocek
|
r544 | painter->setPen(m_linePen); | ||
Michal Klocek
|
r465 | painter->setClipRect(clipRect()); | ||
Michal Klocek
|
r391 | painter->drawPath(m_path); | ||
Michal Klocek
|
r544 | if(m_pointsVisible){ | ||
painter->setPen(m_pointPen); | ||||
painter->drawPoints(points()); | ||||
} | ||||
Michal Klocek
|
r391 | painter->restore(); | ||
} | ||||
Michal Klocek
|
r144 | #include "moc_linechartitem_p.cpp" | ||
Michal Klocek
|
r131 | |||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_END_NAMESPACE | ||