@@ -11,13 +11,27 SplineWidget::SplineWidget(QWidget *parent) | |||
|
11 | 11 | { |
|
12 | 12 | //create QSplineSeries |
|
13 | 13 | QSplineSeries* series = new QSplineSeries(this); |
|
14 | series->add(QPointF(150, 100)); | |
|
15 |
series->add(QPointF(200, 1 |
|
|
16 |
series->add(QPointF(2 |
|
|
17 |
series->add(QPointF( |
|
|
18 |
series->add(QPointF(3 |
|
|
19 |
series->add(QPointF(4 |
|
|
20 |
series->add(QPointF( |
|
|
14 | // series->add(QPointF(150, 100)); | |
|
15 | // series->add(QPointF(200, 130)); | |
|
16 | // series->add(QPointF(250, 120)); | |
|
17 | // series->add(QPointF(300, 140)); | |
|
18 | // series->add(QPointF(350, 100)); | |
|
19 | // series->add(QPointF(400, 120)); | |
|
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 | 36 | series->calculateControlPoints(); |
|
23 | 37 |
@@ -6,21 +6,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
6 | 6 | SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) : |
|
7 | 7 | LineChartItem(0, series, parent)//,m_boundingRect() |
|
8 | 8 | { |
|
9 | // if (parent) | |
|
10 | // m_boundingRect = parent->boundingRect(); | |
|
11 | // else | |
|
12 | // m_boundingRect = QRectF(10,50, 250, 250); | |
|
9 | // | |
|
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 | 14 | QPointF SplinePresenter::calculateGeometryControlPoint(int index) const |
|
26 | 15 | { |
@@ -34,72 +23,51 QPointF SplinePresenter::calculateGeometryControlPoint(int index) const | |||
|
34 | 23 | |
|
35 | 24 | void SplinePresenter::applyGeometry(QVector<QPointF>& points) |
|
36 | 25 | { |
|
37 | if(points.size()==0) return; | |
|
38 | ||
|
39 | // QList<QGraphicsItem*> items = m_items.childItems(); | |
|
40 | ||
|
41 | QPainterPath splinePath; | |
|
42 | const QPointF& point = points.at(0); | |
|
43 | 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 | ||
|
48 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |
|
49 | for (int i = 0; i < splineSeries->count() - 1; i++) | |
|
50 | { | |
|
51 | 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); | |
|
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 | } | |
|
63 | ||
|
64 | // for(int i=1 ; i< points.size();i++) { | |
|
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 | ||
|
72 | prepareGeometryChange(); | |
|
73 | m_path = splinePath; | |
|
74 | m_rect = splinePath.boundingRect(); | |
|
26 | if(points.size()==0) return; | |
|
27 | ||
|
28 | QPainterPath splinePath; | |
|
29 | const QPointF& point = points.at(0); | |
|
30 | splinePath.moveTo(point); | |
|
31 | ||
|
32 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |
|
33 | for (int i = 0; i < splineSeries->count() - 1; i++) | |
|
34 | { | |
|
35 | const QPointF& point = points.at(i + 1); | |
|
36 | splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point); | |
|
37 | } | |
|
38 | ||
|
39 | ||
|
40 | ||
|
41 | prepareGeometryChange(); | |
|
42 | m_path = splinePath; | |
|
43 | m_rect = splinePath.boundingRect(); | |
|
75 | 44 | } |
|
76 | 45 | |
|
77 |
|
|
|
78 | //{ | |
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 | ||
|
83 | // painter->setPen(Qt::SolidLine); | |
|
84 | ||
|
85 | // QPainterPath splinePath; | |
|
86 | // splinePath.moveTo(m_series->at(0)); | |
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
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 | ||
|
93 | // painter->setPen(Qt::blue); | |
|
94 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); | |
|
95 |
|
|
|
96 |
|
|
|
97 | // painter->drawEllipse(m_series->controlPoint(2 * i + 1), 4, 4); | |
|
98 | // } | |
|
99 | // painter->setPen(Qt::red); | |
|
100 |
|
|
|
101 | // painter->restore(); | |
|
102 | //} | |
|
46 | void SplinePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
47 | { | |
|
48 | Q_UNUSED(widget); | |
|
49 | Q_UNUSED(option); | |
|
50 | painter->save(); | |
|
51 | painter->setPen(m_pen); | |
|
52 | painter->setClipRect(m_clipRect); | |
|
53 | painter->drawPath(m_path); | |
|
54 | ||
|
55 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |
|
56 | for (int i = 0; i < splineSeries->count() - 1; i++) | |
|
57 | { | |
|
58 | painter->setPen(Qt::red); | |
|
59 | painter->drawEllipse(m_points[i], 4, 4); | |
|
60 | ||
|
61 | painter->setPen(Qt::blue); | |
|
62 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); | |
|
63 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); | |
|
64 | painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4); | |
|
65 | painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4); | |
|
66 | } | |
|
67 | painter->setPen(Qt::red); | |
|
68 | painter->drawEllipse(m_points[m_points.count() - 1], 4, 4); | |
|
69 | painter->restore(); | |
|
70 | } | |
|
103 | 71 | |
|
104 | 72 | #include "moc_splinepresenter_p.cpp" |
|
105 | 73 |
@@ -20,18 +20,11 public: | |||
|
20 | 20 | |
|
21 | 21 | QPointF calculateGeometryControlPoint(int index) const; |
|
22 | 22 | |
|
23 | // QRectF boundingRect() const { return m_boundingRect; } | |
|
24 | // void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
|
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
|
25 | 24 | |
|
26 | 25 | signals: |
|
27 | 26 | |
|
28 | 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