##// END OF EJS Templates
Spline series windows compilation fix
Michal Klocek -
r467:bda5257e118d
parent child
Show More
@@ -1,117 +1,94
1 #include "qlineseries.h"
1 #include "qlineseries.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
5 /*!
6 \class QLineSeries
6 \class QLineSeries
7 \brief The QLineSeries class is used for making line charts.
7 \brief The QLineSeries class is used for making line charts.
8
8
9 \mainclass
9 \mainclass
10
10
11 A line chart is used to show information as a series of data points
11 A line chart is used to show information as a series of data points
12 connected by straight lines.
12 connected by straight lines.
13
13
14 \image linechart.png
14 \image linechart.png
15
15
16 Creating basic line chart is simple:
16 Creating basic line chart is simple:
17 \code
17 \code
18 QLineSeries* series = new QLineSeries();
18 QLineSeries* series = new QLineSeries();
19 series->add(0, 6);
19 series->add(0, 6);
20 series->add(2, 4);
20 series->add(2, 4);
21 ...
21 ...
22 chartView->addSeries(series);
22 chartView->addSeries(series);
23 \endcode
23 \endcode
24 */
24 */
25
25
26 /*!
26 /*!
27 \fn virtual QSeriesType QLineSeries::type() const
27 \fn virtual QSeriesType QLineSeries::type() const
28 \brief Returns type of series.
28 \brief Returns type of series.
29 \sa QSeries, QSeriesType
29 \sa QSeries, QSeriesType
30 */
30 */
31
31
32 /*!
32 /*!
33 \fn QPen QLineSeries::pen() const
33 \fn QPen QLineSeries::pen() const
34 \brief Returns the pen used to draw line for this series.
34 \brief Returns the pen used to draw line for this series.
35 \sa setPen()
35 \sa setPen()
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn bool QLineSeries::pointsVisible() const
39 \fn bool QLineSeries::pointsVisible() const
40 \brief Returns if the points are drawn for this series.
40 \brief Returns if the points are drawn for this series.
41 \sa setPointsVisible()
41 \sa setPointsVisible()
42 */
42 */
43
43
44
44
45 /*!
45 /*!
46 \fn void QLineSeries::pointReplaced(int index)
46 \fn void QLineSeries::pointReplaced(int index)
47 \brief \internal \a index
47 \brief \internal \a index
48 */
48 */
49
49
50 /*!
50 /*!
51 \fn void QLineSeries::pointAdded(int index)
51 \fn void QLineSeries::pointAdded(int index)
52 \brief \internal \a index
52 \brief \internal \a index
53 */
53 */
54
54
55 /*!
55 /*!
56 \fn void QLineSeries::pointRemoved(int index)
56 \fn void QLineSeries::pointRemoved(int index)
57 \brief \internal \a index
57 \brief \internal \a index
58 */
58 */
59
59
60 /*!
60 /*!
61 \fn void QLineSeries::updated()
61 \fn void QLineSeries::updated()
62 \brief \internal
62 \brief \internal
63 */
63 */
64
64
65 /*!
65 /*!
66 Constructs empty series object which is a child of \a parent.
66 Constructs empty series object which is a child of \a parent.
67 When series object is added to QChartView or QChart instance ownerships is transfered.
67 When series object is added to QChartView or QChart instance ownerships is transfered.
68 */
68 */
69 QLineSeries::QLineSeries(QObject* parent):QXYSeries(parent),
69 QLineSeries::QLineSeries(QObject* parent):QXYSeries(parent)
70 m_pointsVisible(false)
71 {
70 {
72 }
71 }
73 /*!
72 /*!
74 Destroys the object. Series added to QChartView or QChart instances are owned by those,
73 Destroys the object. Series added to QChartView or QChart instances are owned by those,
75 and are deleted when mentioned object are destroyed.
74 and are deleted when mentioned object are destroyed.
76 */
75 */
77 QLineSeries::~QLineSeries()
76 QLineSeries::~QLineSeries()
78 {
77 {
79 }
78 }
80
79
81 /*!
82 Sets \a pen used for drawing given series..
83 */
84 void QLineSeries::setPen(const QPen& pen)
85 {
86 if(pen!=m_pen){
87 m_pen=pen;
88 emit updated();
89 }
90 }
91
92 /*!
93 Sets if data points are \a visible and should be drawn on line.
94 */
95 void QLineSeries::setPointsVisible(bool visible)
96 {
97 if(m_pointsVisible!=visible){
98 m_pointsVisible=visible;
99 emit updated();
100 }
101 }
102
103 QDebug operator<< (QDebug debug, const QLineSeries series)
80 QDebug operator<< (QDebug debug, const QLineSeries series)
104 {
81 {
105 Q_ASSERT(series.m_x.size() == series.m_y.size());
82 Q_ASSERT(series.m_x.size() == series.m_y.size());
106
83
107 int size = series.m_x.size();
84 int size = series.m_x.size();
108
85
109 for (int i=0;i<size;i++) {
86 for (int i=0;i<size;i++) {
110 debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") ";
87 debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") ";
111 }
88 }
112 return debug.space();
89 return debug.space();
113 }
90 }
114
91
115 #include "moc_qlineseries.cpp"
92 #include "moc_qlineseries.cpp"
116
93
117 QTCOMMERCIALCHART_END_NAMESPACE
94 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,35 +1,27
1 #ifndef QLINESERIES_H_
1 #ifndef QLINESERIES_H_
2 #define QLINESERIES_H_
2 #define QLINESERIES_H_
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qxyseries.h"
5 #include "qxyseries.h"
6 #include <QDebug>
6 #include <QDebug>
7 #include <QPen>
7 #include <QPen>
8 #include <QBrush>
8 #include <QBrush>
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 class QTCOMMERCIALCHART_EXPORT QLineSeries : public QXYSeries
12 class QTCOMMERCIALCHART_EXPORT QLineSeries : public QXYSeries
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15 public:
15 public:
16 QLineSeries(QObject* parent=0);
16 QLineSeries(QObject* parent=0);
17 virtual ~QLineSeries();
17 virtual ~QLineSeries();
18
18
19 public: // from QChartSeries
19 public: // from QChartSeries
20 virtual QSeriesType type() const {return QSeries::SeriesTypeLine;}
20 virtual QSeriesType type() const {return QSeries::SeriesTypeLine;}
21 void setPen(const QPen& pen);
22 QPen pen() const {return m_pen;}
23
24 void setPointsVisible(bool visible);
25 bool pointsVisible() const {return m_pointsVisible;}
26
27 friend QDebug operator<< (QDebug d, const QLineSeries series);
21 friend QDebug operator<< (QDebug d, const QLineSeries series);
28 private:
22
29 QPen m_pen;
30 bool m_pointsVisible;
31 };
23 };
32
24
33 QTCOMMERCIALCHART_END_NAMESPACE
25 QTCOMMERCIALCHART_END_NAMESPACE
34
26
35 #endif
27 #endif
@@ -1,142 +1,142
1 #include "qsplineseries.h"
1 #include "qsplineseries.h"
2
2
3 /*!
3 /*!
4 \class QSplineSeries
4 \class QSplineSeries
5 \brief Series type used to store data needed to draw a spline.
5 \brief Series type used to store data needed to draw a spline.
6
6
7 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
7 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
8 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
8 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
9 */
9 */
10
10
11 /*!
11 /*!
12 \fn QSeriesType QSplineSeries::type() const
12 \fn QSeriesType QSplineSeries::type() const
13 Returns the type of the series
13 Returns the type of the series
14 */
14 */
15
15
16 /*!
16 /*!
17 \fn QSeriesType QSplineSeries::controlPoint(int index) const
17 \fn QSeriesType QSplineSeries::controlPoint(int index) const
18 Returns the control point specified by \a index
18 Returns the control point specified by \a index
19 */
19 */
20
20
21 QTCOMMERCIALCHART_BEGIN_NAMESPACE
21 QTCOMMERCIALCHART_BEGIN_NAMESPACE
22
22
23 /*!
23 /*!
24 Constructs empty series object which is a child of \a parent.
24 Constructs empty series object which is a child of \a parent.
25 When series object is added to QChartView or QChart instance then the ownerships is transfered.
25 When series object is added to QChartView or QChart instance then the ownerships is transfered.
26 */
26 */
27
27
28 QSplineSeries::QSplineSeries(QObject *parent) :
28 QSplineSeries::QSplineSeries(QObject *parent) :
29 QLineSeries(parent)
29 QXYSeries(parent)
30 {
30 {
31 connect(this,SIGNAL(pointAdded(int)), this, SLOT(updateControlPoints()));
31 connect(this,SIGNAL(pointAdded(int)), this, SLOT(updateControlPoints()));
32 connect(this,SIGNAL(pointRemoved(int)), this, SLOT(updateControlPoints()));
32 connect(this,SIGNAL(pointRemoved(int)), this, SLOT(updateControlPoints()));
33 connect(this,SIGNAL(pointReplaced(int)), this, SLOT(updateControlPoints()));
33 connect(this,SIGNAL(pointReplaced(int)), this, SLOT(updateControlPoints()));
34 }
34 }
35
35
36 /*!
36 /*!
37 \internal
37 \internal
38 Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
38 Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
39 */
39 */
40 void QSplineSeries::calculateControlPoints()
40 void QSplineSeries::calculateControlPoints()
41 {
41 {
42
42
43 // Based on http://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-wit
43 // Based on http://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-wit
44 // CPOL License
44 // CPOL License
45
45
46 int n = m_x.size() - 1;
46 int n = m_x.size() - 1;
47 if (n == 1)
47 if (n == 1)
48 { // Special case: Bezier curve should be a straight line.
48 { // Special case: Bezier curve should be a straight line.
49 // firstControlPoints = new Point[1];
49 // firstControlPoints = new Point[1];
50 // 3P1 = 2P0 + P3
50 // 3P1 = 2P0 + P3
51 m_controlPoints.append(QPointF((2 * m_x[0] + m_x[1]) / 3, (2 * m_y[0] + m_y[1]) / 3));
51 m_controlPoints.append(QPointF((2 * m_x[0] + m_x[1]) / 3, (2 * m_y[0] + m_y[1]) / 3));
52
52
53 // P2 = 2P1 P0
53 // P2 = 2P1 P0
54 m_controlPoints.append(QPointF(2 * m_controlPoints[0].x() - m_x[0], 2 * m_controlPoints[0].y() - m_y[0]));
54 m_controlPoints.append(QPointF(2 * m_controlPoints[0].x() - m_x[0], 2 * m_controlPoints[0].y() - m_y[0]));
55 return;
55 return;
56 }
56 }
57
57
58 // Calculate first Bezier control points
58 // Calculate first Bezier control points
59 // Right hand side vector
59 // Right hand side vector
60 // Set of equations for P0 to Pn points.
60 // Set of equations for P0 to Pn points.
61 //
61 //
62 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
62 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
63 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
63 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
64 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
64 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
65 // | . . . . . . . . . . . . | | ... | | ... |
65 // | . . . . . . . . . . . . | | ... | | ... |
66 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
66 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
67 // | . . . . . . . . . . . . | | ... | | ... |
67 // | . . . . . . . . . . . . | | ... | | ... |
68 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
68 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
69 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
69 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
70 //
70 //
71 QList<qreal> rhs;
71 QList<qreal> rhs;
72 rhs.append(m_x[0] + 2 * m_x[1]);
72 rhs.append(m_x[0] + 2 * m_x[1]);
73
73
74 // Set right hand side X values
74 // Set right hand side X values
75 for (int i = 1; i < n - 1; ++i)
75 for (int i = 1; i < n - 1; ++i)
76 rhs.append(4 * m_x[i] + 2 * m_x[i + 1]);
76 rhs.append(4 * m_x[i] + 2 * m_x[i + 1]);
77
77
78 rhs.append((8 * m_x[n - 1] + m_x[n]) / 2.0);
78 rhs.append((8 * m_x[n - 1] + m_x[n]) / 2.0);
79 // Get first control points X-values
79 // Get first control points X-values
80 QList<qreal> x = getFirstControlPoints(rhs);
80 QList<qreal> x = getFirstControlPoints(rhs);
81 rhs[0] = m_y[0] + 2 * m_y[1];
81 rhs[0] = m_y[0] + 2 * m_y[1];
82
82
83 // Set right hand side Y values
83 // Set right hand side Y values
84 for (int i = 1; i < n - 1; ++i)
84 for (int i = 1; i < n - 1; ++i)
85 rhs[i] = 4 * m_y[i] + 2 * m_y[i + 1];
85 rhs[i] = 4 * m_y[i] + 2 * m_y[i + 1];
86
86
87 rhs[n - 1] = (8 * m_y[n - 1] + m_y[n]) / 2.0;
87 rhs[n - 1] = (8 * m_y[n - 1] + m_y[n]) / 2.0;
88 // Get first control points Y-values
88 // Get first control points Y-values
89 QList<qreal> y = getFirstControlPoints(rhs);
89 QList<qreal> y = getFirstControlPoints(rhs);
90
90
91 // Fill output arrays.
91 // Fill output arrays.
92 for (int i = 0; i < n; ++i)
92 for (int i = 0; i < n; ++i)
93 {
93 {
94 // First control point
94 // First control point
95 m_controlPoints.append(QPointF(x[i], y[i]));
95 m_controlPoints.append(QPointF(x[i], y[i]));
96 // Second control point
96 // Second control point
97 if (i < n - 1)
97 if (i < n - 1)
98 m_controlPoints.append(QPointF(2 * m_x[i + 1] - x[i + 1], 2 * m_y[i + 1] - y[i + 1]));
98 m_controlPoints.append(QPointF(2 * m_x[i + 1] - x[i + 1], 2 * m_y[i + 1] - y[i + 1]));
99 else
99 else
100 m_controlPoints.append(QPointF((m_x[n] + x[n - 1]) / 2, (m_y[n] + y[n - 1]) / 2));
100 m_controlPoints.append(QPointF((m_x[n] + x[n - 1]) / 2, (m_y[n] + y[n - 1]) / 2));
101 }
101 }
102 }
102 }
103
103
104 /*!
104 /*!
105 \internal
105 \internal
106 */
106 */
107 QList<qreal> QSplineSeries::getFirstControlPoints(QList<qreal> rhs)
107 QList<qreal> QSplineSeries::getFirstControlPoints(QList<qreal> rhs)
108 {
108 {
109 QList<qreal> x; // Solution vector.
109 QList<qreal> x; // Solution vector.
110 QList<qreal> tmp; // Temp workspace.
110 QList<qreal> tmp; // Temp workspace.
111
111
112 qreal b = 2.0;
112 qreal b = 2.0;
113 x.append(rhs[0] / b);
113 x.append(rhs[0] / b);
114 tmp.append(0);
114 tmp.append(0);
115 for (int i = 1; i < rhs.size(); i++) // Decomposition and forward substitution.
115 for (int i = 1; i < rhs.size(); i++) // Decomposition and forward substitution.
116 {
116 {
117 tmp.append(1 / b);
117 tmp.append(1 / b);
118 b = (i < rhs.size() - 1 ? 4.0 : 3.5) - tmp[i];
118 b = (i < rhs.size() - 1 ? 4.0 : 3.5) - tmp[i];
119 x.append((rhs[i] - x[i - 1]) / b);
119 x.append((rhs[i] - x[i - 1]) / b);
120 }
120 }
121 for (int i = 1; i < rhs.size(); i++)
121 for (int i = 1; i < rhs.size(); i++)
122 x[rhs.size() - i - 1] -= tmp[rhs.size() - i] * x[rhs.size() - i]; // Backsubstitution.
122 x[rhs.size() - i - 1] -= tmp[rhs.size() - i] * x[rhs.size() - i]; // Backsubstitution.
123
123
124 return x;
124 return x;
125 }
125 }
126
126
127 /*!
127 /*!
128 \internal
128 \internal
129 Updates the control points, besed on currently avaiable knots.
129 Updates the control points, besed on currently avaiable knots.
130 */
130 */
131 void QSplineSeries::updateControlPoints()
131 void QSplineSeries::updateControlPoints()
132 {
132 {
133 if(m_x.size() > 1)
133 if(m_x.size() > 1)
134 {
134 {
135 m_controlPoints.clear();
135 m_controlPoints.clear();
136 calculateControlPoints();
136 calculateControlPoints();
137 }
137 }
138 }
138 }
139
139
140 #include "moc_qsplineseries.cpp"
140 #include "moc_qsplineseries.cpp"
141
141
142 QTCOMMERCIALCHART_END_NAMESPACE
142 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,42 +1,43
1 #ifndef QSPLINESERIES_H
1 #ifndef QSPLINESERIES_H
2 #define QSPLINESERIES_H
2 #define QSPLINESERIES_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QtGlobal>
5 #include <QtGlobal>
6 #include "qlineseries.h"
6 #include "qxyseries.h"
7 #include <QList>
7 #include <QList>
8 #include <QPointF>
8 #include <QPointF>
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 class QSplineSeries : public QLineSeries
12 class QTCOMMERCIALCHART_EXPORT QSplineSeries : public QXYSeries
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15 public:
15 public:
16
16
17 QSplineSeries(QObject *parent = 0);
17 QSplineSeries(QObject *parent = 0);
18 QSeriesType type() const { return QSeries::SeriesTypeSpline; }
18 QSeriesType type() const {return QSeries::SeriesTypeSpline;}
19
19
20 // int count() const { return m_x.size(); }
20 // int count() const { return m_x.size(); }
21 QPointF controlPoint(int index) const { return m_controlPoints[index]; }
21 QPointF controlPoint(int index) const {return m_controlPoints[index];}
22
22
23 // TODO: allow the user to set custom control points
23 // TODO: allow the user to set custom control points
24 // void setCustomControlPoints(QList<QPointsF> controlPoints);
24 // void setCustomControlPoints(QList<QPointsF> controlPoints);
25 // bool calculateControlPointsAutomatically();
25 // bool calculateControlPointsAutomatically();
26 // void setCalculateControlPointsAutomatically();
26 // void setCalculateControlPointsAutomatically();
27
27
28
28 private:
29 private:
29 void calculateControlPoints();
30 void calculateControlPoints();
30 QList<qreal> getFirstControlPoints(QList<qreal> rhs);
31 QList<qreal> getFirstControlPoints(QList<qreal> rhs);
31
32
32 private slots:
33 private slots:
33 void updateControlPoints();
34 void updateControlPoints();
34
35
35 private:
36 private:
36 QList<QPointF> m_controlPoints;
37 QList<QPointF> m_controlPoints;
37
38
38 };
39 };
39
40
40 QTCOMMERCIALCHART_END_NAMESPACE
41 QTCOMMERCIALCHART_END_NAMESPACE
41
42
42 #endif // QSPLINESERIES_H
43 #endif // QSPLINESERIES_H
@@ -1,189 +1,213
1 #include "qxyseries.h"
1 #include "qxyseries.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
5 /*!
6 \class QXYSeries
6 \class QXYSeries
7 \brief The QXYSeries class is used for making line charts.
7 \brief The QXYSeries class is used for making line charts.
8
8
9 \mainclass
9 \mainclass
10
10
11 A line chart is used to show information as a series of data points
11 A line chart is used to show information as a series of data points
12 connected by straight lines.
12 connected by straight lines.
13
13
14 \image linechart.png
14 \image linechart.png
15
15
16 Creating basic line chart is simple:
16 Creating basic line chart is simple:
17 \code
17 \code
18 QXYSeries* series = new QXYSeries();
18 QXYSeries* series = new QXYSeries();
19 series->add(0, 6);
19 series->add(0, 6);
20 series->add(2, 4);
20 series->add(2, 4);
21 ...
21 ...
22 chartView->addSeries(series);
22 chartView->addSeries(series);
23 \endcode
23 \endcode
24 */
24 */
25
25
26 /*!
26 /*!
27 \fn virtual QSeriesType QXYSeries::type() const
27 \fn virtual QSeriesType QXYSeries::type() const
28 \brief Returns type of series.
28 \brief Returns type of series.
29 \sa QSeries, QSeriesType
29 \sa QSeries, QSeriesType
30 */
30 */
31
31
32 /*!
32 /*!
33 \fn QPen QXYSeries::pen() const
33 \fn QPen QXYSeries::pen() const
34 \brief Returns the pen used to draw line for this series.
34 \brief Returns the pen used to draw line for this series.
35 \sa setPen()
35 \sa setPen()
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn bool QXYSeries::pointsVisible() const
39 \fn bool QXYSeries::pointsVisible() const
40 \brief Returns if the points are drawn for this series.
40 \brief Returns if the points are drawn for this series.
41 \sa setPointsVisible()
41 \sa setPointsVisible()
42 */
42 */
43
43
44
44
45 /*!
45 /*!
46 \fn void QXYSeries::pointReplaced(int index)
46 \fn void QXYSeries::pointReplaced(int index)
47 \brief \internal \a index
47 \brief \internal \a index
48 */
48 */
49
49
50 /*!
50 /*!
51 \fn void QXYSeries::pointAdded(int index)
51 \fn void QXYSeries::pointAdded(int index)
52 \brief \internal \a index
52 \brief \internal \a index
53 */
53 */
54
54
55 /*!
55 /*!
56 \fn void QXYSeries::pointRemoved(int index)
56 \fn void QXYSeries::pointRemoved(int index)
57 \brief \internal \a index
57 \brief \internal \a index
58 */
58 */
59
59
60 /*!
60 /*!
61 \fn void QXYSeries::updated()
61 \fn void QXYSeries::updated()
62 \brief \internal
62 \brief \internal
63 */
63 */
64
64
65 /*!
65 /*!
66 Constructs empty series object which is a child of \a parent.
66 Constructs empty series object which is a child of \a parent.
67 When series object is added to QChartView or QChart instance ownerships is transfered.
67 When series object is added to QChartView or QChart instance ownerships is transfered.
68 */
68 */
69 QXYSeries::QXYSeries(QObject* parent):QSeries(parent)
69 QXYSeries::QXYSeries(QObject* parent):QSeries(parent),
70 m_pointsVisible(false)
70 {
71 {
71 }
72 }
72 /*!
73 /*!
73 Destroys the object. Series added to QChartView or QChart instances are owned by those,
74 Destroys the object. Series added to QChartView or QChart instances are owned by those,
74 and are deleted when mentioned object are destroyed.
75 and are deleted when mentioned object are destroyed.
75 */
76 */
76 QXYSeries::~QXYSeries()
77 QXYSeries::~QXYSeries()
77 {
78 {
78 }
79 }
79
80
80 /*!
81 /*!
81 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
82 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
82 */
83 */
83 void QXYSeries::add(qreal x,qreal y)
84 void QXYSeries::add(qreal x,qreal y)
84 {
85 {
85 Q_ASSERT(m_x.size() == m_y.size());
86 Q_ASSERT(m_x.size() == m_y.size());
86 m_x<<x;
87 m_x<<x;
87 m_y<<y;
88 m_y<<y;
88 emit pointAdded(m_x.size()-1);
89 emit pointAdded(m_x.size()-1);
89 }
90 }
90
91
91 /*!
92 /*!
92 This is an overloaded function.
93 This is an overloaded function.
93 Adds data \a point to the series. Points are connected with lines on the chart.
94 Adds data \a point to the series. Points are connected with lines on the chart.
94 */
95 */
95 void QXYSeries::add(const QPointF& point)
96 void QXYSeries::add(const QPointF& point)
96 {
97 {
97 add(point.x(),point.y());
98 add(point.x(),point.y());
98 }
99 }
99
100
100 /*!
101 /*!
101 Modifies \a y value for given \a x a value.
102 Modifies \a y value for given \a x a value.
102 */
103 */
103 void QXYSeries::replace(qreal x,qreal y)
104 void QXYSeries::replace(qreal x,qreal y)
104 {
105 {
105 int index = m_x.indexOf(x);
106 int index = m_x.indexOf(x);
106 m_x[index]=x;
107 m_x[index]=x;
107 m_y[index]=y;
108 m_y[index]=y;
108 emit pointReplaced(index);
109 emit pointReplaced(index);
109 }
110 }
110
111
111 /*!
112 /*!
112 This is an overloaded function.
113 This is an overloaded function.
113 Replaces current y value of for given \a point x value with \a point y value.
114 Replaces current y value of for given \a point x value with \a point y value.
114 */
115 */
115 void QXYSeries::replace(const QPointF& point)
116 void QXYSeries::replace(const QPointF& point)
116 {
117 {
117 replace(point.x(),point.y());
118 replace(point.x(),point.y());
118 }
119 }
119
120
120 /*!
121 /*!
121 Removes current \a x and y value.
122 Removes current \a x and y value.
122 */
123 */
123 void QXYSeries::remove(qreal x)
124 void QXYSeries::remove(qreal x)
124 {
125 {
125 int index = m_x.indexOf(x);
126 int index = m_x.indexOf(x);
126 emit pointRemoved(index);
127 emit pointRemoved(index);
127 m_x.remove(index);
128 m_x.remove(index);
128 m_y.remove(index);
129 m_y.remove(index);
129 }
130 }
130
131
131 /*!
132 /*!
132 Removes current \a point x value. Note \a point y value is ignored.
133 Removes current \a point x value. Note \a point y value is ignored.
133 */
134 */
134 void QXYSeries::remove(const QPointF& point)
135 void QXYSeries::remove(const QPointF& point)
135 {
136 {
136 remove(point.x());
137 remove(point.x());
137 }
138 }
138
139
139 /*!
140 /*!
140 Clears all the data.
141 Clears all the data.
141 */
142 */
142 void QXYSeries::clear()
143 void QXYSeries::clear()
143 {
144 {
144 m_x.clear();
145 m_x.clear();
145 m_y.clear();
146 m_y.clear();
146 }
147 }
147
148
148 /*!
149 /*!
149 \internal \a pos
150 \internal \a pos
150 */
151 */
151 qreal QXYSeries::x(int pos) const
152 qreal QXYSeries::x(int pos) const
152 {
153 {
153 return m_x.at(pos);
154 return m_x.at(pos);
154 }
155 }
155
156
156 /*!
157 /*!
157 \internal \a pos
158 \internal \a pos
158 */
159 */
159 qreal QXYSeries::y(int pos) const
160 qreal QXYSeries::y(int pos) const
160 {
161 {
161 return m_y.at(pos);
162 return m_y.at(pos);
162 }
163 }
163
164
164 /*!
165 /*!
165 Returns number of data points within series.
166 Returns number of data points within series.
166 */
167 */
167 int QXYSeries::count() const
168 int QXYSeries::count() const
168 {
169 {
169 Q_ASSERT(m_x.size() == m_y.size());
170 Q_ASSERT(m_x.size() == m_y.size());
170
171
171 return m_x.size();
172 return m_x.size();
172
173
173 }
174 }
174
175
175 /*!
176 /*!
177 Sets \a pen used for drawing given series..
178 */
179 void QXYSeries::setPen(const QPen& pen)
180 {
181 if(pen!=m_pen){
182 m_pen=pen;
183 emit updated();
184 }
185 }
186
187 /*!
188 Sets if data points are \a visible and should be drawn on line.
189 */
190 void QXYSeries::setPointsVisible(bool visible)
191 {
192 if(m_pointsVisible!=visible){
193 m_pointsVisible=visible;
194 emit updated();
195 }
196 }
197
198
199 /*!
176 Stream operator for adding a data \a point to the series.
200 Stream operator for adding a data \a point to the series.
177 \sa add()
201 \sa add()
178 */
202 */
179
203
180 QXYSeries& QXYSeries::operator<< (const QPointF &point)
204 QXYSeries& QXYSeries::operator<< (const QPointF &point)
181 {
205 {
182 add(point);
206 add(point);
183 return *this;
207 return *this;
184 }
208 }
185
209
186
210
187 #include "moc_qxyseries.cpp"
211 #include "moc_qxyseries.cpp"
188
212
189 QTCOMMERCIALCHART_END_NAMESPACE
213 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,49 +1,58
1 #ifndef QXYSERIES_H_
1 #ifndef QXYSERIES_H_
2 #define QXYSERIES_H_
2 #define QXYSERIES_H_
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qseries.h"
5 #include "qseries.h"
6 #include <QDebug>
6 #include <QDebug>
7 #include <QPen>
7 #include <QPen>
8 #include <QBrush>
8 #include <QBrush>
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries
12 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15 public:
15 public:
16 QXYSeries(QObject* parent=0);
16 QXYSeries(QObject* parent=0);
17 virtual ~QXYSeries();
17 virtual ~QXYSeries();
18
18
19 public:
19 public:
20 void add(qreal x, qreal y);
20 void add(qreal x, qreal y);
21 void add(const QPointF& point);
21 void add(const QPointF& point);
22 void replace(qreal x,qreal y);
22 void replace(qreal x,qreal y);
23 void replace(const QPointF& point);
23 void replace(const QPointF& point);
24 void remove(qreal x);
24 void remove(qreal x);
25 void remove(const QPointF& point);
25 void remove(const QPointF& point);
26 void clear();
26 void clear();
27
27
28 int count() const;
28 int count() const;
29 qreal x(int pos) const;
29 qreal x(int pos) const;
30 qreal y(int pos) const;
30 qreal y(int pos) const;
31
31
32 QXYSeries& operator << (const QPointF &point);
32 QXYSeries& operator << (const QPointF &point);
33
33
34 void setPen(const QPen& pen);
35 QPen pen() const {return m_pen;}
36
37 void setPointsVisible(bool visible);
38 bool pointsVisible() const {return m_pointsVisible;}
39
34 signals:
40 signals:
35 void updated();
41 void updated();
36 void pointReplaced(int index);
42 void pointReplaced(int index);
37 void pointRemoved(int index);
43 void pointRemoved(int index);
38 void pointAdded(int index);
44 void pointAdded(int index);
39
45
40
46
41 protected:
47 protected:
42 QVector<qreal> m_x;
48 QVector<qreal> m_x;
43 QVector<qreal> m_y;
49 QVector<qreal> m_y;
44
50
51 QPen m_pen;
52 bool m_pointsVisible;
53
45 };
54 };
46
55
47 QTCOMMERCIALCHART_END_NAMESPACE
56 QTCOMMERCIALCHART_END_NAMESPACE
48
57
49 #endif
58 #endif
General Comments 0
You need to be logged in to leave comments. Login now