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