##// END OF EJS Templates
Clarified AreaSeries documentation...
Titta Heikkala -
r2790:f40f14281427
parent child
Show More
@@ -1,697 +1,700
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd
3 ** Copyright (C) 2015 The Qt Company Ltd
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
5 ** For any questions to The Qt Company, 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 The Qt Company.
12 ** agreement between you and The Qt Company.
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/QAreaSeries>
19 #include <QtCharts/QAreaSeries>
20 #include <private/qareaseries_p.h>
20 #include <private/qareaseries_p.h>
21 #include <QtCharts/QLineSeries>
21 #include <QtCharts/QLineSeries>
22 #include <private/areachartitem_p.h>
22 #include <private/areachartitem_p.h>
23 #include <private/abstractdomain_p.h>
23 #include <private/abstractdomain_p.h>
24 #include <private/chartdataset_p.h>
24 #include <private/chartdataset_p.h>
25 #include <private/charttheme_p.h>
25 #include <private/charttheme_p.h>
26 #include <QtCharts/QValueAxis>
26 #include <QtCharts/QValueAxis>
27 #include <QtCharts/QAreaLegendMarker>
27 #include <QtCharts/QAreaLegendMarker>
28 #include <private/qchart_p.h>
28 #include <private/qchart_p.h>
29
29
30 QT_CHARTS_BEGIN_NAMESPACE
30 QT_CHARTS_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \class QAreaSeries
33 \class QAreaSeries
34 \inmodule Qt Charts
34 \inmodule Qt Charts
35 \brief The QAreaSeries class is used for making area charts.
35 \brief The QAreaSeries class is used for making area charts.
36
36
37 An area series is used to show quantitative data. It is based on line series, in the way that
37 An area series is used to show quantitative data. It is based on line series, in the way that
38 the area between the boundary lines is emphasized with color. Since the area series is based on
38 the area between the boundary lines is emphasized with color. Since the area series is based on
39 line series, QAreaSeries constructor needs a QLineSeries instance, which defines "upper"
39 line series, QAreaSeries constructor needs a QLineSeries instance, which defines "upper"
40 boundary of the area. The area chart is drawn using the bottom of the plot area as the "lower"
40 boundary of the area. The area chart is drawn using the bottom of the plot area as the "lower"
41 boundary by default. Instead of the bottom of the plot area, the "lower" boundary can be
41 boundary by default. Instead of the bottom of the plot area, the "lower" boundary can be
42 specified by another line. In that case QAreaSeries should be initialized with two QLineSeries
42 specified by another line. In that case QAreaSeries should be initialized with two QLineSeries
43 instances. Please note that the terms "upper" and "lower" boundary can be misleading in cases
43 instances. Please note that the terms "upper" and "lower" boundary can be misleading in cases
44 where the "lower" boundary has bigger values than the "upper" one. The main point is that the
44 where the "lower" boundary has bigger values than the "upper" one. The main point is that the
45 area between these two boundary lines will be filled.
45 area between these two boundary lines will be filled.
46
46
47 See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart.
47 See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart.
48 \image examples_areachart.png
48 \image examples_areachart.png
49 */
49 */
50
50
51 /*!
51 /*!
52 \qmltype AreaSeries
52 \qmltype AreaSeries
53 \instantiates QAreaSeries
53 \instantiates QAreaSeries
54 \inqmlmodule QtCharts
54 \inqmlmodule QtCharts
55
55
56 \inherits AbstractSeries
56 \inherits AbstractSeries
57
57
58 \brief The AreaSeries type is used for making area charts.
58 \brief The AreaSeries type is used for making area charts.
59
59
60 The following QML shows how to create a simple area chart:
60 The following QML shows how to create a simple area chart:
61 \snippet qmlchart/qml/qmlchart/View4.qml 1
61 \snippet qmlchart/qml/qmlchart/View4.qml 1
62 \beginfloatleft
62 \beginfloatleft
63 \image examples_qmlchart4.png
63 \image examples_qmlchart4.png
64 \endfloat
64 \endfloat
65 \clearfloat
65 \clearfloat
66
67 \note Adding the same line series to chart and area series is not supported. The series used as
68 boundary lines should be defined only for the area series.
66 */
69 */
67
70
68 /*!
71 /*!
69 \property QAreaSeries::upperSeries
72 \property QAreaSeries::upperSeries
70 \brief The upper one of the two line series used to define area series boundaries.
73 \brief The upper one of the two line series used to define area series boundaries.
71 */
74 */
72 /*!
75 /*!
73 \qmlproperty LineSeries AreaSeries::upperSeries
76 \qmlproperty LineSeries AreaSeries::upperSeries
74 The upper one of the two line series used to define area series boundaries.
77 The upper one of the two line series used to define area series boundaries.
75 */
78 */
76
79
77 /*!
80 /*!
78 \property QAreaSeries::lowerSeries
81 \property QAreaSeries::lowerSeries
79 The lower one of the two line series used to define are series boundaries. Note if
82 The lower one of the two line series used to define are series boundaries. Note if
80 QAreaSeries was constructed without a\ lowerSeries this is null.
83 QAreaSeries was constructed without a\ lowerSeries this is null.
81 */
84 */
82 /*!
85 /*!
83 \qmlproperty LineSeries AreaSeries::lowerSeries
86 \qmlproperty LineSeries AreaSeries::lowerSeries
84 The lower one of the two line series used to define are series boundaries. Note if
87 The lower one of the two line series used to define are series boundaries. Note if
85 AreaSeries was constructed without a\ lowerSeries this is null.
88 AreaSeries was constructed without a\ lowerSeries this is null.
86 */
89 */
87
90
88 /*!
91 /*!
89 \property QAreaSeries::color
92 \property QAreaSeries::color
90 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
93 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
91 \sa QAreaSeries::brush()
94 \sa QAreaSeries::brush()
92 */
95 */
93 /*!
96 /*!
94 \qmlproperty color AreaSeries::color
97 \qmlproperty color AreaSeries::color
95 Fill (brush) color of the series.
98 Fill (brush) color of the series.
96 */
99 */
97
100
98 /*!
101 /*!
99 \property QAreaSeries::borderColor
102 \property QAreaSeries::borderColor
100 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
103 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
101 \sa QAreaSeries::pen()
104 \sa QAreaSeries::pen()
102 */
105 */
103 /*!
106 /*!
104 \qmlproperty color AreaSeries::borderColor
107 \qmlproperty color AreaSeries::borderColor
105 Line (pen) color of the series.
108 Line (pen) color of the series.
106 */
109 */
107
110
108 /*!
111 /*!
109 \qmlproperty real AreaSeries::borderWidth
112 \qmlproperty real AreaSeries::borderWidth
110 The width of the border line. By default the width is 2.0.
113 The width of the border line. By default the width is 2.0.
111 */
114 */
112
115
113 /*!
116 /*!
114 \fn QPen QAreaSeries::pen() const
117 \fn QPen QAreaSeries::pen() const
115 \brief Returns the pen used to draw line for this series.
118 \brief Returns the pen used to draw line for this series.
116 \sa setPen()
119 \sa setPen()
117 */
120 */
118
121
119 /*!
122 /*!
120 \fn QPen QAreaSeries::brush() const
123 \fn QPen QAreaSeries::brush() const
121 \brief Returns the brush used to draw line for this series.
124 \brief Returns the brush used to draw line for this series.
122 \sa setBrush()
125 \sa setBrush()
123 */
126 */
124
127
125 /*!
128 /*!
126 \qmlproperty QString AreaSeries::brushFilename
129 \qmlproperty QString AreaSeries::brushFilename
127 The name of the file used as a brush image for the series.
130 The name of the file used as a brush image for the series.
128 */
131 */
129
132
130 /*!
133 /*!
131 \fn void QAreaSeries::colorChanged(QColor color)
134 \fn void QAreaSeries::colorChanged(QColor color)
132 \brief Signal is emitted when the fill (brush) color has changed to \a color.
135 \brief Signal is emitted when the fill (brush) color has changed to \a color.
133 */
136 */
134 /*!
137 /*!
135 \qmlsignal AreaSeries::onColorChanged(color color)
138 \qmlsignal AreaSeries::onColorChanged(color color)
136 Signal is emitted when the fill (brush) color has changed to \a color.
139 Signal is emitted when the fill (brush) color has changed to \a color.
137 */
140 */
138
141
139 /*!
142 /*!
140 \fn void QAreaSeries::borderColorChanged(QColor color)
143 \fn void QAreaSeries::borderColorChanged(QColor color)
141 \brief Signal is emitted when the line (pen) color has changed to \a color.
144 \brief Signal is emitted when the line (pen) color has changed to \a color.
142 */
145 */
143 /*!
146 /*!
144 \qmlsignal AreaSeries::onBorderColorChanged(color color)
147 \qmlsignal AreaSeries::onBorderColorChanged(color color)
145 Signal is emitted when the line (pen) color has changed to \a color.
148 Signal is emitted when the line (pen) color has changed to \a color.
146 */
149 */
147
150
148 /*!
151 /*!
149 \fn void QAreaSeries::clicked(const QPointF& point)
152 \fn void QAreaSeries::clicked(const QPointF& point)
150 \brief Signal is emitted when user clicks the \a point on area chart. The \a point is the point
153 \brief Signal is emitted when user clicks the \a point on area chart. The \a point is the point
151 where the press was triggered.
154 where the press was triggered.
152 \sa pressed, released, doubleClicked
155 \sa pressed, released, doubleClicked
153 */
156 */
154 /*!
157 /*!
155 \qmlsignal AreaSeries::onClicked(QPointF point)
158 \qmlsignal AreaSeries::onClicked(QPointF point)
156 Signal is emitted when user clicks the \a point on area chart. The \a point is the point where
159 Signal is emitted when user clicks the \a point on area chart. The \a point is the point where
157 the press was triggered.
160 the press was triggered.
158 \sa onPressed, onReleased, onDoubleClicked
161 \sa onPressed, onReleased, onDoubleClicked
159 */
162 */
160
163
161 /*!
164 /*!
162 \fn void QAreaSeries::hovered(const QPointF &point, bool state)
165 \fn void QAreaSeries::hovered(const QPointF &point, bool state)
163 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
166 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
164 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
167 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
165 the series.
168 the series.
166 */
169 */
167 /*!
170 /*!
168 \qmlsignal AreaSeries::onHovered(point point, bool state)
171 \qmlsignal AreaSeries::onHovered(point point, bool state)
169 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
172 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
170 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
173 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
171 the series.
174 the series.
172 */
175 */
173
176
174 /*!
177 /*!
175 \fn void QAreaSeries::pressed(const QPointF& point)
178 \fn void QAreaSeries::pressed(const QPointF& point)
176 \brief Signal is emitted when user presses the \a point on area chart.
179 \brief Signal is emitted when user presses the \a point on area chart.
177 \sa clicked, released, doubleClicked
180 \sa clicked, released, doubleClicked
178 */
181 */
179 /*!
182 /*!
180 \qmlsignal AreaSeries::onPressed(QPointF point)
183 \qmlsignal AreaSeries::onPressed(QPointF point)
181 Signal is emitted when user presses the \a point on area chart.
184 Signal is emitted when user presses the \a point on area chart.
182 \sa onClicked, onReleased, onDoubleClicked
185 \sa onClicked, onReleased, onDoubleClicked
183 */
186 */
184
187
185 /*!
188 /*!
186 \fn void QAreaSeries::released(const QPointF& point)
189 \fn void QAreaSeries::released(const QPointF& point)
187 \brief Signal is emitted when user releases a press that was triggered on a \a point on area
190 \brief Signal is emitted when user releases a press that was triggered on a \a point on area
188 chart.
191 chart.
189 \sa pressed, clicked, doubleClicked
192 \sa pressed, clicked, doubleClicked
190 */
193 */
191 /*!
194 /*!
192 \qmlsignal AreaSeries::onReleased(QPointF point)
195 \qmlsignal AreaSeries::onReleased(QPointF point)
193 Signal is emitted when user releases a press that was triggered on a \a point on area chart.
196 Signal is emitted when user releases a press that was triggered on a \a point on area chart.
194 \sa onPressed, onClicked, onDoubleClicked
197 \sa onPressed, onClicked, onDoubleClicked
195 */
198 */
196
199
197 /*!
200 /*!
198 \fn void QAreaSeries::doubleClicked(const QPointF& point)
201 \fn void QAreaSeries::doubleClicked(const QPointF& point)
199 \brief Signal is emitted when user doubleclicks the \a point on area chart. The \a point is the
202 \brief Signal is emitted when user doubleclicks the \a point on area chart. The \a point is the
200 point where the first press was triggered.
203 point where the first press was triggered.
201 \sa pressed, released, clicked
204 \sa pressed, released, clicked
202 */
205 */
203 /*!
206 /*!
204 \qmlsignal AreaSeries::onDoubleClicked(QPointF point)
207 \qmlsignal AreaSeries::onDoubleClicked(QPointF point)
205 Signal is emitted when user doubleclicks the \a point on area chart. The \a point is the point
208 Signal is emitted when user doubleclicks the \a point on area chart. The \a point is the point
206 where the first press was triggered.
209 where the first press was triggered.
207 \sa onPressed, onReleased, onClicked
210 \sa onPressed, onReleased, onClicked
208 */
211 */
209
212
210 /*!
213 /*!
211 \fn void QAreaSeries::selected()
214 \fn void QAreaSeries::selected()
212 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
215 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
213 implemented by the user of QAreaSeries API.
216 implemented by the user of QAreaSeries API.
214 */
217 */
215 /*!
218 /*!
216 \qmlsignal AreaSeries::onSelected()
219 \qmlsignal AreaSeries::onSelected()
217 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
220 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
218 implemented by the user of AreaSeries API.
221 implemented by the user of AreaSeries API.
219 */
222 */
220
223
221 /*!
224 /*!
222 \fn void QAreaSeriesPrivate::updated()
225 \fn void QAreaSeriesPrivate::updated()
223 \brief \internal
226 \brief \internal
224 */
227 */
225
228
226 /*!
229 /*!
227 \property QAreaSeries::pointLabelsFormat
230 \property QAreaSeries::pointLabelsFormat
228 The \a format used for showing labels with series points.
231 The \a format used for showing labels with series points.
229
232
230 QAreaSeries supports the following format tags:
233 QAreaSeries supports the following format tags:
231 \table
234 \table
232 \row
235 \row
233 \li @xPoint \li The x value of the data point
236 \li @xPoint \li The x value of the data point
234 \row
237 \row
235 \li @yPoint \li The y value of the data point
238 \li @yPoint \li The y value of the data point
236 \endtable
239 \endtable
237
240
238 For example, the following usage of the format tags would produce labels that have the data
241 For example, the following usage of the format tags would produce labels that have the data
239 point (x, y) shown inside brackets separated by a comma:
242 point (x, y) shown inside brackets separated by a comma:
240 \code
243 \code
241 series->setPointLabelsFormat("(@xPoint, @yPoint)");
244 series->setPointLabelsFormat("(@xPoint, @yPoint)");
242 \endcode
245 \endcode
243
246
244 By default, the labels format is set to '@xPoint, @yPoint'. The labels are shown on the plot
247 By default, the labels format is set to '@xPoint, @yPoint'. The labels are shown on the plot
245 area, labels on the edge of the plot area are cut. If the points are close to each other the
248 area, labels on the edge of the plot area are cut. If the points are close to each other the
246 labels may overlap.
249 labels may overlap.
247
250
248 \sa QAreaSeries::pointLabelsVisible, QAreaSeries::pointLabelsFont, QAreaSeries::pointLabelsColor
251 \sa QAreaSeries::pointLabelsVisible, QAreaSeries::pointLabelsFont, QAreaSeries::pointLabelsColor
249 */
252 */
250 /*!
253 /*!
251 \qmlproperty string AreaSeries::pointLabelsFormat
254 \qmlproperty string AreaSeries::pointLabelsFormat
252 The \a format used for showing labels with series points.
255 The \a format used for showing labels with series points.
253
256
254 \sa QAreaSeries::pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor
257 \sa QAreaSeries::pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor
255 */
258 */
256 /*!
259 /*!
257 \fn void QAreaSeries::pointLabelsFormatChanged(const QString &format)
260 \fn void QAreaSeries::pointLabelsFormatChanged(const QString &format)
258 Signal is emitted when the \a format of data point labels is changed.
261 Signal is emitted when the \a format of data point labels is changed.
259 */
262 */
260 /*!
263 /*!
261 \qmlsignal AreaSeries::onPointLabelsFormatChanged(string format)
264 \qmlsignal AreaSeries::onPointLabelsFormatChanged(string format)
262 Signal is emitted when the \a format of data point labels is changed.
265 Signal is emitted when the \a format of data point labels is changed.
263 */
266 */
264
267
265 /*!
268 /*!
266 \property QAreaSeries::pointLabelsVisible
269 \property QAreaSeries::pointLabelsVisible
267 Defines the visibility for data point labels. False by default.
270 Defines the visibility for data point labels. False by default.
268
271
269 \sa QAreaSeries::pointLabelsFormat
272 \sa QAreaSeries::pointLabelsFormat
270 */
273 */
271 /*!
274 /*!
272 \qmlproperty bool AreaSeries::pointLabelsVisible
275 \qmlproperty bool AreaSeries::pointLabelsVisible
273 Defines the visibility for data point labels.
276 Defines the visibility for data point labels.
274
277
275 \sa pointLabelsFormat
278 \sa pointLabelsFormat
276 */
279 */
277 /*!
280 /*!
278 \fn void QAreaSeries::pointLabelsVisibilityChanged(bool visible)
281 \fn void QAreaSeries::pointLabelsVisibilityChanged(bool visible)
279 The visibility of the data point labels is changed to \a visible.
282 The visibility of the data point labels is changed to \a visible.
280 */
283 */
281 /*!
284 /*!
282 \qmlsignal AreaSeries::onPointLabelsVisibilityChanged(bool visible)
285 \qmlsignal AreaSeries::onPointLabelsVisibilityChanged(bool visible)
283 The visibility of the data point labels is changed to \a visible.
286 The visibility of the data point labels is changed to \a visible.
284 */
287 */
285
288
286 /*!
289 /*!
287 \property QAreaSeries::pointLabelsFont
290 \property QAreaSeries::pointLabelsFont
288 Defines the font used for data point labels.
291 Defines the font used for data point labels.
289
292
290 \sa QAreaSeries::pointLabelsFormat
293 \sa QAreaSeries::pointLabelsFormat
291 */
294 */
292 /*!
295 /*!
293 \qmlproperty font AreaSeries::pointLabelsFont
296 \qmlproperty font AreaSeries::pointLabelsFont
294 Defines the font used for data point labels.
297 Defines the font used for data point labels.
295
298
296 \sa pointLabelsFormat
299 \sa pointLabelsFormat
297 */
300 */
298 /*!
301 /*!
299 \fn void QAreaSeries::pointLabelsFontChanged(const QFont &font);
302 \fn void QAreaSeries::pointLabelsFontChanged(const QFont &font);
300 The font used for data point labels is changed to \a font.
303 The font used for data point labels is changed to \a font.
301 */
304 */
302 /*!
305 /*!
303 \qmlsignal AreaSeries::onPointLabelsFontChanged(Font font)
306 \qmlsignal AreaSeries::onPointLabelsFontChanged(Font font)
304 The font used for data point labels is changed to \a font.
307 The font used for data point labels is changed to \a font.
305 */
308 */
306
309
307 /*!
310 /*!
308 \property QAreaSeries::pointLabelsColor
311 \property QAreaSeries::pointLabelsColor
309 Defines the color used for data point labels. By default, the color is the color of the brush
312 Defines the color used for data point labels. By default, the color is the color of the brush
310 defined in theme for labels.
313 defined in theme for labels.
311
314
312 \sa QAreaSeries::pointLabelsFormat
315 \sa QAreaSeries::pointLabelsFormat
313 */
316 */
314 /*!
317 /*!
315 \qmlproperty font AreaSeries::pointLabelsColor
318 \qmlproperty font AreaSeries::pointLabelsColor
316 Defines the color used for data point labels. By default, the color is the color of the brush
319 Defines the color used for data point labels. By default, the color is the color of the brush
317 defined in theme for labels.
320 defined in theme for labels.
318
321
319 \sa pointLabelsFormat
322 \sa pointLabelsFormat
320 */
323 */
321 /*!
324 /*!
322 \fn void QAreaSeries::pointLabelsColorChanged(const QColor &color);
325 \fn void QAreaSeries::pointLabelsColorChanged(const QColor &color);
323 The color used for data point labels is changed to \a color.
326 The color used for data point labels is changed to \a color.
324 */
327 */
325 /*!
328 /*!
326 \qmlsignal AreaSeries::onPointLabelsColorChanged(Color color)
329 \qmlsignal AreaSeries::onPointLabelsColorChanged(Color color)
327 The color used for data point labels is changed to \a color.
330 The color used for data point labels is changed to \a color.
328 */
331 */
329
332
330 /*!
333 /*!
331 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
334 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
332 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
335 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
333 When series object is added to QChartView or QChart instance ownerships is transferred.
336 When series object is added to QChartView or QChart instance ownerships is transferred.
334 */
337 */
335 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
338 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
336 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries)
339 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries)
337 {
340 {
338 }
341 }
339
342
340 /*!
343 /*!
341 Constructs area series object without upper or lower series with \a parent object.
344 Constructs area series object without upper or lower series with \a parent object.
342 */
345 */
343 QAreaSeries::QAreaSeries(QObject *parent)
346 QAreaSeries::QAreaSeries(QObject *parent)
344 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
347 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
345 {
348 {
346 }
349 }
347
350
348 /*!
351 /*!
349 Destroys the object.
352 Destroys the object.
350 */
353 */
351 QAreaSeries::~QAreaSeries()
354 QAreaSeries::~QAreaSeries()
352 {
355 {
353 Q_D(QAreaSeries);
356 Q_D(QAreaSeries);
354 if (d->m_chart)
357 if (d->m_chart)
355 d->m_chart->removeSeries(this);
358 d->m_chart->removeSeries(this);
356 }
359 }
357
360
358 /*!
361 /*!
359 Returns QAbstractSeries::SeriesTypeArea.
362 Returns QAbstractSeries::SeriesTypeArea.
360 */
363 */
361 QAbstractSeries::SeriesType QAreaSeries::type() const
364 QAbstractSeries::SeriesType QAreaSeries::type() const
362 {
365 {
363 return QAbstractSeries::SeriesTypeArea;
366 return QAbstractSeries::SeriesTypeArea;
364 }
367 }
365
368
366 /*!
369 /*!
367 Sets the \a series that is to be used as the area chart upper series.
370 Sets the \a series that is to be used as the area chart upper series.
368 */
371 */
369 void QAreaSeries::setUpperSeries(QLineSeries *series)
372 void QAreaSeries::setUpperSeries(QLineSeries *series)
370 {
373 {
371 Q_D(QAreaSeries);
374 Q_D(QAreaSeries);
372 if (d->m_upperSeries != series)
375 if (d->m_upperSeries != series)
373 d->m_upperSeries = series;
376 d->m_upperSeries = series;
374 }
377 }
375
378
376 QLineSeries *QAreaSeries::upperSeries() const
379 QLineSeries *QAreaSeries::upperSeries() const
377 {
380 {
378 Q_D(const QAreaSeries);
381 Q_D(const QAreaSeries);
379 return d->m_upperSeries;
382 return d->m_upperSeries;
380 }
383 }
381
384
382 /*!
385 /*!
383 Sets the \a series that is to be used as the area chart lower series.
386 Sets the \a series that is to be used as the area chart lower series.
384 */
387 */
385 void QAreaSeries::setLowerSeries(QLineSeries *series)
388 void QAreaSeries::setLowerSeries(QLineSeries *series)
386 {
389 {
387 Q_D(QAreaSeries);
390 Q_D(QAreaSeries);
388 d->m_lowerSeries = series;
391 d->m_lowerSeries = series;
389 }
392 }
390
393
391 QLineSeries *QAreaSeries::lowerSeries() const
394 QLineSeries *QAreaSeries::lowerSeries() const
392 {
395 {
393 Q_D(const QAreaSeries);
396 Q_D(const QAreaSeries);
394 return d->m_lowerSeries;
397 return d->m_lowerSeries;
395 }
398 }
396
399
397 /*!
400 /*!
398 Sets \a pen used for drawing area outline.
401 Sets \a pen used for drawing area outline.
399 */
402 */
400 void QAreaSeries::setPen(const QPen &pen)
403 void QAreaSeries::setPen(const QPen &pen)
401 {
404 {
402 Q_D(QAreaSeries);
405 Q_D(QAreaSeries);
403 if (d->m_pen != pen) {
406 if (d->m_pen != pen) {
404 d->m_pen = pen;
407 d->m_pen = pen;
405 emit d->updated();
408 emit d->updated();
406 }
409 }
407 }
410 }
408
411
409 QPen QAreaSeries::pen() const
412 QPen QAreaSeries::pen() const
410 {
413 {
411 Q_D(const QAreaSeries);
414 Q_D(const QAreaSeries);
412 if (d->m_pen == QChartPrivate::defaultPen())
415 if (d->m_pen == QChartPrivate::defaultPen())
413 return QPen();
416 return QPen();
414 else
417 else
415 return d->m_pen;
418 return d->m_pen;
416 }
419 }
417
420
418 /*!
421 /*!
419 Sets \a brush used for filling the area.
422 Sets \a brush used for filling the area.
420 */
423 */
421 void QAreaSeries::setBrush(const QBrush &brush)
424 void QAreaSeries::setBrush(const QBrush &brush)
422 {
425 {
423 Q_D(QAreaSeries);
426 Q_D(QAreaSeries);
424 if (d->m_brush != brush) {
427 if (d->m_brush != brush) {
425 bool emitColorChanged = brush.color() != d->m_brush.color();
428 bool emitColorChanged = brush.color() != d->m_brush.color();
426 d->m_brush = brush;
429 d->m_brush = brush;
427 emit d->updated();
430 emit d->updated();
428 if (emitColorChanged)
431 if (emitColorChanged)
429 emit colorChanged(brush.color());
432 emit colorChanged(brush.color());
430 }
433 }
431 }
434 }
432
435
433 QBrush QAreaSeries::brush() const
436 QBrush QAreaSeries::brush() const
434 {
437 {
435 Q_D(const QAreaSeries);
438 Q_D(const QAreaSeries);
436 if (d->m_brush == QChartPrivate::defaultBrush())
439 if (d->m_brush == QChartPrivate::defaultBrush())
437 return QBrush();
440 return QBrush();
438 else
441 else
439 return d->m_brush;
442 return d->m_brush;
440 }
443 }
441
444
442 void QAreaSeries::setColor(const QColor &color)
445 void QAreaSeries::setColor(const QColor &color)
443 {
446 {
444 QBrush b = brush();
447 QBrush b = brush();
445 if (b == QBrush())
448 if (b == QBrush())
446 b.setStyle(Qt::SolidPattern);
449 b.setStyle(Qt::SolidPattern);
447 b.setColor(color);
450 b.setColor(color);
448 setBrush(b);
451 setBrush(b);
449 }
452 }
450
453
451 QColor QAreaSeries::color() const
454 QColor QAreaSeries::color() const
452 {
455 {
453 return brush().color();
456 return brush().color();
454 }
457 }
455
458
456 void QAreaSeries::setBorderColor(const QColor &color)
459 void QAreaSeries::setBorderColor(const QColor &color)
457 {
460 {
458 QPen p = pen();
461 QPen p = pen();
459 if (p.color() != color) {
462 if (p.color() != color) {
460 p.setColor(color);
463 p.setColor(color);
461 setPen(p);
464 setPen(p);
462 emit borderColorChanged(color);
465 emit borderColorChanged(color);
463 }
466 }
464 }
467 }
465
468
466 QColor QAreaSeries::borderColor() const
469 QColor QAreaSeries::borderColor() const
467 {
470 {
468 return pen().color();
471 return pen().color();
469 }
472 }
470
473
471 /*!
474 /*!
472 Sets if data points are \a visible and should be drawn on line.
475 Sets if data points are \a visible and should be drawn on line.
473 */
476 */
474 void QAreaSeries::setPointsVisible(bool visible)
477 void QAreaSeries::setPointsVisible(bool visible)
475 {
478 {
476 Q_D(QAreaSeries);
479 Q_D(QAreaSeries);
477 if (d->m_pointsVisible != visible) {
480 if (d->m_pointsVisible != visible) {
478 d->m_pointsVisible = visible;
481 d->m_pointsVisible = visible;
479 emit d->updated();
482 emit d->updated();
480 }
483 }
481 }
484 }
482
485
483 /*!
486 /*!
484 Returns if the points are drawn for this series.
487 Returns if the points are drawn for this series.
485 \sa setPointsVisible()
488 \sa setPointsVisible()
486 */
489 */
487 bool QAreaSeries::pointsVisible() const
490 bool QAreaSeries::pointsVisible() const
488 {
491 {
489 Q_D(const QAreaSeries);
492 Q_D(const QAreaSeries);
490 return d->m_pointsVisible;
493 return d->m_pointsVisible;
491 }
494 }
492
495
493 void QAreaSeries::setPointLabelsFormat(const QString &format)
496 void QAreaSeries::setPointLabelsFormat(const QString &format)
494 {
497 {
495 Q_D(QAreaSeries);
498 Q_D(QAreaSeries);
496 if (d->m_pointLabelsFormat != format) {
499 if (d->m_pointLabelsFormat != format) {
497 d->m_pointLabelsFormat = format;
500 d->m_pointLabelsFormat = format;
498 emit pointLabelsFormatChanged(format);
501 emit pointLabelsFormatChanged(format);
499 }
502 }
500 }
503 }
501
504
502 QString QAreaSeries::pointLabelsFormat() const
505 QString QAreaSeries::pointLabelsFormat() const
503 {
506 {
504 Q_D(const QAreaSeries);
507 Q_D(const QAreaSeries);
505 return d->m_pointLabelsFormat;
508 return d->m_pointLabelsFormat;
506 }
509 }
507
510
508 void QAreaSeries::setPointLabelsVisible(bool visible)
511 void QAreaSeries::setPointLabelsVisible(bool visible)
509 {
512 {
510 Q_D(QAreaSeries);
513 Q_D(QAreaSeries);
511 if (d->m_pointLabelsVisible != visible) {
514 if (d->m_pointLabelsVisible != visible) {
512 d->m_pointLabelsVisible = visible;
515 d->m_pointLabelsVisible = visible;
513 emit pointLabelsVisibilityChanged(visible);
516 emit pointLabelsVisibilityChanged(visible);
514 }
517 }
515 }
518 }
516
519
517 bool QAreaSeries::pointLabelsVisible() const
520 bool QAreaSeries::pointLabelsVisible() const
518 {
521 {
519 Q_D(const QAreaSeries);
522 Q_D(const QAreaSeries);
520 return d->m_pointLabelsVisible;
523 return d->m_pointLabelsVisible;
521 }
524 }
522
525
523 void QAreaSeries::setPointLabelsFont(const QFont &font)
526 void QAreaSeries::setPointLabelsFont(const QFont &font)
524 {
527 {
525 Q_D(QAreaSeries);
528 Q_D(QAreaSeries);
526 if (d->m_pointLabelsFont != font) {
529 if (d->m_pointLabelsFont != font) {
527 d->m_pointLabelsFont = font;
530 d->m_pointLabelsFont = font;
528 emit pointLabelsFontChanged(font);
531 emit pointLabelsFontChanged(font);
529 }
532 }
530 }
533 }
531
534
532 QFont QAreaSeries::pointLabelsFont() const
535 QFont QAreaSeries::pointLabelsFont() const
533 {
536 {
534 Q_D(const QAreaSeries);
537 Q_D(const QAreaSeries);
535 return d->m_pointLabelsFont;
538 return d->m_pointLabelsFont;
536 }
539 }
537
540
538 void QAreaSeries::setPointLabelsColor(const QColor &color)
541 void QAreaSeries::setPointLabelsColor(const QColor &color)
539 {
542 {
540 Q_D(QAreaSeries);
543 Q_D(QAreaSeries);
541 if (d->m_pointLabelsColor != color) {
544 if (d->m_pointLabelsColor != color) {
542 d->m_pointLabelsColor = color;
545 d->m_pointLabelsColor = color;
543 emit pointLabelsColorChanged(color);
546 emit pointLabelsColorChanged(color);
544 }
547 }
545 }
548 }
546
549
547 QColor QAreaSeries::pointLabelsColor() const
550 QColor QAreaSeries::pointLabelsColor() const
548 {
551 {
549 Q_D(const QAreaSeries);
552 Q_D(const QAreaSeries);
550 if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color())
553 if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color())
551 return QPen().color();
554 return QPen().color();
552 else
555 else
553 return d->m_pointLabelsColor;
556 return d->m_pointLabelsColor;
554 }
557 }
555
558
556 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
559 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
557
560
558 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q)
561 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q)
559 : QAbstractSeriesPrivate(q),
562 : QAbstractSeriesPrivate(q),
560 m_brush(QChartPrivate::defaultBrush()),
563 m_brush(QChartPrivate::defaultBrush()),
561 m_pen(QChartPrivate::defaultPen()),
564 m_pen(QChartPrivate::defaultPen()),
562 m_upperSeries(upperSeries),
565 m_upperSeries(upperSeries),
563 m_lowerSeries(lowerSeries),
566 m_lowerSeries(lowerSeries),
564 m_pointsVisible(false),
567 m_pointsVisible(false),
565 m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")),
568 m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")),
566 m_pointLabelsVisible(false),
569 m_pointLabelsVisible(false),
567 m_pointLabelsFont(QChartPrivate::defaultFont()),
570 m_pointLabelsFont(QChartPrivate::defaultFont()),
568 m_pointLabelsColor(QChartPrivate::defaultPen().color())
571 m_pointLabelsColor(QChartPrivate::defaultPen().color())
569 {
572 {
570 }
573 }
571
574
572 void QAreaSeriesPrivate::initializeDomain()
575 void QAreaSeriesPrivate::initializeDomain()
573 {
576 {
574 Q_Q(QAreaSeries);
577 Q_Q(QAreaSeries);
575
578
576 qreal minX(domain()->minX());
579 qreal minX(domain()->minX());
577 qreal minY(domain()->minY());
580 qreal minY(domain()->minY());
578 qreal maxX(domain()->maxX());
581 qreal maxX(domain()->maxX());
579 qreal maxY(domain()->maxY());
582 qreal maxY(domain()->maxY());
580
583
581 QLineSeries *upperSeries = q->upperSeries();
584 QLineSeries *upperSeries = q->upperSeries();
582 QLineSeries *lowerSeries = q->lowerSeries();
585 QLineSeries *lowerSeries = q->lowerSeries();
583
586
584 if (upperSeries) {
587 if (upperSeries) {
585 const QList<QPointF>& points = upperSeries->points();
588 const QList<QPointF>& points = upperSeries->points();
586
589
587 for (int i = 0; i < points.count(); i++) {
590 for (int i = 0; i < points.count(); i++) {
588 qreal x = points[i].x();
591 qreal x = points[i].x();
589 qreal y = points[i].y();
592 qreal y = points[i].y();
590 minX = qMin(minX, x);
593 minX = qMin(minX, x);
591 minY = qMin(minY, y);
594 minY = qMin(minY, y);
592 maxX = qMax(maxX, x);
595 maxX = qMax(maxX, x);
593 maxY = qMax(maxY, y);
596 maxY = qMax(maxY, y);
594 }
597 }
595 }
598 }
596 if (lowerSeries) {
599 if (lowerSeries) {
597
600
598 const QList<QPointF>& points = lowerSeries->points();
601 const QList<QPointF>& points = lowerSeries->points();
599
602
600 for (int i = 0; i < points.count(); i++) {
603 for (int i = 0; i < points.count(); i++) {
601 qreal x = points[i].x();
604 qreal x = points[i].x();
602 qreal y = points[i].y();
605 qreal y = points[i].y();
603 minX = qMin(minX, x);
606 minX = qMin(minX, x);
604 minY = qMin(minY, y);
607 minY = qMin(minY, y);
605 maxX = qMax(maxX, x);
608 maxX = qMax(maxX, x);
606 maxY = qMax(maxY, y);
609 maxY = qMax(maxY, y);
607 }
610 }
608 }
611 }
609
612
610 domain()->setRange(minX, maxX, minY, maxY);
613 domain()->setRange(minX, maxX, minY, maxY);
611 }
614 }
612
615
613 void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
616 void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
614 {
617 {
615 Q_Q(QAreaSeries);
618 Q_Q(QAreaSeries);
616 AreaChartItem *area = new AreaChartItem(q,parent);
619 AreaChartItem *area = new AreaChartItem(q,parent);
617 m_item.reset(area);
620 m_item.reset(area);
618 QAbstractSeriesPrivate::initializeGraphics(parent);
621 QAbstractSeriesPrivate::initializeGraphics(parent);
619 }
622 }
620 void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
623 void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
621 {
624 {
622 Q_Q(QAreaSeries);
625 Q_Q(QAreaSeries);
623 AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data());
626 AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data());
624
627
625 if (q->upperSeries() && area->upperLineItem()->animation())
628 if (q->upperSeries() && area->upperLineItem()->animation())
626 area->upperLineItem()->animation()->stopAndDestroyLater();
629 area->upperLineItem()->animation()->stopAndDestroyLater();
627 if (q->lowerSeries() && area->lowerLineItem()->animation())
630 if (q->lowerSeries() && area->lowerLineItem()->animation())
628 area->lowerLineItem()->animation()->stopAndDestroyLater();
631 area->lowerLineItem()->animation()->stopAndDestroyLater();
629
632
630 if (options.testFlag(QChart::SeriesAnimations)) {
633 if (options.testFlag(QChart::SeriesAnimations)) {
631 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
634 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
632 if (q->lowerSeries())
635 if (q->lowerSeries())
633 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
636 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
634 } else {
637 } else {
635 if (q->upperSeries())
638 if (q->upperSeries())
636 area->upperLineItem()->setAnimation(0);
639 area->upperLineItem()->setAnimation(0);
637 if (q->lowerSeries())
640 if (q->lowerSeries())
638 area->lowerLineItem()->setAnimation(0);
641 area->lowerLineItem()->setAnimation(0);
639 }
642 }
640 QAbstractSeriesPrivate::initializeAnimations(options);
643 QAbstractSeriesPrivate::initializeAnimations(options);
641 }
644 }
642
645
643 QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend)
646 QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend)
644 {
647 {
645 Q_Q(QAreaSeries);
648 Q_Q(QAreaSeries);
646 QList<QLegendMarker*> list;
649 QList<QLegendMarker*> list;
647 return list << new QAreaLegendMarker(q,legend);
650 return list << new QAreaLegendMarker(q,legend);
648 }
651 }
649
652
650
653
651 void QAreaSeriesPrivate::initializeAxes()
654 void QAreaSeriesPrivate::initializeAxes()
652 {
655 {
653
656
654 }
657 }
655
658
656 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
659 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
657 {
660 {
658 Q_UNUSED(orientation);
661 Q_UNUSED(orientation);
659 return QAbstractAxis::AxisTypeValue;
662 return QAbstractAxis::AxisTypeValue;
660 }
663 }
661
664
662 QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
665 QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
663 {
666 {
664 Q_UNUSED(orientation);
667 Q_UNUSED(orientation);
665 return new QValueAxis;
668 return new QValueAxis;
666 }
669 }
667
670
668 void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
671 void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
669 {
672 {
670 Q_Q(QAreaSeries);
673 Q_Q(QAreaSeries);
671
674
672 const QList<QGradient> gradients = theme->seriesGradients();
675 const QList<QGradient> gradients = theme->seriesGradients();
673 const QList<QColor> colors = theme->seriesColors();
676 const QList<QColor> colors = theme->seriesColors();
674
677
675 if (forced || QChartPrivate::defaultPen() == m_pen) {
678 if (forced || QChartPrivate::defaultPen() == m_pen) {
676 QPen pen;
679 QPen pen;
677 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
680 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
678 pen.setWidthF(2);
681 pen.setWidthF(2);
679 q->setPen(pen);
682 q->setPen(pen);
680 }
683 }
681
684
682 if (forced || QChartPrivate::defaultBrush() == m_brush) {
685 if (forced || QChartPrivate::defaultBrush() == m_brush) {
683 QBrush brush(colors.at(index % colors.size()));
686 QBrush brush(colors.at(index % colors.size()));
684 q->setBrush(brush);
687 q->setBrush(brush);
685 }
688 }
686
689
687 if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) {
690 if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) {
688 QColor color = theme->labelBrush().color();
691 QColor color = theme->labelBrush().color();
689 q->setPointLabelsColor(color);
692 q->setPointLabelsColor(color);
690 }
693 }
691 }
694 }
692
695
693
696
694 #include "moc_qareaseries.cpp"
697 #include "moc_qareaseries.cpp"
695 #include "moc_qareaseries_p.cpp"
698 #include "moc_qareaseries_p.cpp"
696
699
697 QT_CHARTS_END_NAMESPACE
700 QT_CHARTS_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now