@@ -1,109 +1,111 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "linechartitem_p.h" |
|
22 | 22 | #include "qlineseries.h" |
|
23 | 23 | #include "qlineseries_p.h" |
|
24 | 24 | #include "chartpresenter_p.h" |
|
25 | 25 | #include <QPainter> |
|
26 | 26 | #include <QGraphicsSceneMouseEvent> |
|
27 | 27 | |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | //TODO: optimize : remove points which are not visible |
|
32 | 32 | |
|
33 | 33 | LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter):XYChart(series,presenter), |
|
34 | 34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), |
|
35 | 35 | m_series(series), |
|
36 | 36 | m_pointsVisible(false) |
|
37 | 37 | { |
|
38 | 38 | setZValue(ChartPresenter::LineChartZValue); |
|
39 | 39 | QObject::connect(series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
40 | 40 | handleUpdated(); |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | QRectF LineChartItem::boundingRect() const |
|
44 | 44 | { |
|
45 | 45 | return m_rect; |
|
46 | 46 | } |
|
47 | 47 | |
|
48 | 48 | QPainterPath LineChartItem::shape() const |
|
49 | 49 | { |
|
50 | 50 | return m_path; |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | void LineChartItem::updateGeometry() |
|
54 | 54 | { |
|
55 | 55 | const QVector<QPointF>& points = geometryPoints(); |
|
56 | 56 | |
|
57 | 57 | if(points.size()==0) |
|
58 | 58 | { |
|
59 | prepareGeometryChange(); | |
|
59 | 60 | m_path = QPainterPath(); |
|
61 | m_rect = QRect(); | |
|
60 | 62 | return; |
|
61 | 63 | } |
|
62 | 64 | |
|
63 | 65 | QPainterPath linePath(points.at(0)); |
|
64 | 66 | |
|
65 | 67 | for(int i=1; i< points.size();i++) { |
|
66 | 68 | linePath.lineTo(points.at(i)); |
|
67 | 69 | } |
|
68 | 70 | |
|
69 | 71 | prepareGeometryChange(); |
|
70 | 72 | m_path = linePath; |
|
71 | 73 | m_rect = linePath.boundingRect(); |
|
72 | 74 | setPos(origin()); |
|
73 | 75 | } |
|
74 | 76 | |
|
75 | 77 | void LineChartItem::handleUpdated() |
|
76 | 78 | { |
|
77 | 79 | m_pointsVisible = m_series->pointsVisible(); |
|
78 | 80 | m_linePen = m_series->pen(); |
|
79 | 81 | m_pointPen = m_series->pen(); |
|
80 | 82 | m_pointPen.setWidthF(2*m_pointPen.width()); |
|
81 | 83 | update(); |
|
82 | 84 | } |
|
83 | 85 | |
|
84 | 86 | //painter |
|
85 | 87 | |
|
86 | 88 | void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
87 | 89 | { |
|
88 | 90 | Q_UNUSED(widget) |
|
89 | 91 | Q_UNUSED(option) |
|
90 | 92 | |
|
91 | 93 | painter->save(); |
|
92 | 94 | painter->setPen(m_linePen); |
|
93 | 95 | painter->setClipRect(clipRect()); |
|
94 | 96 | painter->drawPath(m_path); |
|
95 | 97 | if(m_pointsVisible){ |
|
96 | 98 | painter->setPen(m_pointPen); |
|
97 | 99 | painter->drawPoints(geometryPoints()); |
|
98 | 100 | } |
|
99 | 101 | painter->restore(); |
|
100 | 102 | } |
|
101 | 103 | |
|
102 | 104 | void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
103 | 105 | { |
|
104 | 106 | emit XYChart::clicked(calculateDomainPoint(event->pos())); |
|
105 | 107 | } |
|
106 | 108 | |
|
107 | 109 | #include "moc_linechartitem_p.cpp" |
|
108 | 110 | |
|
109 | 111 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now