linechartitem.cpp
103 lines
| 2.5 KiB
| text/x-c
|
CppLexer
|
r794 | /**************************************************************************** | ||
** | ||||
** Copyright (C) 2012 Digia Plc | ||||
** All rights reserved. | ||||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
** This file is part of the Qt Commercial Charts Add-on. | ||||
** | ||||
** $QT_BEGIN_LICENSE$ | ||||
** Licensees holding valid Qt Commercial licenses may use this file in | ||||
** accordance with the Qt Commercial License Agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and Digia. | ||||
** | ||||
** If you have questions regarding the use of this file, please use | ||||
** contact form at http://qt.digia.com | ||||
** $QT_END_LICENSE$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r144 | #include "linechartitem_p.h" | ||
|
r349 | #include "qlineseries.h" | ||
|
r131 | #include "chartpresenter_p.h" | ||
|
r21 | #include <QPainter> | ||
|
r144 | |||
|
r21 | |||
|
r30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
|
r21 | |||
|
r391 | //TODO: optimize : remove points which are not visible | ||
|
r150 | |||
|
r677 | LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter):XYChartItem(series,presenter), | ||
|
r391 | m_series(series), | ||
|
r544 | m_pointsVisible(false) | ||
|
r21 | { | ||
|
r262 | setZValue(ChartPresenter::LineChartZValue); | ||
|
r421 | QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated())); | ||
|
r439 | handleUpdated(); | ||
|
r21 | } | ||
|
r144 | QRectF LineChartItem::boundingRect() const | ||
|
r103 | { | ||
|
r131 | return m_rect; | ||
|
r103 | } | ||
|
r85 | |||
|
r144 | QPainterPath LineChartItem::shape() const | ||
|
r67 | { | ||
|
r131 | return m_path; | ||
} | ||||
|
r85 | |||
|
r557 | void LineChartItem::setLayout(QVector<QPointF>& points) | ||
|
r131 | { | ||
|
r545 | if(points.size()==0) | ||
{ | ||||
|
r557 | XYChartItem::setLayout(points); | ||
|
r545 | return; | ||
} | ||||
|
r464 | |||
|
r465 | QList<QGraphicsItem*> items = m_items.childItems(); | ||
|
r464 | |||
|
r544 | QPainterPath linePath(points.at(0)); | ||
|
r464 | |||
|
r465 | for(int i=1; i< points.size();i++) { | ||
|
r544 | linePath.lineTo(points.at(i)); | ||
|
r465 | } | ||
|
r464 | |||
|
r465 | prepareGeometryChange(); | ||
|
r544 | m_path = linePath; | ||
m_rect = linePath.boundingRect(); | ||||
|
r131 | |||
|
r557 | XYChartItem::setLayout(points); | ||
|
r847 | |||
|
r21 | } | ||
|
r392 | void LineChartItem::handleUpdated() | ||
|
r389 | { | ||
|
r544 | m_pointsVisible = m_series->pointsVisible(); | ||
m_linePen = m_series->pen(); | ||||
m_pointPen = m_series->pen(); | ||||
m_pointPen.setWidthF(2*m_pointPen.width()); | ||||
|
r139 | update(); | ||
} | ||||
|
r391 | //painter | ||
void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||||
{ | ||||
|
r611 | Q_UNUSED(widget) | ||
Q_UNUSED(option) | ||||
|
r391 | painter->save(); | ||
|
r544 | painter->setPen(m_linePen); | ||
|
r465 | painter->setClipRect(clipRect()); | ||
|
r391 | painter->drawPath(m_path); | ||
|
r544 | if(m_pointsVisible){ | ||
painter->setPen(m_pointPen); | ||||
painter->drawPoints(points()); | ||||
} | ||||
|
r391 | painter->restore(); | ||
} | ||||
|
r144 | #include "moc_linechartitem_p.cpp" | ||
|
r131 | |||
|
r30 | QTCOMMERCIALCHART_END_NAMESPACE | ||