##// END OF EJS Templates
qxyseries doc update
Jani Honkonen -
r1336:8115fc705636
parent child
Show More
@@ -1,340 +1,361
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qxyseries.h"
21 #include "qxyseries.h"
22 #include "qxyseries_p.h"
22 #include "qxyseries_p.h"
23 #include "domain_p.h"
23 #include "domain_p.h"
24 #include "legendmarker_p.h"
24 #include "legendmarker_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QXYSeries
29 \class QXYSeries
30 \brief The QXYSeries class is a base class for line, spline and scatter series.
30 \brief The QXYSeries class is a base class for line, spline and scatter series.
31 */
31 */
32
32
33 /*!
33 /*!
34 \property QXYSeries::pointsVisible
35
36 Controls if the data points are visible and should be drawn.
37 */
38
39 /*!
40 \property QXYSeries::count
41
42 Number of points in the series.
43 */
44
45 /*!
34 \fn QPen QXYSeries::pen() const
46 \fn QPen QXYSeries::pen() const
35 \brief Returns pen used to draw points for series.
47 \brief Returns pen used to draw points for series.
36 \sa setPen()
48 \sa setPen()
37 */
49 */
38
50
39 /*!
51 /*!
40 \fn QBrush QXYSeries::brush() const
52 \fn QBrush QXYSeries::brush() const
41 \brief Returns brush used to draw points for series.
53 \brief Returns brush used to draw points for series.
42 \sa setBrush()
54 \sa setBrush()
43 */
55 */
44
56
45 /*!
57 /*!
46 \fn void QXYSeries::clicked(const QPointF& point)
58 \fn void QXYSeries::clicked(const QPointF& point)
47 \brief Signal is emitted when user clicks the \a point on chart.
59 \brief Signal is emitted when user clicks the \a point on chart.
48 */
60 */
49
61
50
51 /*!
62 /*!
52 \fn void QXYSeriesPrivate::pointReplaced(int index)
63 \fn void QXYSeries::pointReplaced(int index)
53 \brief \internal \a index
64 \brief Signal is emitted when user replaces a point at \a index.
65 \sa replace()
54 */
66 */
55
67
56 /*!
68 /*!
57 \fn void QXYSeriesPrivate::pointAdded(int index)
69 \fn void QXYSeries::pointAdded(int index)
58 \brief \internal \a index
70 \brief Signal is emitted when user adds a point at \a index.
71 \sa append(), insert()
59 */
72 */
60
73
61 /*!
74 /*!
62 \fn void QXYSeriesPrivate::pointRemoved(int index)
75 \fn void QXYSeries::pointRemoved(int index)
63 \brief \internal \a index
76 \brief Signal is emitted when user removes a point at \a index.
77 \sa remove()
64 */
78 */
65
79
66 /*!
80 /*!
67 \fn void QXYSeriesPrivate::updated()
81 \fn void QXYSeriesPrivate::updated()
68 \brief \internal
82 \brief \internal
69 */
83 */
70
84
71 /*!
85 /*!
72 \internal
86 \internal
73
87
74 Constructs empty series object which is a child of \a parent.
88 Constructs empty series object which is a child of \a parent.
75 When series object is added to QChartView or QChart instance ownerships is transferred.
89 When series object is added to QChartView or QChart instance ownerships is transferred.
76 */
90 */
77 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
91 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
78 {
92 {
79
93
80 }
94 }
81 /*!
95 /*!
82 Destroys the object. Series added to QChartView or QChart instances are owned by those,
96 Destroys the object. Series added to QChartView or QChart instances are owned by those,
83 and are deleted when mentioned object are destroyed.
97 and are deleted when mentioned object are destroyed.
84 */
98 */
85 QXYSeries::~QXYSeries()
99 QXYSeries::~QXYSeries()
86 {
100 {
87 }
101 }
88
102
89 /*!
103 /*!
90 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
104 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
91 */
105 */
92 void QXYSeries::append(qreal x,qreal y)
106 void QXYSeries::append(qreal x,qreal y)
93 {
107 {
94 append(QPointF(x,y));
108 append(QPointF(x,y));
95 }
109 }
96
110
97 /*!
111 /*!
98 This is an overloaded function.
112 This is an overloaded function.
99 Adds data \a point to the series. Points are connected with lines on the chart.
113 Adds data \a point to the series. Points are connected with lines on the chart.
100 */
114 */
101 void QXYSeries::append(const QPointF &point)
115 void QXYSeries::append(const QPointF &point)
102 {
116 {
103 Q_D(QXYSeries);
117 Q_D(QXYSeries);
104 d->m_points<<point;
118 d->m_points<<point;
105 // emit d->pointAdded(d->m_points.count()-1);
119 // emit d->pointAdded(d->m_points.count()-1);
106 emit pointAdded(d->m_points.count()-1);
120 emit pointAdded(d->m_points.count()-1);
107 }
121 }
108
122
109 /*!
123 /*!
110 This is an overloaded function.
124 This is an overloaded function.
111 Adds list of data \a points to the series. Points are connected with lines on the chart.
125 Adds list of data \a points to the series. Points are connected with lines on the chart.
112 */
126 */
113 void QXYSeries::append(const QList<QPointF> &points)
127 void QXYSeries::append(const QList<QPointF> &points)
114 {
128 {
115 foreach(const QPointF& point , points) {
129 foreach(const QPointF& point , points) {
116 append(point);
130 append(point);
117 }
131 }
118 }
132 }
119
133
120
134 /*!
135 Replaces data point \a oldX \a oldY with data point \a newX \a newY.
136 */
121 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
137 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
122 {
138 {
123 replace(QPointF(oldX,oldY),QPointF(newX,newY));
139 replace(QPointF(oldX,oldY),QPointF(newX,newY));
124 }
140 }
125
141
142 /*!
143 Replaces \a oldPoint with \a newPoint.
144 */
126 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
145 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
127 {
146 {
128 Q_D(QXYSeries);
147 Q_D(QXYSeries);
129 int index = d->m_points.indexOf(oldPoint);
148 int index = d->m_points.indexOf(oldPoint);
130 if(index==-1) return;
149 if(index==-1) return;
131 d->m_points[index] = newPoint;
150 d->m_points[index] = newPoint;
132 // emit d->pointReplaced(index);
151 // emit d->pointReplaced(index);
133 emit pointReplaced(index);
152 emit pointReplaced(index);
134 }
153 }
135
154
136 /*!
155 /*!
137 Removes current \a x and \a y value.
156 Removes current \a x and \a y value.
138 */
157 */
139 void QXYSeries::remove(qreal x,qreal y)
158 void QXYSeries::remove(qreal x,qreal y)
140 {
159 {
141 remove(QPointF(x,y));
160 remove(QPointF(x,y));
142 }
161 }
143
162
144 /*!
163 /*!
145 Removes current \a point x value. Note \a point y value is ignored.
164 Removes current \a point x value.
165
166 Note: point y value is ignored.
146 */
167 */
147 void QXYSeries::remove(const QPointF &point)
168 void QXYSeries::remove(const QPointF &point)
148 {
169 {
149 Q_D(QXYSeries);
170 Q_D(QXYSeries);
150 int index = d->m_points.indexOf(point);
171 int index = d->m_points.indexOf(point);
151 if(index==-1) return;
172 if(index==-1) return;
152 d->m_points.remove(index);
173 d->m_points.remove(index);
153 // emit d->pointRemoved(index);
174 // emit d->pointRemoved(index);
154 emit pointRemoved(index);
175 emit pointRemoved(index);
155 }
176 }
156
177
157 /*!
178 /*!
158 Removes all data points from the series.
179 Removes all data points from the series.
159 */
180 */
160 void QXYSeries::removeAll()
181 void QXYSeries::removeAll()
161 {
182 {
162 Q_D(QXYSeries);
183 Q_D(QXYSeries);
163 foreach(const QPointF& point, d->m_points) {
184 foreach(const QPointF& point, d->m_points) {
164 remove(point);
185 remove(point);
165 }
186 }
166 }
187 }
167
188
189 /*!
190 Inserts a \a point in the series at \a index position.
191 */
168 void QXYSeries::insert(int index, const QPointF &point)
192 void QXYSeries::insert(int index, const QPointF &point)
169 {
193 {
170 Q_D(QXYSeries);
194 Q_D(QXYSeries);
171 d->m_points.insert(index, point);
195 d->m_points.insert(index, point);
172 // emit d->pointAdded(index);
196 // emit d->pointAdded(index);
173 emit pointAdded(index);
197 emit pointAdded(index);
174 }
198 }
175
199
200 /*!
201 Removes all points from the series.
202 */
176 void QXYSeries::clear()
203 void QXYSeries::clear()
177 {
204 {
178 Q_D(QXYSeries);
205 Q_D(QXYSeries);
179 for (int i = d->m_points.size() - 1; i >= 0; i--)
206 for (int i = d->m_points.size() - 1; i >= 0; i--)
180 remove(d->m_points.at(i));
207 remove(d->m_points.at(i));
181 }
208 }
182
209
183 /*!
210 /*!
184 \internal \a pos
211 \internal \a pos
185 */
212 */
186 QList<QPointF> QXYSeries::points() const
213 QList<QPointF> QXYSeries::points() const
187 {
214 {
188 Q_D(const QXYSeries);
215 Q_D(const QXYSeries);
189 return d->m_points.toList();
216 return d->m_points.toList();
190 }
217 }
191
218
192 /*!
219 /*!
193 Returns number of data points within series.
220 Returns number of data points within series.
194 */
221 */
195 int QXYSeries::count() const
222 int QXYSeries::count() const
196 {
223 {
197 Q_D(const QXYSeries);
224 Q_D(const QXYSeries);
198 return d->m_points.count();
225 return d->m_points.count();
199 }
226 }
200
227
201
228
202 /*!
229 /*!
203 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
230 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
204 pen from chart theme is used.
231 pen from chart theme is used.
205 \sa QChart::setTheme()
232 \sa QChart::setTheme()
206 */
233 */
207 void QXYSeries::setPen(const QPen &pen)
234 void QXYSeries::setPen(const QPen &pen)
208 {
235 {
209 Q_D(QXYSeries);
236 Q_D(QXYSeries);
210 if (d->m_pen!=pen) {
237 if (d->m_pen!=pen) {
211 d->m_pen = pen;
238 d->m_pen = pen;
212 emit d->updated();
239 emit d->updated();
213 }
240 }
214 }
241 }
215
242
216 QPen QXYSeries::pen() const
243 QPen QXYSeries::pen() const
217 {
244 {
218 Q_D(const QXYSeries);
245 Q_D(const QXYSeries);
219 return d->m_pen;
246 return d->m_pen;
220 }
247 }
221
248
222 /*!
249 /*!
223 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
250 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
224 from chart theme setting is used.
251 from chart theme setting is used.
225 \sa QChart::setTheme()
252 \sa QChart::setTheme()
226 */
253 */
227 void QXYSeries::setBrush(const QBrush &brush)
254 void QXYSeries::setBrush(const QBrush &brush)
228 {
255 {
229 Q_D(QXYSeries);
256 Q_D(QXYSeries);
230 if (d->m_brush!=brush) {
257 if (d->m_brush!=brush) {
231 d->m_brush = brush;
258 d->m_brush = brush;
232 emit d->updated();
259 emit d->updated();
233 }
260 }
234 }
261 }
235
262
236 QBrush QXYSeries::brush() const
263 QBrush QXYSeries::brush() const
237 {
264 {
238 Q_D(const QXYSeries);
265 Q_D(const QXYSeries);
239 return d->m_brush;
266 return d->m_brush;
240 }
267 }
241
268
242
269
243 /*!
244 Sets if data points are \a visible and should be drawn on line.
245 */
246 void QXYSeries::setPointsVisible(bool visible)
270 void QXYSeries::setPointsVisible(bool visible)
247 {
271 {
248 Q_D(QXYSeries);
272 Q_D(QXYSeries);
249 if (d->m_pointsVisible != visible){
273 if (d->m_pointsVisible != visible){
250 d->m_pointsVisible = visible;
274 d->m_pointsVisible = visible;
251 emit d->updated();
275 emit d->updated();
252 }
276 }
253 }
277 }
254
278
255 /*!
256 Returns true if drawing the data points of the series is enabled.
257 */
258 bool QXYSeries::pointsVisible() const
279 bool QXYSeries::pointsVisible() const
259 {
280 {
260 Q_D(const QXYSeries);
281 Q_D(const QXYSeries);
261 return d->m_pointsVisible;
282 return d->m_pointsVisible;
262 }
283 }
263
284
264
285
265 /*!
286 /*!
266 Stream operator for adding a data \a point to the series.
287 Stream operator for adding a data \a point to the series.
267 \sa append()
288 \sa append()
268 */
289 */
269 QXYSeries& QXYSeries::operator<< (const QPointF &point)
290 QXYSeries& QXYSeries::operator<< (const QPointF &point)
270 {
291 {
271 append(point);
292 append(point);
272 return *this;
293 return *this;
273 }
294 }
274
295
275
296
276 /*!
297 /*!
277 Stream operator for adding a list of \a points to the series.
298 Stream operator for adding a list of \a points to the series.
278 \sa append()
299 \sa append()
279 */
300 */
280
301
281 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
302 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
282 {
303 {
283 append(points);
304 append(points);
284 return *this;
305 return *this;
285 }
306 }
286
307
287 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
308 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
288
309
289
310
290 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) :
311 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) :
291 QAbstractSeriesPrivate(q),
312 QAbstractSeriesPrivate(q),
292 m_pointsVisible(false)
313 m_pointsVisible(false)
293 {
314 {
294 }
315 }
295
316
296 void QXYSeriesPrivate::scaleDomain(Domain& domain)
317 void QXYSeriesPrivate::scaleDomain(Domain& domain)
297 {
318 {
298 qreal minX(domain.minX());
319 qreal minX(domain.minX());
299 qreal minY(domain.minY());
320 qreal minY(domain.minY());
300 qreal maxX(domain.maxX());
321 qreal maxX(domain.maxX());
301 qreal maxY(domain.maxY());
322 qreal maxY(domain.maxY());
302 int tickXCount(domain.tickXCount());
323 int tickXCount(domain.tickXCount());
303 int tickYCount(domain.tickYCount());
324 int tickYCount(domain.tickYCount());
304
325
305 Q_Q(QXYSeries);
326 Q_Q(QXYSeries);
306
327
307 const QList<QPointF>& points = q->points();
328 const QList<QPointF>& points = q->points();
308
329
309
330
310 if(points.isEmpty()){
331 if(points.isEmpty()){
311 minX=0.0;
332 minX=0.0;
312 minY=0.0;
333 minY=0.0;
313 maxX=1.0;
334 maxX=1.0;
314 maxY=1.0;
335 maxY=1.0;
315 }
336 }
316
337
317 for (int i = 0; i < points.count(); i++)
338 for (int i = 0; i < points.count(); i++)
318 {
339 {
319 qreal x = points[i].x();
340 qreal x = points[i].x();
320 qreal y = points[i].y();
341 qreal y = points[i].y();
321 minX = qMin(minX, x);
342 minX = qMin(minX, x);
322 minY = qMin(minY, y);
343 minY = qMin(minY, y);
323 maxX = qMax(maxX, x);
344 maxX = qMax(maxX, x);
324 maxY = qMax(maxY, y);
345 maxY = qMax(maxY, y);
325 }
346 }
326
347
327 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
348 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
328 }
349 }
329
350
330 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
351 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
331 {
352 {
332 Q_Q(QXYSeries);
353 Q_Q(QXYSeries);
333 QList<LegendMarker*> list;
354 QList<LegendMarker*> list;
334 return list << new XYLegendMarker(q,legend);
355 return list << new XYLegendMarker(q,legend);
335 }
356 }
336
357
337 #include "moc_qxyseries.cpp"
358 #include "moc_qxyseries.cpp"
338 #include "moc_qxyseries_p.cpp"
359 #include "moc_qxyseries_p.cpp"
339
360
340 QTCOMMERCIALCHART_END_NAMESPACE
361 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now