@@ -4,51 +4,69 | |||
|
4 | 4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | 5 | |
|
6 | 6 | SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) : |
|
7 | ChartItem(parent),m_series(series),m_boundingRect() | |
|
7 | LineChartItem(this, parent),m_series(series)//,m_boundingRect() | |
|
8 | 8 | { |
|
9 | if (parent) | |
|
10 | m_boundingRect = parent->boundingRect(); | |
|
11 | else | |
|
12 | m_boundingRect = QRectF(10,50, 250, 250); | |
|
9 | // if (parent) | |
|
10 | // m_boundingRect = parent->boundingRect(); | |
|
11 | // else | |
|
12 | // m_boundingRect = QRectF(10,50, 250, 250); | |
|
13 | 13 | } |
|
14 | 14 | |
|
15 | void SplinePresenter::handleGeometryChanged(const QRectF&) | |
|
16 | { | |
|
17 | update(); | |
|
18 | } | |
|
15 | //void SplinePresenter::handleGeometryChanged(const QRectF&) | |
|
16 | //{ | |
|
17 | // update(); | |
|
18 | //} | |
|
19 | 19 | |
|
20 | void SplinePresenter::handleDomainChanged(const Domain& domain) | |
|
21 | { | |
|
22 | // | |
|
23 | } | |
|
20 | //void SplinePresenter::handleDomainChanged(const Domain& domain) | |
|
21 | //{ | |
|
22 | // // | |
|
23 | //} | |
|
24 | 24 | |
|
25 | void SplinePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
25 | void SplinePresenter::updateGeometry() | |
|
26 | 26 | { |
|
27 | Q_UNUSED(widget); | |
|
28 | Q_UNUSED(option); | |
|
29 | painter->save(); | |
|
30 | ||
|
31 | painter->setPen(Qt::SolidLine); | |
|
32 | ||
|
33 | QPainterPath splinePath; | |
|
34 | splinePath.moveTo(m_series->at(0)); | |
|
35 | for (int i = 0; i < m_series->count() - 1; i++) | |
|
36 | { | |
|
37 | painter->setPen(Qt::red); | |
|
38 | splinePath.cubicTo(m_series->controlPoint(2 * i), m_series->controlPoint(2 * i + 1), m_series->at(i + 1)); | |
|
39 | painter->drawEllipse(m_series->at(i), 4, 4); | |
|
40 | ||
|
41 | painter->setPen(Qt::blue); | |
|
42 | painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); | |
|
43 | painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); | |
|
44 | painter->drawEllipse(m_series->controlPoint(2 * i), 4, 4); | |
|
45 | painter->drawEllipse(m_series->controlPoint(2 * i + 1), 4, 4); | |
|
46 | } | |
|
47 | painter->setPen(Qt::red); | |
|
48 | painter->drawPath(splinePath); | |
|
49 | painter->restore(); | |
|
27 | ||
|
28 | if(m_data.size()==0) return; | |
|
29 | ||
|
30 | prepareGeometryChange(); | |
|
31 | QPainterPath path; | |
|
32 | const QPointF& point = m_data.at(0); | |
|
33 | path.moveTo(point); | |
|
34 | ||
|
35 | foreach( const QPointF& point , m_data) { | |
|
36 | path.lineTo(point); | |
|
37 | } | |
|
38 | ||
|
39 | m_path = path; | |
|
40 | m_rect = path.boundingRect(); | |
|
50 | 41 | } |
|
51 | 42 | |
|
43 | //void SplinePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
44 | //{ | |
|
45 | // Q_UNUSED(widget); | |
|
46 | // Q_UNUSED(option); | |
|
47 | // painter->save(); | |
|
48 | ||
|
49 | // painter->setPen(Qt::SolidLine); | |
|
50 | ||
|
51 | // QPainterPath splinePath; | |
|
52 | // splinePath.moveTo(m_series->at(0)); | |
|
53 | // for (int i = 0; i < m_series->count() - 1; i++) | |
|
54 | // { | |
|
55 | // painter->setPen(Qt::red); | |
|
56 | // splinePath.cubicTo(m_series->controlPoint(2 * i), m_series->controlPoint(2 * i + 1), m_series->at(i + 1)); | |
|
57 | // painter->drawEllipse(m_series->at(i), 4, 4); | |
|
58 | ||
|
59 | // painter->setPen(Qt::blue); | |
|
60 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); | |
|
61 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); | |
|
62 | // painter->drawEllipse(m_series->controlPoint(2 * i), 4, 4); | |
|
63 | // painter->drawEllipse(m_series->controlPoint(2 * i + 1), 4, 4); | |
|
64 | // } | |
|
65 | // painter->setPen(Qt::red); | |
|
66 | // painter->drawPath(splinePath); | |
|
67 | // painter->restore(); | |
|
68 | //} | |
|
69 | ||
|
52 | 70 | #include "moc_splinepresenter_p.cpp" |
|
53 | 71 | |
|
54 | 72 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -4,27 +4,30 | |||
|
4 | 4 | #include "chartitem_p.h" |
|
5 | 5 | #include <QObject> |
|
6 | 6 | #include "qsplineseries.h" |
|
7 | #include "linechartitem_p.h" | |
|
7 | 8 | |
|
8 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 10 | |
|
10 |
class SplinePresenter : public |
|
|
11 | class SplinePresenter : public LineChartItem | |
|
11 | 12 | { |
|
12 | 13 | Q_OBJECT |
|
13 | 14 | public: |
|
14 | 15 | SplinePresenter(QSplineSeries* series, QGraphicsObject *parent = 0); |
|
15 | 16 | |
|
16 | QRectF boundingRect() const { return m_boundingRect; } | |
|
17 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
|
17 | void updateGeometry(); | |
|
18 | ||
|
19 | // QRectF boundingRect() const { return m_boundingRect; } | |
|
20 | // void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
|
18 | 21 | |
|
19 | 22 | signals: |
|
20 | 23 | |
|
21 | 24 | public slots: |
|
22 | void handleDomainChanged(const Domain& domain); | |
|
23 | void handleGeometryChanged(const QRectF& rect); | |
|
25 | // void handleDomainChanged(const Domain& domain); | |
|
26 | // void handleGeometryChanged(const QRectF& rect); | |
|
24 | 27 | |
|
25 | 28 | private: |
|
26 | 29 | QSplineSeries* m_series; |
|
27 | QRectF m_boundingRect; | |
|
30 | // QRectF m_boundingRect; | |
|
28 | 31 | |
|
29 | 32 | }; |
|
30 | 33 |
General Comments 0
You need to be logged in to leave comments.
Login now