##// END OF EJS Templates
QXYSeries::insert(): Handle out-of-range indexes gracefully....
Friedemann Kleint -
r2772:8fa17eb15940
parent child
Show More
@@ -1,862 +1,863
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.io
5 ** For any questions to Digia, please use contact form at http://qt.io
6 **
6 **
7 ** This file is part of the Qt Charts module.
7 ** This file is part of the Qt Charts module.
8 **
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and Digia.
12 ** agreement between you and Digia.
13 **
13 **
14 ** If you have questions regarding the use of this file, please use
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
15 ** contact form at http://qt.io
16 **
16 **
17 ****************************************************************************/
17 ****************************************************************************/
18
18
19 #include <QtCharts/QXYSeries>
19 #include <QtCharts/QXYSeries>
20 #include <private/qxyseries_p.h>
20 #include <private/qxyseries_p.h>
21 #include <private/abstractdomain_p.h>
21 #include <private/abstractdomain_p.h>
22 #include <QtCharts/QValueAxis>
22 #include <QtCharts/QValueAxis>
23 #include <private/xychart_p.h>
23 #include <private/xychart_p.h>
24 #include <QtCharts/QXYLegendMarker>
24 #include <QtCharts/QXYLegendMarker>
25 #include <private/charthelpers_p.h>
25 #include <private/charthelpers_p.h>
26 #include <private/qchart_p.h>
26 #include <private/qchart_p.h>
27 #include <QtGui/QPainter>
27 #include <QtGui/QPainter>
28
28
29 QT_CHARTS_BEGIN_NAMESPACE
29 QT_CHARTS_BEGIN_NAMESPACE
30
30
31 /*!
31 /*!
32 \class QXYSeries
32 \class QXYSeries
33 \inmodule Qt Charts
33 \inmodule Qt Charts
34 \brief The QXYSeries class is a base class for line, spline and scatter series.
34 \brief The QXYSeries class is a base class for line, spline and scatter series.
35 */
35 */
36 /*!
36 /*!
37 \qmltype XYSeries
37 \qmltype XYSeries
38 \instantiates QXYSeries
38 \instantiates QXYSeries
39 \inqmlmodule QtCharts
39 \inqmlmodule QtCharts
40
40
41 \inherits AbstractSeries
41 \inherits AbstractSeries
42
42
43 \brief The XYSeries type is a base type for line, spline and scatter series.
43 \brief The XYSeries type is a base type for line, spline and scatter series.
44
44
45 The XYSeries class is a base class for line, spline and scatter series.
45 The XYSeries class is a base class for line, spline and scatter series.
46 The class cannot be instantiated directly.
46 The class cannot be instantiated directly.
47 */
47 */
48
48
49 /*!
49 /*!
50 \qmlproperty AbstractAxis XYSeries::axisX
50 \qmlproperty AbstractAxis XYSeries::axisX
51 The x axis used for the series. If you leave both axisX and axisXTop undefined, a ValueAxis is created for
51 The x axis used for the series. If you leave both axisX and axisXTop undefined, a ValueAxis is created for
52 the series.
52 the series.
53 \sa axisXTop
53 \sa axisXTop
54 */
54 */
55
55
56 /*!
56 /*!
57 \qmlproperty AbstractAxis XYSeries::axisY
57 \qmlproperty AbstractAxis XYSeries::axisY
58 The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for
58 The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for
59 the series.
59 the series.
60 \sa axisYRight
60 \sa axisYRight
61 */
61 */
62
62
63 /*!
63 /*!
64 \qmlproperty AbstractAxis XYSeries::axisXTop
64 \qmlproperty AbstractAxis XYSeries::axisXTop
65 The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or
65 The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or
66 axisXTop, but not both.
66 axisXTop, but not both.
67 \sa axisX
67 \sa axisX
68 */
68 */
69
69
70 /*!
70 /*!
71 \qmlproperty AbstractAxis XYSeries::axisYRight
71 \qmlproperty AbstractAxis XYSeries::axisYRight
72 The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY
72 The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY
73 or axisYRight, but not both.
73 or axisYRight, but not both.
74 \sa axisY
74 \sa axisY
75 */
75 */
76
76
77 /*!
77 /*!
78 \qmlproperty AbstractAxis XYSeries::axisAngular
78 \qmlproperty AbstractAxis XYSeries::axisAngular
79 The angular axis used for the series, drawn around the polar chart view.
79 The angular axis used for the series, drawn around the polar chart view.
80 \sa axisX
80 \sa axisX
81 */
81 */
82
82
83 /*!
83 /*!
84 \qmlproperty AbstractAxis XYSeries::axisRadial
84 \qmlproperty AbstractAxis XYSeries::axisRadial
85 The radial axis used for the series, drawn inside the polar chart view.
85 The radial axis used for the series, drawn inside the polar chart view.
86 \sa axisY
86 \sa axisY
87 */
87 */
88
88
89 /*!
89 /*!
90 \property QXYSeries::pointsVisible
90 \property QXYSeries::pointsVisible
91 Controls if the data points are visible and should be drawn.
91 Controls if the data points are visible and should be drawn.
92 */
92 */
93 /*!
93 /*!
94 \qmlproperty bool XYSeries::pointsVisible
94 \qmlproperty bool XYSeries::pointsVisible
95 Controls if the data points are visible and should be drawn.
95 Controls if the data points are visible and should be drawn.
96 */
96 */
97
97
98 /*!
98 /*!
99 \fn QPen QXYSeries::pen() const
99 \fn QPen QXYSeries::pen() const
100 \brief Returns pen used to draw points for series.
100 \brief Returns pen used to draw points for series.
101 \sa setPen()
101 \sa setPen()
102 */
102 */
103
103
104 /*!
104 /*!
105 \fn QBrush QXYSeries::brush() const
105 \fn QBrush QXYSeries::brush() const
106 \brief Returns brush used to draw points for series.
106 \brief Returns brush used to draw points for series.
107 \sa setBrush()
107 \sa setBrush()
108 */
108 */
109
109
110 /*!
110 /*!
111 \property QXYSeries::color
111 \property QXYSeries::color
112 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
112 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
113 fill (brush) color in case of QScatterSeries or QAreaSeries.
113 fill (brush) color in case of QScatterSeries or QAreaSeries.
114 \sa QXYSeries::pen(), QXYSeries::brush()
114 \sa QXYSeries::pen(), QXYSeries::brush()
115 */
115 */
116 /*!
116 /*!
117 \qmlproperty color XYSeries::color
117 \qmlproperty color XYSeries::color
118 The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and
118 The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and
119 fill (brush) color in case of ScatterSeries or AreaSeries.
119 fill (brush) color in case of ScatterSeries or AreaSeries.
120 */
120 */
121
121
122 /*!
122 /*!
123 \property QXYSeries::pointLabelsFormat
123 \property QXYSeries::pointLabelsFormat
124 The \a format used for showing labels with series points.
124 The \a format used for showing labels with series points.
125
125
126 QXYSeries supports the following format tags:
126 QXYSeries supports the following format tags:
127 \table
127 \table
128 \row
128 \row
129 \li @xPoint \li The x value of the data point
129 \li @xPoint \li The x value of the data point
130 \row
130 \row
131 \li @yPoint \li The y value of the data point
131 \li @yPoint \li The y value of the data point
132 \endtable
132 \endtable
133
133
134 For example, the following usage of the format tags would produce labels that have the data
134 For example, the following usage of the format tags would produce labels that have the data
135 point (x, y) shown inside brackets separated by a comma:
135 point (x, y) shown inside brackets separated by a comma:
136 \code
136 \code
137 series->setPointLabelsFormat("(@xPoint, @yPoint)");
137 series->setPointLabelsFormat("(@xPoint, @yPoint)");
138 \endcode
138 \endcode
139
139
140 By default, the labels format is set to '@xPoint, @yPoint'. The labels are shown on the plot
140 By default, the labels format is set to '@xPoint, @yPoint'. The labels are shown on the plot
141 area, labels on the edge of the plot area are cut. If the points are close to each other the
141 area, labels on the edge of the plot area are cut. If the points are close to each other the
142 labels may overlap.
142 labels may overlap.
143
143
144 \sa QXYSeries::pointLabelsVisible, QXYSeries::pointLabelsFont, QXYSeries::pointLabelsColor
144 \sa QXYSeries::pointLabelsVisible, QXYSeries::pointLabelsFont, QXYSeries::pointLabelsColor
145 */
145 */
146 /*!
146 /*!
147 \qmlproperty string XYSeries::pointLabelsFormat
147 \qmlproperty string XYSeries::pointLabelsFormat
148 The \a format used for showing labels with series points.
148 The \a format used for showing labels with series points.
149
149
150 \sa QXYSeries::pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor
150 \sa QXYSeries::pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor
151 */
151 */
152 /*!
152 /*!
153 \fn void QXYSeries::pointLabelsFormatChanged(const QString &format)
153 \fn void QXYSeries::pointLabelsFormatChanged(const QString &format)
154 Signal is emitted when the \a format of data point labels is changed.
154 Signal is emitted when the \a format of data point labels is changed.
155 */
155 */
156 /*!
156 /*!
157 \qmlsignal XYSeries::onPointLabelsFormatChanged(string format)
157 \qmlsignal XYSeries::onPointLabelsFormatChanged(string format)
158 Signal is emitted when the \a format of data point labels is changed.
158 Signal is emitted when the \a format of data point labels is changed.
159 */
159 */
160
160
161 /*!
161 /*!
162 \property QXYSeries::pointLabelsVisible
162 \property QXYSeries::pointLabelsVisible
163 Defines the visibility for data point labels. False by default.
163 Defines the visibility for data point labels. False by default.
164
164
165 \sa QXYSeries::pointLabelsFormat
165 \sa QXYSeries::pointLabelsFormat
166 */
166 */
167 /*!
167 /*!
168 \qmlproperty bool XYSeries::pointLabelsVisible
168 \qmlproperty bool XYSeries::pointLabelsVisible
169 Defines the visibility for data point labels.
169 Defines the visibility for data point labels.
170
170
171 \sa pointLabelsFormat
171 \sa pointLabelsFormat
172 */
172 */
173 /*!
173 /*!
174 \fn void QXYSeries::pointLabelsVisibilityChanged(bool visible)
174 \fn void QXYSeries::pointLabelsVisibilityChanged(bool visible)
175 The visibility of the data point labels is changed to \a visible.
175 The visibility of the data point labels is changed to \a visible.
176 */
176 */
177 /*!
177 /*!
178 \qmlsignal XYSeries::onPointLabelsVisibilityChanged(bool visible)
178 \qmlsignal XYSeries::onPointLabelsVisibilityChanged(bool visible)
179 The visibility of the data point labels is changed to \a visible.
179 The visibility of the data point labels is changed to \a visible.
180 */
180 */
181
181
182 /*!
182 /*!
183 \property QXYSeries::pointLabelsFont
183 \property QXYSeries::pointLabelsFont
184 Defines the font used for data point labels.
184 Defines the font used for data point labels.
185
185
186 \sa QXYSeries::pointLabelsFormat
186 \sa QXYSeries::pointLabelsFormat
187 */
187 */
188 /*!
188 /*!
189 \qmlproperty font XYSeries::pointLabelsFont
189 \qmlproperty font XYSeries::pointLabelsFont
190 Defines the font used for data point labels.
190 Defines the font used for data point labels.
191
191
192 \sa pointLabelsFormat
192 \sa pointLabelsFormat
193 */
193 */
194 /*!
194 /*!
195 \fn void QXYSeries::pointLabelsFontChanged(const QFont &font);
195 \fn void QXYSeries::pointLabelsFontChanged(const QFont &font);
196 The font used for data point labels is changed to \a font.
196 The font used for data point labels is changed to \a font.
197 */
197 */
198 /*!
198 /*!
199 \qmlsignal XYSeries::onPointLabelsFontChanged(Font font)
199 \qmlsignal XYSeries::onPointLabelsFontChanged(Font font)
200 The font used for data point labels is changed to \a font.
200 The font used for data point labels is changed to \a font.
201 */
201 */
202
202
203 /*!
203 /*!
204 \property QXYSeries::pointLabelsColor
204 \property QXYSeries::pointLabelsColor
205 Defines the color used for data point labels. By default, the color is the color of the brush
205 Defines the color used for data point labels. By default, the color is the color of the brush
206 defined in theme for labels.
206 defined in theme for labels.
207
207
208 \sa QXYSeries::pointLabelsFormat
208 \sa QXYSeries::pointLabelsFormat
209 */
209 */
210 /*!
210 /*!
211 \qmlproperty font XYSeries::pointLabelsColor
211 \qmlproperty font XYSeries::pointLabelsColor
212 Defines the color used for data point labels. By default, the color is the color of the brush
212 Defines the color used for data point labels. By default, the color is the color of the brush
213 defined in theme for labels.
213 defined in theme for labels.
214
214
215 \sa pointLabelsFormat
215 \sa pointLabelsFormat
216 */
216 */
217 /*!
217 /*!
218 \fn void QXYSeries::pointLabelsColorChanged(const QColor &color);
218 \fn void QXYSeries::pointLabelsColorChanged(const QColor &color);
219 The color used for data point labels is changed to \a color.
219 The color used for data point labels is changed to \a color.
220 */
220 */
221 /*!
221 /*!
222 \qmlsignal XYSeries::onPointLabelsColorChanged(Color color)
222 \qmlsignal XYSeries::onPointLabelsColorChanged(Color color)
223 The color used for data point labels is changed to \a color.
223 The color used for data point labels is changed to \a color.
224 */
224 */
225
225
226 /*!
226 /*!
227 \fn void QXYSeries::clicked(const QPointF& point)
227 \fn void QXYSeries::clicked(const QPointF& point)
228 \brief Signal is emitted when user clicks the \a point on chart. The \a point is the point
228 \brief Signal is emitted when user clicks the \a point on chart. The \a point is the point
229 where the press was triggered.
229 where the press was triggered.
230 \sa pressed, released, doubleClicked
230 \sa pressed, released, doubleClicked
231 */
231 */
232 /*!
232 /*!
233 \qmlsignal XYSeries::onClicked(QPointF point)
233 \qmlsignal XYSeries::onClicked(QPointF point)
234 Signal is emitted when user clicks the \a point on chart. The \a point is the point where the
234 Signal is emitted when user clicks the \a point on chart. The \a point is the point where the
235 press was triggered. For example:
235 press was triggered. For example:
236 \code
236 \code
237 LineSeries {
237 LineSeries {
238 XYPoint { x: 0; y: 0 }
238 XYPoint { x: 0; y: 0 }
239 XYPoint { x: 1.1; y: 2.1 }
239 XYPoint { x: 1.1; y: 2.1 }
240 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
240 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
241 }
241 }
242 \endcode
242 \endcode
243 \sa onPressed, onReleased, onDoubleClicked
243 \sa onPressed, onReleased, onDoubleClicked
244 */
244 */
245
245
246 /*!
246 /*!
247 \fn void QXYSeries::hovered(const QPointF &point, bool state)
247 \fn void QXYSeries::hovered(const QPointF &point, bool state)
248 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
248 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
249 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
249 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
250 the series.
250 the series.
251 */
251 */
252 /*!
252 /*!
253 \qmlsignal XYSeries::onHovered(point point, bool state)
253 \qmlsignal XYSeries::onHovered(point point, bool state)
254 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
254 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
255 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
255 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
256 the series.
256 the series.
257 */
257 */
258
258
259 /*!
259 /*!
260 \fn void QXYSeries::pressed(const QPointF& point)
260 \fn void QXYSeries::pressed(const QPointF& point)
261 \brief Signal is emitted when user presses the \a point on chart.
261 \brief Signal is emitted when user presses the \a point on chart.
262 \sa clicked, released, doubleClicked
262 \sa clicked, released, doubleClicked
263 */
263 */
264 /*!
264 /*!
265 \qmlsignal XYSeries::onPressed(QPointF point)
265 \qmlsignal XYSeries::onPressed(QPointF point)
266 Signal is emitted when user presses the \a point on chart. For example:
266 Signal is emitted when user presses the \a point on chart. For example:
267 \code
267 \code
268 LineSeries {
268 LineSeries {
269 XYPoint { x: 0; y: 0 }
269 XYPoint { x: 0; y: 0 }
270 XYPoint { x: 1.1; y: 2.1 }
270 XYPoint { x: 1.1; y: 2.1 }
271 onPressed: console.log("onPressed: " + point.x + ", " + point.y);
271 onPressed: console.log("onPressed: " + point.x + ", " + point.y);
272 }
272 }
273 \endcode
273 \endcode
274 \sa onClicked, onReleased, onDoubleClicked
274 \sa onClicked, onReleased, onDoubleClicked
275 */
275 */
276
276
277 /*!
277 /*!
278 \fn void QXYSeries::released(const QPointF& point)
278 \fn void QXYSeries::released(const QPointF& point)
279 \brief Signal is emitted when user releases a press that was triggered on a \a point on chart.
279 \brief Signal is emitted when user releases a press that was triggered on a \a point on chart.
280 \sa pressed, clicked, doubleClicked
280 \sa pressed, clicked, doubleClicked
281 */
281 */
282 /*!
282 /*!
283 \qmlsignal XYSeries::onReleased(QPointF point)
283 \qmlsignal XYSeries::onReleased(QPointF point)
284 Signal is emitted when user releases a press that was triggered on a \a point on chart.
284 Signal is emitted when user releases a press that was triggered on a \a point on chart.
285 For example:
285 For example:
286 \code
286 \code
287 LineSeries {
287 LineSeries {
288 XYPoint { x: 0; y: 0 }
288 XYPoint { x: 0; y: 0 }
289 XYPoint { x: 1.1; y: 2.1 }
289 XYPoint { x: 1.1; y: 2.1 }
290 onReleased: console.log("onReleased: " + point.x + ", " + point.y);
290 onReleased: console.log("onReleased: " + point.x + ", " + point.y);
291 }
291 }
292 \endcode
292 \endcode
293 \sa onPressed, onClicked, onDoubleClicked
293 \sa onPressed, onClicked, onDoubleClicked
294 */
294 */
295
295
296 /*!
296 /*!
297 \fn void QXYSeries::doubleClicked(const QPointF& point)
297 \fn void QXYSeries::doubleClicked(const QPointF& point)
298 \brief Signal is emitted when user doubleclicks the \a point on chart. The \a point is the
298 \brief Signal is emitted when user doubleclicks the \a point on chart. The \a point is the
299 point where the first press was triggered.
299 point where the first press was triggered.
300 \sa pressed, released, clicked
300 \sa pressed, released, clicked
301 */
301 */
302 /*!
302 /*!
303 \qmlsignal XYSeries::onDoubleClicked(QPointF point)
303 \qmlsignal XYSeries::onDoubleClicked(QPointF point)
304 Signal is emitted when user doubleclicks the \a point on chart. The \a point is the point where
304 Signal is emitted when user doubleclicks the \a point on chart. The \a point is the point where
305 the first press was triggered. For example:
305 the first press was triggered. For example:
306 \code
306 \code
307 LineSeries {
307 LineSeries {
308 XYPoint { x: 0; y: 0 }
308 XYPoint { x: 0; y: 0 }
309 XYPoint { x: 1.1; y: 2.1 }
309 XYPoint { x: 1.1; y: 2.1 }
310 onDoubleClicked: console.log("onDoubleClicked: " + point.x + ", " + point.y);
310 onDoubleClicked: console.log("onDoubleClicked: " + point.x + ", " + point.y);
311 }
311 }
312 \endcode
312 \endcode
313 \sa onPressed, onReleased, onClicked
313 \sa onPressed, onReleased, onClicked
314 */
314 */
315
315
316 /*!
316 /*!
317 \fn void QXYSeries::pointReplaced(int index)
317 \fn void QXYSeries::pointReplaced(int index)
318 Signal is emitted when a point has been replaced at \a index.
318 Signal is emitted when a point has been replaced at \a index.
319 \sa replace()
319 \sa replace()
320 */
320 */
321 /*!
321 /*!
322 \qmlsignal XYSeries::onPointReplaced(int index)
322 \qmlsignal XYSeries::onPointReplaced(int index)
323 Signal is emitted when a point has been replaced at \a index.
323 Signal is emitted when a point has been replaced at \a index.
324 */
324 */
325
325
326 /*!
326 /*!
327 \fn void QXYSeries::pointsReplaced()
327 \fn void QXYSeries::pointsReplaced()
328 Signal is emitted when all points have been replaced with other points.
328 Signal is emitted when all points have been replaced with other points.
329 \sa replace()
329 \sa replace()
330 */
330 */
331 /*!
331 /*!
332 \qmlsignal XYSeries::onPointsReplaced()
332 \qmlsignal XYSeries::onPointsReplaced()
333 Signal is emitted when all points have been replaced with other points.
333 Signal is emitted when all points have been replaced with other points.
334 */
334 */
335
335
336 /*!
336 /*!
337 \fn void QXYSeries::pointAdded(int index)
337 \fn void QXYSeries::pointAdded(int index)
338 Signal is emitted when a point has been added at \a index.
338 Signal is emitted when a point has been added at \a index.
339 \sa append(), insert()
339 \sa append(), insert()
340 */
340 */
341 /*!
341 /*!
342 \qmlsignal XYSeries::onPointAdded(int index)
342 \qmlsignal XYSeries::onPointAdded(int index)
343 Signal is emitted when a point has been added at \a index.
343 Signal is emitted when a point has been added at \a index.
344 */
344 */
345
345
346 /*!
346 /*!
347 \fn void QXYSeries::pointRemoved(int index)
347 \fn void QXYSeries::pointRemoved(int index)
348 Signal is emitted when a point has been removed from \a index.
348 Signal is emitted when a point has been removed from \a index.
349 \sa remove()
349 \sa remove()
350 */
350 */
351
351
352 /*!
352 /*!
353 \qmlsignal XYSeries::onPointRemoved(int index)
353 \qmlsignal XYSeries::onPointRemoved(int index)
354 Signal is emitted when a point has been removed from \a index.
354 Signal is emitted when a point has been removed from \a index.
355 */
355 */
356
356
357 /*!
357 /*!
358 \fn void QXYSeries::colorChanged(QColor color)
358 \fn void QXYSeries::colorChanged(QColor color)
359 \brief Signal is emitted when the line (pen) color has changed to \a color.
359 \brief Signal is emitted when the line (pen) color has changed to \a color.
360 */
360 */
361 /*!
361 /*!
362 \qmlsignal XYSeries::onColorChanged(color color)
362 \qmlsignal XYSeries::onColorChanged(color color)
363 Signal is emitted when the line (pen) color has changed to \a color.
363 Signal is emitted when the line (pen) color has changed to \a color.
364 */
364 */
365
365
366 /*!
366 /*!
367 \fn void QXYSeriesPrivate::updated()
367 \fn void QXYSeriesPrivate::updated()
368 \brief \internal
368 \brief \internal
369 */
369 */
370
370
371 /*!
371 /*!
372 \qmlmethod XYSeries::append(real x, real y)
372 \qmlmethod XYSeries::append(real x, real y)
373 Append point (\a x, \a y) to the series
373 Append point (\a x, \a y) to the series
374 */
374 */
375
375
376 /*!
376 /*!
377 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
377 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
378 Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not
378 Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not
379 exist.
379 exist.
380 */
380 */
381
381
382 /*!
382 /*!
383 \qmlmethod XYSeries::remove(real x, real y)
383 \qmlmethod XYSeries::remove(real x, real y)
384 Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist.
384 Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist.
385 */
385 */
386
386
387 /*!
387 /*!
388 \qmlmethod XYSeries::insert(int index, real x, real y)
388 \qmlmethod XYSeries::insert(int index, real x, real y)
389 Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of
389 Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of
390 points. If index is the same as or bigger than count, the point is appended to the list of points.
390 points. If index is the same as or bigger than count, the point is appended to the list of points.
391 */
391 */
392
392
393 /*!
393 /*!
394 \qmlmethod QPointF XYSeries::at(int index)
394 \qmlmethod QPointF XYSeries::at(int index)
395 Returns point at \a index. Returns (0, 0) if the index is not valid.
395 Returns point at \a index. Returns (0, 0) if the index is not valid.
396 */
396 */
397
397
398 /*!
398 /*!
399 \internal
399 \internal
400
400
401 Constructs empty series object which is a child of \a parent.
401 Constructs empty series object which is a child of \a parent.
402 When series object is added to QChart instance ownerships is transferred.
402 When series object is added to QChart instance ownerships is transferred.
403 */
403 */
404 QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent)
404 QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent)
405 : QAbstractSeries(d, parent)
405 : QAbstractSeries(d, parent)
406 {
406 {
407 }
407 }
408
408
409 /*!
409 /*!
410 Destroys the object. Series added to QChart instances are owned by those,
410 Destroys the object. Series added to QChart instances are owned by those,
411 and are destroyed when QChart instances are destroyed.
411 and are destroyed when QChart instances are destroyed.
412 */
412 */
413 QXYSeries::~QXYSeries()
413 QXYSeries::~QXYSeries()
414 {
414 {
415 }
415 }
416
416
417 /*!
417 /*!
418 Adds data point (\a x, \a y) to the series.
418 Adds data point (\a x, \a y) to the series.
419 */
419 */
420 void QXYSeries::append(qreal x, qreal y)
420 void QXYSeries::append(qreal x, qreal y)
421 {
421 {
422 append(QPointF(x, y));
422 append(QPointF(x, y));
423 }
423 }
424
424
425 /*!
425 /*!
426 This is an overloaded function.
426 This is an overloaded function.
427 Adds data \a point to the series.
427 Adds data \a point to the series.
428 */
428 */
429 void QXYSeries::append(const QPointF &point)
429 void QXYSeries::append(const QPointF &point)
430 {
430 {
431 Q_D(QXYSeries);
431 Q_D(QXYSeries);
432
432
433 if (isValidValue(point)) {
433 if (isValidValue(point)) {
434 d->m_points << point;
434 d->m_points << point;
435 emit pointAdded(d->m_points.count() - 1);
435 emit pointAdded(d->m_points.count() - 1);
436 }
436 }
437 }
437 }
438
438
439 /*!
439 /*!
440 This is an overloaded function.
440 This is an overloaded function.
441 Adds list of data \a points to the series.
441 Adds list of data \a points to the series.
442 */
442 */
443 void QXYSeries::append(const QList<QPointF> &points)
443 void QXYSeries::append(const QList<QPointF> &points)
444 {
444 {
445 foreach (const QPointF &point , points)
445 foreach (const QPointF &point , points)
446 append(point);
446 append(point);
447 }
447 }
448
448
449 /*!
449 /*!
450 Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY).
450 Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY).
451 \sa QXYSeries::pointReplaced()
451 \sa QXYSeries::pointReplaced()
452 */
452 */
453 void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
453 void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
454 {
454 {
455 replace(QPointF(oldX, oldY), QPointF(newX, newY));
455 replace(QPointF(oldX, oldY), QPointF(newX, newY));
456 }
456 }
457
457
458 /*!
458 /*!
459 Replaces \a oldPoint with \a newPoint.
459 Replaces \a oldPoint with \a newPoint.
460 \sa QXYSeries::pointReplaced()
460 \sa QXYSeries::pointReplaced()
461 */
461 */
462 void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint)
462 void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint)
463 {
463 {
464 Q_D(QXYSeries);
464 Q_D(QXYSeries);
465 int index = d->m_points.indexOf(oldPoint);
465 int index = d->m_points.indexOf(oldPoint);
466 if (index == -1)
466 if (index == -1)
467 return;
467 return;
468 replace(index, newPoint);
468 replace(index, newPoint);
469 }
469 }
470
470
471 /*!
471 /*!
472 Replaces the point at \a index with data point (\a newX, \a newY).
472 Replaces the point at \a index with data point (\a newX, \a newY).
473 \sa QXYSeries::pointReplaced()
473 \sa QXYSeries::pointReplaced()
474 */
474 */
475 void QXYSeries::replace(int index, qreal newX, qreal newY)
475 void QXYSeries::replace(int index, qreal newX, qreal newY)
476 {
476 {
477 replace(index, QPointF(newX, newY));
477 replace(index, QPointF(newX, newY));
478 }
478 }
479
479
480 /*!
480 /*!
481 Replaces the point at \a index with \a newPoint.
481 Replaces the point at \a index with \a newPoint.
482 \sa QXYSeries::pointReplaced()
482 \sa QXYSeries::pointReplaced()
483 */
483 */
484 void QXYSeries::replace(int index, const QPointF &newPoint)
484 void QXYSeries::replace(int index, const QPointF &newPoint)
485 {
485 {
486 Q_D(QXYSeries);
486 Q_D(QXYSeries);
487 if (isValidValue(newPoint)) {
487 if (isValidValue(newPoint)) {
488 d->m_points[index] = newPoint;
488 d->m_points[index] = newPoint;
489 emit pointReplaced(index);
489 emit pointReplaced(index);
490 }
490 }
491 }
491 }
492
492
493 /*!
493 /*!
494 Replaces the current points with \a points.
494 Replaces the current points with \a points.
495 \note This is much faster than replacing data points one by one,
495 \note This is much faster than replacing data points one by one,
496 or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced()
496 or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced()
497 when the points have been replaced.
497 when the points have been replaced.
498 \sa QXYSeries::pointsReplaced()
498 \sa QXYSeries::pointsReplaced()
499 */
499 */
500 void QXYSeries::replace(QList<QPointF> points)
500 void QXYSeries::replace(QList<QPointF> points)
501 {
501 {
502 Q_D(QXYSeries);
502 Q_D(QXYSeries);
503 d->m_points = points.toVector();
503 d->m_points = points.toVector();
504 emit pointsReplaced();
504 emit pointsReplaced();
505 }
505 }
506
506
507 /*!
507 /*!
508 Removes the point (\a x, \a y) from the series.
508 Removes the point (\a x, \a y) from the series.
509 */
509 */
510 void QXYSeries::remove(qreal x, qreal y)
510 void QXYSeries::remove(qreal x, qreal y)
511 {
511 {
512 remove(QPointF(x, y));
512 remove(QPointF(x, y));
513 }
513 }
514
514
515 /*!
515 /*!
516 Removes the \a point from the series.
516 Removes the \a point from the series.
517 */
517 */
518 void QXYSeries::remove(const QPointF &point)
518 void QXYSeries::remove(const QPointF &point)
519 {
519 {
520 Q_D(QXYSeries);
520 Q_D(QXYSeries);
521 int index = d->m_points.indexOf(point);
521 int index = d->m_points.indexOf(point);
522 if (index == -1)
522 if (index == -1)
523 return;
523 return;
524 remove(index);
524 remove(index);
525 }
525 }
526
526
527 /*!
527 /*!
528 Removes the point at \a index from the series.
528 Removes the point at \a index from the series.
529 */
529 */
530 void QXYSeries::remove(int index)
530 void QXYSeries::remove(int index)
531 {
531 {
532 Q_D(QXYSeries);
532 Q_D(QXYSeries);
533 d->m_points.remove(index);
533 d->m_points.remove(index);
534 emit pointRemoved(index);
534 emit pointRemoved(index);
535 }
535 }
536
536
537 /*!
537 /*!
538 Inserts a \a point in the series at \a index position.
538 Inserts a \a point in the series at \a index position.
539 */
539 */
540 void QXYSeries::insert(int index, const QPointF &point)
540 void QXYSeries::insert(int index, const QPointF &point)
541 {
541 {
542 Q_D(QXYSeries);
542 Q_D(QXYSeries);
543 if (isValidValue(point)) {
543 if (isValidValue(point)) {
544 index = qMax(0, qMin(index, d->m_points.size()));
544 d->m_points.insert(index, point);
545 d->m_points.insert(index, point);
545 emit pointAdded(index);
546 emit pointAdded(index);
546 }
547 }
547 }
548 }
548
549
549 /*!
550 /*!
550 Removes all points from the series.
551 Removes all points from the series.
551 */
552 */
552 void QXYSeries::clear()
553 void QXYSeries::clear()
553 {
554 {
554 Q_D(QXYSeries);
555 Q_D(QXYSeries);
555 for (int i = d->m_points.size() - 1; i >= 0; i--)
556 for (int i = d->m_points.size() - 1; i >= 0; i--)
556 remove(d->m_points.at(i));
557 remove(d->m_points.at(i));
557 }
558 }
558
559
559 /*!
560 /*!
560 Returns list of points in the series.
561 Returns list of points in the series.
561 */
562 */
562 QList<QPointF> QXYSeries::points() const
563 QList<QPointF> QXYSeries::points() const
563 {
564 {
564 Q_D(const QXYSeries);
565 Q_D(const QXYSeries);
565 return d->m_points.toList();
566 return d->m_points.toList();
566 }
567 }
567
568
568 /*!
569 /*!
569 Returns point at \a index in internal points vector.
570 Returns point at \a index in internal points vector.
570 */
571 */
571 const QPointF &QXYSeries::at(int index) const
572 const QPointF &QXYSeries::at(int index) const
572 {
573 {
573 Q_D(const QXYSeries);
574 Q_D(const QXYSeries);
574 return d->m_points.at(index);
575 return d->m_points.at(index);
575 }
576 }
576
577
577 /*!
578 /*!
578 Returns number of data points within series.
579 Returns number of data points within series.
579 */
580 */
580 int QXYSeries::count() const
581 int QXYSeries::count() const
581 {
582 {
582 Q_D(const QXYSeries);
583 Q_D(const QXYSeries);
583 return d->m_points.count();
584 return d->m_points.count();
584 }
585 }
585
586
586
587
587 /*!
588 /*!
588 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
589 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
589 pen from chart theme is used.
590 pen from chart theme is used.
590 \sa QChart::setTheme()
591 \sa QChart::setTheme()
591 */
592 */
592 void QXYSeries::setPen(const QPen &pen)
593 void QXYSeries::setPen(const QPen &pen)
593 {
594 {
594 Q_D(QXYSeries);
595 Q_D(QXYSeries);
595 if (d->m_pen != pen) {
596 if (d->m_pen != pen) {
596 bool emitColorChanged = d->m_pen.color() != pen.color();
597 bool emitColorChanged = d->m_pen.color() != pen.color();
597 d->m_pen = pen;
598 d->m_pen = pen;
598 emit d->updated();
599 emit d->updated();
599 if (emitColorChanged)
600 if (emitColorChanged)
600 emit colorChanged(pen.color());
601 emit colorChanged(pen.color());
601 }
602 }
602 }
603 }
603
604
604 QPen QXYSeries::pen() const
605 QPen QXYSeries::pen() const
605 {
606 {
606 Q_D(const QXYSeries);
607 Q_D(const QXYSeries);
607 if (d->m_pen == QChartPrivate::defaultPen())
608 if (d->m_pen == QChartPrivate::defaultPen())
608 return QPen();
609 return QPen();
609 else
610 else
610 return d->m_pen;
611 return d->m_pen;
611 }
612 }
612
613
613 /*!
614 /*!
614 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
615 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
615 from chart theme setting is used.
616 from chart theme setting is used.
616 \sa QChart::setTheme()
617 \sa QChart::setTheme()
617 */
618 */
618 void QXYSeries::setBrush(const QBrush &brush)
619 void QXYSeries::setBrush(const QBrush &brush)
619 {
620 {
620 Q_D(QXYSeries);
621 Q_D(QXYSeries);
621 if (d->m_brush != brush) {
622 if (d->m_brush != brush) {
622 d->m_brush = brush;
623 d->m_brush = brush;
623 emit d->updated();
624 emit d->updated();
624 }
625 }
625 }
626 }
626
627
627 QBrush QXYSeries::brush() const
628 QBrush QXYSeries::brush() const
628 {
629 {
629 Q_D(const QXYSeries);
630 Q_D(const QXYSeries);
630 if (d->m_brush == QChartPrivate::defaultBrush())
631 if (d->m_brush == QChartPrivate::defaultBrush())
631 return QBrush();
632 return QBrush();
632 else
633 else
633 return d->m_brush;
634 return d->m_brush;
634 }
635 }
635
636
636 void QXYSeries::setColor(const QColor &color)
637 void QXYSeries::setColor(const QColor &color)
637 {
638 {
638 QPen p = pen();
639 QPen p = pen();
639 if (p.color() != color) {
640 if (p.color() != color) {
640 p.setColor(color);
641 p.setColor(color);
641 setPen(p);
642 setPen(p);
642 }
643 }
643 }
644 }
644
645
645 QColor QXYSeries::color() const
646 QColor QXYSeries::color() const
646 {
647 {
647 return pen().color();
648 return pen().color();
648 }
649 }
649
650
650 void QXYSeries::setPointsVisible(bool visible)
651 void QXYSeries::setPointsVisible(bool visible)
651 {
652 {
652 Q_D(QXYSeries);
653 Q_D(QXYSeries);
653 if (d->m_pointsVisible != visible) {
654 if (d->m_pointsVisible != visible) {
654 d->m_pointsVisible = visible;
655 d->m_pointsVisible = visible;
655 emit d->updated();
656 emit d->updated();
656 }
657 }
657 }
658 }
658
659
659 bool QXYSeries::pointsVisible() const
660 bool QXYSeries::pointsVisible() const
660 {
661 {
661 Q_D(const QXYSeries);
662 Q_D(const QXYSeries);
662 return d->m_pointsVisible;
663 return d->m_pointsVisible;
663 }
664 }
664
665
665 void QXYSeries::setPointLabelsFormat(const QString &format)
666 void QXYSeries::setPointLabelsFormat(const QString &format)
666 {
667 {
667 Q_D(QXYSeries);
668 Q_D(QXYSeries);
668 if (d->m_pointLabelsFormat != format) {
669 if (d->m_pointLabelsFormat != format) {
669 d->m_pointLabelsFormat = format;
670 d->m_pointLabelsFormat = format;
670 emit pointLabelsFormatChanged(format);
671 emit pointLabelsFormatChanged(format);
671 }
672 }
672 }
673 }
673
674
674 QString QXYSeries::pointLabelsFormat() const
675 QString QXYSeries::pointLabelsFormat() const
675 {
676 {
676 Q_D(const QXYSeries);
677 Q_D(const QXYSeries);
677 return d->m_pointLabelsFormat;
678 return d->m_pointLabelsFormat;
678 }
679 }
679
680
680 void QXYSeries::setPointLabelsVisible(bool visible)
681 void QXYSeries::setPointLabelsVisible(bool visible)
681 {
682 {
682 Q_D(QXYSeries);
683 Q_D(QXYSeries);
683 if (d->m_pointLabelsVisible != visible) {
684 if (d->m_pointLabelsVisible != visible) {
684 d->m_pointLabelsVisible = visible;
685 d->m_pointLabelsVisible = visible;
685 emit pointLabelsVisibilityChanged(visible);
686 emit pointLabelsVisibilityChanged(visible);
686 }
687 }
687 }
688 }
688
689
689 bool QXYSeries::pointLabelsVisible() const
690 bool QXYSeries::pointLabelsVisible() const
690 {
691 {
691 Q_D(const QXYSeries);
692 Q_D(const QXYSeries);
692 return d->m_pointLabelsVisible;
693 return d->m_pointLabelsVisible;
693 }
694 }
694
695
695 void QXYSeries::setPointLabelsFont(const QFont &font)
696 void QXYSeries::setPointLabelsFont(const QFont &font)
696 {
697 {
697 Q_D(QXYSeries);
698 Q_D(QXYSeries);
698 if (d->m_pointLabelsFont != font) {
699 if (d->m_pointLabelsFont != font) {
699 d->m_pointLabelsFont = font;
700 d->m_pointLabelsFont = font;
700 emit pointLabelsFontChanged(font);
701 emit pointLabelsFontChanged(font);
701 }
702 }
702 }
703 }
703
704
704 QFont QXYSeries::pointLabelsFont() const
705 QFont QXYSeries::pointLabelsFont() const
705 {
706 {
706 Q_D(const QXYSeries);
707 Q_D(const QXYSeries);
707 return d->m_pointLabelsFont;
708 return d->m_pointLabelsFont;
708 }
709 }
709
710
710 void QXYSeries::setPointLabelsColor(const QColor &color)
711 void QXYSeries::setPointLabelsColor(const QColor &color)
711 {
712 {
712 Q_D(QXYSeries);
713 Q_D(QXYSeries);
713 if (d->m_pointLabelsColor != color) {
714 if (d->m_pointLabelsColor != color) {
714 d->m_pointLabelsColor = color;
715 d->m_pointLabelsColor = color;
715 emit pointLabelsColorChanged(color);
716 emit pointLabelsColorChanged(color);
716 }
717 }
717 }
718 }
718
719
719 QColor QXYSeries::pointLabelsColor() const
720 QColor QXYSeries::pointLabelsColor() const
720 {
721 {
721 Q_D(const QXYSeries);
722 Q_D(const QXYSeries);
722 if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color())
723 if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color())
723 return QPen().color();
724 return QPen().color();
724 else
725 else
725 return d->m_pointLabelsColor;
726 return d->m_pointLabelsColor;
726 }
727 }
727
728
728 /*!
729 /*!
729 Stream operator for adding a data \a point to the series.
730 Stream operator for adding a data \a point to the series.
730 \sa append()
731 \sa append()
731 */
732 */
732 QXYSeries &QXYSeries::operator<< (const QPointF &point)
733 QXYSeries &QXYSeries::operator<< (const QPointF &point)
733 {
734 {
734 append(point);
735 append(point);
735 return *this;
736 return *this;
736 }
737 }
737
738
738
739
739 /*!
740 /*!
740 Stream operator for adding a list of \a points to the series.
741 Stream operator for adding a list of \a points to the series.
741 \sa append()
742 \sa append()
742 */
743 */
743
744
744 QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points)
745 QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points)
745 {
746 {
746 append(points);
747 append(points);
747 return *this;
748 return *this;
748 }
749 }
749
750
750 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
751 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
751
752
752
753
753 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q)
754 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q)
754 : QAbstractSeriesPrivate(q),
755 : QAbstractSeriesPrivate(q),
755 m_pen(QChartPrivate::defaultPen()),
756 m_pen(QChartPrivate::defaultPen()),
756 m_brush(QChartPrivate::defaultBrush()),
757 m_brush(QChartPrivate::defaultBrush()),
757 m_pointsVisible(false),
758 m_pointsVisible(false),
758 m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")),
759 m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")),
759 m_pointLabelsVisible(false),
760 m_pointLabelsVisible(false),
760 m_pointLabelsFont(QChartPrivate::defaultFont()),
761 m_pointLabelsFont(QChartPrivate::defaultFont()),
761 m_pointLabelsColor(QChartPrivate::defaultPen().color())
762 m_pointLabelsColor(QChartPrivate::defaultPen().color())
762 {
763 {
763 }
764 }
764
765
765 void QXYSeriesPrivate::initializeDomain()
766 void QXYSeriesPrivate::initializeDomain()
766 {
767 {
767 qreal minX(0);
768 qreal minX(0);
768 qreal minY(0);
769 qreal minY(0);
769 qreal maxX(1);
770 qreal maxX(1);
770 qreal maxY(1);
771 qreal maxY(1);
771
772
772 Q_Q(QXYSeries);
773 Q_Q(QXYSeries);
773
774
774 const QList<QPointF>& points = q->points();
775 const QList<QPointF>& points = q->points();
775
776
776 if (!points.isEmpty()) {
777 if (!points.isEmpty()) {
777 minX = points[0].x();
778 minX = points[0].x();
778 minY = points[0].y();
779 minY = points[0].y();
779 maxX = minX;
780 maxX = minX;
780 maxY = minY;
781 maxY = minY;
781
782
782 for (int i = 0; i < points.count(); i++) {
783 for (int i = 0; i < points.count(); i++) {
783 qreal x = points[i].x();
784 qreal x = points[i].x();
784 qreal y = points[i].y();
785 qreal y = points[i].y();
785 minX = qMin(minX, x);
786 minX = qMin(minX, x);
786 minY = qMin(minY, y);
787 minY = qMin(minY, y);
787 maxX = qMax(maxX, x);
788 maxX = qMax(maxX, x);
788 maxY = qMax(maxY, y);
789 maxY = qMax(maxY, y);
789 }
790 }
790 }
791 }
791
792
792 domain()->setRange(minX, maxX, minY, maxY);
793 domain()->setRange(minX, maxX, minY, maxY);
793 }
794 }
794
795
795 QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend)
796 QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend)
796 {
797 {
797 Q_Q(QXYSeries);
798 Q_Q(QXYSeries);
798 QList<QLegendMarker*> list;
799 QList<QLegendMarker*> list;
799 return list << new QXYLegendMarker(q,legend);
800 return list << new QXYLegendMarker(q,legend);
800 }
801 }
801
802
802 void QXYSeriesPrivate::initializeAxes()
803 void QXYSeriesPrivate::initializeAxes()
803 {
804 {
804
805
805 }
806 }
806
807
807 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
808 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
808 {
809 {
809 Q_UNUSED(orientation);
810 Q_UNUSED(orientation);
810 return QAbstractAxis::AxisTypeValue;
811 return QAbstractAxis::AxisTypeValue;
811 }
812 }
812
813
813 QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
814 QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
814 {
815 {
815 Q_UNUSED(orientation);
816 Q_UNUSED(orientation);
816 return new QValueAxis;
817 return new QValueAxis;
817 }
818 }
818
819
819 void QXYSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options)
820 void QXYSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options)
820 {
821 {
821 XYChart *item = static_cast<XYChart *>(m_item.data());
822 XYChart *item = static_cast<XYChart *>(m_item.data());
822 Q_ASSERT(item);
823 Q_ASSERT(item);
823 if (item->animation())
824 if (item->animation())
824 item->animation()->stopAndDestroyLater();
825 item->animation()->stopAndDestroyLater();
825
826
826 if (options.testFlag(QChart::SeriesAnimations))
827 if (options.testFlag(QChart::SeriesAnimations))
827 item->setAnimation(new XYAnimation(item));
828 item->setAnimation(new XYAnimation(item));
828 else
829 else
829 item->setAnimation(0);
830 item->setAnimation(0);
830 QAbstractSeriesPrivate::initializeAnimations(options);
831 QAbstractSeriesPrivate::initializeAnimations(options);
831 }
832 }
832
833
833 void QXYSeriesPrivate::drawSeriesPointLabels(QPainter *painter, const QVector<QPointF> &points,
834 void QXYSeriesPrivate::drawSeriesPointLabels(QPainter *painter, const QVector<QPointF> &points,
834 const int offset)
835 const int offset)
835 {
836 {
836 static const QString xPointTag(QLatin1String("@xPoint"));
837 static const QString xPointTag(QLatin1String("@xPoint"));
837 static const QString yPointTag(QLatin1String("@yPoint"));
838 static const QString yPointTag(QLatin1String("@yPoint"));
838 const int labelOffset = offset + 2;
839 const int labelOffset = offset + 2;
839
840
840 painter->setFont(m_pointLabelsFont);
841 painter->setFont(m_pointLabelsFont);
841 painter->setPen(QPen(m_pointLabelsColor));
842 painter->setPen(QPen(m_pointLabelsColor));
842 QFontMetrics fm(painter->font());
843 QFontMetrics fm(painter->font());
843
844
844 for (int i(0); i < points.size(); i++) {
845 for (int i(0); i < points.size(); i++) {
845 QString pointLabel = m_pointLabelsFormat;
846 QString pointLabel = m_pointLabelsFormat;
846 pointLabel.replace(xPointTag, presenter()->numberToString(points.at(i).x()));
847 pointLabel.replace(xPointTag, presenter()->numberToString(points.at(i).x()));
847 pointLabel.replace(yPointTag, presenter()->numberToString(points.at(i).y()));
848 pointLabel.replace(yPointTag, presenter()->numberToString(points.at(i).y()));
848
849
849 // Position text in relation to the point
850 // Position text in relation to the point
850 int pointLabelWidth = fm.width(pointLabel);
851 int pointLabelWidth = fm.width(pointLabel);
851 QPointF position(points.at(i));
852 QPointF position(points.at(i));
852 position.setX(position.x() - pointLabelWidth / 2);
853 position.setX(position.x() - pointLabelWidth / 2);
853 position.setY(position.y() - labelOffset);
854 position.setY(position.y() - labelOffset);
854
855
855 painter->drawText(position, pointLabel);
856 painter->drawText(position, pointLabel);
856 }
857 }
857 }
858 }
858
859
859 #include "moc_qxyseries.cpp"
860 #include "moc_qxyseries.cpp"
860 #include "moc_qxyseries_p.cpp"
861 #include "moc_qxyseries_p.cpp"
861
862
862 QT_CHARTS_END_NAMESPACE
863 QT_CHARTS_END_NAMESPACE
@@ -1,204 +1,227
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.io
5 ** For any questions to Digia, please use contact form at http://qt.io
6 **
6 **
7 ** This file is part of the Qt Charts module.
7 ** This file is part of the Qt Charts module.
8 **
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and Digia.
12 ** agreement between you and Digia.
13 **
13 **
14 ** If you have questions regarding the use of this file, please use
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
15 ** contact form at http://qt.io
16 **
16 **
17 ****************************************************************************/
17 ****************************************************************************/
18
18
19 #include "../qxyseries/tst_qxyseries.h"
19 #include "../qxyseries/tst_qxyseries.h"
20 #include <QtCharts/QLineSeries>
20 #include <QtCharts/QLineSeries>
21
21
22
22
23 Q_DECLARE_METATYPE(QList<QPointF>)
23 Q_DECLARE_METATYPE(QList<QPointF>)
24
24
25 class tst_QLineSeries : public tst_QXYSeries
25 class tst_QLineSeries : public tst_QXYSeries
26 {
26 {
27 Q_OBJECT
27 Q_OBJECT
28
28
29 public slots:
29 public slots:
30 void initTestCase();
30 void initTestCase();
31 void cleanupTestCase();
31 void cleanupTestCase();
32 void init();
32 void init();
33 void cleanup();
33 void cleanup();
34 private slots:
34 private slots:
35 void qlineseries_data();
35 void qlineseries_data();
36 void qlineseries();
36 void qlineseries();
37 void pressedSignal();
37 void pressedSignal();
38 void releasedSignal();
38 void releasedSignal();
39 void doubleClickedSignal();
39 void doubleClickedSignal();
40 void insert();
40 protected:
41 protected:
41 void pointsVisible_data();
42 void pointsVisible_data();
42 };
43 };
43
44
44 void tst_QLineSeries::initTestCase()
45 void tst_QLineSeries::initTestCase()
45 {
46 {
46 }
47 }
47
48
48 void tst_QLineSeries::cleanupTestCase()
49 void tst_QLineSeries::cleanupTestCase()
49 {
50 {
50 QTest::qWait(1); // Allow final deleteLaters to run
51 QTest::qWait(1); // Allow final deleteLaters to run
51 }
52 }
52
53
53 void tst_QLineSeries::init()
54 void tst_QLineSeries::init()
54 {
55 {
55 tst_QXYSeries::init();
56 tst_QXYSeries::init();
56 m_series = new QLineSeries();
57 m_series = new QLineSeries();
57 }
58 }
58
59
59 void tst_QLineSeries::cleanup()
60 void tst_QLineSeries::cleanup()
60 {
61 {
61 delete m_series;
62 delete m_series;
62 m_series=0;
63 m_series=0;
63 tst_QXYSeries::cleanup();
64 tst_QXYSeries::cleanup();
64 }
65 }
65
66
66 void tst_QLineSeries::qlineseries_data()
67 void tst_QLineSeries::qlineseries_data()
67 {
68 {
68
69
69 }
70 }
70
71
71 void tst_QLineSeries::qlineseries()
72 void tst_QLineSeries::qlineseries()
72 {
73 {
73 QLineSeries series;
74 QLineSeries series;
74
75
75 QCOMPARE(series.count(),0);
76 QCOMPARE(series.count(),0);
76 QCOMPARE(series.brush(), QBrush());
77 QCOMPARE(series.brush(), QBrush());
77 QCOMPARE(series.points(), QList<QPointF>());
78 QCOMPARE(series.points(), QList<QPointF>());
78 QCOMPARE(series.pen(), QPen());
79 QCOMPARE(series.pen(), QPen());
79 QCOMPARE(series.pointsVisible(), false);
80 QCOMPARE(series.pointsVisible(), false);
80 QCOMPARE(series.pointLabelsVisible(), false);
81 QCOMPARE(series.pointLabelsVisible(), false);
81 QCOMPARE(series.pointLabelsFormat(), QLatin1String("@xPoint, @yPoint"));
82 QCOMPARE(series.pointLabelsFormat(), QLatin1String("@xPoint, @yPoint"));
82
83
83 series.append(QList<QPointF>());
84 series.append(QList<QPointF>());
84 series.append(0.0,0.0);
85 series.append(0.0,0.0);
85 series.append(QPointF());
86 series.append(QPointF());
86
87
87 series.remove(0.0,0.0);
88 series.remove(0.0,0.0);
88 series.remove(QPointF());
89 series.remove(QPointF());
89 series.clear();
90 series.clear();
90
91
91 series.replace(QPointF(),QPointF());
92 series.replace(QPointF(),QPointF());
92 series.replace(0,0,0,0);
93 series.replace(0,0,0,0);
93 series.setBrush(QBrush());
94 series.setBrush(QBrush());
94
95
95 series.setPen(QPen());
96 series.setPen(QPen());
96 series.setPointsVisible(false);
97 series.setPointsVisible(false);
97
98
98 series.setPointLabelsVisible(false);
99 series.setPointLabelsVisible(false);
99 series.setPointLabelsFormat(QString());
100 series.setPointLabelsFormat(QString());
100
101
101 m_chart->addSeries(&series);
102 m_chart->addSeries(&series);
102 m_view->show();
103 m_view->show();
103 QTest::qWaitForWindowShown(m_view);
104 QTest::qWaitForWindowShown(m_view);
104 }
105 }
105
106
106 void tst_QLineSeries::pressedSignal()
107 void tst_QLineSeries::pressedSignal()
107 {
108 {
108 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
109 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
109
110
110 QPointF linePoint(4, 12);
111 QPointF linePoint(4, 12);
111 QLineSeries *lineSeries = new QLineSeries();
112 QLineSeries *lineSeries = new QLineSeries();
112 lineSeries->append(QPointF(2, 1));
113 lineSeries->append(QPointF(2, 1));
113 lineSeries->append(linePoint);
114 lineSeries->append(linePoint);
114 lineSeries->append(QPointF(6, 12));
115 lineSeries->append(QPointF(6, 12));
115
116
116 QChartView view;
117 QChartView view;
117 view.chart()->legend()->setVisible(false);
118 view.chart()->legend()->setVisible(false);
118 view.chart()->addSeries(lineSeries);
119 view.chart()->addSeries(lineSeries);
119 view.show();
120 view.show();
120 QTest::qWaitForWindowShown(&view);
121 QTest::qWaitForWindowShown(&view);
121
122
122 QSignalSpy seriesSpy(lineSeries, SIGNAL(pressed(QPointF)));
123 QSignalSpy seriesSpy(lineSeries, SIGNAL(pressed(QPointF)));
123
124
124 QPointF checkPoint = view.chart()->mapToPosition(linePoint);
125 QPointF checkPoint = view.chart()->mapToPosition(linePoint);
125 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
126 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
126 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
127 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
127
128
128 QCOMPARE(seriesSpy.count(), 1);
129 QCOMPARE(seriesSpy.count(), 1);
129 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
130 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
130 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
131 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
131 // this causes small distinction in decimals so we round it before comparing
132 // this causes small distinction in decimals so we round it before comparing
132 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
133 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
133 QCOMPARE(qRound(signalPoint.x()), qRound(linePoint.x()));
134 QCOMPARE(qRound(signalPoint.x()), qRound(linePoint.x()));
134 QCOMPARE(qRound(signalPoint.y()), qRound(linePoint.y()));
135 QCOMPARE(qRound(signalPoint.y()), qRound(linePoint.y()));
135 }
136 }
136
137
137 void tst_QLineSeries::releasedSignal()
138 void tst_QLineSeries::releasedSignal()
138 {
139 {
139 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
140 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
140
141
141 QPointF linePoint(4, 12);
142 QPointF linePoint(4, 12);
142 QLineSeries *lineSeries = new QLineSeries();
143 QLineSeries *lineSeries = new QLineSeries();
143 lineSeries->append(QPointF(2, 20));
144 lineSeries->append(QPointF(2, 20));
144 lineSeries->append(linePoint);
145 lineSeries->append(linePoint);
145 lineSeries->append(QPointF(6, 12));
146 lineSeries->append(QPointF(6, 12));
146
147
147 QChartView view;
148 QChartView view;
148 view.chart()->legend()->setVisible(false);
149 view.chart()->legend()->setVisible(false);
149 view.chart()->addSeries(lineSeries);
150 view.chart()->addSeries(lineSeries);
150 view.show();
151 view.show();
151 QTest::qWaitForWindowShown(&view);
152 QTest::qWaitForWindowShown(&view);
152
153
153 QSignalSpy seriesSpy(lineSeries, SIGNAL(released(QPointF)));
154 QSignalSpy seriesSpy(lineSeries, SIGNAL(released(QPointF)));
154
155
155 QPointF checkPoint = view.chart()->mapToPosition(linePoint);
156 QPointF checkPoint = view.chart()->mapToPosition(linePoint);
156 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
157 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
157 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
158 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
158
159
159 QCOMPARE(seriesSpy.count(), 1);
160 QCOMPARE(seriesSpy.count(), 1);
160 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
161 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
161 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
162 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
162 // this causes small distinction in decimals so we round it before comparing
163 // this causes small distinction in decimals so we round it before comparing
163 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
164 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
164 QCOMPARE(qRound(signalPoint.x()), qRound(linePoint.x()));
165 QCOMPARE(qRound(signalPoint.x()), qRound(linePoint.x()));
165 QCOMPARE(qRound(signalPoint.y()), qRound(linePoint.y()));
166 QCOMPARE(qRound(signalPoint.y()), qRound(linePoint.y()));
166 }
167 }
167
168
169 void tst_QLineSeries::insert()
170 {
171 QLineSeries lineSeries;
172 QSignalSpy insertSpy(&lineSeries, &QXYSeries::pointAdded);
173 lineSeries.insert(0, QPoint(3, 3));
174 QCOMPARE(insertSpy.count(), 1);
175 QVariantList arguments = insertSpy.takeFirst();
176 QCOMPARE(arguments.first().toInt(), 0);
177 lineSeries.insert(0, QPoint(1, 1));
178 arguments = insertSpy.takeFirst();
179 QCOMPARE(arguments.first().toInt(), 0);
180 lineSeries.insert(1, QPoint(2, 2));
181 arguments = insertSpy.takeFirst();
182 QCOMPARE(arguments.first().toInt(), 1);
183 lineSeries.insert(42, QPoint(0, 0));
184 arguments = insertSpy.takeFirst();
185 QCOMPARE(arguments.first().toInt(), 3);
186 lineSeries.insert(-42, QPoint(0, 0));
187 arguments = insertSpy.takeFirst();
188 QCOMPARE(arguments.first().toInt(), 0);
189 }
190
168 void tst_QLineSeries::doubleClickedSignal()
191 void tst_QLineSeries::doubleClickedSignal()
169 {
192 {
170 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
193 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
171
194
172 QPointF linePoint(4, 12);
195 QPointF linePoint(4, 12);
173 QLineSeries *lineSeries = new QLineSeries();
196 QLineSeries *lineSeries = new QLineSeries();
174 lineSeries->append(QPointF(2, 20));
197 lineSeries->append(QPointF(2, 20));
175 lineSeries->append(linePoint);
198 lineSeries->append(linePoint);
176 lineSeries->append(QPointF(6, 12));
199 lineSeries->append(QPointF(6, 12));
177
200
178 QChartView view;
201 QChartView view;
179 view.chart()->legend()->setVisible(false);
202 view.chart()->legend()->setVisible(false);
180 view.chart()->addSeries(lineSeries);
203 view.chart()->addSeries(lineSeries);
181 view.show();
204 view.show();
182 QTest::qWaitForWindowShown(&view);
205 QTest::qWaitForWindowShown(&view);
183
206
184 QSignalSpy seriesSpy(lineSeries, SIGNAL(doubleClicked(QPointF)));
207 QSignalSpy seriesSpy(lineSeries, SIGNAL(doubleClicked(QPointF)));
185
208
186 QPointF checkPoint = view.chart()->mapToPosition(linePoint);
209 QPointF checkPoint = view.chart()->mapToPosition(linePoint);
187 // mouseClick needed first to save the position
210 // mouseClick needed first to save the position
188 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
211 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
189 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
212 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
190 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
213 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
191
214
192 QCOMPARE(seriesSpy.count(), 1);
215 QCOMPARE(seriesSpy.count(), 1);
193 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
216 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
194 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
217 // checkPoint is QPointF and for the mouseClick it it's changed to QPoint
195 // this causes small distinction in decimals so we round it before comparing
218 // this causes small distinction in decimals so we round it before comparing
196 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
219 QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0));
197 QCOMPARE(qRound(signalPoint.x()), qRound(linePoint.x()));
220 QCOMPARE(qRound(signalPoint.x()), qRound(linePoint.x()));
198 QCOMPARE(qRound(signalPoint.y()), qRound(linePoint.y()));
221 QCOMPARE(qRound(signalPoint.y()), qRound(linePoint.y()));
199 }
222 }
200
223
201 QTEST_MAIN(tst_QLineSeries)
224 QTEST_MAIN(tst_QLineSeries)
202
225
203 #include "tst_qlineseries.moc"
226 #include "tst_qlineseries.moc"
204
227
General Comments 0
You need to be logged in to leave comments. Login now