##// END OF EJS Templates
Limit code presented on qlineseries docs
Michal Klocek -
r369:c421a07af9b9
parent child
Show More
@@ -1,195 +1,191
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 To create line charts, users need to first QLineSeries object.
16 Creating basic line chart is simple:
17
17 \code
18 \snippet ../example/linechart/main.cpp 1
18 QLineSeries* series = new QLineSeries();
19
19 series->add(0, 6);
20 Populate with the data
20 series->add(2, 4);
21
21 ...
22 \snippet ../example/linechart/main.cpp 2
22 chartView->addSeries(series);
23
23 \endcode
24 Add created series objects to QChartView or QChart instance.
25
26 \snippet ../example/linechart/main.cpp 3
27
28 */
24 */
29
25
30 /*!
26 /*!
31 \fn virtual QSeriesType QLineSeries::type() const
27 \fn virtual QSeriesType QLineSeries::type() const
32 \brief Returns type of series.
28 \brief Returns type of series.
33 \sa QSeries, QSeriesType
29 \sa QSeries, QSeriesType
34 */
30 */
35
31
36 /*!
32 /*!
37 \fn QPen QLineSeries::pen() const
33 \fn QPen QLineSeries::pen() const
38 \brief Returns the pen used to draw line for this series.
34 \brief Returns the pen used to draw line for this series.
39 \sa setPen()
35 \sa setPen()
40 */
36 */
41
37
42 /*!
38 /*!
43 \fn bool QLineSeries::pointsVisible() const
39 \fn bool QLineSeries::pointsVisible() const
44 \brief Returns if the points are drawn for this series.
40 \brief Returns if the points are drawn for this series.
45 \sa setPointsVisible()
41 \sa setPointsVisible()
46 */
42 */
47
43
48
44
49 /*!
45 /*!
50 \fn void QLineSeries::changed(int index)
46 \fn void QLineSeries::changed(int index)
51 \brief \internal \a index
47 \brief \internal \a index
52 */
48 */
53
49
54 /*!
50 /*!
55 Constructs empty series object which is a child of \a parent.
51 Constructs empty series object which is a child of \a parent.
56 When series object is added to QChartView or QChart instance ownerships is transfered.
52 When series object is added to QChartView or QChart instance ownerships is transfered.
57 */
53 */
58 QLineSeries::QLineSeries(QObject* parent):QSeries(parent),
54 QLineSeries::QLineSeries(QObject* parent):QSeries(parent),
59 m_pointsVisible(false)
55 m_pointsVisible(false)
60 {
56 {
61 }
57 }
62 /*!
58 /*!
63 Destroys the object. Series added to QChartView or QChart instances are owned by those,
59 Destroys the object. Series added to QChartView or QChart instances are owned by those,
64 and are deleted when mentioned object are destroyed.
60 and are deleted when mentioned object are destroyed.
65 */
61 */
66 QLineSeries::~QLineSeries()
62 QLineSeries::~QLineSeries()
67 {
63 {
68 }
64 }
69
65
70 /*!
66 /*!
71 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
67 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
72 */
68 */
73 void QLineSeries::add(qreal x,qreal y)
69 void QLineSeries::add(qreal x,qreal y)
74 {
70 {
75 m_x<<x;
71 m_x<<x;
76 m_y<<y;
72 m_y<<y;
77 }
73 }
78
74
79 /*!
75 /*!
80 This is an overloaded function.
76 This is an overloaded function.
81 Adds data \a point to the series. Points are connected with lines on the chart.
77 Adds data \a point to the series. Points are connected with lines on the chart.
82 */
78 */
83 void QLineSeries::add(const QPointF& point)
79 void QLineSeries::add(const QPointF& point)
84 {
80 {
85 m_x<<point.x();
81 m_x<<point.x();
86 m_y<<point.y();
82 m_y<<point.y();
87 }
83 }
88
84
89 /*!
85 /*!
90 Modifies \a y value for given \a x a value.
86 Modifies \a y value for given \a x a value.
91 */
87 */
92 void QLineSeries::replace(qreal x,qreal y)
88 void QLineSeries::replace(qreal x,qreal y)
93 {
89 {
94 int index = m_x.indexOf(x);
90 int index = m_x.indexOf(x);
95 m_x[index]=x;
91 m_x[index]=x;
96 m_y[index]=y;
92 m_y[index]=y;
97 emit changed(index);
93 emit changed(index);
98 }
94 }
99
95
100 /*!
96 /*!
101 This is an overloaded function.
97 This is an overloaded function.
102 Replaces current y value of for given \a point x value with \a point y value.
98 Replaces current y value of for given \a point x value with \a point y value.
103 */
99 */
104 void QLineSeries::replace(const QPointF& point)
100 void QLineSeries::replace(const QPointF& point)
105 {
101 {
106 int index = m_x.indexOf(point.x());
102 int index = m_x.indexOf(point.x());
107 m_x[index]=point.x();
103 m_x[index]=point.x();
108 m_y[index]=point.y();
104 m_y[index]=point.y();
109 emit changed(index);
105 emit changed(index);
110 }
106 }
111
107
112 /*!
108 /*!
113 Removes current \a x and y value.
109 Removes current \a x and y value.
114 */
110 */
115 void QLineSeries::remove(qreal x)
111 void QLineSeries::remove(qreal x)
116 {
112 {
117
113
118 }
114 }
119
115
120 /*!
116 /*!
121 Removes current \a point x value. Note \a point y value is ignored.
117 Removes current \a point x value. Note \a point y value is ignored.
122 */
118 */
123 void QLineSeries::remove(const QPointF& point)
119 void QLineSeries::remove(const QPointF& point)
124 {
120 {
125
121
126 }
122 }
127
123
128 /*!
124 /*!
129 Clears all the data.
125 Clears all the data.
130 */
126 */
131 void QLineSeries::clear()
127 void QLineSeries::clear()
132 {
128 {
133 m_x.clear();
129 m_x.clear();
134 m_y.clear();
130 m_y.clear();
135 }
131 }
136
132
137 /*!
133 /*!
138 \internal \a pos
134 \internal \a pos
139 */
135 */
140 qreal QLineSeries::x(int pos) const
136 qreal QLineSeries::x(int pos) const
141 {
137 {
142 return m_x.at(pos);
138 return m_x.at(pos);
143 }
139 }
144
140
145 /*!
141 /*!
146 \internal \a pos
142 \internal \a pos
147 */
143 */
148 qreal QLineSeries::y(int pos) const
144 qreal QLineSeries::y(int pos) const
149 {
145 {
150 return m_y.at(pos);
146 return m_y.at(pos);
151 }
147 }
152
148
153 /*!
149 /*!
154 Returns number of data points within series.
150 Returns number of data points within series.
155 */
151 */
156 int QLineSeries::count() const
152 int QLineSeries::count() const
157 {
153 {
158 Q_ASSERT(m_x.size() == m_y.size());
154 Q_ASSERT(m_x.size() == m_y.size());
159
155
160 return m_x.size();
156 return m_x.size();
161
157
162 }
158 }
163
159
164 /*!
160 /*!
165 Sets \a pen used for drawing given series..
161 Sets \a pen used for drawing given series..
166 */
162 */
167 void QLineSeries::setPen(const QPen& pen)
163 void QLineSeries::setPen(const QPen& pen)
168 {
164 {
169 m_pen=pen;
165 m_pen=pen;
170 }
166 }
171
167
172 /*!
168 /*!
173 Sets if data points are \a visible and should be drawn on line.
169 Sets if data points are \a visible and should be drawn on line.
174 */
170 */
175 void QLineSeries::setPointsVisible(bool visible)
171 void QLineSeries::setPointsVisible(bool visible)
176 {
172 {
177 m_pointsVisible=visible;
173 m_pointsVisible=visible;
178 }
174 }
179
175
180 QDebug operator<< (QDebug debug, const QLineSeries series)
176 QDebug operator<< (QDebug debug, const QLineSeries series)
181 {
177 {
182 Q_ASSERT(series.m_x.size() == series.m_y.size());
178 Q_ASSERT(series.m_x.size() == series.m_y.size());
183
179
184 int size = series.m_x.size();
180 int size = series.m_x.size();
185
181
186 for (int i=0;i<size;i++) {
182 for (int i=0;i<size;i++) {
187 debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") ";
183 debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") ";
188 }
184 }
189 return debug.space();
185 return debug.space();
190 }
186 }
191
187
192
188
193 #include "moc_qlineseries.cpp"
189 #include "moc_qlineseries.cpp"
194
190
195 QTCOMMERCIALCHART_END_NAMESPACE
191 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now