##// END OF EJS Templates
Fix color setting...
Titta Heikkala -
r2852:5f71da41b84f
parent child
Show More
@@ -1,1093 +1,1093
1 /******************************************************************************
1 /******************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
4 ** Contact: http://www.qt.io/licensing/
5 **
5 **
6 ** This file is part of the Qt Charts module.
6 ** This file is part of the Qt Charts module.
7 **
7 **
8 ** $QT_BEGIN_LICENSE:COMM$
8 ** $QT_BEGIN_LICENSE:COMM$
9 **
9 **
10 ** Commercial License Usage
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** and conditions see http://www.qt.io/terms-conditions. For further
16 ** information use the contact form at http://www.qt.io/contact-us.
16 ** information use the contact form at http://www.qt.io/contact-us.
17 **
17 **
18 ** $QT_END_LICENSE$
18 ** $QT_END_LICENSE$
19 **
19 **
20 ******************************************************************************/
20 ******************************************************************************/
21
21
22 #include <QtCharts/QAbstractAxis>
22 #include <QtCharts/QAbstractAxis>
23 #include <private/qabstractaxis_p.h>
23 #include <private/qabstractaxis_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 <private/qchart_p.h>
26 #include <private/qchart_p.h>
27
27
28 QT_CHARTS_BEGIN_NAMESPACE
28 QT_CHARTS_BEGIN_NAMESPACE
29
29
30 /*!
30 /*!
31 \class QAbstractAxis
31 \class QAbstractAxis
32 \inmodule Qt Charts
32 \inmodule Qt Charts
33 \brief The QAbstractAxis class is used for manipulating chart's axis.
33 \brief The QAbstractAxis class is used for manipulating chart's axis.
34
34
35 Each series can be bound to one or more horizontal and vertical axes, but mixing axis types
35 Each series can be bound to one or more horizontal and vertical axes, but mixing axis types
36 that would result in different domains is not supported, such as specifying
36 that would result in different domains is not supported, such as specifying
37 QValueAxis and QLogValueAxis on the same orientation.
37 QValueAxis and QLogValueAxis on the same orientation.
38
38
39 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
39 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
40 and shades can be individually controlled.
40 and shades can be individually controlled.
41 */
41 */
42 /*!
42 /*!
43 \qmltype AbstractAxis
43 \qmltype AbstractAxis
44 \instantiates QAbstractAxis
44 \instantiates QAbstractAxis
45 \inqmlmodule QtCharts
45 \inqmlmodule QtCharts
46
46
47 \brief The AbstractAxis is a base element used for specialized axis elements.
47 \brief The AbstractAxis is a base element used for specialized axis elements.
48
48
49 Each series can be bound to only one horizontal and vertical axis.
49 Each series can be bound to only one horizontal and vertical axis.
50
50
51 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
51 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
52 and shades can be individually controlled.
52 and shades can be individually controlled.
53 */
53 */
54
54
55 /*!
55 /*!
56 \enum QAbstractAxis::AxisType
56 \enum QAbstractAxis::AxisType
57
57
58 The type of the axis object.
58 The type of the axis object.
59
59
60 \value AxisTypeNoAxis
60 \value AxisTypeNoAxis
61 \value AxisTypeValue
61 \value AxisTypeValue
62 \value AxisTypeBarCategory
62 \value AxisTypeBarCategory
63 \value AxisTypeCategory
63 \value AxisTypeCategory
64 \value AxisTypeDateTime
64 \value AxisTypeDateTime
65 \value AxisTypeLogValue
65 \value AxisTypeLogValue
66 */
66 */
67
67
68 /*!
68 /*!
69 *\fn void QAbstractAxis::type() const
69 *\fn void QAbstractAxis::type() const
70 Returns the type of the axis
70 Returns the type of the axis
71 */
71 */
72
72
73 /*!
73 /*!
74 \property QAbstractAxis::lineVisible
74 \property QAbstractAxis::lineVisible
75 The visibility of the axis line
75 The visibility of the axis line
76 */
76 */
77 /*!
77 /*!
78 \qmlproperty bool AbstractAxis::lineVisible
78 \qmlproperty bool AbstractAxis::lineVisible
79 The visibility of the axis line
79 The visibility of the axis line
80 */
80 */
81
81
82 /*!
82 /*!
83 \property QAbstractAxis::linePen
83 \property QAbstractAxis::linePen
84 The pen of the line.
84 The pen of the line.
85 */
85 */
86
86
87 /*!
87 /*!
88 \property QAbstractAxis::labelsVisible
88 \property QAbstractAxis::labelsVisible
89 Defines if axis labels are visible.
89 Defines if axis labels are visible.
90 */
90 */
91 /*!
91 /*!
92 \qmlproperty bool AbstractAxis::labelsVisible
92 \qmlproperty bool AbstractAxis::labelsVisible
93 Defines if axis labels are visible.
93 Defines if axis labels are visible.
94 */
94 */
95
95
96 /*!
96 /*!
97 \property QAbstractAxis::labelsBrush
97 \property QAbstractAxis::labelsBrush
98 The brush of the labels. Only the color of the brush is relevant.
98 The brush of the labels. Only the color of the brush is relevant.
99 */
99 */
100
100
101 /*!
101 /*!
102 \property QAbstractAxis::visible
102 \property QAbstractAxis::visible
103 The visibility of the axis.
103 The visibility of the axis.
104 */
104 */
105 /*!
105 /*!
106 \qmlproperty bool AbstractAxis::visible
106 \qmlproperty bool AbstractAxis::visible
107 The visibility of the axis.
107 The visibility of the axis.
108 */
108 */
109
109
110 /*!
110 /*!
111 \property QAbstractAxis::gridVisible
111 \property QAbstractAxis::gridVisible
112 The visibility of the grid lines.
112 The visibility of the grid lines.
113 */
113 */
114 /*!
114 /*!
115 \qmlproperty bool AbstractAxis::gridVisible
115 \qmlproperty bool AbstractAxis::gridVisible
116 The visibility of the grid lines.
116 The visibility of the grid lines.
117 */
117 */
118
118
119 /*!
119 /*!
120 \property QAbstractAxis::minorGridVisible
120 \property QAbstractAxis::minorGridVisible
121 The visibility of the minor grid lines. Applies only to QValueAxis.
121 The visibility of the minor grid lines. Applies only to QValueAxis.
122 */
122 */
123 /*!
123 /*!
124 \qmlproperty bool AbstractAxis::minorGridVisible
124 \qmlproperty bool AbstractAxis::minorGridVisible
125 The visibility of the minor grid lines. Applies only to QValueAxis.
125 The visibility of the minor grid lines. Applies only to QValueAxis.
126 */
126 */
127
127
128 /*!
128 /*!
129 \property QAbstractAxis::color
129 \property QAbstractAxis::color
130 The color of the axis and ticks.
130 The color of the axis and ticks.
131 */
131 */
132 /*!
132 /*!
133 \qmlproperty color AbstractAxis::color
133 \qmlproperty color AbstractAxis::color
134 The color of the axis and ticks.
134 The color of the axis and ticks.
135 */
135 */
136
136
137 /*!
137 /*!
138 \property QAbstractAxis::gridLinePen
138 \property QAbstractAxis::gridLinePen
139 The pen of the grid line.
139 The pen of the grid line.
140 */
140 */
141
141
142 /*!
142 /*!
143 \property QAbstractAxis::minorGridLinePen
143 \property QAbstractAxis::minorGridLinePen
144 The pen of the minor grid line. Applies only to QValueAxis.
144 The pen of the minor grid line. Applies only to QValueAxis.
145 */
145 */
146
146
147 /*!
147 /*!
148 \property QAbstractAxis::gridLineColor
148 \property QAbstractAxis::gridLineColor
149 The color of the grid line.
149 The color of the grid line.
150 */
150 */
151
151
152 /*!
152 /*!
153 \property QAbstractAxis::minorGridLineColor
153 \property QAbstractAxis::minorGridLineColor
154 The color of the minor grid line. Applies only to QValueAxis.
154 The color of the minor grid line. Applies only to QValueAxis.
155 */
155 */
156
156
157 /*!
157 /*!
158 \property QAbstractAxis::labelsFont
158 \property QAbstractAxis::labelsFont
159 The font of the axis labels.
159 The font of the axis labels.
160 */
160 */
161
161
162 /*!
162 /*!
163 \qmlproperty Font AbstractAxis::labelsFont
163 \qmlproperty Font AbstractAxis::labelsFont
164 The font of the axis labels.
164 The font of the axis labels.
165
165
166 See the Qt documentation for more details of Font.
166 See the Qt documentation for more details of Font.
167 */
167 */
168
168
169 /*!
169 /*!
170 \property QAbstractAxis::labelsColor
170 \property QAbstractAxis::labelsColor
171 The color of the axis labels.
171 The color of the axis labels.
172 */
172 */
173 /*!
173 /*!
174 \qmlproperty color AbstractAxis::labelsColor
174 \qmlproperty color AbstractAxis::labelsColor
175 The color of the axis labels.
175 The color of the axis labels.
176 */
176 */
177
177
178 /*!
178 /*!
179 \property QAbstractAxis::labelsAngle
179 \property QAbstractAxis::labelsAngle
180 The angle of the axis labels in degrees.
180 The angle of the axis labels in degrees.
181 */
181 */
182 /*!
182 /*!
183 \qmlproperty int AbstractAxis::labelsAngle
183 \qmlproperty int AbstractAxis::labelsAngle
184 The angle of the axis labels in degrees.
184 The angle of the axis labels in degrees.
185 */
185 */
186
186
187 /*!
187 /*!
188 \property QAbstractAxis::shadesVisible
188 \property QAbstractAxis::shadesVisible
189 The visibility of the axis shades.
189 The visibility of the axis shades.
190 */
190 */
191 /*!
191 /*!
192 \qmlproperty bool AbstractAxis::shadesVisible
192 \qmlproperty bool AbstractAxis::shadesVisible
193 The visibility of the axis shades.
193 The visibility of the axis shades.
194 */
194 */
195
195
196 /*!
196 /*!
197 \property QAbstractAxis::shadesColor
197 \property QAbstractAxis::shadesColor
198 The fill (brush) color of the axis shades.
198 The fill (brush) color of the axis shades.
199 */
199 */
200 /*!
200 /*!
201 \qmlproperty color AbstractAxis::shadesColor
201 \qmlproperty color AbstractAxis::shadesColor
202 The fill (brush) color of the axis shades.
202 The fill (brush) color of the axis shades.
203 */
203 */
204
204
205 /*!
205 /*!
206 \property QAbstractAxis::shadesBorderColor
206 \property QAbstractAxis::shadesBorderColor
207 The border (pen) color of the axis shades.
207 The border (pen) color of the axis shades.
208 */
208 */
209 /*!
209 /*!
210 \qmlproperty color AbstractAxis::shadesBorderColor
210 \qmlproperty color AbstractAxis::shadesBorderColor
211 The border (pen) color of the axis shades.
211 The border (pen) color of the axis shades.
212 */
212 */
213
213
214 /*!
214 /*!
215 \property QAbstractAxis::shadesPen
215 \property QAbstractAxis::shadesPen
216 The pen of the axis shades (area between grid lines).
216 The pen of the axis shades (area between grid lines).
217 */
217 */
218
218
219 /*!
219 /*!
220 \property QAbstractAxis::shadesBrush
220 \property QAbstractAxis::shadesBrush
221 The brush of the axis shades (area between grid lines).
221 The brush of the axis shades (area between grid lines).
222 */
222 */
223
223
224 /*!
224 /*!
225 \property QAbstractAxis::titleVisible
225 \property QAbstractAxis::titleVisible
226 The visibility of the axis title. By default the value is true.
226 The visibility of the axis title. By default the value is true.
227 */
227 */
228 /*!
228 /*!
229 \qmlproperty bool AbstractAxis::titleVisible
229 \qmlproperty bool AbstractAxis::titleVisible
230 The visibility of the axis title. By default the value is true.
230 The visibility of the axis title. By default the value is true.
231 */
231 */
232
232
233 /*!
233 /*!
234 \property QAbstractAxis::titleText
234 \property QAbstractAxis::titleText
235 The title of the axis. Empty by default. Axis titles support html formatting.
235 The title of the axis. Empty by default. Axis titles support html formatting.
236 */
236 */
237 /*!
237 /*!
238 \qmlproperty String AbstractAxis::titleText
238 \qmlproperty String AbstractAxis::titleText
239 The title of the axis. Empty by default. Axis titles support html formatting.
239 The title of the axis. Empty by default. Axis titles support html formatting.
240 */
240 */
241
241
242 /*!
242 /*!
243 \property QAbstractAxis::titleBrush
243 \property QAbstractAxis::titleBrush
244 The brush of the title text. Only the color of the brush is relevant.
244 The brush of the title text. Only the color of the brush is relevant.
245 */
245 */
246
246
247 /*!
247 /*!
248 \property QAbstractAxis::titleFont
248 \property QAbstractAxis::titleFont
249 The font of the title of the axis.
249 The font of the title of the axis.
250 */
250 */
251 /*!
251 /*!
252 \qmlproperty Font AbstractAxis::titleFont
252 \qmlproperty Font AbstractAxis::titleFont
253 The font of the title of the axis.
253 The font of the title of the axis.
254 */
254 */
255
255
256 /*!
256 /*!
257 \property QAbstractAxis::orientation
257 \property QAbstractAxis::orientation
258 The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart.
258 The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart.
259 */
259 */
260 /*!
260 /*!
261 \qmlproperty Qt.Orientation AbstractAxis::orientation
261 \qmlproperty Qt.Orientation AbstractAxis::orientation
262 The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series.
262 The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series.
263 */
263 */
264
264
265 /*!
265 /*!
266 \property QAbstractAxis::alignment
266 \property QAbstractAxis::alignment
267 The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop.
267 The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop.
268 */
268 */
269 /*!
269 /*!
270 \qmlproperty alignment AbstractAxis::alignment
270 \qmlproperty alignment AbstractAxis::alignment
271 The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop.
271 The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop.
272 */
272 */
273
273
274 /*!
274 /*!
275 \property QAbstractAxis::reverse
275 \property QAbstractAxis::reverse
276 The reverse property defines if reverse axis is used. By default the value is false.
276 The reverse property defines if reverse axis is used. By default the value is false.
277
277
278 Reverse axis is supported with line, spline, scatter and area series with cartesian chart.
278 Reverse axis is supported with line, spline, scatter and area series with cartesian chart.
279 All axes of the same orientation attached to same series must be reversed if one is reversed or
279 All axes of the same orientation attached to same series must be reversed if one is reversed or
280 the behavior is undefined.
280 the behavior is undefined.
281 */
281 */
282 /*!
282 /*!
283 \qmlproperty alignment AbstractAxis::reverse
283 \qmlproperty alignment AbstractAxis::reverse
284 The reverse property defines if reverse axis is used. By default the value is false.
284 The reverse property defines if reverse axis is used. By default the value is false.
285
285
286 Reverse axis is supported with line, spline, scatter and area series with cartesian chart.
286 Reverse axis is supported with line, spline, scatter and area series with cartesian chart.
287 All axes of the same orientation attached to same series must be reversed if one is reversed or
287 All axes of the same orientation attached to same series must be reversed if one is reversed or
288 the behavior is undefined.
288 the behavior is undefined.
289 */
289 */
290
290
291 /*!
291 /*!
292 \fn void QAbstractAxis::visibleChanged(bool visible)
292 \fn void QAbstractAxis::visibleChanged(bool visible)
293 Visibility of the axis has changed to \a visible.
293 Visibility of the axis has changed to \a visible.
294 */
294 */
295 /*!
295 /*!
296 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
296 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
297 Visibility of the axis has changed to \a visible.
297 Visibility of the axis has changed to \a visible.
298 */
298 */
299
299
300 /*!
300 /*!
301 \fn void QAbstractAxis::linePenChanged(const QPen& pen)
301 \fn void QAbstractAxis::linePenChanged(const QPen& pen)
302 The pen of the line of the axis has changed to \a pen.
302 The pen of the line of the axis has changed to \a pen.
303 */
303 */
304
304
305 /*!
305 /*!
306 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
306 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
307 Visibility of the axis line has changed to \a visible.
307 Visibility of the axis line has changed to \a visible.
308 */
308 */
309 /*!
309 /*!
310 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
310 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
311 Visibility of the axis line has changed to \a visible.
311 Visibility of the axis line has changed to \a visible.
312 */
312 */
313
313
314 /*!
314 /*!
315 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
315 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
316 Visibility of the labels of the axis has changed to \a visible.
316 Visibility of the labels of the axis has changed to \a visible.
317 */
317 */
318 /*!
318 /*!
319 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
319 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
320 Visibility of the labels of the axis has changed to \a visible.
320 Visibility of the labels of the axis has changed to \a visible.
321 */
321 */
322
322
323 /*!
323 /*!
324 \fn void QAbstractAxis::labelsFontChanged(const QFont& font)
324 \fn void QAbstractAxis::labelsFontChanged(const QFont& font)
325 The font of the axis labels has changed to \a font.
325 The font of the axis labels has changed to \a font.
326 */
326 */
327 /*!
327 /*!
328 \qmlsignal AbstractAxis::onLabelsFontChanged(Font font)
328 \qmlsignal AbstractAxis::onLabelsFontChanged(Font font)
329 The font of the axis labels has changed to \a font.
329 The font of the axis labels has changed to \a font.
330 */
330 */
331
331
332 /*!
332 /*!
333 \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush)
333 \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush)
334 The brush of the axis labels has changed to \a brush.
334 The brush of the axis labels has changed to \a brush.
335 */
335 */
336
336
337 /*!
337 /*!
338 \fn void QAbstractAxis::labelsAngleChanged(int angle)
338 \fn void QAbstractAxis::labelsAngleChanged(int angle)
339 The angle of the axis labels has changed to \a angle.
339 The angle of the axis labels has changed to \a angle.
340 */
340 */
341 /*!
341 /*!
342 \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle)
342 \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle)
343 The angle of the axis labels has changed to \a angle.
343 The angle of the axis labels has changed to \a angle.
344 */
344 */
345
345
346 /*!
346 /*!
347 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
347 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
348 Visibility of the grid lines of the axis has changed to \a visible.
348 Visibility of the grid lines of the axis has changed to \a visible.
349 */
349 */
350 /*!
350 /*!
351 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
351 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
352 Visibility of the grid lines of the axis has changed to \a visible.
352 Visibility of the grid lines of the axis has changed to \a visible.
353 */
353 */
354
354
355 /*!
355 /*!
356 \fn void QAbstractAxis::minorGridVisibleChanged(bool visible)
356 \fn void QAbstractAxis::minorGridVisibleChanged(bool visible)
357 Visibility of the minor grid lines of the axis has changed to \a visible.
357 Visibility of the minor grid lines of the axis has changed to \a visible.
358 */
358 */
359 /*!
359 /*!
360 \qmlsignal AbstractAxis::onMinorGridVisibleChanged(bool visible)
360 \qmlsignal AbstractAxis::onMinorGridVisibleChanged(bool visible)
361 Visibility of the minor grid lines of the axis has changed to \a visible.
361 Visibility of the minor grid lines of the axis has changed to \a visible.
362 */
362 */
363
363
364 /*!
364 /*!
365 \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen)
365 \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen)
366 The pen of the grid line has changed to \a pen.
366 The pen of the grid line has changed to \a pen.
367 */
367 */
368
368
369 /*!
369 /*!
370 \fn void QAbstractAxis::minorGridLinePenChanged(const QPen& pen)
370 \fn void QAbstractAxis::minorGridLinePenChanged(const QPen& pen)
371 The pen of the minor grid line has changed to \a pen.
371 The pen of the minor grid line has changed to \a pen.
372 */
372 */
373
373
374 /*!
374 /*!
375 \fn void QAbstractAxis::gridLineColorChanged(const QColor &color)
375 \fn void QAbstractAxis::gridLineColorChanged(const QColor &color)
376 The color of the pen of the grid line has changed to \a color.
376 The color of the pen of the grid line has changed to \a color.
377 */
377 */
378
378
379 /*!
379 /*!
380 \fn void QAbstractAxis::minorGridLineColorChanged(const QColor &color)
380 \fn void QAbstractAxis::minorGridLineColorChanged(const QColor &color)
381 The color of the pen of the minor grid line has changed to \a color.
381 The color of the pen of the minor grid line has changed to \a color.
382 */
382 */
383
383
384 /*!
384 /*!
385 \fn void QAbstractAxis::colorChanged(QColor color)
385 \fn void QAbstractAxis::colorChanged(QColor color)
386 Emitted if the \a color of the axis is changed.
386 Emitted if the \a color of the axis is changed.
387 */
387 */
388 /*!
388 /*!
389 \qmlsignal AbstractAxis::onColorChanged(QColor color)
389 \qmlsignal AbstractAxis::onColorChanged(QColor color)
390 Emitted if the \a color of the axis is changed.
390 Emitted if the \a color of the axis is changed.
391 */
391 */
392
392
393 /*!
393 /*!
394 \fn void QAbstractAxis::labelsColorChanged(QColor color)
394 \fn void QAbstractAxis::labelsColorChanged(QColor color)
395 Emitted if the \a color of the axis labels is changed.
395 Emitted if the \a color of the axis labels is changed.
396 */
396 */
397 /*!
397 /*!
398 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
398 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
399 Emitted if the \a color of the axis labels is changed.
399 Emitted if the \a color of the axis labels is changed.
400 */
400 */
401
401
402 /*!
402 /*!
403 \fn void QAbstractAxis::titleVisibleChanged(bool visible)
403 \fn void QAbstractAxis::titleVisibleChanged(bool visible)
404 Visibility of the title text of the axis has changed to \a visible.
404 Visibility of the title text of the axis has changed to \a visible.
405 */
405 */
406 /*!
406 /*!
407 \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible)
407 \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible)
408 Visibility of the title text of the axis has changed to \a visible.
408 Visibility of the title text of the axis has changed to \a visible.
409 */
409 */
410
410
411 /*!
411 /*!
412 \fn void QAbstractAxis::titleTextChanged(const QString& text)
412 \fn void QAbstractAxis::titleTextChanged(const QString& text)
413 The text of the axis title has changed to \a text.
413 The text of the axis title has changed to \a text.
414 */
414 */
415 /*!
415 /*!
416 \qmlsignal AbstractAxis::onTitleTextChanged(String text)
416 \qmlsignal AbstractAxis::onTitleTextChanged(String text)
417 The text of the axis title has changed to \a text.
417 The text of the axis title has changed to \a text.
418 */
418 */
419
419
420 /*!
420 /*!
421 \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush)
421 \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush)
422 The brush of the axis title has changed to \a brush.
422 The brush of the axis title has changed to \a brush.
423 */
423 */
424
424
425 /*!
425 /*!
426 \fn void QAbstractAxis::titleFontChanged(const QFont& font)
426 \fn void QAbstractAxis::titleFontChanged(const QFont& font)
427 The font of the axis title has changed to \a font.
427 The font of the axis title has changed to \a font.
428 */
428 */
429 /*!
429 /*!
430 \qmlsignal AbstractAxis::onTitleFontChanged(Font font)
430 \qmlsignal AbstractAxis::onTitleFontChanged(Font font)
431 The font of the axis title has changed to \a font.
431 The font of the axis title has changed to \a font.
432 */
432 */
433
433
434 /*!
434 /*!
435 \fn void QAbstractAxis::shadesVisibleChanged(bool)
435 \fn void QAbstractAxis::shadesVisibleChanged(bool)
436 Emitted if the visibility of the axis shades is changed to \a visible.
436 Emitted if the visibility of the axis shades is changed to \a visible.
437 */
437 */
438 /*!
438 /*!
439 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
439 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
440 Emitted if the visibility of the axis shades is changed to \a visible.
440 Emitted if the visibility of the axis shades is changed to \a visible.
441 */
441 */
442
442
443 /*!
443 /*!
444 \fn void QAbstractAxis::shadesColorChanged(QColor color)
444 \fn void QAbstractAxis::shadesColorChanged(QColor color)
445 Emitted if the \a color of the axis shades is changed.
445 Emitted if the \a color of the axis shades is changed.
446 */
446 */
447 /*!
447 /*!
448 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
448 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
449 Emitted if the \a color of the axis shades is changed.
449 Emitted if the \a color of the axis shades is changed.
450 */
450 */
451
451
452 /*!
452 /*!
453 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
453 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
454 Emitted if the border \a color of the axis shades is changed.
454 Emitted if the border \a color of the axis shades is changed.
455 */
455 */
456 /*!
456 /*!
457 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
457 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
458 Emitted if the border \a color of the axis shades is changed.
458 Emitted if the border \a color of the axis shades is changed.
459 */
459 */
460
460
461 /*!
461 /*!
462 \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush)
462 \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush)
463 The brush of the axis shades has changed to \a brush.
463 The brush of the axis shades has changed to \a brush.
464 */
464 */
465
465
466 /*!
466 /*!
467 \fn void QAbstractAxis::shadesPenChanged(const QPen& pen)
467 \fn void QAbstractAxis::shadesPenChanged(const QPen& pen)
468 The pen of the axis shades has changed to \a pen.
468 The pen of the axis shades has changed to \a pen.
469 */
469 */
470
470
471 /*!
471 /*!
472 \internal
472 \internal
473 Constructs new axis object which is a child of \a parent. Ownership is taken by
473 Constructs new axis object which is a child of \a parent. Ownership is taken by
474 QChart when axis added.
474 QChart when axis added.
475 */
475 */
476
476
477 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
477 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
478 : QObject(parent),
478 : QObject(parent),
479 d_ptr(&d)
479 d_ptr(&d)
480 {
480 {
481 }
481 }
482
482
483 /*!
483 /*!
484 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
484 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
485 */
485 */
486
486
487 QAbstractAxis::~QAbstractAxis()
487 QAbstractAxis::~QAbstractAxis()
488 {
488 {
489 if (d_ptr->m_chart)
489 if (d_ptr->m_chart)
490 qFatal("Still binded axis detected !");
490 qFatal("Still binded axis detected !");
491 }
491 }
492
492
493 /*!
493 /*!
494 Sets \a pen used to draw axis line and ticks.
494 Sets \a pen used to draw axis line and ticks.
495 */
495 */
496 void QAbstractAxis::setLinePen(const QPen &pen)
496 void QAbstractAxis::setLinePen(const QPen &pen)
497 {
497 {
498 if (d_ptr->m_axisPen != pen) {
498 if (d_ptr->m_axisPen != pen) {
499 d_ptr->m_axisPen = pen;
499 d_ptr->m_axisPen = pen;
500 emit linePenChanged(pen);
500 emit linePenChanged(pen);
501 }
501 }
502 }
502 }
503
503
504 /*!
504 /*!
505 Returns pen used to draw axis and ticks.
505 Returns pen used to draw axis and ticks.
506 */
506 */
507 QPen QAbstractAxis::linePen() const
507 QPen QAbstractAxis::linePen() const
508 {
508 {
509 if (d_ptr->m_axisPen == QChartPrivate::defaultPen())
509 if (d_ptr->m_axisPen == QChartPrivate::defaultPen())
510 return QPen();
510 return QPen();
511 else
511 else
512 return d_ptr->m_axisPen;
512 return d_ptr->m_axisPen;
513 }
513 }
514
514
515 void QAbstractAxis::setLinePenColor(QColor color)
515 void QAbstractAxis::setLinePenColor(QColor color)
516 {
516 {
517 QPen p = d_ptr->m_axisPen;
517 QPen p = linePen();
518 if (p.color() != color) {
518 if (p.color() != color) {
519 p.setColor(color);
519 p.setColor(color);
520 setLinePen(p);
520 setLinePen(p);
521 emit colorChanged(color);
521 emit colorChanged(color);
522 }
522 }
523 }
523 }
524
524
525 QColor QAbstractAxis::linePenColor() const
525 QColor QAbstractAxis::linePenColor() const
526 {
526 {
527 return linePen().color();
527 return linePen().color();
528 }
528 }
529
529
530 /*!
530 /*!
531 Sets if axis and ticks are \a visible.
531 Sets if axis and ticks are \a visible.
532 */
532 */
533 void QAbstractAxis::setLineVisible(bool visible)
533 void QAbstractAxis::setLineVisible(bool visible)
534 {
534 {
535 if (d_ptr->m_arrowVisible != visible) {
535 if (d_ptr->m_arrowVisible != visible) {
536 d_ptr->m_arrowVisible = visible;
536 d_ptr->m_arrowVisible = visible;
537 emit lineVisibleChanged(visible);
537 emit lineVisibleChanged(visible);
538 }
538 }
539 }
539 }
540
540
541 bool QAbstractAxis::isLineVisible() const
541 bool QAbstractAxis::isLineVisible() const
542 {
542 {
543 return d_ptr->m_arrowVisible;
543 return d_ptr->m_arrowVisible;
544 }
544 }
545
545
546 void QAbstractAxis::setGridLineVisible(bool visible)
546 void QAbstractAxis::setGridLineVisible(bool visible)
547 {
547 {
548 if (d_ptr->m_gridLineVisible != visible) {
548 if (d_ptr->m_gridLineVisible != visible) {
549 d_ptr->m_gridLineVisible = visible;
549 d_ptr->m_gridLineVisible = visible;
550 emit gridVisibleChanged(visible);
550 emit gridVisibleChanged(visible);
551 }
551 }
552 }
552 }
553
553
554 bool QAbstractAxis::isGridLineVisible() const
554 bool QAbstractAxis::isGridLineVisible() const
555 {
555 {
556 return d_ptr->m_gridLineVisible;
556 return d_ptr->m_gridLineVisible;
557 }
557 }
558
558
559 void QAbstractAxis::setMinorGridLineVisible(bool visible)
559 void QAbstractAxis::setMinorGridLineVisible(bool visible)
560 {
560 {
561 if (d_ptr->m_minorGridLineVisible != visible) {
561 if (d_ptr->m_minorGridLineVisible != visible) {
562 d_ptr->m_minorGridLineVisible = visible;
562 d_ptr->m_minorGridLineVisible = visible;
563 emit minorGridVisibleChanged(visible);
563 emit minorGridVisibleChanged(visible);
564 }
564 }
565 }
565 }
566
566
567 bool QAbstractAxis::isMinorGridLineVisible() const
567 bool QAbstractAxis::isMinorGridLineVisible() const
568 {
568 {
569 return d_ptr->m_minorGridLineVisible;
569 return d_ptr->m_minorGridLineVisible;
570 }
570 }
571
571
572 /*!
572 /*!
573 Sets \a pen used to draw grid line.
573 Sets \a pen used to draw grid line.
574 */
574 */
575 void QAbstractAxis::setGridLinePen(const QPen &pen)
575 void QAbstractAxis::setGridLinePen(const QPen &pen)
576 {
576 {
577 if (d_ptr->m_gridLinePen != pen) {
577 if (d_ptr->m_gridLinePen != pen) {
578 d_ptr->m_gridLinePen = pen;
578 d_ptr->m_gridLinePen = pen;
579 emit gridLinePenChanged(pen);
579 emit gridLinePenChanged(pen);
580 }
580 }
581 }
581 }
582
582
583 /*!
583 /*!
584 Returns pen used to draw grid.
584 Returns pen used to draw grid.
585 */
585 */
586 QPen QAbstractAxis::gridLinePen() const
586 QPen QAbstractAxis::gridLinePen() const
587 {
587 {
588 if (d_ptr->m_gridLinePen == QChartPrivate::defaultPen())
588 if (d_ptr->m_gridLinePen == QChartPrivate::defaultPen())
589 return QPen();
589 return QPen();
590 else
590 else
591 return d_ptr->m_gridLinePen;
591 return d_ptr->m_gridLinePen;
592 }
592 }
593
593
594 void QAbstractAxis::setMinorGridLinePen(const QPen &pen)
594 void QAbstractAxis::setMinorGridLinePen(const QPen &pen)
595 {
595 {
596 if (d_ptr->m_minorGridLinePen != pen) {
596 if (d_ptr->m_minorGridLinePen != pen) {
597 d_ptr->m_minorGridLinePen = pen;
597 d_ptr->m_minorGridLinePen = pen;
598 emit minorGridLinePenChanged(pen);
598 emit minorGridLinePenChanged(pen);
599 }
599 }
600 }
600 }
601
601
602 QPen QAbstractAxis::minorGridLinePen() const
602 QPen QAbstractAxis::minorGridLinePen() const
603 {
603 {
604 if (d_ptr->m_minorGridLinePen == QChartPrivate::defaultPen())
604 if (d_ptr->m_minorGridLinePen == QChartPrivate::defaultPen())
605 return QPen();
605 return QPen();
606 else
606 else
607 return d_ptr->m_minorGridLinePen;
607 return d_ptr->m_minorGridLinePen;
608 }
608 }
609
609
610 void QAbstractAxis::setGridLineColor(const QColor &color)
610 void QAbstractAxis::setGridLineColor(const QColor &color)
611 {
611 {
612 QPen pen = d_ptr->m_gridLinePen;
612 QPen pen = gridLinePen();
613 if (color != pen.color()) {
613 if (color != pen.color()) {
614 pen.setColor(color);
614 pen.setColor(color);
615 d_ptr->m_gridLinePen = pen;
615 d_ptr->m_gridLinePen = pen;
616 emit gridLineColorChanged(color);
616 emit gridLineColorChanged(color);
617 }
617 }
618 }
618 }
619
619
620 QColor QAbstractAxis::gridLineColor()
620 QColor QAbstractAxis::gridLineColor()
621 {
621 {
622 return d_ptr->m_gridLinePen.color();
622 return d_ptr->m_gridLinePen.color();
623 }
623 }
624
624
625 void QAbstractAxis::setMinorGridLineColor(const QColor &color)
625 void QAbstractAxis::setMinorGridLineColor(const QColor &color)
626 {
626 {
627 QPen pen = d_ptr->m_minorGridLinePen;
627 QPen pen = minorGridLinePen();
628 if (color != pen.color()) {
628 if (color != pen.color()) {
629 pen.setColor(color);
629 pen.setColor(color);
630 d_ptr->m_minorGridLinePen = pen;
630 d_ptr->m_minorGridLinePen = pen;
631 emit minorGridLineColorChanged(color);
631 emit minorGridLineColorChanged(color);
632 }
632 }
633 }
633 }
634
634
635 QColor QAbstractAxis::minorGridLineColor()
635 QColor QAbstractAxis::minorGridLineColor()
636 {
636 {
637 return d_ptr->m_minorGridLinePen.color();
637 return d_ptr->m_minorGridLinePen.color();
638 }
638 }
639
639
640 void QAbstractAxis::setLabelsVisible(bool visible)
640 void QAbstractAxis::setLabelsVisible(bool visible)
641 {
641 {
642 if (d_ptr->m_labelsVisible != visible) {
642 if (d_ptr->m_labelsVisible != visible) {
643 d_ptr->m_labelsVisible = visible;
643 d_ptr->m_labelsVisible = visible;
644 emit labelsVisibleChanged(visible);
644 emit labelsVisibleChanged(visible);
645 }
645 }
646 }
646 }
647
647
648 bool QAbstractAxis::labelsVisible() const
648 bool QAbstractAxis::labelsVisible() const
649 {
649 {
650 return d_ptr->m_labelsVisible;
650 return d_ptr->m_labelsVisible;
651 }
651 }
652
652
653 /*!
653 /*!
654 Sets \a brush used to draw labels.
654 Sets \a brush used to draw labels.
655 */
655 */
656 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
656 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
657 {
657 {
658 if (d_ptr->m_labelsBrush != brush) {
658 if (d_ptr->m_labelsBrush != brush) {
659 d_ptr->m_labelsBrush = brush;
659 d_ptr->m_labelsBrush = brush;
660 emit labelsBrushChanged(brush);
660 emit labelsBrushChanged(brush);
661 }
661 }
662 }
662 }
663
663
664 /*!
664 /*!
665 Returns brush used to draw labels.
665 Returns brush used to draw labels.
666 */
666 */
667 QBrush QAbstractAxis::labelsBrush() const
667 QBrush QAbstractAxis::labelsBrush() const
668 {
668 {
669 if (d_ptr->m_labelsBrush == QChartPrivate::defaultBrush())
669 if (d_ptr->m_labelsBrush == QChartPrivate::defaultBrush())
670 return QBrush();
670 return QBrush();
671 else
671 else
672 return d_ptr->m_labelsBrush;
672 return d_ptr->m_labelsBrush;
673 }
673 }
674
674
675 /*!
675 /*!
676 Sets \a font used to draw labels.
676 Sets \a font used to draw labels.
677 */
677 */
678 void QAbstractAxis::setLabelsFont(const QFont &font)
678 void QAbstractAxis::setLabelsFont(const QFont &font)
679 {
679 {
680 if (d_ptr->m_labelsFont != font) {
680 if (d_ptr->m_labelsFont != font) {
681 d_ptr->m_labelsFont = font;
681 d_ptr->m_labelsFont = font;
682 emit labelsFontChanged(font);
682 emit labelsFontChanged(font);
683 }
683 }
684 }
684 }
685
685
686 /*!
686 /*!
687 Returns font used to draw labels.
687 Returns font used to draw labels.
688 */
688 */
689 QFont QAbstractAxis::labelsFont() const
689 QFont QAbstractAxis::labelsFont() const
690 {
690 {
691 if (d_ptr->m_labelsFont == QChartPrivate::defaultFont())
691 if (d_ptr->m_labelsFont == QChartPrivate::defaultFont())
692 return QFont();
692 return QFont();
693 else
693 else
694 return d_ptr->m_labelsFont;
694 return d_ptr->m_labelsFont;
695 }
695 }
696
696
697 void QAbstractAxis::setLabelsAngle(int angle)
697 void QAbstractAxis::setLabelsAngle(int angle)
698 {
698 {
699 if (d_ptr->m_labelsAngle != angle) {
699 if (d_ptr->m_labelsAngle != angle) {
700 d_ptr->m_labelsAngle = angle;
700 d_ptr->m_labelsAngle = angle;
701 emit labelsAngleChanged(angle);
701 emit labelsAngleChanged(angle);
702 }
702 }
703 }
703 }
704
704
705 int QAbstractAxis::labelsAngle() const
705 int QAbstractAxis::labelsAngle() const
706 {
706 {
707 return d_ptr->m_labelsAngle;
707 return d_ptr->m_labelsAngle;
708 }
708 }
709 void QAbstractAxis::setLabelsColor(QColor color)
709 void QAbstractAxis::setLabelsColor(QColor color)
710 {
710 {
711 QBrush b = d_ptr->m_labelsBrush;
711 QBrush b = labelsBrush();
712 if (b.color() != color) {
712 if (b.color() != color) {
713 b.setColor(color);
713 b.setColor(color);
714 setLabelsBrush(b);
714 setLabelsBrush(b);
715 emit labelsColorChanged(color);
715 emit labelsColorChanged(color);
716 }
716 }
717 }
717 }
718
718
719 QColor QAbstractAxis::labelsColor() const
719 QColor QAbstractAxis::labelsColor() const
720 {
720 {
721 return labelsBrush().color();
721 return labelsBrush().color();
722 }
722 }
723
723
724 void QAbstractAxis::setTitleVisible(bool visible)
724 void QAbstractAxis::setTitleVisible(bool visible)
725 {
725 {
726 if (d_ptr->m_titleVisible != visible) {
726 if (d_ptr->m_titleVisible != visible) {
727 d_ptr->m_titleVisible = visible;
727 d_ptr->m_titleVisible = visible;
728 emit titleVisibleChanged(visible);
728 emit titleVisibleChanged(visible);
729 }
729 }
730 }
730 }
731
731
732 bool QAbstractAxis::isTitleVisible() const
732 bool QAbstractAxis::isTitleVisible() const
733 {
733 {
734 return d_ptr->m_titleVisible;
734 return d_ptr->m_titleVisible;
735 }
735 }
736
736
737 /*!
737 /*!
738 Sets \a brush used to draw title.
738 Sets \a brush used to draw title.
739 */
739 */
740 void QAbstractAxis::setTitleBrush(const QBrush &brush)
740 void QAbstractAxis::setTitleBrush(const QBrush &brush)
741 {
741 {
742 if (d_ptr->m_titleBrush != brush) {
742 if (d_ptr->m_titleBrush != brush) {
743 d_ptr->m_titleBrush = brush;
743 d_ptr->m_titleBrush = brush;
744 emit titleBrushChanged(brush);
744 emit titleBrushChanged(brush);
745 }
745 }
746 }
746 }
747
747
748 /*!
748 /*!
749 Returns brush used to draw title.
749 Returns brush used to draw title.
750 */
750 */
751 QBrush QAbstractAxis::titleBrush() const
751 QBrush QAbstractAxis::titleBrush() const
752 {
752 {
753 if (d_ptr->m_titleBrush == QChartPrivate::defaultBrush())
753 if (d_ptr->m_titleBrush == QChartPrivate::defaultBrush())
754 return QBrush();
754 return QBrush();
755 else
755 else
756 return d_ptr->m_titleBrush;
756 return d_ptr->m_titleBrush;
757 }
757 }
758
758
759 /*!
759 /*!
760 Sets \a font used to draw title.
760 Sets \a font used to draw title.
761 */
761 */
762 void QAbstractAxis::setTitleFont(const QFont &font)
762 void QAbstractAxis::setTitleFont(const QFont &font)
763 {
763 {
764 if (d_ptr->m_titleFont != font) {
764 if (d_ptr->m_titleFont != font) {
765 d_ptr->m_titleFont = font;
765 d_ptr->m_titleFont = font;
766 emit titleFontChanged(font);
766 emit titleFontChanged(font);
767 }
767 }
768 }
768 }
769
769
770 /*!
770 /*!
771 Returns font used to draw title.
771 Returns font used to draw title.
772 */
772 */
773 QFont QAbstractAxis::titleFont() const
773 QFont QAbstractAxis::titleFont() const
774 {
774 {
775 if (d_ptr->m_titleFont == QChartPrivate::defaultFont())
775 if (d_ptr->m_titleFont == QChartPrivate::defaultFont())
776 return QFont();
776 return QFont();
777 else
777 else
778 return d_ptr->m_titleFont;
778 return d_ptr->m_titleFont;
779 }
779 }
780
780
781 void QAbstractAxis::setTitleText(const QString &title)
781 void QAbstractAxis::setTitleText(const QString &title)
782 {
782 {
783 if (d_ptr->m_title != title) {
783 if (d_ptr->m_title != title) {
784 d_ptr->m_title = title;
784 d_ptr->m_title = title;
785 emit titleTextChanged(title);
785 emit titleTextChanged(title);
786 }
786 }
787 }
787 }
788
788
789 QString QAbstractAxis::titleText() const
789 QString QAbstractAxis::titleText() const
790 {
790 {
791 return d_ptr->m_title;
791 return d_ptr->m_title;
792 }
792 }
793
793
794
794
795 void QAbstractAxis::setShadesVisible(bool visible)
795 void QAbstractAxis::setShadesVisible(bool visible)
796 {
796 {
797 if (d_ptr->m_shadesVisible != visible) {
797 if (d_ptr->m_shadesVisible != visible) {
798 d_ptr->m_shadesVisible = visible;
798 d_ptr->m_shadesVisible = visible;
799 emit shadesVisibleChanged(visible);
799 emit shadesVisibleChanged(visible);
800 }
800 }
801 }
801 }
802
802
803 bool QAbstractAxis::shadesVisible() const
803 bool QAbstractAxis::shadesVisible() const
804 {
804 {
805 return d_ptr->m_shadesVisible;
805 return d_ptr->m_shadesVisible;
806 }
806 }
807
807
808 /*!
808 /*!
809 Sets \a pen used to draw shades.
809 Sets \a pen used to draw shades.
810 */
810 */
811 void QAbstractAxis::setShadesPen(const QPen &pen)
811 void QAbstractAxis::setShadesPen(const QPen &pen)
812 {
812 {
813 if (d_ptr->m_shadesPen != pen) {
813 if (d_ptr->m_shadesPen != pen) {
814 d_ptr->m_shadesPen = pen;
814 d_ptr->m_shadesPen = pen;
815 emit shadesPenChanged(pen);
815 emit shadesPenChanged(pen);
816 }
816 }
817 }
817 }
818
818
819 /*!
819 /*!
820 Returns pen used to draw shades.
820 Returns pen used to draw shades.
821 */
821 */
822 QPen QAbstractAxis::shadesPen() const
822 QPen QAbstractAxis::shadesPen() const
823 {
823 {
824 if (d_ptr->m_shadesPen == QChartPrivate::defaultPen())
824 if (d_ptr->m_shadesPen == QChartPrivate::defaultPen())
825 return QPen();
825 return QPen();
826 else
826 else
827 return d_ptr->m_shadesPen;
827 return d_ptr->m_shadesPen;
828 }
828 }
829
829
830 /*!
830 /*!
831 Sets \a brush used to draw shades.
831 Sets \a brush used to draw shades.
832 */
832 */
833 void QAbstractAxis::setShadesBrush(const QBrush &brush)
833 void QAbstractAxis::setShadesBrush(const QBrush &brush)
834 {
834 {
835 if (d_ptr->m_shadesBrush != brush) {
835 if (d_ptr->m_shadesBrush != brush) {
836 d_ptr->m_shadesBrush = brush;
836 d_ptr->m_shadesBrush = brush;
837 emit shadesBrushChanged(brush);
837 emit shadesBrushChanged(brush);
838 }
838 }
839 }
839 }
840
840
841 /*!
841 /*!
842 Returns brush used to draw shades.
842 Returns brush used to draw shades.
843 */
843 */
844 QBrush QAbstractAxis::shadesBrush() const
844 QBrush QAbstractAxis::shadesBrush() const
845 {
845 {
846 if (d_ptr->m_shadesBrush == QChartPrivate::defaultBrush())
846 if (d_ptr->m_shadesBrush == QChartPrivate::defaultBrush())
847 return QBrush(Qt::SolidPattern);
847 return QBrush(Qt::SolidPattern);
848 else
848 else
849 return d_ptr->m_shadesBrush;
849 return d_ptr->m_shadesBrush;
850 }
850 }
851
851
852 void QAbstractAxis::setShadesColor(QColor color)
852 void QAbstractAxis::setShadesColor(QColor color)
853 {
853 {
854 QBrush b = d_ptr->m_shadesBrush;
854 QBrush b = shadesBrush();
855 if (b.color() != color) {
855 if (b.color() != color) {
856 b.setColor(color);
856 b.setColor(color);
857 setShadesBrush(b);
857 setShadesBrush(b);
858 emit shadesColorChanged(color);
858 emit shadesColorChanged(color);
859 }
859 }
860 }
860 }
861
861
862 QColor QAbstractAxis::shadesColor() const
862 QColor QAbstractAxis::shadesColor() const
863 {
863 {
864 return shadesBrush().color();
864 return shadesBrush().color();
865 }
865 }
866
866
867 void QAbstractAxis::setShadesBorderColor(QColor color)
867 void QAbstractAxis::setShadesBorderColor(QColor color)
868 {
868 {
869 QPen p = d_ptr->m_shadesPen;
869 QPen p = d_ptr->m_shadesPen;
870 if (p.color() != color) {
870 if (p.color() != color) {
871 p.setColor(color);
871 p.setColor(color);
872 setShadesPen(p);
872 setShadesPen(p);
873 emit shadesColorChanged(color);
873 emit shadesColorChanged(color);
874 }
874 }
875 }
875 }
876
876
877 QColor QAbstractAxis::shadesBorderColor() const
877 QColor QAbstractAxis::shadesBorderColor() const
878 {
878 {
879 return shadesPen().color();
879 return shadesPen().color();
880 }
880 }
881
881
882
882
883 bool QAbstractAxis::isVisible() const
883 bool QAbstractAxis::isVisible() const
884 {
884 {
885 return d_ptr->m_visible;
885 return d_ptr->m_visible;
886 }
886 }
887
887
888 /*!
888 /*!
889 Sets axis, shades, labels and grid lines visibility to \a visible.
889 Sets axis, shades, labels and grid lines visibility to \a visible.
890 */
890 */
891 void QAbstractAxis::setVisible(bool visible)
891 void QAbstractAxis::setVisible(bool visible)
892 {
892 {
893 if (d_ptr->m_visible != visible) {
893 if (d_ptr->m_visible != visible) {
894 d_ptr->m_visible = visible;
894 d_ptr->m_visible = visible;
895 emit visibleChanged(visible);
895 emit visibleChanged(visible);
896 }
896 }
897 }
897 }
898
898
899
899
900 /*!
900 /*!
901 Sets axis, shades, labels and grid lines to be visible.
901 Sets axis, shades, labels and grid lines to be visible.
902 */
902 */
903 void QAbstractAxis::show()
903 void QAbstractAxis::show()
904 {
904 {
905 setVisible(true);
905 setVisible(true);
906 }
906 }
907
907
908 /*!
908 /*!
909 Sets axis, shades, labels and grid lines to not be visible.
909 Sets axis, shades, labels and grid lines to not be visible.
910 */
910 */
911 void QAbstractAxis::hide()
911 void QAbstractAxis::hide()
912 {
912 {
913 setVisible(false);
913 setVisible(false);
914 }
914 }
915
915
916 /*!
916 /*!
917 Sets the minimum value shown on the axis.
917 Sets the minimum value shown on the axis.
918 Depending on the actual axis type the \a min parameter is converted to appropriate type.
918 Depending on the actual axis type the \a min parameter is converted to appropriate type.
919 If the conversion is impossible then the function call does nothing
919 If the conversion is impossible then the function call does nothing
920 */
920 */
921 void QAbstractAxis::setMin(const QVariant &min)
921 void QAbstractAxis::setMin(const QVariant &min)
922 {
922 {
923 d_ptr->setMin(min);
923 d_ptr->setMin(min);
924 }
924 }
925
925
926 /*!
926 /*!
927 Sets the maximum value shown on the axis.
927 Sets the maximum value shown on the axis.
928 Depending on the actual axis type the \a max parameter is converted to appropriate type.
928 Depending on the actual axis type the \a max parameter is converted to appropriate type.
929 If the conversion is impossible then the function call does nothing
929 If the conversion is impossible then the function call does nothing
930 */
930 */
931 void QAbstractAxis::setMax(const QVariant &max)
931 void QAbstractAxis::setMax(const QVariant &max)
932 {
932 {
933 d_ptr->setMax(max);
933 d_ptr->setMax(max);
934 }
934 }
935
935
936 /*!
936 /*!
937 Sets the range shown on the axis.
937 Sets the range shown on the axis.
938 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
938 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
939 If the conversion is impossible then the function call does nothing.
939 If the conversion is impossible then the function call does nothing.
940 */
940 */
941 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
941 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
942 {
942 {
943 d_ptr->setRange(min, max);
943 d_ptr->setRange(min, max);
944 }
944 }
945
945
946
946
947 /*!
947 /*!
948 Returns the orientation in which the axis is being used (Vertical or Horizontal)
948 Returns the orientation in which the axis is being used (Vertical or Horizontal)
949 */
949 */
950 Qt::Orientation QAbstractAxis::orientation() const
950 Qt::Orientation QAbstractAxis::orientation() const
951 {
951 {
952 return d_ptr->orientation();
952 return d_ptr->orientation();
953 }
953 }
954
954
955 Qt::Alignment QAbstractAxis::alignment() const
955 Qt::Alignment QAbstractAxis::alignment() const
956 {
956 {
957 return d_ptr->alignment();
957 return d_ptr->alignment();
958 }
958 }
959
959
960 bool QAbstractAxis::isReverse() const
960 bool QAbstractAxis::isReverse() const
961 {
961 {
962 return d_ptr->m_reverse;
962 return d_ptr->m_reverse;
963 }
963 }
964
964
965 void QAbstractAxis::setReverse(bool reverse)
965 void QAbstractAxis::setReverse(bool reverse)
966 {
966 {
967 if (d_ptr->m_reverse != reverse && type() != QAbstractAxis::AxisTypeBarCategory) {
967 if (d_ptr->m_reverse != reverse && type() != QAbstractAxis::AxisTypeBarCategory) {
968 d_ptr->m_reverse = reverse;
968 d_ptr->m_reverse = reverse;
969 emit reverseChanged(reverse);
969 emit reverseChanged(reverse);
970 }
970 }
971 }
971 }
972
972
973 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
973 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
974
974
975 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
975 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
976 : q_ptr(q),
976 : q_ptr(q),
977 m_chart(0),
977 m_chart(0),
978 m_alignment(0),
978 m_alignment(0),
979 m_orientation(Qt::Orientation(0)),
979 m_orientation(Qt::Orientation(0)),
980 m_visible(true),
980 m_visible(true),
981 m_arrowVisible(true),
981 m_arrowVisible(true),
982 m_axisPen(QChartPrivate::defaultPen()),
982 m_axisPen(QChartPrivate::defaultPen()),
983 m_axisBrush(QChartPrivate::defaultBrush()),
983 m_axisBrush(QChartPrivate::defaultBrush()),
984 m_gridLineVisible(true),
984 m_gridLineVisible(true),
985 m_gridLinePen(QChartPrivate::defaultPen()),
985 m_gridLinePen(QChartPrivate::defaultPen()),
986 m_minorGridLineVisible(true),
986 m_minorGridLineVisible(true),
987 m_minorGridLinePen(QChartPrivate::defaultPen()),
987 m_minorGridLinePen(QChartPrivate::defaultPen()),
988 m_labelsVisible(true),
988 m_labelsVisible(true),
989 m_labelsBrush(QChartPrivate::defaultBrush()),
989 m_labelsBrush(QChartPrivate::defaultBrush()),
990 m_labelsFont(QChartPrivate::defaultFont()),
990 m_labelsFont(QChartPrivate::defaultFont()),
991 m_labelsAngle(0),
991 m_labelsAngle(0),
992 m_titleVisible(true),
992 m_titleVisible(true),
993 m_titleBrush(QChartPrivate::defaultBrush()),
993 m_titleBrush(QChartPrivate::defaultBrush()),
994 m_titleFont(QChartPrivate::defaultFont()),
994 m_titleFont(QChartPrivate::defaultFont()),
995 m_shadesVisible(false),
995 m_shadesVisible(false),
996 m_shadesPen(QChartPrivate::defaultPen()),
996 m_shadesPen(QChartPrivate::defaultPen()),
997 m_shadesBrush(QChartPrivate::defaultBrush()),
997 m_shadesBrush(QChartPrivate::defaultBrush()),
998 m_shadesOpacity(1.0),
998 m_shadesOpacity(1.0),
999 m_dirty(false),
999 m_dirty(false),
1000 m_reverse(false)
1000 m_reverse(false)
1001 {
1001 {
1002 }
1002 }
1003
1003
1004 QAbstractAxisPrivate::~QAbstractAxisPrivate()
1004 QAbstractAxisPrivate::~QAbstractAxisPrivate()
1005 {
1005 {
1006 }
1006 }
1007
1007
1008 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
1008 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
1009 {
1009 {
1010 switch(alignment) {
1010 switch(alignment) {
1011 case Qt::AlignTop:
1011 case Qt::AlignTop:
1012 case Qt::AlignBottom:
1012 case Qt::AlignBottom:
1013 m_orientation = Qt::Horizontal;
1013 m_orientation = Qt::Horizontal;
1014 break;
1014 break;
1015 case Qt::AlignLeft:
1015 case Qt::AlignLeft:
1016 case Qt::AlignRight:
1016 case Qt::AlignRight:
1017 m_orientation = Qt::Vertical;
1017 m_orientation = Qt::Vertical;
1018 break;
1018 break;
1019 default:
1019 default:
1020 qWarning()<<"No alignment specified !";
1020 qWarning()<<"No alignment specified !";
1021 break;
1021 break;
1022 };
1022 };
1023 m_alignment=alignment;
1023 m_alignment=alignment;
1024 }
1024 }
1025
1025
1026 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
1026 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
1027 {
1027 {
1028 if (forced || QChartPrivate::defaultPen() == m_axisPen)
1028 if (forced || QChartPrivate::defaultPen() == m_axisPen)
1029 q_ptr->setLinePen(theme->axisLinePen());
1029 q_ptr->setLinePen(theme->axisLinePen());
1030
1030
1031 if (forced || QChartPrivate::defaultPen() == m_gridLinePen)
1031 if (forced || QChartPrivate::defaultPen() == m_gridLinePen)
1032 q_ptr->setGridLinePen(theme->gridLinePen());
1032 q_ptr->setGridLinePen(theme->gridLinePen());
1033 if (forced || QChartPrivate::defaultPen() == m_minorGridLinePen)
1033 if (forced || QChartPrivate::defaultPen() == m_minorGridLinePen)
1034 q_ptr->setMinorGridLinePen(theme->minorGridLinePen());
1034 q_ptr->setMinorGridLinePen(theme->minorGridLinePen());
1035
1035
1036 if (forced || QChartPrivate::defaultBrush() == m_labelsBrush)
1036 if (forced || QChartPrivate::defaultBrush() == m_labelsBrush)
1037 q_ptr->setLabelsBrush(theme->labelBrush());
1037 q_ptr->setLabelsBrush(theme->labelBrush());
1038 if (forced || QChartPrivate::defaultFont() == m_labelsFont)
1038 if (forced || QChartPrivate::defaultFont() == m_labelsFont)
1039 q_ptr->setLabelsFont(theme->labelFont());
1039 q_ptr->setLabelsFont(theme->labelFont());
1040
1040
1041 if (forced || QChartPrivate::defaultBrush() == m_titleBrush)
1041 if (forced || QChartPrivate::defaultBrush() == m_titleBrush)
1042 q_ptr->setTitleBrush(theme->labelBrush());
1042 q_ptr->setTitleBrush(theme->labelBrush());
1043 if (forced || QChartPrivate::defaultFont() == m_titleFont) {
1043 if (forced || QChartPrivate::defaultFont() == m_titleFont) {
1044 QFont font(m_labelsFont);
1044 QFont font(m_labelsFont);
1045 font.setBold(true);
1045 font.setBold(true);
1046 q_ptr->setTitleFont(font);
1046 q_ptr->setTitleFont(font);
1047 }
1047 }
1048
1048
1049 if (forced || QChartPrivate::defaultBrush() == m_shadesBrush)
1049 if (forced || QChartPrivate::defaultBrush() == m_shadesBrush)
1050 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
1050 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
1051 if (forced || QChartPrivate::defaultPen() == m_shadesPen)
1051 if (forced || QChartPrivate::defaultPen() == m_shadesPen)
1052 q_ptr->setShadesPen(theme->backgroundShadesPen());
1052 q_ptr->setShadesPen(theme->backgroundShadesPen());
1053
1053
1054 bool axisX = m_orientation == Qt::Horizontal;
1054 bool axisX = m_orientation == Qt::Horizontal;
1055 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
1055 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
1056 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
1056 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
1057 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
1057 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
1058 q_ptr->setShadesVisible(true);
1058 q_ptr->setShadesVisible(true);
1059 } else if (forced) {
1059 } else if (forced) {
1060 q_ptr->setShadesVisible(false);
1060 q_ptr->setShadesVisible(false);
1061 }
1061 }
1062 }
1062 }
1063
1063
1064 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
1064 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
1065 {
1065 {
1066 setRange(min,max);
1066 setRange(min,max);
1067 }
1067 }
1068
1068
1069 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
1069 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
1070 {
1070 {
1071 Q_UNUSED(parent);
1071 Q_UNUSED(parent);
1072 }
1072 }
1073
1073
1074 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options, int duration,
1074 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options, int duration,
1075 QEasingCurve &curve)
1075 QEasingCurve &curve)
1076 {
1076 {
1077 ChartAxisElement *axis = m_item.data();
1077 ChartAxisElement *axis = m_item.data();
1078 Q_ASSERT(axis);
1078 Q_ASSERT(axis);
1079 if (axis->animation())
1079 if (axis->animation())
1080 axis->animation()->stopAndDestroyLater();
1080 axis->animation()->stopAndDestroyLater();
1081
1081
1082 if (options.testFlag(QChart::GridAxisAnimations))
1082 if (options.testFlag(QChart::GridAxisAnimations))
1083 axis->setAnimation(new AxisAnimation(axis, duration, curve));
1083 axis->setAnimation(new AxisAnimation(axis, duration, curve));
1084 else
1084 else
1085 axis->setAnimation(0);
1085 axis->setAnimation(0);
1086 }
1086 }
1087
1087
1088
1088
1089
1089
1090 #include "moc_qabstractaxis.cpp"
1090 #include "moc_qabstractaxis.cpp"
1091 #include "moc_qabstractaxis_p.cpp"
1091 #include "moc_qabstractaxis_p.cpp"
1092
1092
1093 QT_CHARTS_END_NAMESPACE
1093 QT_CHARTS_END_NAMESPACE
@@ -1,641 +1,650
1 /******************************************************************************
1 /******************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
4 ** Contact: http://www.qt.io/licensing/
5 **
5 **
6 ** This file is part of the Qt Charts module.
6 ** This file is part of the Qt Charts module.
7 **
7 **
8 ** $QT_BEGIN_LICENSE:COMM$
8 ** $QT_BEGIN_LICENSE:COMM$
9 **
9 **
10 ** Commercial License Usage
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** and conditions see http://www.qt.io/terms-conditions. For further
16 ** information use the contact form at http://www.qt.io/contact-us.
16 ** information use the contact form at http://www.qt.io/contact-us.
17 **
17 **
18 ** $QT_END_LICENSE$
18 ** $QT_END_LICENSE$
19 **
19 **
20 ******************************************************************************/
20 ******************************************************************************/
21
21
22 #include <QtCharts/QLegend>
22 #include <QtCharts/QLegend>
23 #include <private/qlegend_p.h>
23 #include <private/qlegend_p.h>
24 #include <QtCharts/QAbstractSeries>
24 #include <QtCharts/QAbstractSeries>
25 #include <private/qabstractseries_p.h>
25 #include <private/qabstractseries_p.h>
26 #include <private/qchart_p.h>
26 #include <private/qchart_p.h>
27 #include <private/legendlayout_p.h>
27 #include <private/legendlayout_p.h>
28 #include <private/chartpresenter_p.h>
28 #include <private/chartpresenter_p.h>
29 #include <private/abstractchartlayout_p.h>
29 #include <private/abstractchartlayout_p.h>
30 #include <QtCharts/QLegendMarker>
30 #include <QtCharts/QLegendMarker>
31 #include <private/qlegendmarker_p.h>
31 #include <private/qlegendmarker_p.h>
32 #include <private/legendmarkeritem_p.h>
32 #include <private/legendmarkeritem_p.h>
33 #include <private/chartdataset_p.h>
33 #include <private/chartdataset_p.h>
34 #include <QtGui/QPainter>
34 #include <QtGui/QPainter>
35 #include <QtGui/QPen>
35 #include <QtGui/QPen>
36 #include <QtWidgets/QGraphicsItemGroup>
36 #include <QtWidgets/QGraphicsItemGroup>
37
37
38 QT_CHARTS_BEGIN_NAMESPACE
38 QT_CHARTS_BEGIN_NAMESPACE
39
39
40 /*!
40 /*!
41 \class QLegend
41 \class QLegend
42 \inmodule Qt Charts
42 \inmodule Qt Charts
43 \inherits QGraphicsWidget
43 \inherits QGraphicsWidget
44 \brief Legend object.
44 \brief Legend object.
45
45
46 QLegend is a graphical object for displaying the legend of the chart. Legend state is updated by QChart, when
46 QLegend is a graphical object for displaying the legend of the chart. Legend state is updated by QChart, when
47 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
47 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
48 handle the drawing manually.
48 handle the drawing manually.
49 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
49 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
50
50
51 \image examples_percentbarchart_legend.png
51 \image examples_percentbarchart_legend.png
52
52
53 \sa QChart
53 \sa QChart
54 */
54 */
55 /*!
55 /*!
56 \qmltype Legend
56 \qmltype Legend
57 \instantiates QLegend
57 \instantiates QLegend
58 \inqmlmodule QtCharts
58 \inqmlmodule QtCharts
59
59
60 \brief Legend is part of Qt Chart QML API.
60 \brief Legend is part of Qt Chart QML API.
61
61
62 Legend is a graphical object, which displays legend of the chart. Legend state is updated by
62 Legend is a graphical object, which displays legend of the chart. Legend state is updated by
63 ChartView, when series have been changed. Legend is used via ChartView class. For example:
63 ChartView, when series have been changed. Legend is used via ChartView class. For example:
64 \code
64 \code
65 ChartView {
65 ChartView {
66 legend.visible: true
66 legend.visible: true
67 legend.alignment: Qt.AlignBottom
67 legend.alignment: Qt.AlignBottom
68 // Add a few series...
68 // Add a few series...
69 }
69 }
70 \endcode
70 \endcode
71
71
72 \image examples_percentbarchart_legend.png
72 \image examples_percentbarchart_legend.png
73
73
74 Please note that there is no QML API available for modifying legend markers, unlike in the Qt
74 Please note that there is no QML API available for modifying legend markers, unlike in the Qt
75 API of Charts. The use case of modifying markers can be implemented for example by creating your
75 API of Charts. The use case of modifying markers can be implemented for example by creating your
76 own custom legend. For an example on how to do this,
76 own custom legend. For an example on how to do this,
77 see \l {qmlcustomlegend}{Qml Custom Example} application.
77 see \l {qmlcustomlegend}{Qml Custom Example} application.
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QLegend::alignment
81 \property QLegend::alignment
82 \brief The alignment of the legend.
82 \brief The alignment of the legend.
83
83
84 Legend paints on the defined position in the chart. The following alignments are supported:
84 Legend paints on the defined position in the chart. The following alignments are supported:
85 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
85 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
86 */
86 */
87 /*!
87 /*!
88 \qmlproperty Qt.Alignment Legend::alignment
88 \qmlproperty Qt.Alignment Legend::alignment
89 \brief The alignment of the legend.
89 \brief The alignment of the legend.
90
90
91 Legend paints on the defined position in the chart. The following alignments are supported:
91 Legend paints on the defined position in the chart. The following alignments are supported:
92 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
92 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
93 */
93 */
94
94
95 /*!
95 /*!
96 \property QLegend::backgroundVisible
96 \property QLegend::backgroundVisible
97 Whether the legend background is visible or not.
97 Whether the legend background is visible or not.
98 */
98 */
99 /*!
99 /*!
100 \qmlproperty bool Legend::backgroundVisible
100 \qmlproperty bool Legend::backgroundVisible
101 Whether the legend background is visible or not.
101 Whether the legend background is visible or not.
102 */
102 */
103
103
104 /*!
104 /*!
105 \qmlproperty bool Legend::visible
105 \qmlproperty bool Legend::visible
106 \brief Whether the legend is visible or not.
106 \brief Whether the legend is visible or not.
107
107
108 By default, this property is \c true.
108 By default, this property is \c true.
109 \sa QGraphicsObject::visible
109 \sa QGraphicsObject::visible
110 */
110 */
111
111
112 /*!
112 /*!
113 \property QLegend::color
113 \property QLegend::color
114 The color of the legend, i.e. the background (brush) color. Note that if you change the color
114 The color of the legend, i.e. the background (brush) color. Note that if you change the color
115 of the legend, the style of the legend brush is set to Qt::SolidPattern.
115 of the legend, the style of the legend brush is set to Qt::SolidPattern.
116 */
116 */
117 /*!
117 /*!
118 \qmlproperty color Legend::color
118 \qmlproperty color Legend::color
119 The color of the legend, i.e. the background (brush) color.
119 The color of the legend, i.e. the background (brush) color.
120 */
120 */
121
121
122 /*!
122 /*!
123 \property QLegend::borderColor
123 \property QLegend::borderColor
124 The border color of the legend, i.e. the line color.
124 The border color of the legend, i.e. the line color.
125 */
125 */
126 /*!
126 /*!
127 \qmlproperty color Legend::borderColor
127 \qmlproperty color Legend::borderColor
128 The border color of the legend, i.e. the line color.
128 The border color of the legend, i.e. the line color.
129 */
129 */
130
130
131 /*!
131 /*!
132 \property QLegend::font
132 \property QLegend::font
133 The font of markers used by legend.
133 The font of markers used by legend.
134 */
134 */
135 /*!
135 /*!
136 \qmlproperty Font Legend::font
136 \qmlproperty Font Legend::font
137 The font of markers used by legend.
137 The font of markers used by legend.
138 */
138 */
139
139
140 /*!
140 /*!
141 \property QLegend::labelColor
141 \property QLegend::labelColor
142 The color of brush used to draw labels.
142 The color of brush used to draw labels.
143 */
143 */
144 /*!
144 /*!
145 \qmlproperty color Legend::labelColor
145 \qmlproperty color Legend::labelColor
146 The color of brush used to draw labels.
146 The color of brush used to draw labels.
147 */
147 */
148
148
149 /*!
149 /*!
150 \property QLegend::reverseMarkers
150 \property QLegend::reverseMarkers
151 Whether reverse order is used for the markers in legend or not. False by default.
151 Whether reverse order is used for the markers in legend or not. False by default.
152 */
152 */
153 /*!
153 /*!
154 \qmlproperty bool Legend::reverseMarkers
154 \qmlproperty bool Legend::reverseMarkers
155 Whether reverse order is used for the markers in legend or not. False by default.
155 Whether reverse order is used for the markers in legend or not. False by default.
156 */
156 */
157
157
158 /*!
158 /*!
159 \fn void QLegend::backgroundVisibleChanged(bool)
159 \fn void QLegend::backgroundVisibleChanged(bool)
160 The visibility of the legend background changed to \a visible.
160 The visibility of the legend background changed to \a visible.
161 */
161 */
162
162
163 /*!
163 /*!
164 \fn void QLegend::colorChanged(QColor)
164 \fn void QLegend::colorChanged(QColor)
165 The color of the legend background changed to \a color.
165 The color of the legend background changed to \a color.
166 */
166 */
167
167
168 /*!
168 /*!
169 \fn void QLegend::borderColorChanged(QColor)
169 \fn void QLegend::borderColorChanged(QColor)
170 The border color of the legend background changed to \a color.
170 The border color of the legend background changed to \a color.
171 */
171 */
172
172
173 /*!
173 /*!
174 \fn void QLegend::fontChanged(QFont)
174 \fn void QLegend::fontChanged(QFont)
175 The font of markers of the legend changed to \a font.
175 The font of markers of the legend changed to \a font.
176 */
176 */
177
177
178 /*!
178 /*!
179 \fn void QLegend::labelColorChanged(QColor color)
179 \fn void QLegend::labelColorChanged(QColor color)
180 This signal is emitted when the color of brush used to draw labels has changed to \a color.
180 This signal is emitted when the color of brush used to draw labels has changed to \a color.
181 */
181 */
182
182
183 /*!
183 /*!
184 \fn void QLegend::reverseMarkersChanged(bool)
184 \fn void QLegend::reverseMarkersChanged(bool)
185 The use of reverse order for the markers in legend is changed to \a reverseMarkers.
185 The use of reverse order for the markers in legend is changed to \a reverseMarkers.
186 */
186 */
187
187
188 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
188 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
189 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this))
189 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this))
190 {
190 {
191 setZValue(ChartPresenter::LegendZValue);
191 setZValue(ChartPresenter::LegendZValue);
192 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
192 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
193 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*)));
193 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*)));
194 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
194 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
195 setLayout(d_ptr->m_layout);
195 setLayout(d_ptr->m_layout);
196 }
196 }
197
197
198 /*!
198 /*!
199 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
199 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
200 */
200 */
201 QLegend::~QLegend()
201 QLegend::~QLegend()
202 {
202 {
203 }
203 }
204
204
205 /*!
205 /*!
206 \internal
206 \internal
207 */
207 */
208 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
208 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
209 {
209 {
210 Q_UNUSED(option)
210 Q_UNUSED(option)
211 Q_UNUSED(widget)
211 Q_UNUSED(widget)
212
212
213 if (!d_ptr->m_backgroundVisible)
213 if (!d_ptr->m_backgroundVisible)
214 return;
214 return;
215
215
216 painter->setOpacity(opacity());
216 painter->setOpacity(opacity());
217 painter->setPen(d_ptr->m_pen);
217 painter->setPen(d_ptr->m_pen);
218 painter->setBrush(d_ptr->m_brush);
218 painter->setBrush(d_ptr->m_brush);
219 painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
219 painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
220 }
220 }
221
221
222
222
223 /*!
223 /*!
224 Sets the \a brush of legend. Brush affects the background of legend.
224 Sets the \a brush of legend. Brush affects the background of legend.
225 */
225 */
226 void QLegend::setBrush(const QBrush &brush)
226 void QLegend::setBrush(const QBrush &brush)
227 {
227 {
228 if (d_ptr->m_brush != brush) {
228 if (d_ptr->m_brush != brush) {
229 d_ptr->m_brush = brush;
229 d_ptr->m_brush = brush;
230 update();
230 update();
231 emit colorChanged(brush.color());
231 emit colorChanged(brush.color());
232 }
232 }
233 }
233 }
234
234
235 /*!
235 /*!
236 Returns the brush used by legend.
236 Returns the brush used by legend.
237 */
237 */
238 QBrush QLegend::brush() const
238 QBrush QLegend::brush() const
239 {
239 {
240 return d_ptr->m_brush;
240 if (d_ptr->m_brush == QChartPrivate::defaultBrush())
241 return QBrush();
242 else
243 return d_ptr->m_brush;
241 }
244 }
242
245
243 void QLegend::setColor(QColor color)
246 void QLegend::setColor(QColor color)
244 {
247 {
245 QBrush b = d_ptr->m_brush;
248 QBrush b = brush();
246 if (b.style() != Qt::SolidPattern || b.color() != color) {
249 if (b.style() != Qt::SolidPattern || b.color() != color) {
247 b.setStyle(Qt::SolidPattern);
250 b.setStyle(Qt::SolidPattern);
248 b.setColor(color);
251 b.setColor(color);
249 setBrush(b);
252 setBrush(b);
250 }
253 }
251 }
254 }
252
255
253 QColor QLegend::color()
256 QColor QLegend::color()
254 {
257 {
255 return d_ptr->m_brush.color();
258 return d_ptr->m_brush.color();
256 }
259 }
257
260
258 /*!
261 /*!
259 Sets the \a pen of legend. Pen affects the legend borders.
262 Sets the \a pen of legend. Pen affects the legend borders.
260 */
263 */
261 void QLegend::setPen(const QPen &pen)
264 void QLegend::setPen(const QPen &pen)
262 {
265 {
263 if (d_ptr->m_pen != pen) {
266 if (d_ptr->m_pen != pen) {
264 d_ptr->m_pen = pen;
267 d_ptr->m_pen = pen;
265 update();
268 update();
266 emit borderColorChanged(pen.color());
269 emit borderColorChanged(pen.color());
267 }
270 }
268 }
271 }
269
272
270 /*!
273 /*!
271 Returns the pen used by legend.
274 Returns the pen used by legend.
272 */
275 */
273
276
274 QPen QLegend::pen() const
277 QPen QLegend::pen() const
275 {
278 {
276 return d_ptr->m_pen;
279 if (d_ptr->m_pen == QChartPrivate::defaultPen())
280 return QPen();
281 else
282 return d_ptr->m_pen;
277 }
283 }
278
284
279 void QLegend::setFont(const QFont &font)
285 void QLegend::setFont(const QFont &font)
280 {
286 {
281 if (d_ptr->m_font != font) {
287 if (d_ptr->m_font != font) {
282 // Hide items to avoid flickering
288 // Hide items to avoid flickering
283 d_ptr->items()->setVisible(false);
289 d_ptr->items()->setVisible(false);
284 d_ptr->m_font = font;
290 d_ptr->m_font = font;
285 foreach (QLegendMarker *marker, d_ptr->markers()) {
291 foreach (QLegendMarker *marker, d_ptr->markers()) {
286 marker->setFont(d_ptr->m_font);
292 marker->setFont(d_ptr->m_font);
287 }
293 }
288 layout()->invalidate();
294 layout()->invalidate();
289 emit fontChanged(font);
295 emit fontChanged(font);
290 }
296 }
291 }
297 }
292
298
293 QFont QLegend::font() const
299 QFont QLegend::font() const
294 {
300 {
295 return d_ptr->m_font;
301 return d_ptr->m_font;
296 }
302 }
297
303
298 void QLegend::setBorderColor(QColor color)
304 void QLegend::setBorderColor(QColor color)
299 {
305 {
300 QPen p = d_ptr->m_pen;
306 QPen p = pen();
301 if (p.color() != color) {
307 if (p.color() != color) {
302 p.setColor(color);
308 p.setColor(color);
303 setPen(p);
309 setPen(p);
304 }
310 }
305 }
311 }
306
312
307 QColor QLegend::borderColor()
313 QColor QLegend::borderColor()
308 {
314 {
309 return d_ptr->m_pen.color();
315 return d_ptr->m_pen.color();
310 }
316 }
311
317
312 /*!
318 /*!
313 Set brush used to draw labels to \a brush.
319 Set brush used to draw labels to \a brush.
314 */
320 */
315 void QLegend::setLabelBrush(const QBrush &brush)
321 void QLegend::setLabelBrush(const QBrush &brush)
316 {
322 {
317 if (d_ptr->m_labelBrush != brush) {
323 if (d_ptr->m_labelBrush != brush) {
318 d_ptr->m_labelBrush = brush;
324 d_ptr->m_labelBrush = brush;
319 foreach (QLegendMarker *marker, d_ptr->markers()) {
325 foreach (QLegendMarker *marker, d_ptr->markers()) {
320 marker->setLabelBrush(d_ptr->m_labelBrush);
326 marker->setLabelBrush(d_ptr->m_labelBrush);
321 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
327 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
322 // instead of mapping it from label brush color
328 // instead of mapping it from label brush color
323 marker->setPen(brush.color());
329 marker->setPen(brush.color());
324 }
330 }
325 emit labelColorChanged(brush.color());
331 emit labelColorChanged(brush.color());
326 }
332 }
327 }
333 }
328
334
329 /*!
335 /*!
330 Brush used to draw labels.
336 Brush used to draw labels.
331 */
337 */
332 QBrush QLegend::labelBrush() const
338 QBrush QLegend::labelBrush() const
333 {
339 {
334 return d_ptr->m_labelBrush;
340 if (d_ptr->m_labelBrush == QChartPrivate::defaultBrush())
341 return QBrush();
342 else
343 return d_ptr->m_labelBrush;
335 }
344 }
336
345
337 void QLegend::setLabelColor(QColor color)
346 void QLegend::setLabelColor(QColor color)
338 {
347 {
339 QBrush b = d_ptr->m_labelBrush;
348 QBrush b = labelBrush();
340 if (b.style() != Qt::SolidPattern || b.color() != color) {
349 if (b.style() != Qt::SolidPattern || b.color() != color) {
341 b.setStyle(Qt::SolidPattern);
350 b.setStyle(Qt::SolidPattern);
342 b.setColor(color);
351 b.setColor(color);
343 setLabelBrush(b);
352 setLabelBrush(b);
344 }
353 }
345 }
354 }
346
355
347 QColor QLegend::labelColor() const
356 QColor QLegend::labelColor() const
348 {
357 {
349 return d_ptr->m_labelBrush.color();
358 return d_ptr->m_labelBrush.color();
350 }
359 }
351
360
352
361
353 void QLegend::setAlignment(Qt::Alignment alignment)
362 void QLegend::setAlignment(Qt::Alignment alignment)
354 {
363 {
355 if (d_ptr->m_alignment != alignment) {
364 if (d_ptr->m_alignment != alignment) {
356 d_ptr->m_alignment = alignment;
365 d_ptr->m_alignment = alignment;
357 layout()->invalidate();
366 layout()->invalidate();
358 }
367 }
359 }
368 }
360
369
361 Qt::Alignment QLegend::alignment() const
370 Qt::Alignment QLegend::alignment() const
362 {
371 {
363 return d_ptr->m_alignment;
372 return d_ptr->m_alignment;
364 }
373 }
365
374
366 /*!
375 /*!
367 Detaches the legend from chart. Chart won't change layout of the legend.
376 Detaches the legend from chart. Chart won't change layout of the legend.
368 */
377 */
369 void QLegend::detachFromChart()
378 void QLegend::detachFromChart()
370 {
379 {
371 d_ptr->m_attachedToChart = false;
380 d_ptr->m_attachedToChart = false;
372 // layout()->invalidate();
381 // layout()->invalidate();
373 d_ptr->m_chart->layout()->invalidate();
382 d_ptr->m_chart->layout()->invalidate();
374 setParent(0);
383 setParent(0);
375
384
376 }
385 }
377
386
378 /*!
387 /*!
379 Attaches the legend to chart. Chart may change layout of the legend.
388 Attaches the legend to chart. Chart may change layout of the legend.
380 */
389 */
381 void QLegend::attachToChart()
390 void QLegend::attachToChart()
382 {
391 {
383 d_ptr->m_attachedToChart = true;
392 d_ptr->m_attachedToChart = true;
384 // layout()->invalidate();
393 // layout()->invalidate();
385 d_ptr->m_chart->layout()->invalidate();
394 d_ptr->m_chart->layout()->invalidate();
386 setParent(d_ptr->m_chart);
395 setParent(d_ptr->m_chart);
387 }
396 }
388
397
389 /*!
398 /*!
390 Returns true, if legend is attached to chart.
399 Returns true, if legend is attached to chart.
391 */
400 */
392 bool QLegend::isAttachedToChart()
401 bool QLegend::isAttachedToChart()
393 {
402 {
394 return d_ptr->m_attachedToChart;
403 return d_ptr->m_attachedToChart;
395 }
404 }
396
405
397 /*!
406 /*!
398 Sets the visibility of legend background to \a visible
407 Sets the visibility of legend background to \a visible
399 */
408 */
400 void QLegend::setBackgroundVisible(bool visible)
409 void QLegend::setBackgroundVisible(bool visible)
401 {
410 {
402 if (d_ptr->m_backgroundVisible != visible) {
411 if (d_ptr->m_backgroundVisible != visible) {
403 d_ptr->m_backgroundVisible = visible;
412 d_ptr->m_backgroundVisible = visible;
404 update();
413 update();
405 emit backgroundVisibleChanged(visible);
414 emit backgroundVisibleChanged(visible);
406 }
415 }
407 }
416 }
408
417
409 /*!
418 /*!
410 Returns the visibility of legend background
419 Returns the visibility of legend background
411 */
420 */
412 bool QLegend::isBackgroundVisible() const
421 bool QLegend::isBackgroundVisible() const
413 {
422 {
414 return d_ptr->m_backgroundVisible;
423 return d_ptr->m_backgroundVisible;
415 }
424 }
416
425
417 /*!
426 /*!
418 Returns the list of markers in legend. The list can be filtered with \a series parameter.
427 Returns the list of markers in legend. The list can be filtered with \a series parameter.
419 If \a series is given, only markers related to that series are returned.
428 If \a series is given, only markers related to that series are returned.
420 */
429 */
421 QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const
430 QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const
422 {
431 {
423 return d_ptr->markers(series);
432 return d_ptr->markers(series);
424 }
433 }
425
434
426 bool QLegend::reverseMarkers()
435 bool QLegend::reverseMarkers()
427 {
436 {
428 return d_ptr->m_reverseMarkers;
437 return d_ptr->m_reverseMarkers;
429 }
438 }
430
439
431 void QLegend::setReverseMarkers(bool reverseMarkers)
440 void QLegend::setReverseMarkers(bool reverseMarkers)
432 {
441 {
433 if (d_ptr->m_reverseMarkers != reverseMarkers) {
442 if (d_ptr->m_reverseMarkers != reverseMarkers) {
434 d_ptr->m_reverseMarkers = reverseMarkers;
443 d_ptr->m_reverseMarkers = reverseMarkers;
435 layout()->invalidate();
444 layout()->invalidate();
436 emit reverseMarkersChanged(reverseMarkers);
445 emit reverseMarkersChanged(reverseMarkers);
437 }
446 }
438 }
447 }
439
448
440 /*!
449 /*!
441 \internal \a event see QGraphicsWidget for details
450 \internal \a event see QGraphicsWidget for details
442 */
451 */
443 void QLegend::hideEvent(QHideEvent *event)
452 void QLegend::hideEvent(QHideEvent *event)
444 {
453 {
445 if (isAttachedToChart())
454 if (isAttachedToChart())
446 d_ptr->m_presenter->layout()->invalidate();
455 d_ptr->m_presenter->layout()->invalidate();
447 QGraphicsWidget::hideEvent(event);
456 QGraphicsWidget::hideEvent(event);
448 }
457 }
449 /*!
458 /*!
450 \internal \a event see QGraphicsWidget for details
459 \internal \a event see QGraphicsWidget for details
451 */
460 */
452 void QLegend::showEvent(QShowEvent *event)
461 void QLegend::showEvent(QShowEvent *event)
453 {
462 {
454 if (isAttachedToChart())
463 if (isAttachedToChart())
455 layout()->invalidate();
464 layout()->invalidate();
456 QGraphicsWidget::showEvent(event);
465 QGraphicsWidget::showEvent(event);
457 //layout activation will show the items
466 //layout activation will show the items
458 }
467 }
459
468
460 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
469 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
461
470
462 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q)
471 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q)
463 : q_ptr(q),
472 : q_ptr(q),
464 m_presenter(presenter),
473 m_presenter(presenter),
465 m_layout(new LegendLayout(q)),
474 m_layout(new LegendLayout(q)),
466 m_chart(chart),
475 m_chart(chart),
467 m_items(new QGraphicsItemGroup(q)),
476 m_items(new QGraphicsItemGroup(q)),
468 m_alignment(Qt::AlignTop),
477 m_alignment(Qt::AlignTop),
469 m_brush(QBrush()),
478 m_brush(QChartPrivate::defaultBrush()),
470 m_pen(QPen()),
479 m_pen(QChartPrivate::defaultPen()),
471 m_labelBrush(QBrush()),
480 m_labelBrush(QChartPrivate::defaultBrush()),
472 m_diameter(5),
481 m_diameter(5),
473 m_attachedToChart(true),
482 m_attachedToChart(true),
474 m_backgroundVisible(false),
483 m_backgroundVisible(false),
475 m_reverseMarkers(false)
484 m_reverseMarkers(false)
476 {
485 {
477 m_items->setHandlesChildEvents(false);
486 m_items->setHandlesChildEvents(false);
478 }
487 }
479
488
480 QLegendPrivate::~QLegendPrivate()
489 QLegendPrivate::~QLegendPrivate()
481 {
490 {
482
491
483 }
492 }
484
493
485 void QLegendPrivate::setOffset(const QPointF &offset)
494 void QLegendPrivate::setOffset(const QPointF &offset)
486 {
495 {
487 m_layout->setOffset(offset.x(), offset.y());
496 m_layout->setOffset(offset.x(), offset.y());
488 }
497 }
489
498
490 QPointF QLegendPrivate::offset() const
499 QPointF QLegendPrivate::offset() const
491 {
500 {
492 return m_layout->offset();
501 return m_layout->offset();
493 }
502 }
494
503
495 int QLegendPrivate::roundness(qreal size)
504 int QLegendPrivate::roundness(qreal size)
496 {
505 {
497 return 100 * m_diameter / int(size);
506 return 100 * m_diameter / int(size);
498 }
507 }
499
508
500 QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series)
509 QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series)
501 {
510 {
502 // Return all markers
511 // Return all markers
503 if (!series) {
512 if (!series) {
504 return m_markers;
513 return m_markers;
505 }
514 }
506
515
507 // Create filtered list
516 // Create filtered list
508 QList<QLegendMarker *> markers;
517 QList<QLegendMarker *> markers;
509 foreach (QLegendMarker *marker, m_markers) {
518 foreach (QLegendMarker *marker, m_markers) {
510 if (marker->series() == series) {
519 if (marker->series() == series) {
511 markers.append(marker);
520 markers.append(marker);
512 }
521 }
513 }
522 }
514 return markers;
523 return markers;
515 }
524 }
516
525
517 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series)
526 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series)
518 {
527 {
519 if (m_series.contains(series)) {
528 if (m_series.contains(series)) {
520 return;
529 return;
521 }
530 }
522
531
523 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
532 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
524 decorateMarkers(newMarkers);
533 decorateMarkers(newMarkers);
525 addMarkers(newMarkers);
534 addMarkers(newMarkers);
526
535
527 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
536 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
528 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
537 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
529
538
530 m_series.append(series);
539 m_series.append(series);
531 m_items->setVisible(false);
540 m_items->setVisible(false);
532 m_layout->invalidate();
541 m_layout->invalidate();
533 }
542 }
534
543
535 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
544 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
536 {
545 {
537 if (m_series.contains(series)) {
546 if (m_series.contains(series)) {
538 m_series.removeOne(series);
547 m_series.removeOne(series);
539 }
548 }
540
549
541 // Find out, which markers to remove
550 // Find out, which markers to remove
542 QList<QLegendMarker *> removed;
551 QList<QLegendMarker *> removed;
543 foreach (QLegendMarker *m, m_markers) {
552 foreach (QLegendMarker *m, m_markers) {
544 if (m->series() == series) {
553 if (m->series() == series) {
545 removed << m;
554 removed << m;
546 }
555 }
547 }
556 }
548 removeMarkers(removed);
557 removeMarkers(removed);
549
558
550 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
559 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
551 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
560 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
552
561
553 m_layout->invalidate();
562 m_layout->invalidate();
554 }
563 }
555
564
556 void QLegendPrivate::handleSeriesVisibleChanged()
565 void QLegendPrivate::handleSeriesVisibleChanged()
557 {
566 {
558 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
567 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
559 Q_ASSERT(series);
568 Q_ASSERT(series);
560
569
561 foreach (QLegendMarker *marker, m_markers) {
570 foreach (QLegendMarker *marker, m_markers) {
562 if (marker->series() == series) {
571 if (marker->series() == series) {
563 marker->setVisible(series->isVisible());
572 marker->setVisible(series->isVisible());
564 }
573 }
565 }
574 }
566
575
567 if (m_chart->isVisible())
576 if (m_chart->isVisible())
568 m_layout->invalidate();
577 m_layout->invalidate();
569 }
578 }
570
579
571 void QLegendPrivate::handleCountChanged()
580 void QLegendPrivate::handleCountChanged()
572 {
581 {
573 // Here we handle the changes in marker count.
582 // Here we handle the changes in marker count.
574 // Can happen for example when pieslice(s) have been added to or removed from pieseries.
583 // Can happen for example when pieslice(s) have been added to or removed from pieseries.
575
584
576 QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender());
585 QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender());
577 QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr);
586 QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr);
578
587
579 // Find out removed markers and created markers
588 // Find out removed markers and created markers
580 QList<QLegendMarker *> removedMarkers;
589 QList<QLegendMarker *> removedMarkers;
581 foreach (QLegendMarker *oldMarker, m_markers) {
590 foreach (QLegendMarker *oldMarker, m_markers) {
582 // we have marker, which is related to sender.
591 // we have marker, which is related to sender.
583 if (oldMarker->series() == series->q_ptr) {
592 if (oldMarker->series() == series->q_ptr) {
584 bool found = false;
593 bool found = false;
585 foreach(QLegendMarker *newMarker, createdMarkers) {
594 foreach(QLegendMarker *newMarker, createdMarkers) {
586 // New marker considered existing if:
595 // New marker considered existing if:
587 // - d_ptr->relatedObject() is same for both markers.
596 // - d_ptr->relatedObject() is same for both markers.
588 if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) {
597 if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) {
589 // Delete the new marker, since we already have existing marker, that might be connected on user side.
598 // Delete the new marker, since we already have existing marker, that might be connected on user side.
590 found = true;
599 found = true;
591 createdMarkers.removeOne(newMarker);
600 createdMarkers.removeOne(newMarker);
592 delete newMarker;
601 delete newMarker;
593 }
602 }
594 }
603 }
595 if (!found) {
604 if (!found) {
596 // No related object found for marker, add to removedMarkers list
605 // No related object found for marker, add to removedMarkers list
597 removedMarkers << oldMarker;
606 removedMarkers << oldMarker;
598 }
607 }
599 }
608 }
600 }
609 }
601
610
602 removeMarkers(removedMarkers);
611 removeMarkers(removedMarkers);
603 decorateMarkers(createdMarkers);
612 decorateMarkers(createdMarkers);
604 addMarkers(createdMarkers);
613 addMarkers(createdMarkers);
605
614
606 q_ptr->layout()->invalidate();
615 q_ptr->layout()->invalidate();
607 }
616 }
608
617
609 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers)
618 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers)
610 {
619 {
611 foreach (QLegendMarker *marker, markers) {
620 foreach (QLegendMarker *marker, markers) {
612 m_items->addToGroup(marker->d_ptr.data()->item());
621 m_items->addToGroup(marker->d_ptr.data()->item());
613 m_markers << marker;
622 m_markers << marker;
614 m_markerHash.insert(marker->d_ptr->item(), marker);
623 m_markerHash.insert(marker->d_ptr->item(), marker);
615 }
624 }
616 }
625 }
617
626
618 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers)
627 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers)
619 {
628 {
620 foreach (QLegendMarker *marker, markers) {
629 foreach (QLegendMarker *marker, markers) {
621 marker->d_ptr->item()->setVisible(false);
630 marker->d_ptr->item()->setVisible(false);
622 m_items->removeFromGroup(marker->d_ptr->item());
631 m_items->removeFromGroup(marker->d_ptr->item());
623 m_markers.removeOne(marker);
632 m_markers.removeOne(marker);
624 m_markerHash.remove(marker->d_ptr->item());
633 m_markerHash.remove(marker->d_ptr->item());
625 delete marker;
634 delete marker;
626 }
635 }
627 }
636 }
628
637
629 void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers)
638 void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers)
630 {
639 {
631 foreach (QLegendMarker *marker, markers) {
640 foreach (QLegendMarker *marker, markers) {
632 marker->setFont(m_font);
641 marker->setFont(m_font);
633 marker->setLabelBrush(m_labelBrush);
642 marker->setLabelBrush(m_labelBrush);
634 }
643 }
635 }
644 }
636
645
637
646
638 #include "moc_qlegend.cpp"
647 #include "moc_qlegend.cpp"
639 #include "moc_qlegend_p.cpp"
648 #include "moc_qlegend_p.cpp"
640
649
641 QT_CHARTS_END_NAMESPACE
650 QT_CHARTS_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now