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