##// END OF EJS Templates
Experimenting
Marek Rosa -
r417:ac4db33427b7
parent child
Show More
@@ -1,54 +1,72
1 #include "splinepresenter_p.h"
1 #include "splinepresenter_p.h"
2 #include <QPainter>
2 #include <QPainter>
3
3
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
5
6 SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) :
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)
9 // if (parent)
10 m_boundingRect = parent->boundingRect();
10 // m_boundingRect = parent->boundingRect();
11 else
11 // else
12 m_boundingRect = QRectF(10,50, 250, 250);
12 // m_boundingRect = QRectF(10,50, 250, 250);
13 }
13 }
14
14
15 void SplinePresenter::handleGeometryChanged(const QRectF&)
15 //void SplinePresenter::handleGeometryChanged(const QRectF&)
16 {
16 //{
17 update();
17 // update();
18 }
18 //}
19
19
20 void SplinePresenter::handleDomainChanged(const Domain& domain)
20 //void SplinePresenter::handleDomainChanged(const Domain& domain)
21 {
21 //{
22 //
22 // //
23 }
23 //}
24
24
25 void SplinePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
25 void SplinePresenter::updateGeometry()
26 {
26 {
27 Q_UNUSED(widget);
27
28 Q_UNUSED(option);
28 if(m_data.size()==0) return;
29 painter->save();
29
30
30 prepareGeometryChange();
31 painter->setPen(Qt::SolidLine);
31 QPainterPath path;
32
32 const QPointF& point = m_data.at(0);
33 QPainterPath splinePath;
33 path.moveTo(point);
34 splinePath.moveTo(m_series->at(0));
34
35 for (int i = 0; i < m_series->count() - 1; i++)
35 foreach( const QPointF& point , m_data) {
36 {
36 path.lineTo(point);
37 painter->setPen(Qt::red);
37 }
38 splinePath.cubicTo(m_series->controlPoint(2 * i), m_series->controlPoint(2 * i + 1), m_series->at(i + 1));
38
39 painter->drawEllipse(m_series->at(i), 4, 4);
39 m_path = path;
40
40 m_rect = path.boundingRect();
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();
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 #include "moc_splinepresenter_p.cpp"
70 #include "moc_splinepresenter_p.cpp"
53
71
54 QTCOMMERCIALCHART_END_NAMESPACE
72 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,33 +1,36
1 #ifndef SPLINEPRESENTER_P_H
1 #ifndef SPLINEPRESENTER_P_H
2 #define SPLINEPRESENTER_P_H
2 #define SPLINEPRESENTER_P_H
3
3
4 #include "chartitem_p.h"
4 #include "chartitem_p.h"
5 #include <QObject>
5 #include <QObject>
6 #include "qsplineseries.h"
6 #include "qsplineseries.h"
7 #include "linechartitem_p.h"
7
8
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10
10 class SplinePresenter : public QObject, public ChartItem
11 class SplinePresenter : public LineChartItem
11 {
12 {
12 Q_OBJECT
13 Q_OBJECT
13 public:
14 public:
14 SplinePresenter(QSplineSeries* series, QGraphicsObject *parent = 0);
15 SplinePresenter(QSplineSeries* series, QGraphicsObject *parent = 0);
15
16
16 QRectF boundingRect() const { return m_boundingRect; }
17 void updateGeometry();
17 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
18
19 // QRectF boundingRect() const { return m_boundingRect; }
20 // void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
18
21
19 signals:
22 signals:
20
23
21 public slots:
24 public slots:
22 void handleDomainChanged(const Domain& domain);
25 // void handleDomainChanged(const Domain& domain);
23 void handleGeometryChanged(const QRectF& rect);
26 // void handleGeometryChanged(const QRectF& rect);
24
27
25 private:
28 private:
26 QSplineSeries* m_series;
29 QSplineSeries* m_series;
27 QRectF m_boundingRect;
30 // QRectF m_boundingRect;
28
31
29 };
32 };
30
33
31 QTCOMMERCIALCHART_END_NAMESPACE
34 QTCOMMERCIALCHART_END_NAMESPACE
32
35
33 #endif // SPLINEPRESENTER_P_H
36 #endif // SPLINEPRESENTER_P_H
General Comments 0
You need to be logged in to leave comments. Login now