linechartitem.cpp
114 lines
| 2.9 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
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$ | ||||
** | ||||
****************************************************************************/ | ||||
Michal Klocek
|
r144 | #include "linechartitem_p.h" | ||
Michal Klocek
|
r349 | #include "qlineseries.h" | ||
Michal Klocek
|
r938 | #include "qlineseries_p.h" | ||
Michal Klocek
|
r131 | #include "chartpresenter_p.h" | ||
Michal Klocek
|
r21 | #include <QPainter> | ||
Michal Klocek
|
r1218 | #include <QGraphicsSceneMouseEvent> | ||
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 | |||
Tero Ahola
|
r1346 | LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter): | ||
XYChart(series, presenter), | ||||
QGraphicsItem(presenter ? presenter->rootItem() : 0), | ||||
m_series(series), | ||||
m_pointsVisible(false) | ||||
Michal Klocek
|
r21 | { | ||
Michal Klocek
|
r262 | setZValue(ChartPresenter::LineChartZValue); | ||
Michal Klocek
|
r938 | QObject::connect(series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); | ||
Tero Ahola
|
r1342 | QObject::connect(series, SIGNAL(visibleChanged()), 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
|
r1217 | void LineChartItem::updateGeometry() | ||
Michal Klocek
|
r131 | { | ||
Michal Klocek
|
r1217 | const QVector<QPointF>& points = geometryPoints(); | ||
Marek Rosa
|
r545 | if(points.size()==0) | ||
{ | ||||
Michal Klocek
|
r1269 | prepareGeometryChange(); | ||
Marek Rosa
|
r1085 | m_path = QPainterPath(); | ||
Michal Klocek
|
r1269 | m_rect = QRect(); | ||
Marek Rosa
|
r545 | return; | ||
} | ||||
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
|
r1218 | setPos(origin()); | ||
Michal Klocek
|
r21 | } | ||
Michal Klocek
|
r392 | void LineChartItem::handleUpdated() | ||
Michal Klocek
|
r389 | { | ||
Tero Ahola
|
r1346 | setVisible(m_series->isVisible()); | ||
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) | ||||
{ | ||||
Tero Ahola
|
r611 | Q_UNUSED(widget) | ||
Q_UNUSED(option) | ||||
Tero Ahola
|
r1346 | painter->save(); | ||
painter->setPen(m_linePen); | ||||
painter->setClipRect(clipRect()); | ||||
painter->drawPath(m_path); | ||||
if (m_pointsVisible){ | ||||
painter->setPen(m_pointPen); | ||||
painter->drawPoints(geometryPoints()); | ||||
Michal Klocek
|
r544 | } | ||
Tero Ahola
|
r1346 | painter->restore(); | ||
Michal Klocek
|
r391 | } | ||
Michal Klocek
|
r1218 | void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | ||
{ | ||||
emit XYChart::clicked(calculateDomainPoint(event->pos())); | ||||
} | ||||
Michal Klocek
|
r144 | #include "moc_linechartitem_p.cpp" | ||
Michal Klocek
|
r131 | |||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_END_NAMESPACE | ||