@@ -1,101 +1,100 | |||
|
1 | 1 | #include "splinechartitem_p.h" |
|
2 | 2 | #include "chartpresenter_p.h" |
|
3 | 3 | #include <QPainter> |
|
4 | 4 | |
|
5 | 5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | 6 | |
|
7 | 7 | SplineChartItem::SplineChartItem(QSplineSeries* series, QGraphicsItem *parent) : |
|
8 | 8 | XYChartItem(series, parent), |
|
9 | 9 | m_series(series) |
|
10 | 10 | { |
|
11 | 11 | setZValue(ChartPresenter::LineChartZValue); |
|
12 | 12 | QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
13 | 13 | handleUpdated(); |
|
14 | 14 | } |
|
15 | 15 | |
|
16 | 16 | QRectF SplineChartItem::boundingRect() const |
|
17 | 17 | { |
|
18 | 18 | return m_rect; |
|
19 | 19 | } |
|
20 | 20 | |
|
21 | 21 | QPainterPath SplineChartItem::shape() const |
|
22 | 22 | { |
|
23 | 23 | return m_path; |
|
24 | 24 | } |
|
25 | 25 | |
|
26 | 26 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const |
|
27 | 27 | { |
|
28 | 28 | return XYChartItem::calculateGeometryPoint(m_series->controlPoint(index)); |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | void SplineChartItem::setLayout(QVector<QPointF>& points) |
|
32 | 32 | { |
|
33 | 33 | |
|
34 | 34 | if(points.size()==0) |
|
35 | 35 | { |
|
36 | 36 | XYChartItem::setLayout(points); |
|
37 | 37 | return; |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | QPainterPath splinePath; |
|
41 | 41 | const QPointF& point = points.at(0); |
|
42 | 42 | splinePath.moveTo(point); |
|
43 | 43 | |
|
44 | 44 | for (int i = 0; i < points.size() - 1; i++) |
|
45 | 45 | { |
|
46 | 46 | const QPointF& point = points.at(i + 1); |
|
47 | 47 | splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point); |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | prepareGeometryChange(); |
|
51 | 51 | m_path = splinePath; |
|
52 | 52 | m_rect = splinePath.boundingRect(); |
|
53 | 53 | XYChartItem::setLayout(points); |
|
54 | 54 | } |
|
55 | 55 | |
|
56 | 56 | //handlers |
|
57 | 57 | |
|
58 | 58 | void SplineChartItem::handleUpdated() |
|
59 | 59 | { |
|
60 | 60 | m_pen = m_series->pen(); |
|
61 | 61 | update(); |
|
62 | 62 | } |
|
63 | 63 | |
|
64 | 64 | //painter |
|
65 | 65 | |
|
66 | 66 | void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
67 | 67 | { |
|
68 | 68 | Q_UNUSED(widget); |
|
69 | 69 | Q_UNUSED(option); |
|
70 | 70 | painter->save(); |
|
71 | 71 | painter->setClipRect(clipRect()); |
|
72 |
|
|
|
73 | painter->setPen(m_series->pen()); | |
|
72 | painter->setPen(m_pen); | |
|
74 | 73 | painter->drawPath(m_path); |
|
75 | 74 | |
|
76 | 75 | // const QVector<QPointF> points = XYChartItem::points(); |
|
77 | 76 | |
|
78 | 77 | // for (int i = 0; i < points.size() - 1; i++) |
|
79 | 78 | // { |
|
80 | 79 | // painter->setPen(Qt::red); |
|
81 | 80 | // painter->drawEllipse(points[i], 2, 2); |
|
82 | 81 | |
|
83 | 82 | // painter->setPen(Qt::blue); |
|
84 | 83 | // // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); |
|
85 | 84 | // // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); |
|
86 | 85 | // // painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4); |
|
87 | 86 | // // painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4); |
|
88 | 87 | // } |
|
89 | 88 | // if (points.count() > 0) |
|
90 | 89 | // { |
|
91 | 90 | // painter->setPen(Qt::red); |
|
92 | 91 | // painter->drawEllipse(points[points.count() - 1], 2, 2); |
|
93 | 92 | // } |
|
94 | 93 | painter->restore(); |
|
95 | 94 | } |
|
96 | 95 | |
|
97 | 96 | |
|
98 | 97 | |
|
99 | 98 | #include "moc_splinechartitem_p.cpp" |
|
100 | 99 | |
|
101 | 100 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now