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