@@ -11,13 +11,27 SplineWidget::SplineWidget(QWidget *parent) | |||||
11 | { |
|
11 | { | |
12 | //create QSplineSeries |
|
12 | //create QSplineSeries | |
13 | QSplineSeries* series = new QSplineSeries(this); |
|
13 | QSplineSeries* series = new QSplineSeries(this); | |
14 | series->add(QPointF(150, 100)); |
|
14 | // series->add(QPointF(150, 100)); | |
15 |
series->add(QPointF(200, 1 |
|
15 | // series->add(QPointF(200, 130)); | |
16 |
series->add(QPointF(2 |
|
16 | // series->add(QPointF(250, 120)); | |
17 |
series->add(QPointF( |
|
17 | // series->add(QPointF(300, 140)); | |
18 |
series->add(QPointF(3 |
|
18 | // series->add(QPointF(350, 100)); | |
19 |
series->add(QPointF(4 |
|
19 | // series->add(QPointF(400, 120)); | |
20 |
series->add(QPointF( |
|
20 | // series->add(QPointF(450, 150)); | |
|
21 | //// series->add(QPointF(600, 150)); | |||
|
22 | // series->add(QPointF(500, 145)); | |||
|
23 | // series->add(QPointF(550, 170)); | |||
|
24 | // series->add(QPointF(600, 190)); | |||
|
25 | // series->add(QPointF(650, 210)); | |||
|
26 | // series->add(QPointF(700, 190)); | |||
|
27 | // series->add(QPointF(750, 180)); | |||
|
28 | // series->add(QPointF(800, 170)); | |||
|
29 | ||||
|
30 | qsrand(time(NULL)); | |||
|
31 | for (int i = 0; i < 100; i++) | |||
|
32 | { | |||
|
33 | series->add(QPointF(i*7, qrand()%600)); | |||
|
34 | } | |||
21 |
|
35 | |||
22 | series->calculateControlPoints(); |
|
36 | series->calculateControlPoints(); | |
23 |
|
37 |
@@ -6,21 +6,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
6 | SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) : |
|
6 | SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) : | |
7 | LineChartItem(0, series, parent)//,m_boundingRect() |
|
7 | LineChartItem(0, series, parent)//,m_boundingRect() | |
8 | { |
|
8 | { | |
9 | // if (parent) |
|
9 | // | |
10 | // m_boundingRect = parent->boundingRect(); |
|
|||
11 | // else |
|
|||
12 | // m_boundingRect = QRectF(10,50, 250, 250); |
|
|||
13 | } |
|
10 | } | |
14 |
|
11 | |||
15 | //void SplinePresenter::handleGeometryChanged(const QRectF&) |
|
|||
16 | //{ |
|
|||
17 | // update(); |
|
|||
18 | //} |
|
|||
19 |
|
12 | |||
20 | //void SplinePresenter::handleDomainChanged(const Domain& domain) |
|
|||
21 | //{ |
|
|||
22 | // // |
|
|||
23 | //} |
|
|||
24 |
|
13 | |||
25 | QPointF SplinePresenter::calculateGeometryControlPoint(int index) const |
|
14 | QPointF SplinePresenter::calculateGeometryControlPoint(int index) const | |
26 | { |
|
15 | { | |
@@ -36,70 +25,49 void SplinePresenter::applyGeometry(QVector<QPointF>& points) | |||||
36 | { |
|
25 | { | |
37 | if(points.size()==0) return; |
|
26 | if(points.size()==0) return; | |
38 |
|
27 | |||
39 | // QList<QGraphicsItem*> items = m_items.childItems(); |
|
|||
40 |
|
||||
41 | QPainterPath splinePath; |
|
28 | QPainterPath splinePath; | |
42 | const QPointF& point = points.at(0); |
|
29 | const QPointF& point = points.at(0); | |
43 | splinePath.moveTo(point); |
|
30 | splinePath.moveTo(point); | |
44 | // QGraphicsItem* item = items.at(0); |
|
|||
45 | // item->setPos(point.x()-1,point.y()-1); |
|
|||
46 | // if(!m_clipRect.contains(point)) item->setVisible(false); |
|
|||
47 |
|
31 | |||
48 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); |
|
32 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |
49 | for (int i = 0; i < splineSeries->count() - 1; i++) |
|
33 | for (int i = 0; i < splineSeries->count() - 1; i++) | |
50 |
|
|
34 | { | |
51 | const QPointF& point = points.at(i + 1); |
|
35 | const QPointF& point = points.at(i + 1); | |
52 | // painter->setPen(Qt::red); |
|
|||
53 | // splinePath.cubicTo(qobject_cast<QSplineSeries*>(m_series)->controlPoint(2 * i), qobject_cast<QSplineSeries*>(m_series)->controlPoint(2 * i + 1), QPointF(m_series->x(i + 1), m_series->y(i + 1))); |
|
|||
54 | splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point); |
|
36 | splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point); | |
55 | // painter->drawEllipse(m_series->at(i), 4, 4); |
|
|||
56 |
|
||||
57 | // painter->setPen(Qt::blue); |
|
|||
58 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); |
|
|||
59 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); |
|
|||
60 | // painter->drawEllipse(m_series->controlPoint(2 * i), 4, 4); |
|
|||
61 | // painter->drawEllipse(m_series->controlPoint(2 * i + 1), 4, 4); |
|
|||
62 |
|
|
37 | } | |
63 |
|
38 | |||
64 | // for(int i=1 ; i< points.size();i++) { |
|
39 | ||
65 | // QGraphicsItem* item = items.at(i); |
|
|||
66 | // const QPointF& point = points.at(i); |
|
|||
67 | // item->setPos(point.x()-1,point.y()-1); |
|
|||
68 | // if(!m_clipRect.contains(point)) item->setVisible(false); |
|
|||
69 | // path.lineTo(point); |
|
|||
70 | // } |
|
|||
71 |
|
40 | |||
72 | prepareGeometryChange(); |
|
41 | prepareGeometryChange(); | |
73 | m_path = splinePath; |
|
42 | m_path = splinePath; | |
74 | m_rect = splinePath.boundingRect(); |
|
43 | m_rect = splinePath.boundingRect(); | |
75 | } |
|
44 | } | |
76 |
|
45 | |||
77 |
|
|
46 | void SplinePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
78 | //{ |
|
47 | { | |
79 |
|
|
48 | Q_UNUSED(widget); | |
80 |
|
|
49 | Q_UNUSED(option); | |
81 |
|
|
50 | painter->save(); | |
82 |
|
51 | painter->setPen(m_pen); | ||
83 | // painter->setPen(Qt::SolidLine); |
|
52 | painter->setClipRect(m_clipRect); | |
|
53 | painter->drawPath(m_path); | |||
84 |
|
54 | |||
85 | // QPainterPath splinePath; |
|
55 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |
86 | // splinePath.moveTo(m_series->at(0)); |
|
56 | for (int i = 0; i < splineSeries->count() - 1; i++) | |
87 | // for (int i = 0; i < m_series->count() - 1; i++) |
|
57 | { | |
88 | // { |
|
58 | painter->setPen(Qt::red); | |
89 | // painter->setPen(Qt::red); |
|
59 | painter->drawEllipse(m_points[i], 4, 4); | |
90 | // splinePath.cubicTo(m_series->controlPoint(2 * i), m_series->controlPoint(2 * i + 1), m_series->at(i + 1)); |
|
|||
91 | // painter->drawEllipse(m_series->at(i), 4, 4); |
|
|||
92 |
|
60 | |||
93 |
|
|
61 | painter->setPen(Qt::blue); | |
94 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); |
|
62 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); | |
95 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); |
|
63 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); | |
96 |
|
|
64 | painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4); | |
97 |
|
|
65 | painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4); | |
98 |
|
|
66 | } | |
99 |
|
|
67 | painter->setPen(Qt::red); | |
100 | // painter->drawPath(splinePath); |
|
68 | painter->drawEllipse(m_points[m_points.count() - 1], 4, 4); | |
101 |
|
|
69 | painter->restore(); | |
102 | //} |
|
70 | } | |
103 |
|
71 | |||
104 | #include "moc_splinepresenter_p.cpp" |
|
72 | #include "moc_splinepresenter_p.cpp" | |
105 |
|
73 |
@@ -20,18 +20,11 public: | |||||
20 |
|
20 | |||
21 | QPointF calculateGeometryControlPoint(int index) const; |
|
21 | QPointF calculateGeometryControlPoint(int index) const; | |
22 |
|
22 | |||
23 | // QRectF boundingRect() const { return m_boundingRect; } |
|
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
24 | // void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
|||
25 |
|
24 | |||
26 | signals: |
|
25 | signals: | |
27 |
|
26 | |||
28 | public slots: |
|
27 | public slots: | |
29 | // void handleDomainChanged(const Domain& domain); |
|
|||
30 | // void handleGeometryChanged(const QRectF& rect); |
|
|||
31 |
|
||||
32 | private: |
|
|||
33 | // QSplineSeries* m_series; |
|
|||
34 | // QRectF m_boundingRect; |
|
|||
35 |
|
28 | |||
36 | }; |
|
29 | }; | |
37 |
|
30 |
General Comments 0
You need to be logged in to leave comments.
Login now