##// END OF EJS Templates
Fixed several documentation issues
Tero Ahola -
r2265:b004c42eda51
parent child
Show More
@@ -1,758 +1,794
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qabstractaxis.h"
21 #include "qabstractaxis.h"
22 #include "qabstractaxis_p.h"
22 #include "qabstractaxis_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QAbstractAxis
27 \class QAbstractAxis
28 \brief The QAbstractAxis class is used for manipulating chart's axis.
28 \brief The QAbstractAxis class is used for manipulating chart's axis.
29 \mainclass
29 \mainclass
30
30
31 There is only one x Axis visible at the time, however there can be multiple y axes.
31 There is only one x Axis visible at the time, however there can be multiple y axes.
32 Each chart series can be bound to exactly one Y axis and the shared common X axis.
32 Each chart series can be bound to exactly one Y axis and the shared common X axis.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 */
34 */
35
35
36 /*!
36 /*!
37 \qmlclass AbstractAxis QAbstractAxis
37 \qmlclass AbstractAxis QAbstractAxis
38 \brief The Axis element is used for manipulating chart's axes
38 \brief The Axis element is used for manipulating chart's axes
39
39
40 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
40 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
41 Each chart series can be bound to exactly one Y axis and the shared common X axis.
41 Each chart series can be bound to exactly one Y axis and the shared common X axis.
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
43
43
44 To access Axes you can use ChartView API. For example:
44 To access Axes you can use ChartView API. For example:
45 \code
45 \code
46 ChartView {
46 ChartView {
47 axisX.min: 0
47 axisX.min: 0
48 axisX.max: 3
48 axisX.max: 3
49 axisX.ticksCount: 4
49 axisX.ticksCount: 4
50 axisY.min: 0
50 axisY.min: 0
51 axisY.max: 4
51 axisY.max: 4
52 // Add a few series...
52 // Add a few series...
53 }
53 }
54 \endcode
54 \endcode
55 */
55 */
56
56
57 /*!
57 /*!
58 \enum QAbstractAxis::AxisType
58 \enum QAbstractAxis::AxisType
59
59
60 The type of the series object.
60 The type of the series object.
61
61
62 \value AxisTypeNoAxis
62 \value AxisTypeNoAxis
63 \value AxisTypeValue
63 \value AxisTypeValue
64 \value AxisTypeBarCategory
64 \value AxisTypeBarCategory
65 \value AxisTypeCategory
65 \value AxisTypeCategory
66 \value AxisTypeDateTime
66 \value AxisTypeDateTime
67 */
67 */
68
68
69 /*!
69 /*!
70 *\fn void QAbstractAxis::type() const
70 *\fn void QAbstractAxis::type() const
71 Returns the type of the axis
71 Returns the type of the axis
72 */
72 */
73
73
74 /*!
74 /*!
75 \property QAbstractAxis::lineVisible
75 \property QAbstractAxis::lineVisible
76 The visibility of the axis line
76 The visibility of the axis line
77 */
77 */
78 /*!
78 /*!
79 \qmlproperty bool AbstractAxis::lineVisible
79 \qmlproperty bool AbstractAxis::lineVisible
80 The visibility of the axis line
80 The visibility of the axis line
81 */
81 */
82
82
83 /*!
83 /*!
84 \property QAbstractAxis::labelsVisible
84 \property QAbstractAxis::labelsVisible
85 Defines if axis labels are visible.
85 Defines if axis labels are visible.
86 */
86 */
87 /*!
87 /*!
88 \qmlproperty bool AbstractAxis::labelsVisible
88 \qmlproperty bool AbstractAxis::labelsVisible
89 Defines if axis labels are visible.
89 Defines if axis labels are visible.
90 */
90 */
91
91
92 /*!
92 /*!
93 \property QAbstractAxis::visible
93 \property QAbstractAxis::visible
94 The visibility of the axis.
94 The visibility of the axis.
95 */
95 */
96 /*!
96 /*!
97 \qmlproperty bool AbstractAxis::visible
97 \qmlproperty bool AbstractAxis::visible
98 The visibility of the axis.
98 The visibility of the axis.
99 */
99 */
100
100
101 /*!
101 /*!
102 \property QAbstractAxis::gridVisible
102 \property QAbstractAxis::gridVisible
103 The visibility of the grid lines.
103 The visibility of the grid lines.
104 */
104 */
105 /*!
105 /*!
106 \qmlproperty bool AbstractAxis::gridVisible
106 \qmlproperty bool AbstractAxis::gridVisible
107 The visibility of the grid lines.
107 The visibility of the grid lines.
108 */
108 */
109
109
110 /*!
110 /*!
111 \property QAbstractAxis::color
111 \property QAbstractAxis::color
112 The color of the axis and ticks.
112 The color of the axis and ticks.
113 */
113 */
114 /*!
114 /*!
115 \qmlproperty color AbstractAxis::color
115 \qmlproperty color AbstractAxis::color
116 The color of the axis and ticks.
116 The color of the axis and ticks.
117 */
117 */
118
118
119 /*!
119 /*!
120 \property QAbstractAxis::labelsFont
120 \property QAbstractAxis::labelsFont
121 The font of the axis labels.
121 The font of the axis labels.
122 */
122 */
123
123
124 /*!
124 /*!
125 \qmlproperty Font AbstractAxis::labelsFont
125 \qmlproperty Font AbstractAxis::labelsFont
126 The font of the axis labels.
126 The font of the axis labels.
127
127
128 See the \l {Font} {QML Font Element} for detailed documentation.
128 See the \l {Font} {QML Font Element} for detailed documentation.
129 */
129 */
130
130
131 /*!
131 /*!
132 \property QAbstractAxis::labelsColor
132 \property QAbstractAxis::labelsColor
133 The color of the axis labels.
133 The color of the axis labels.
134 */
134 */
135 /*!
135 /*!
136 \qmlproperty color AbstractAxis::labelsColor
136 \qmlproperty color AbstractAxis::labelsColor
137 The color of the axis labels.
137 The color of the axis labels.
138 */
138 */
139
139
140 /*!
140 /*!
141 \property QAbstractAxis::labelsAngle
141 \property QAbstractAxis::labelsAngle
142 The angle of the axis labels in degrees.
142 The angle of the axis labels in degrees.
143 */
143 */
144 /*!
144 /*!
145 \qmlproperty int AbstractAxis::labelsAngle
145 \qmlproperty int AbstractAxis::labelsAngle
146 The angle of the axis labels in degrees.
146 The angle of the axis labels in degrees.
147 */
147 */
148
148
149 /*!
149 /*!
150 \property QAbstractAxis::shadesVisible
150 \property QAbstractAxis::shadesVisible
151 The visibility of the axis shades.
151 The visibility of the axis shades.
152 */
152 */
153 /*!
153 /*!
154 \qmlproperty bool AbstractAxis::shadesVisible
154 \qmlproperty bool AbstractAxis::shadesVisible
155 The visibility of the axis shades.
155 The visibility of the axis shades.
156 */
156 */
157
157
158 /*!
158 /*!
159 \property QAbstractAxis::shadesColor
159 \property QAbstractAxis::shadesColor
160 The fill (brush) color of the axis shades.
160 The fill (brush) color of the axis shades.
161 */
161 */
162 /*!
162 /*!
163 \qmlproperty color AbstractAxis::shadesColor
163 \qmlproperty color AbstractAxis::shadesColor
164 The fill (brush) color of the axis shades.
164 The fill (brush) color of the axis shades.
165 */
165 */
166
166
167 /*!
167 /*!
168 \property QAbstractAxis::shadesBorderColor
168 \property QAbstractAxis::shadesBorderColor
169 The border (pen) color of the axis shades.
169 The border (pen) color of the axis shades.
170 */
170 */
171 /*!
171 /*!
172 \qmlproperty color AbstractAxis::shadesBorderColor
172 \qmlproperty color AbstractAxis::shadesBorderColor
173 The border (pen) color of the axis shades.
173 The border (pen) color of the axis shades.
174 */
174 */
175
175
176 /*!
176 /*!
177 \property QAbstractAxis::titleVisible
178 The visibility of the axis title. By default the value is true.
179 */
180 /*!
181 \qmlproperty bool AbstractAxis::titleVisible
182 The visibility of the axis title. By default the value is true.
183 */
184
185 /*!
186 \property QAbstractAxis::titleFont
187 The font of the title of the axis.
188 */
189 /*!
190 \qmlproperty Font AbstractAxis::title
191 The font of the title of the axis.
192 */
193
194 /*!
195 \property QAbstractAxis::title
196 The title of the axis. Empty by default.
197 */
198 /*!
199 \qmlproperty string AbstractAxis::title
200 The title of the axis. Empty string by default.
201 */
202
203 /*!
204 \property QAbstractAxis::alignment
205 The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom.
206 */
207 /*!
208 \qmlproperty alignment AbstractAxis::alignment
209 The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom.
210 */
211
212 /*!
177 \fn void QAbstractAxis::visibleChanged(bool visible)
213 \fn void QAbstractAxis::visibleChanged(bool visible)
178 Visibility of the axis has changed to \a visible.
214 Visibility of the axis has changed to \a visible.
179 */
215 */
180 /*!
216 /*!
181 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
217 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
182 Visibility of the axis has changed to \a visible.
218 Visibility of the axis has changed to \a visible.
183 */
219 */
184
220
185 /*!
221 /*!
186 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
222 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
187 Visibility of the axis line has changed to \a visible.
223 Visibility of the axis line has changed to \a visible.
188 */
224 */
189 /*!
225 /*!
190 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
226 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
191 Visibility of the axis line has changed to \a visible.
227 Visibility of the axis line has changed to \a visible.
192 */
228 */
193
229
194 /*!
230 /*!
195 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
231 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
196 Visibility of the labels of the axis has changed to \a visible.
232 Visibility of the labels of the axis has changed to \a visible.
197 */
233 */
198 /*!
234 /*!
199 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
235 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
200 Visibility of the labels of the axis has changed to \a visible.
236 Visibility of the labels of the axis has changed to \a visible.
201 */
237 */
202
238
203 /*!
239 /*!
204 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
240 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
205 Visibility of the grid lines of the axis has changed to \a visible.
241 Visibility of the grid lines of the axis has changed to \a visible.
206 */
242 */
207 /*!
243 /*!
208 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
244 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
209 Visibility of the grid lines of the axis has changed to \a visible.
245 Visibility of the grid lines of the axis has changed to \a visible.
210 */
246 */
211
247
212 /*!
248 /*!
213 \fn void QAbstractAxis::colorChanged(QColor color)
249 \fn void QAbstractAxis::colorChanged(QColor color)
214 Emitted if the \a color of the axis is changed.
250 Emitted if the \a color of the axis is changed.
215 */
251 */
216 /*!
252 /*!
217 \qmlsignal AbstractAxis::onColorChanged(QColor color)
253 \qmlsignal AbstractAxis::onColorChanged(QColor color)
218 Emitted if the \a color of the axis is changed.
254 Emitted if the \a color of the axis is changed.
219 */
255 */
220
256
221 /*!
257 /*!
222 \fn void QAbstractAxis::labelsColorChanged(QColor color)
258 \fn void QAbstractAxis::labelsColorChanged(QColor color)
223 Emitted if the \a color of the axis labels is changed.
259 Emitted if the \a color of the axis labels is changed.
224 */
260 */
225 /*!
261 /*!
226 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
262 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
227 Emitted if the \a color of the axis labels is changed.
263 Emitted if the \a color of the axis labels is changed.
228 */
264 */
229
265
230 /*!
266 /*!
231 \fn void QAbstractAxis::shadesVisibleChanged(bool)
267 \fn void QAbstractAxis::shadesVisibleChanged(bool)
232 Emitted if the visibility of the axis shades is changed to \a visible.
268 Emitted if the visibility of the axis shades is changed to \a visible.
233 */
269 */
234 /*!
270 /*!
235 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
271 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
236 Emitted if the visibility of the axis shades is changed to \a visible.
272 Emitted if the visibility of the axis shades is changed to \a visible.
237 */
273 */
238
274
239 /*!
275 /*!
240 \fn void QAbstractAxis::shadesColorChanged(QColor color)
276 \fn void QAbstractAxis::shadesColorChanged(QColor color)
241 Emitted if the \a color of the axis shades is changed.
277 Emitted if the \a color of the axis shades is changed.
242 */
278 */
243 /*!
279 /*!
244 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
280 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
245 Emitted if the \a color of the axis shades is changed.
281 Emitted if the \a color of the axis shades is changed.
246 */
282 */
247
283
248 /*!
284 /*!
249 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
285 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
250 Emitted if the border \a color of the axis shades is changed.
286 Emitted if the border \a color of the axis shades is changed.
251 */
287 */
252 /*!
288 /*!
253 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
289 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
254 Emitted if the border \a color of the axis shades is changed.
290 Emitted if the border \a color of the axis shades is changed.
255 */
291 */
256
292
257 /*!
293 /*!
258 \internal
294 \internal
259 Constructs new axis object which is a child of \a parent. Ownership is taken by
295 Constructs new axis object which is a child of \a parent. Ownership is taken by
260 QChart when axis added.
296 QChart when axis added.
261 */
297 */
262
298
263 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
299 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
264 : QObject(parent),
300 : QObject(parent),
265 d_ptr(&d)
301 d_ptr(&d)
266 {
302 {
267 }
303 }
268
304
269 /*!
305 /*!
270 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
306 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
271 */
307 */
272
308
273 QAbstractAxis::~QAbstractAxis()
309 QAbstractAxis::~QAbstractAxis()
274 {
310 {
275 if (d_ptr->m_dataset)
311 if (d_ptr->m_dataset)
276 qFatal("Still binded axis detected !");
312 qFatal("Still binded axis detected !");
277 }
313 }
278
314
279 /*!
315 /*!
280 Sets \a pen used to draw axis line and ticks.
316 Sets \a pen used to draw axis line and ticks.
281 */
317 */
282 void QAbstractAxis::setLinePen(const QPen &pen)
318 void QAbstractAxis::setLinePen(const QPen &pen)
283 {
319 {
284 if (d_ptr->m_axisPen != pen) {
320 if (d_ptr->m_axisPen != pen) {
285 d_ptr->m_axisPen = pen;
321 d_ptr->m_axisPen = pen;
286 d_ptr->emitUpdated();
322 d_ptr->emitUpdated();
287 }
323 }
288 }
324 }
289
325
290 /*!
326 /*!
291 Returns pen used to draw axis and ticks.
327 Returns pen used to draw axis and ticks.
292 */
328 */
293 QPen QAbstractAxis::linePen() const
329 QPen QAbstractAxis::linePen() const
294 {
330 {
295 return d_ptr->m_axisPen;
331 return d_ptr->m_axisPen;
296 }
332 }
297
333
298 void QAbstractAxis::setLinePenColor(QColor color)
334 void QAbstractAxis::setLinePenColor(QColor color)
299 {
335 {
300 QPen p = d_ptr->m_axisPen;
336 QPen p = d_ptr->m_axisPen;
301 if (p.color() != color) {
337 if (p.color() != color) {
302 p.setColor(color);
338 p.setColor(color);
303 setLinePen(p);
339 setLinePen(p);
304 emit colorChanged(color);
340 emit colorChanged(color);
305 }
341 }
306 }
342 }
307
343
308 QColor QAbstractAxis::linePenColor() const
344 QColor QAbstractAxis::linePenColor() const
309 {
345 {
310 return d_ptr->m_axisPen.color();
346 return d_ptr->m_axisPen.color();
311 }
347 }
312
348
313 /*!
349 /*!
314 Sets if axis and ticks are \a visible.
350 Sets if axis and ticks are \a visible.
315 */
351 */
316 void QAbstractAxis::setLineVisible(bool visible)
352 void QAbstractAxis::setLineVisible(bool visible)
317 {
353 {
318 if (d_ptr->m_arrowVisible != visible) {
354 if (d_ptr->m_arrowVisible != visible) {
319 d_ptr->m_arrowVisible = visible;
355 d_ptr->m_arrowVisible = visible;
320 d_ptr->emitUpdated();
356 d_ptr->emitUpdated();
321 emit lineVisibleChanged(visible);
357 emit lineVisibleChanged(visible);
322 }
358 }
323 }
359 }
324
360
325 bool QAbstractAxis::isLineVisible() const
361 bool QAbstractAxis::isLineVisible() const
326 {
362 {
327 return d_ptr->m_arrowVisible;
363 return d_ptr->m_arrowVisible;
328 }
364 }
329
365
330 void QAbstractAxis::setGridLineVisible(bool visible)
366 void QAbstractAxis::setGridLineVisible(bool visible)
331 {
367 {
332 if (d_ptr->m_gridLineVisible != visible) {
368 if (d_ptr->m_gridLineVisible != visible) {
333 d_ptr->m_gridLineVisible = visible;
369 d_ptr->m_gridLineVisible = visible;
334 d_ptr->emitUpdated();
370 d_ptr->emitUpdated();
335 emit gridVisibleChanged(visible);
371 emit gridVisibleChanged(visible);
336 }
372 }
337 }
373 }
338
374
339 bool QAbstractAxis::isGridLineVisible() const
375 bool QAbstractAxis::isGridLineVisible() const
340 {
376 {
341 return d_ptr->m_gridLineVisible;
377 return d_ptr->m_gridLineVisible;
342 }
378 }
343
379
344 /*!
380 /*!
345 Sets \a pen used to draw grid line.
381 Sets \a pen used to draw grid line.
346 */
382 */
347 void QAbstractAxis::setGridLinePen(const QPen &pen)
383 void QAbstractAxis::setGridLinePen(const QPen &pen)
348 {
384 {
349 if (d_ptr->m_gridLinePen != pen) {
385 if (d_ptr->m_gridLinePen != pen) {
350 d_ptr->m_gridLinePen = pen;
386 d_ptr->m_gridLinePen = pen;
351 d_ptr->emitUpdated();
387 d_ptr->emitUpdated();
352 }
388 }
353 }
389 }
354
390
355 /*!
391 /*!
356 Returns pen used to draw grid.
392 Returns pen used to draw grid.
357 */
393 */
358 QPen QAbstractAxis::gridLinePen() const
394 QPen QAbstractAxis::gridLinePen() const
359 {
395 {
360 return d_ptr->m_gridLinePen;
396 return d_ptr->m_gridLinePen;
361 }
397 }
362
398
363 void QAbstractAxis::setLabelsVisible(bool visible)
399 void QAbstractAxis::setLabelsVisible(bool visible)
364 {
400 {
365 if (d_ptr->m_labelsVisible != visible) {
401 if (d_ptr->m_labelsVisible != visible) {
366 d_ptr->m_labelsVisible = visible;
402 d_ptr->m_labelsVisible = visible;
367 d_ptr->emitUpdated();
403 d_ptr->emitUpdated();
368 emit labelsVisibleChanged(visible);
404 emit labelsVisibleChanged(visible);
369 }
405 }
370 }
406 }
371
407
372 bool QAbstractAxis::labelsVisible() const
408 bool QAbstractAxis::labelsVisible() const
373 {
409 {
374 return d_ptr->m_labelsVisible;
410 return d_ptr->m_labelsVisible;
375 }
411 }
376
412
377 /*!
413 /*!
378 Sets \a pen used to draw labels.
414 Sets \a pen used to draw labels.
379 */
415 */
380 void QAbstractAxis::setLabelsPen(const QPen &pen)
416 void QAbstractAxis::setLabelsPen(const QPen &pen)
381 {
417 {
382 if (d_ptr->m_labelsPen != pen) {
418 if (d_ptr->m_labelsPen != pen) {
383 d_ptr->m_labelsPen = pen;
419 d_ptr->m_labelsPen = pen;
384 d_ptr->emitUpdated();
420 d_ptr->emitUpdated();
385 }
421 }
386 }
422 }
387
423
388 /*!
424 /*!
389 Returns the pen used to labels.
425 Returns the pen used to labels.
390 */
426 */
391 QPen QAbstractAxis::labelsPen() const
427 QPen QAbstractAxis::labelsPen() const
392 {
428 {
393 return d_ptr->m_labelsPen;
429 return d_ptr->m_labelsPen;
394 }
430 }
395
431
396 /*!
432 /*!
397 Sets \a brush used to draw labels.
433 Sets \a brush used to draw labels.
398 */
434 */
399 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
435 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
400 {
436 {
401 if (d_ptr->m_labelsBrush != brush) {
437 if (d_ptr->m_labelsBrush != brush) {
402 d_ptr->m_labelsBrush = brush;
438 d_ptr->m_labelsBrush = brush;
403 d_ptr->emitUpdated();
439 d_ptr->emitUpdated();
404 }
440 }
405 }
441 }
406
442
407 /*!
443 /*!
408 Returns brush used to draw labels.
444 Returns brush used to draw labels.
409 */
445 */
410 QBrush QAbstractAxis::labelsBrush() const
446 QBrush QAbstractAxis::labelsBrush() const
411 {
447 {
412 return d_ptr->m_labelsBrush;
448 return d_ptr->m_labelsBrush;
413 }
449 }
414
450
415 /*!
451 /*!
416 Sets \a font used to draw labels.
452 Sets \a font used to draw labels.
417 */
453 */
418 void QAbstractAxis::setLabelsFont(const QFont &font)
454 void QAbstractAxis::setLabelsFont(const QFont &font)
419 {
455 {
420 if (d_ptr->m_labelsFont != font) {
456 if (d_ptr->m_labelsFont != font) {
421 d_ptr->m_labelsFont = font;
457 d_ptr->m_labelsFont = font;
422 d_ptr->emitUpdated();
458 d_ptr->emitUpdated();
423 }
459 }
424 }
460 }
425
461
426 /*!
462 /*!
427 Returns font used to draw labels.
463 Returns font used to draw labels.
428 */
464 */
429 QFont QAbstractAxis::labelsFont() const
465 QFont QAbstractAxis::labelsFont() const
430 {
466 {
431 return d_ptr->m_labelsFont;
467 return d_ptr->m_labelsFont;
432 }
468 }
433
469
434 void QAbstractAxis::setLabelsAngle(int angle)
470 void QAbstractAxis::setLabelsAngle(int angle)
435 {
471 {
436 if (d_ptr->m_labelsAngle != angle) {
472 if (d_ptr->m_labelsAngle != angle) {
437 d_ptr->m_labelsAngle = angle;
473 d_ptr->m_labelsAngle = angle;
438 d_ptr->emitUpdated();
474 d_ptr->emitUpdated();
439 }
475 }
440 }
476 }
441
477
442 int QAbstractAxis::labelsAngle() const
478 int QAbstractAxis::labelsAngle() const
443 {
479 {
444 return d_ptr->m_labelsAngle;
480 return d_ptr->m_labelsAngle;
445 }
481 }
446
482
447 void QAbstractAxis::setLabelsColor(QColor color)
483 void QAbstractAxis::setLabelsColor(QColor color)
448 {
484 {
449 QBrush b = d_ptr->m_labelsBrush;
485 QBrush b = d_ptr->m_labelsBrush;
450 if (b.color() != color) {
486 if (b.color() != color) {
451 b.setColor(color);
487 b.setColor(color);
452 setLabelsBrush(b);
488 setLabelsBrush(b);
453 emit labelsColorChanged(color);
489 emit labelsColorChanged(color);
454 }
490 }
455 }
491 }
456
492
457 QColor QAbstractAxis::labelsColor() const
493 QColor QAbstractAxis::labelsColor() const
458 {
494 {
459 return d_ptr->m_labelsBrush.color();
495 return d_ptr->m_labelsBrush.color();
460 }
496 }
461
497
462 void QAbstractAxis::setTitleVisible(bool visible)
498 void QAbstractAxis::setTitleVisible(bool visible)
463 {
499 {
464 if (d_ptr->m_titleVisible != visible) {
500 if (d_ptr->m_titleVisible != visible) {
465 d_ptr->m_titleVisible = visible;
501 d_ptr->m_titleVisible = visible;
466 d_ptr->emitUpdated();
502 d_ptr->emitUpdated();
467 }
503 }
468 }
504 }
469
505
470 bool QAbstractAxis::titleVisible() const
506 bool QAbstractAxis::titleVisible() const
471 {
507 {
472 return d_ptr->m_titleVisible;
508 return d_ptr->m_titleVisible;
473 }
509 }
474
510
475 /*!
511 /*!
476 Sets \a pen used to draw title.
512 Sets \a pen used to draw title.
477 */
513 */
478 void QAbstractAxis::setTitlePen(const QPen &pen)
514 void QAbstractAxis::setTitlePen(const QPen &pen)
479 {
515 {
480 if (d_ptr->m_titlePen != pen) {
516 if (d_ptr->m_titlePen != pen) {
481 d_ptr->m_titlePen = pen;
517 d_ptr->m_titlePen = pen;
482 d_ptr->emitUpdated();
518 d_ptr->emitUpdated();
483 }
519 }
484 }
520 }
485
521
486 /*!
522 /*!
487 Returns the pen used to title.
523 Returns the pen used to title.
488 */
524 */
489 QPen QAbstractAxis::titlePen() const
525 QPen QAbstractAxis::titlePen() const
490 {
526 {
491 return d_ptr->m_titlePen;
527 return d_ptr->m_titlePen;
492 }
528 }
493
529
494 /*!
530 /*!
495 Sets \a brush used to draw title.
531 Sets \a brush used to draw title.
496 */
532 */
497 void QAbstractAxis::setTitleBrush(const QBrush &brush)
533 void QAbstractAxis::setTitleBrush(const QBrush &brush)
498 {
534 {
499 if (d_ptr->m_titleBrush != brush) {
535 if (d_ptr->m_titleBrush != brush) {
500 d_ptr->m_titleBrush = brush;
536 d_ptr->m_titleBrush = brush;
501 d_ptr->emitUpdated();
537 d_ptr->emitUpdated();
502 }
538 }
503 }
539 }
504
540
505 /*!
541 /*!
506 Returns brush used to draw title.
542 Returns brush used to draw title.
507 */
543 */
508 QBrush QAbstractAxis::titleBrush() const
544 QBrush QAbstractAxis::titleBrush() const
509 {
545 {
510 return d_ptr->m_titleBrush;
546 return d_ptr->m_titleBrush;
511 }
547 }
512
548
513 /*!
549 /*!
514 Sets \a font used to draw title.
550 Sets \a font used to draw title.
515 */
551 */
516 void QAbstractAxis::setTitleFont(const QFont &font)
552 void QAbstractAxis::setTitleFont(const QFont &font)
517 {
553 {
518 if (d_ptr->m_titleFont != font) {
554 if (d_ptr->m_titleFont != font) {
519 d_ptr->m_titleFont = font;
555 d_ptr->m_titleFont = font;
520 d_ptr->emitUpdated();
556 d_ptr->emitUpdated();
521 }
557 }
522 }
558 }
523
559
524 /*!
560 /*!
525 Returns font used to draw title.
561 Returns font used to draw title.
526 */
562 */
527 QFont QAbstractAxis::titleFont() const
563 QFont QAbstractAxis::titleFont() const
528 {
564 {
529 return d_ptr->m_titleFont;
565 return d_ptr->m_titleFont;
530 }
566 }
531
567
532 void QAbstractAxis::setTitle(const QString &title)
568 void QAbstractAxis::setTitle(const QString &title)
533 {
569 {
534 if (d_ptr->m_title != title) {
570 if (d_ptr->m_title != title) {
535 d_ptr->m_title = title;
571 d_ptr->m_title = title;
536 d_ptr->emitUpdated();
572 d_ptr->emitUpdated();
537 }
573 }
538 }
574 }
539
575
540 QString QAbstractAxis::title() const
576 QString QAbstractAxis::title() const
541 {
577 {
542 return d_ptr->m_title;
578 return d_ptr->m_title;
543 }
579 }
544
580
545
581
546 void QAbstractAxis::setShadesVisible(bool visible)
582 void QAbstractAxis::setShadesVisible(bool visible)
547 {
583 {
548 if (d_ptr->m_shadesVisible != visible) {
584 if (d_ptr->m_shadesVisible != visible) {
549 d_ptr->m_shadesVisible = visible;
585 d_ptr->m_shadesVisible = visible;
550 d_ptr->emitUpdated();
586 d_ptr->emitUpdated();
551 emit shadesVisibleChanged(visible);
587 emit shadesVisibleChanged(visible);
552 }
588 }
553 }
589 }
554
590
555 bool QAbstractAxis::shadesVisible() const
591 bool QAbstractAxis::shadesVisible() const
556 {
592 {
557 return d_ptr->m_shadesVisible;
593 return d_ptr->m_shadesVisible;
558 }
594 }
559
595
560 /*!
596 /*!
561 Sets \a pen used to draw shades.
597 Sets \a pen used to draw shades.
562 */
598 */
563 void QAbstractAxis::setShadesPen(const QPen &pen)
599 void QAbstractAxis::setShadesPen(const QPen &pen)
564 {
600 {
565 if (d_ptr->m_shadesPen != pen) {
601 if (d_ptr->m_shadesPen != pen) {
566 d_ptr->m_shadesPen = pen;
602 d_ptr->m_shadesPen = pen;
567 d_ptr->emitUpdated();
603 d_ptr->emitUpdated();
568 }
604 }
569 }
605 }
570
606
571 /*!
607 /*!
572 Returns pen used to draw shades.
608 Returns pen used to draw shades.
573 */
609 */
574 QPen QAbstractAxis::shadesPen() const
610 QPen QAbstractAxis::shadesPen() const
575 {
611 {
576 return d_ptr->m_shadesPen;
612 return d_ptr->m_shadesPen;
577 }
613 }
578
614
579 /*!
615 /*!
580 Sets \a brush used to draw shades.
616 Sets \a brush used to draw shades.
581 */
617 */
582 void QAbstractAxis::setShadesBrush(const QBrush &brush)
618 void QAbstractAxis::setShadesBrush(const QBrush &brush)
583 {
619 {
584 if (d_ptr->m_shadesBrush != brush) {
620 if (d_ptr->m_shadesBrush != brush) {
585 d_ptr->m_shadesBrush = brush;
621 d_ptr->m_shadesBrush = brush;
586 d_ptr->emitUpdated();
622 d_ptr->emitUpdated();
587 emit shadesColorChanged(brush.color());
623 emit shadesColorChanged(brush.color());
588 }
624 }
589 }
625 }
590
626
591 /*!
627 /*!
592 Returns brush used to draw shades.
628 Returns brush used to draw shades.
593 */
629 */
594 QBrush QAbstractAxis::shadesBrush() const
630 QBrush QAbstractAxis::shadesBrush() const
595 {
631 {
596 return d_ptr->m_shadesBrush;
632 return d_ptr->m_shadesBrush;
597 }
633 }
598
634
599 void QAbstractAxis::setShadesColor(QColor color)
635 void QAbstractAxis::setShadesColor(QColor color)
600 {
636 {
601 QBrush b = d_ptr->m_shadesBrush;
637 QBrush b = d_ptr->m_shadesBrush;
602 b.setColor(color);
638 b.setColor(color);
603 setShadesBrush(b);
639 setShadesBrush(b);
604 }
640 }
605
641
606 QColor QAbstractAxis::shadesColor() const
642 QColor QAbstractAxis::shadesColor() const
607 {
643 {
608 return d_ptr->m_shadesBrush.color();
644 return d_ptr->m_shadesBrush.color();
609 }
645 }
610
646
611 void QAbstractAxis::setShadesBorderColor(QColor color)
647 void QAbstractAxis::setShadesBorderColor(QColor color)
612 {
648 {
613 QPen p = d_ptr->m_shadesPen;
649 QPen p = d_ptr->m_shadesPen;
614 p.setColor(color);
650 p.setColor(color);
615 setShadesPen(p);
651 setShadesPen(p);
616 }
652 }
617
653
618 QColor QAbstractAxis::shadesBorderColor() const
654 QColor QAbstractAxis::shadesBorderColor() const
619 {
655 {
620 return d_ptr->m_shadesPen.color();
656 return d_ptr->m_shadesPen.color();
621 }
657 }
622
658
623
659
624 bool QAbstractAxis::isVisible() const
660 bool QAbstractAxis::isVisible() const
625 {
661 {
626 return d_ptr->m_visible;
662 return d_ptr->m_visible;
627 }
663 }
628
664
629 /*!
665 /*!
630 Sets axis, shades, labels and grid lines to be visible.
666 Sets axis, shades, labels and grid lines to be visible.
631 */
667 */
632 void QAbstractAxis::setVisible(bool visible)
668 void QAbstractAxis::setVisible(bool visible)
633 {
669 {
634 if (d_ptr->m_visible != visible) {
670 if (d_ptr->m_visible != visible) {
635 d_ptr->m_visible = visible;
671 d_ptr->m_visible = visible;
636 d_ptr->emitUpdated();
672 d_ptr->emitUpdated();
637 emit visibleChanged(visible);
673 emit visibleChanged(visible);
638 }
674 }
639 }
675 }
640
676
641
677
642 /*!
678 /*!
643 Sets axis, shades, labels and grid lines to be visible.
679 Sets axis, shades, labels and grid lines to be visible.
644 */
680 */
645 void QAbstractAxis::show()
681 void QAbstractAxis::show()
646 {
682 {
647 setVisible(true);
683 setVisible(true);
648 }
684 }
649
685
650 /*!
686 /*!
651 Sets axis, shades, labels and grid lines to not be visible.
687 Sets axis, shades, labels and grid lines to not be visible.
652 */
688 */
653 void QAbstractAxis::hide()
689 void QAbstractAxis::hide()
654 {
690 {
655 setVisible(false);
691 setVisible(false);
656 }
692 }
657
693
658 /*!
694 /*!
659 Sets the minimum value shown on the axis.
695 Sets the minimum value shown on the axis.
660 Depending on the actual axis type the \a min parameter is converted to appropriate type.
696 Depending on the actual axis type the \a min parameter is converted to appropriate type.
661 If the conversion is impossible then the function call does nothing
697 If the conversion is impossible then the function call does nothing
662 */
698 */
663 void QAbstractAxis::setMin(const QVariant &min)
699 void QAbstractAxis::setMin(const QVariant &min)
664 {
700 {
665 d_ptr->setMin(min);
701 d_ptr->setMin(min);
666 }
702 }
667
703
668 /*!
704 /*!
669 Sets the maximum value shown on the axis.
705 Sets the maximum value shown on the axis.
670 Depending on the actual axis type the \a max parameter is converted to appropriate type.
706 Depending on the actual axis type the \a max parameter is converted to appropriate type.
671 If the conversion is impossible then the function call does nothing
707 If the conversion is impossible then the function call does nothing
672 */
708 */
673 void QAbstractAxis::setMax(const QVariant &max)
709 void QAbstractAxis::setMax(const QVariant &max)
674 {
710 {
675 d_ptr->setMax(max);
711 d_ptr->setMax(max);
676 }
712 }
677
713
678 /*!
714 /*!
679 Sets the range shown on the axis.
715 Sets the range shown on the axis.
680 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
716 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
681 If the conversion is impossible then the function call does nothing.
717 If the conversion is impossible then the function call does nothing.
682 */
718 */
683 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
719 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
684 {
720 {
685 d_ptr->setRange(min, max);
721 d_ptr->setRange(min, max);
686 }
722 }
687
723
688
724
689 /*!
725 /*!
690 Returns the orientation in which the axis is being used (Vertical or Horizontal)
726 Returns the orientation in which the axis is being used (Vertical or Horizontal)
691 */
727 */
692 Qt::Orientation QAbstractAxis::orientation() const
728 Qt::Orientation QAbstractAxis::orientation() const
693 {
729 {
694 return d_ptr->m_orientation;
730 return d_ptr->m_orientation;
695 }
731 }
696
732
697 Qt::Alignment QAbstractAxis::alignment() const
733 Qt::Alignment QAbstractAxis::alignment() const
698 {
734 {
699 return d_ptr->m_alignment;
735 return d_ptr->m_alignment;
700 }
736 }
701
737
702 void QAbstractAxis::setAlignment(Qt::Alignment alignment)
738 void QAbstractAxis::setAlignment(Qt::Alignment alignment)
703 {
739 {
704 d_ptr->m_alignment = alignment;
740 d_ptr->m_alignment = alignment;
705 }
741 }
706
742
707 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
743 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
708
744
709 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
745 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
710 : q_ptr(q),
746 : q_ptr(q),
711 m_orientation(Qt::Orientation(0)),
747 m_orientation(Qt::Orientation(0)),
712 m_alignment(0),
748 m_alignment(0),
713 m_dataset(0),
749 m_dataset(0),
714 m_visible(true),
750 m_visible(true),
715 m_arrowVisible(true),
751 m_arrowVisible(true),
716 m_gridLineVisible(true),
752 m_gridLineVisible(true),
717 m_labelsVisible(true),
753 m_labelsVisible(true),
718 m_labelsAngle(0),
754 m_labelsAngle(0),
719 m_shadesVisible(false),
755 m_shadesVisible(false),
720 m_shadesBrush(Qt::SolidPattern),
756 m_shadesBrush(Qt::SolidPattern),
721 m_shadesOpacity(1.0),
757 m_shadesOpacity(1.0),
722 m_dirty(false)
758 m_dirty(false)
723 {
759 {
724
760
725 }
761 }
726
762
727 QAbstractAxisPrivate::~QAbstractAxisPrivate()
763 QAbstractAxisPrivate::~QAbstractAxisPrivate()
728 {
764 {
729
765
730 }
766 }
731
767
732 void QAbstractAxisPrivate::emitUpdated()
768 void QAbstractAxisPrivate::emitUpdated()
733 {
769 {
734 if (!m_dirty) {
770 if (!m_dirty) {
735 m_dirty = true;
771 m_dirty = true;
736 emit updated();
772 emit updated();
737 }
773 }
738 }
774 }
739
775
740 void QAbstractAxisPrivate::setDirty(bool dirty)
776 void QAbstractAxisPrivate::setDirty(bool dirty)
741 {
777 {
742 m_dirty = dirty;
778 m_dirty = dirty;
743 }
779 }
744
780
745 void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation)
781 void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation)
746 {
782 {
747 m_orientation = orientation;
783 m_orientation = orientation;
748 if (m_orientation == Qt::Horizontal && !m_alignment)
784 if (m_orientation == Qt::Horizontal && !m_alignment)
749 m_alignment = Qt::AlignBottom;
785 m_alignment = Qt::AlignBottom;
750 else if (m_orientation == Qt::Vertical && !m_alignment)
786 else if (m_orientation == Qt::Vertical && !m_alignment)
751 m_alignment = Qt::AlignLeft;
787 m_alignment = Qt::AlignLeft;
752 }
788 }
753
789
754
790
755 #include "moc_qabstractaxis.cpp"
791 #include "moc_qabstractaxis.cpp"
756 #include "moc_qabstractaxis_p.cpp"
792 #include "moc_qabstractaxis_p.cpp"
757
793
758 QTCOMMERCIALCHART_END_NAMESPACE
794 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,125 +1,125
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qarealegendmarker.h"
21 #include "qarealegendmarker.h"
22 #include "qarealegendmarker_p.h"
22 #include "qarealegendmarker_p.h"
23 #include "qareaseries_p.h"
23 #include "qareaseries_p.h"
24 #include <QAreaSeries>
24 #include <QAreaSeries>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QAreaLegendMarker
29 \class QAreaLegendMarker
30 \brief QAreaLegendMarker object
30 \brief QAreaLegendMarker object
31 \mainclass
31 \mainclass
32
32
33 QAreaLegendMarker is related to QAreaSeries. One QAreaSeries results in one marker.
33 QAreaLegendMarker is related to QAreaSeries. One QAreaSeries results in one marker.
34
34
35 \sa QLegend QAreaSeries
35 \sa QLegend QAreaSeries
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn virtual LegendMarkerType QAreaLegendMarker::type()
39 \fn virtual LegendMarkerType QAreaLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypeArea
40 Returns QLegendMarker::LegendMarkerTypeArea
41 */
41 */
42
42
43 /*!
43 /*!
44 Constructor
44 \internal
45 */
45 */
46 QAreaLegendMarker::QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent) :
46 QAreaLegendMarker::QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent) :
47 QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent)
47 QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent)
48 {
48 {
49 d_ptr->updated();
49 d_ptr->updated();
50 }
50 }
51
51
52 /*!
52 /*!
53 Destructor
53 Destructor
54 */
54 */
55 QAreaLegendMarker::~QAreaLegendMarker()
55 QAreaLegendMarker::~QAreaLegendMarker()
56 {
56 {
57 }
57 }
58
58
59 /*!
59 /*!
60 \internal
60 \internal
61 */
61 */
62 QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) :
62 QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) :
63 QLegendMarker(d, parent)
63 QLegendMarker(d, parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns related series of marker
68 Returns related series of marker
69 */
69 */
70 QAreaSeries* QAreaLegendMarker::series()
70 QAreaSeries* QAreaLegendMarker::series()
71 {
71 {
72 Q_D(QAreaLegendMarker);
72 Q_D(QAreaLegendMarker);
73 return d->m_series;
73 return d->m_series;
74 }
74 }
75
75
76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77
77
78 QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) :
78 QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) :
79 QLegendMarkerPrivate(q,legend),
79 QLegendMarkerPrivate(q,legend),
80 q_ptr(q),
80 q_ptr(q),
81 m_series(series)
81 m_series(series)
82 {
82 {
83 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
83 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
84 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
84 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
85 }
85 }
86
86
87 QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
87 QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
88 {
88 {
89 }
89 }
90
90
91 QAreaSeries* QAreaLegendMarkerPrivate::series()
91 QAreaSeries* QAreaLegendMarkerPrivate::series()
92 {
92 {
93 return m_series;
93 return m_series;
94 }
94 }
95
95
96 QObject* QAreaLegendMarkerPrivate::relatedObject()
96 QObject* QAreaLegendMarkerPrivate::relatedObject()
97 {
97 {
98 return m_series;
98 return m_series;
99 }
99 }
100
100
101 void QAreaLegendMarkerPrivate::updated()
101 void QAreaLegendMarkerPrivate::updated()
102 {
102 {
103 bool labelChanged = false;
103 bool labelChanged = false;
104 bool brushChanged = false;
104 bool brushChanged = false;
105
105
106 if (m_item->brush() != m_series->brush()) {
106 if (m_item->brush() != m_series->brush()) {
107 m_item->setBrush(m_series->brush());
107 m_item->setBrush(m_series->brush());
108 brushChanged = true;
108 brushChanged = true;
109 }
109 }
110 if (m_item->label() != m_series->name()) {
110 if (m_item->label() != m_series->name()) {
111 m_item->setLabel(m_series->name());
111 m_item->setLabel(m_series->name());
112 labelChanged = true;
112 labelChanged = true;
113 }
113 }
114 invalidateLegend();
114 invalidateLegend();
115
115
116 if (labelChanged)
116 if (labelChanged)
117 emit q_ptr->labelChanged();
117 emit q_ptr->labelChanged();
118 if (brushChanged)
118 if (brushChanged)
119 emit q_ptr->brushChanged();
119 emit q_ptr->brushChanged();
120 }
120 }
121
121
122 #include "moc_qarealegendmarker.cpp"
122 #include "moc_qarealegendmarker.cpp"
123 #include "moc_qarealegendmarker_p.cpp"
123 #include "moc_qarealegendmarker_p.cpp"
124
124
125 QTCOMMERCIALCHART_END_NAMESPACE
125 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,144 +1,145
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarlegendmarker.h"
21 #include "qbarlegendmarker.h"
22 #include "qbarlegendmarker_p.h"
22 #include "qbarlegendmarker_p.h"
23 #include <QAbstractBarSeries>
23 #include <QAbstractBarSeries>
24 #include <QBarSet>
24 #include <QBarSet>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QBarLegendMarker
29 \class QBarLegendMarker
30 \brief QBarLegendMarker object
30 \brief QBarLegendMarker object
31 \mainclass
31 \mainclass
32
32
33 QBarLegendMarker is related to QAbstractBarSeries derived classes. With bar series, each marker is related to one QBarSet.
33 QBarLegendMarker is related to QAbstractBarSeries derived classes. With bar series, each marker is related to one QBarSet.
34
34
35 \sa QLegend QAbstractBarSeries QBarSet
35 \sa QLegend QAbstractBarSeries QBarSet
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn virtual LegendMarkerType QBarLegendMarker::type()
39 \fn virtual LegendMarkerType QBarLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypeBar
40 Returns QLegendMarker::LegendMarkerTypeBar
41 */
41 */
42
42
43 /*!
43 /*!
44 \internal
44 Constructor
45 Constructor
45 */
46 */
46 QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent) :
47 QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent) :
47 QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent)
48 QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent)
48 {
49 {
49 d_ptr->updated();
50 d_ptr->updated();
50 }
51 }
51
52
52 /*!
53 /*!
53 Desturctor
54 Desturctor
54 */
55 */
55 QBarLegendMarker::~QBarLegendMarker()
56 QBarLegendMarker::~QBarLegendMarker()
56 {
57 {
57 }
58 }
58
59
59 /*!
60 /*!
60 \internal
61 \internal
61 */
62 */
62 QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) :
63 QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) :
63 QLegendMarker(d, parent)
64 QLegendMarker(d, parent)
64 {
65 {
65 }
66 }
66
67
67 /*!
68 /*!
68 Returns the related series of marker
69 Returns the related series of marker
69 */
70 */
70 QAbstractBarSeries *QBarLegendMarker::series()
71 QAbstractBarSeries *QBarLegendMarker::series()
71 {
72 {
72 Q_D(QBarLegendMarker);
73 Q_D(QBarLegendMarker);
73 return d->m_series;
74 return d->m_series;
74 }
75 }
75
76
76 /*!
77 /*!
77 Returns the related barset of marker
78 Returns the related barset of marker
78 */
79 */
79 QBarSet* QBarLegendMarker::barset()
80 QBarSet* QBarLegendMarker::barset()
80 {
81 {
81 Q_D(QBarLegendMarker);
82 Q_D(QBarLegendMarker);
82 return d->m_barset;
83 return d->m_barset;
83 }
84 }
84
85
85 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86
87
87 QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) :
88 QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) :
88 QLegendMarkerPrivate(q,legend),
89 QLegendMarkerPrivate(q,legend),
89 q_ptr(q),
90 q_ptr(q),
90 m_series(series),
91 m_series(series),
91 m_barset(barset)
92 m_barset(barset)
92 {
93 {
93 QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
94 QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
94 QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
95 QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
95 QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
96 QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
96 }
97 }
97
98
98 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
99 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
99 {
100 {
100 }
101 }
101
102
102 QAbstractBarSeries* QBarLegendMarkerPrivate::series()
103 QAbstractBarSeries* QBarLegendMarkerPrivate::series()
103 {
104 {
104 return m_series;
105 return m_series;
105 }
106 }
106
107
107 QObject* QBarLegendMarkerPrivate::relatedObject()
108 QObject* QBarLegendMarkerPrivate::relatedObject()
108 {
109 {
109 return m_barset;
110 return m_barset;
110 }
111 }
111
112
112 void QBarLegendMarkerPrivate::updated()
113 void QBarLegendMarkerPrivate::updated()
113 {
114 {
114 bool labelChanged = false;
115 bool labelChanged = false;
115 bool brushChanged = false;
116 bool brushChanged = false;
116 bool penChanged = false;
117 bool penChanged = false;
117
118
118 if (m_item->pen() != m_barset->pen()) {
119 if (m_item->pen() != m_barset->pen()) {
119 m_item->setPen(m_barset->pen());
120 m_item->setPen(m_barset->pen());
120 penChanged = true;
121 penChanged = true;
121 }
122 }
122 if (m_item->brush() != m_barset->brush()) {
123 if (m_item->brush() != m_barset->brush()) {
123 m_item->setBrush(m_barset->brush());
124 m_item->setBrush(m_barset->brush());
124 brushChanged = true;
125 brushChanged = true;
125 }
126 }
126 if (m_item->label() != m_barset->label()) {
127 if (m_item->label() != m_barset->label()) {
127 m_item->setLabel(m_barset->label());
128 m_item->setLabel(m_barset->label());
128 labelChanged = true;
129 labelChanged = true;
129 }
130 }
130 invalidateLegend();
131 invalidateLegend();
131
132
132 if (labelChanged)
133 if (labelChanged)
133 emit q_ptr->labelChanged();
134 emit q_ptr->labelChanged();
134 if (brushChanged)
135 if (brushChanged)
135 emit q_ptr->brushChanged();
136 emit q_ptr->brushChanged();
136 if (penChanged)
137 if (penChanged)
137 emit q_ptr->penChanged();
138 emit q_ptr->penChanged();
138 }
139 }
139
140
140 #include "moc_qbarlegendmarker.cpp"
141 #include "moc_qbarlegendmarker.cpp"
141 #include "moc_qbarlegendmarker_p.cpp"
142 #include "moc_qbarlegendmarker_p.cpp"
142
143
143 QTCOMMERCIALCHART_END_NAMESPACE
144 QTCOMMERCIALCHART_END_NAMESPACE
144
145
@@ -1,597 +1,593
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qlegend.h"
21 #include "qlegend.h"
22 #include "qlegend_p.h"
22 #include "qlegend_p.h"
23 #include "qabstractseries.h"
23 #include "qabstractseries.h"
24 #include "qabstractseries_p.h"
24 #include "qabstractseries_p.h"
25 #include "qchart_p.h"
25 #include "qchart_p.h"
26 #include "legendlayout_p.h"
26 #include "legendlayout_p.h"
27 #include "chartpresenter_p.h"
27 #include "chartpresenter_p.h"
28 #include "chartlayout_p.h"
28 #include "chartlayout_p.h"
29 #include "qlegendmarker.h"
29 #include "qlegendmarker.h"
30 #include "qlegendmarker_p.h"
30 #include "qlegendmarker_p.h"
31 #include "legendmarkeritem_p.h"
31 #include "legendmarkeritem_p.h"
32 #include <QPainter>
32 #include <QPainter>
33 #include <QPen>
33 #include <QPen>
34 #include <QGraphicsItemGroup>
34 #include <QGraphicsItemGroup>
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 /*!
38 /*!
39 \class QLegend
39 \class QLegend
40 \brief Legend object
40 \brief Legend object
41 \mainclass
41 \mainclass
42
42
43 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
43 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
44 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
44 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
45 handle the drawing manually.
45 handle the drawing manually.
46 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
46 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
47
47
48 \image examples_percentbarchart_legend.png
48 \image examples_percentbarchart_legend.png
49
49
50 \sa QChart
50 \sa QChart
51 */
51 */
52 /*!
52 /*!
53 \qmlclass Legend QLegend
53 \qmlclass Legend QLegend
54 \brief Legend is part of QtCommercial Chart QML API.
54 \brief Legend is part of QtCommercial Chart QML API.
55
55
56 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
56 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
57 series have been changed. Legend is used via ChartView class. For example:
57 series have been changed. Legend is used via ChartView class. For example:
58 \code
58 \code
59 ChartView {
59 ChartView {
60 legend.visible: true
60 legend.visible: true
61 legend.alignment: Qt.AlignBottom
61 legend.alignment: Qt.AlignBottom
62 // Add a few series...
62 // Add a few series...
63 }
63 }
64 \endcode
64 \endcode
65
65
66 \image examples_percentbarchart_legend.png
66 \image examples_percentbarchart_legend.png
67
67
68 Please note that there is no QML API available for modifying legend markers, unlike in the Qt API of Charts.
68 Please note that there is no QML API available for modifying legend markers, unlike in the Qt API of Charts.
69 The use case of modifying markers can be implemented for example by creating your own custom legend. For an example
69 The use case of modifying markers can be implemented for example by creating your own custom legend. For an example
70 on how to do this, see \l {demos/qmlcustomlegend}{Qml Custom Demo} application.
70 on how to do this, see \l {demos/qmlcustomlegend}{Qml Custom Demo} application.
71 */
71 */
72
72
73 /*!
73 /*!
74 \property QLegend::alignment
74 \property QLegend::alignment
75 \brief The alignment of the legend.
75 \brief The alignment of the legend.
76
76
77 Legend paints on the defined position in the chart. The following alignments are supported:
77 Legend paints on the defined position in the chart. The following alignments are supported:
78 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
78 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
79 */
79 */
80 /*!
80 /*!
81 \qmlproperty Qt.Alignment Legend::alignment
81 \qmlproperty Qt.Alignment Legend::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 /*!
88 /*!
89 \property QLegend::backgroundVisible
89 \property QLegend::backgroundVisible
90 Whether the legend background is visible or not.
90 Whether the legend background is visible or not.
91 */
91 */
92 /*!
92 /*!
93 \qmlproperty bool Legend::backgroundVisible
93 \qmlproperty bool Legend::backgroundVisible
94 Whether the legend background is visible or not.
94 Whether the legend background is visible or not.
95 */
95 */
96
96
97 /*!
97 /*!
98 \property QLegend::color
98 \property QLegend::color
99 The color of the legend, i.e. the background (brush) color. Note that if you change the color
99 The color of the legend, i.e. the background (brush) color. Note that if you change the color
100 of the legend, the style of the legend brush is set to Qt::SolidPattern.
100 of the legend, the style of the legend brush is set to Qt::SolidPattern.
101 */
101 */
102 /*!
102 /*!
103 \qmlproperty color Legend::color
103 \qmlproperty color Legend::color
104 The color of the legend, i.e. the background (brush) color.
104 The color of the legend, i.e. the background (brush) color.
105 */
105 */
106
106
107 /*!
107 /*!
108 \property QLegend::borderColor
108 \property QLegend::borderColor
109 The border color of the legend, i.e. the line color.
109 The border color of the legend, i.e. the line color.
110 */
110 */
111 /*!
111 /*!
112 \qmlproperty color Legend::borderColor
112 \qmlproperty color Legend::borderColor
113 The border color of the legend, i.e. the line color.
113 The border color of the legend, i.e. the line color.
114 */
114 */
115
115
116 /*!
116 /*!
117 \property QLegend::font
117 \property QLegend::font
118 The font of markers used by legend
118 The font of markers used by legend
119 */
119 */
120 /*!
120 /*!
121 \qmlproperty Font Legend::font
121 \qmlproperty Font Legend::font
122 The font of markers used by legend
122 The font of markers used by legend
123 */
123 */
124
124
125 /*!
125 /*!
126 \property QLegend::labelColor
126 \property QLegend::labelColor
127 The color of brush used to draw labels.
127 The color of brush used to draw labels.
128 */
128 */
129 /*!
129 /*!
130 \qmlproperty color QLegend::labelColor
130 \qmlproperty color QLegend::labelColor
131 The color of brush used to draw labels.
131 The color of brush used to draw labels.
132 */
132 */
133
133
134 /*!
134 /*!
135 \fn void QLegend::backgroundVisibleChanged(bool)
135 \fn void QLegend::backgroundVisibleChanged(bool)
136 The visibility of the legend background changed to \a visible.
136 The visibility of the legend background changed to \a visible.
137 */
137 */
138
138
139 /*!
139 /*!
140 \fn void QLegend::colorChanged(QColor)
140 \fn void QLegend::colorChanged(QColor)
141 The color of the legend background changed to \a color.
141 The color of the legend background changed to \a color.
142 */
142 */
143
143
144 /*!
144 /*!
145 \fn void QLegend::borderColorChanged(QColor)
145 \fn void QLegend::borderColorChanged(QColor)
146 The border color of the legend background changed to \a color.
146 The border color of the legend background changed to \a color.
147 */
147 */
148
148
149 /*!
149 /*!
150 \fn void QLegend::fontChanged(QFont)
150 \fn void QLegend::fontChanged(QFont)
151 The font of markers of the legend changed to \a font.
151 The font of markers of the legend changed to \a font.
152 */
152 */
153
153
154 /*!
154 /*!
155 \fn void QLegend::labelColorChanged(QColor color)
155 \fn void QLegend::labelColorChanged(QColor color)
156 This signal is emitted when the color of brush used to draw labels has changed to \a color.
156 This signal is emitted when the color of brush used to draw labels has changed to \a color.
157 */
157 */
158
158
159 /*!
160 Constructs the legend object and sets the parent to \a parent
161 */
162
163 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
159 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
164 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this))
160 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this))
165 {
161 {
166 setZValue(ChartPresenter::LegendZValue);
162 setZValue(ChartPresenter::LegendZValue);
167 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
163 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
168 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*)));
164 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*)));
169 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
165 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
170 setLayout(d_ptr->m_layout);
166 setLayout(d_ptr->m_layout);
171 }
167 }
172
168
173 /*!
169 /*!
174 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
170 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
175 */
171 */
176 QLegend::~QLegend()
172 QLegend::~QLegend()
177 {
173 {
178 }
174 }
179
175
180 /*!
176 /*!
181 \internal
177 \internal
182 */
178 */
183 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
179 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
184 {
180 {
185 Q_UNUSED(option)
181 Q_UNUSED(option)
186 Q_UNUSED(widget)
182 Q_UNUSED(widget)
187
183
188 if (!d_ptr->m_backgroundVisible)
184 if (!d_ptr->m_backgroundVisible)
189 return;
185 return;
190
186
191 painter->setOpacity(opacity());
187 painter->setOpacity(opacity());
192 painter->setPen(d_ptr->m_pen);
188 painter->setPen(d_ptr->m_pen);
193 painter->setBrush(d_ptr->m_brush);
189 painter->setBrush(d_ptr->m_brush);
194 painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
190 painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
195 }
191 }
196
192
197
193
198 /*!
194 /*!
199 Sets the \a brush of legend. Brush affects the background of legend.
195 Sets the \a brush of legend. Brush affects the background of legend.
200 */
196 */
201 void QLegend::setBrush(const QBrush &brush)
197 void QLegend::setBrush(const QBrush &brush)
202 {
198 {
203 if (d_ptr->m_brush != brush) {
199 if (d_ptr->m_brush != brush) {
204 d_ptr->m_brush = brush;
200 d_ptr->m_brush = brush;
205 update();
201 update();
206 emit colorChanged(brush.color());
202 emit colorChanged(brush.color());
207 }
203 }
208 }
204 }
209
205
210 /*!
206 /*!
211 Returns the brush used by legend.
207 Returns the brush used by legend.
212 */
208 */
213 QBrush QLegend::brush() const
209 QBrush QLegend::brush() const
214 {
210 {
215 return d_ptr->m_brush;
211 return d_ptr->m_brush;
216 }
212 }
217
213
218 void QLegend::setColor(QColor color)
214 void QLegend::setColor(QColor color)
219 {
215 {
220 QBrush b = d_ptr->m_brush;
216 QBrush b = d_ptr->m_brush;
221 if (b.style() != Qt::SolidPattern || b.color() != color) {
217 if (b.style() != Qt::SolidPattern || b.color() != color) {
222 b.setStyle(Qt::SolidPattern);
218 b.setStyle(Qt::SolidPattern);
223 b.setColor(color);
219 b.setColor(color);
224 setBrush(b);
220 setBrush(b);
225 }
221 }
226 }
222 }
227
223
228 QColor QLegend::color()
224 QColor QLegend::color()
229 {
225 {
230 return d_ptr->m_brush.color();
226 return d_ptr->m_brush.color();
231 }
227 }
232
228
233 /*!
229 /*!
234 Sets the \a pen of legend. Pen affects the legend borders.
230 Sets the \a pen of legend. Pen affects the legend borders.
235 */
231 */
236 void QLegend::setPen(const QPen &pen)
232 void QLegend::setPen(const QPen &pen)
237 {
233 {
238 if (d_ptr->m_pen != pen) {
234 if (d_ptr->m_pen != pen) {
239 d_ptr->m_pen = pen;
235 d_ptr->m_pen = pen;
240 update();
236 update();
241 emit borderColorChanged(pen.color());
237 emit borderColorChanged(pen.color());
242 }
238 }
243 }
239 }
244
240
245 /*!
241 /*!
246 Returns the pen used by legend
242 Returns the pen used by legend
247 */
243 */
248
244
249 QPen QLegend::pen() const
245 QPen QLegend::pen() const
250 {
246 {
251 return d_ptr->m_pen;
247 return d_ptr->m_pen;
252 }
248 }
253
249
254 void QLegend::setFont(const QFont &font)
250 void QLegend::setFont(const QFont &font)
255 {
251 {
256 if (d_ptr->m_font != font)
252 if (d_ptr->m_font != font)
257 d_ptr->m_font = font;
253 d_ptr->m_font = font;
258
254
259 foreach (QLegendMarker *marker, d_ptr->markers()) {
255 foreach (QLegendMarker *marker, d_ptr->markers()) {
260 marker->setFont(d_ptr->m_font);
256 marker->setFont(d_ptr->m_font);
261 }
257 }
262 layout()->invalidate();
258 layout()->invalidate();
263 emit fontChanged(font);
259 emit fontChanged(font);
264 }
260 }
265
261
266 QFont QLegend::font() const
262 QFont QLegend::font() const
267 {
263 {
268 return d_ptr->m_font;
264 return d_ptr->m_font;
269 }
265 }
270
266
271 void QLegend::setBorderColor(QColor color)
267 void QLegend::setBorderColor(QColor color)
272 {
268 {
273 QPen p = d_ptr->m_pen;
269 QPen p = d_ptr->m_pen;
274 if (p.color() != color) {
270 if (p.color() != color) {
275 p.setColor(color);
271 p.setColor(color);
276 setPen(p);
272 setPen(p);
277 }
273 }
278 }
274 }
279
275
280 QColor QLegend::borderColor()
276 QColor QLegend::borderColor()
281 {
277 {
282 return d_ptr->m_pen.color();
278 return d_ptr->m_pen.color();
283 }
279 }
284
280
285 /*!
281 /*!
286 Set brush used to draw labels to \a brush.
282 Set brush used to draw labels to \a brush.
287 */
283 */
288 void QLegend::setLabelBrush(const QBrush &brush)
284 void QLegend::setLabelBrush(const QBrush &brush)
289 {
285 {
290 if (d_ptr->m_labelBrush != brush) {
286 if (d_ptr->m_labelBrush != brush) {
291 d_ptr->m_labelBrush = brush;
287 d_ptr->m_labelBrush = brush;
292 foreach (QLegendMarker *marker, d_ptr->markers()) {
288 foreach (QLegendMarker *marker, d_ptr->markers()) {
293 marker->setLabelBrush(d_ptr->m_labelBrush);
289 marker->setLabelBrush(d_ptr->m_labelBrush);
294 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
290 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
295 // instead of mapping it from label brush color
291 // instead of mapping it from label brush color
296 marker->setPen(brush.color());
292 marker->setPen(brush.color());
297 }
293 }
298 emit labelColorChanged(brush.color());
294 emit labelColorChanged(brush.color());
299 }
295 }
300 }
296 }
301
297
302 /*!
298 /*!
303 Brush used to draw labels.
299 Brush used to draw labels.
304 */
300 */
305 QBrush QLegend::labelBrush() const
301 QBrush QLegend::labelBrush() const
306 {
302 {
307 return d_ptr->m_labelBrush;
303 return d_ptr->m_labelBrush;
308 }
304 }
309
305
310 void QLegend::setLabelColor(QColor color)
306 void QLegend::setLabelColor(QColor color)
311 {
307 {
312 QBrush b = d_ptr->m_labelBrush;
308 QBrush b = d_ptr->m_labelBrush;
313 if (b.style() != Qt::SolidPattern || b.color() != color) {
309 if (b.style() != Qt::SolidPattern || b.color() != color) {
314 b.setStyle(Qt::SolidPattern);
310 b.setStyle(Qt::SolidPattern);
315 b.setColor(color);
311 b.setColor(color);
316 setLabelBrush(b);
312 setLabelBrush(b);
317 }
313 }
318 }
314 }
319
315
320 QColor QLegend::labelColor() const
316 QColor QLegend::labelColor() const
321 {
317 {
322 return d_ptr->m_labelBrush.color();
318 return d_ptr->m_labelBrush.color();
323 }
319 }
324
320
325
321
326 void QLegend::setAlignment(Qt::Alignment alignment)
322 void QLegend::setAlignment(Qt::Alignment alignment)
327 {
323 {
328 if (d_ptr->m_alignment != alignment) {
324 if (d_ptr->m_alignment != alignment) {
329 d_ptr->m_alignment = alignment;
325 d_ptr->m_alignment = alignment;
330 layout()->invalidate();
326 layout()->invalidate();
331 }
327 }
332 }
328 }
333
329
334 Qt::Alignment QLegend::alignment() const
330 Qt::Alignment QLegend::alignment() const
335 {
331 {
336 return d_ptr->m_alignment;
332 return d_ptr->m_alignment;
337 }
333 }
338
334
339 /*!
335 /*!
340 Detaches the legend from chart. Chart won't change layout of the legend.
336 Detaches the legend from chart. Chart won't change layout of the legend.
341 */
337 */
342 void QLegend::detachFromChart()
338 void QLegend::detachFromChart()
343 {
339 {
344 d_ptr->m_attachedToChart = false;
340 d_ptr->m_attachedToChart = false;
345 layout()->invalidate();
341 layout()->invalidate();
346 setParent(0);
342 setParent(0);
347
343
348 }
344 }
349
345
350 /*!
346 /*!
351 Attaches the legend to chart. Chart may change layout of the legend.
347 Attaches the legend to chart. Chart may change layout of the legend.
352 */
348 */
353 void QLegend::attachToChart()
349 void QLegend::attachToChart()
354 {
350 {
355 d_ptr->m_attachedToChart = true;
351 d_ptr->m_attachedToChart = true;
356 layout()->invalidate();
352 layout()->invalidate();
357 setParent(d_ptr->m_chart);
353 setParent(d_ptr->m_chart);
358 }
354 }
359
355
360 /*!
356 /*!
361 Returns true, if legend is attached to chart.
357 Returns true, if legend is attached to chart.
362 */
358 */
363 bool QLegend::isAttachedToChart()
359 bool QLegend::isAttachedToChart()
364 {
360 {
365 return d_ptr->m_attachedToChart;
361 return d_ptr->m_attachedToChart;
366 }
362 }
367
363
368 /*!
364 /*!
369 Sets the visibility of legend background to \a visible
365 Sets the visibility of legend background to \a visible
370 */
366 */
371 void QLegend::setBackgroundVisible(bool visible)
367 void QLegend::setBackgroundVisible(bool visible)
372 {
368 {
373 if (d_ptr->m_backgroundVisible != visible) {
369 if (d_ptr->m_backgroundVisible != visible) {
374 d_ptr->m_backgroundVisible = visible;
370 d_ptr->m_backgroundVisible = visible;
375 update();
371 update();
376 emit backgroundVisibleChanged(visible);
372 emit backgroundVisibleChanged(visible);
377 }
373 }
378 }
374 }
379
375
380 /*!
376 /*!
381 Returns the visibility of legend background
377 Returns the visibility of legend background
382 */
378 */
383 bool QLegend::isBackgroundVisible() const
379 bool QLegend::isBackgroundVisible() const
384 {
380 {
385 return d_ptr->m_backgroundVisible;
381 return d_ptr->m_backgroundVisible;
386 }
382 }
387
383
388 /*!
384 /*!
389 Returns the list of markers in legend. The list can be filtered with \a series parameter.
385 Returns the list of markers in legend. The list can be filtered with \a series parameter.
390 If \a series is given, only markers related to that series are returned.
386 If \a series is given, only markers related to that series are returned.
391 */
387 */
392 QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const
388 QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const
393 {
389 {
394 return d_ptr->markers(series);
390 return d_ptr->markers(series);
395 }
391 }
396
392
397 /*!
393 /*!
398 \internal \a event see QGraphicsWidget for details
394 \internal \a event see QGraphicsWidget for details
399 */
395 */
400 void QLegend::hideEvent(QHideEvent *event)
396 void QLegend::hideEvent(QHideEvent *event)
401 {
397 {
402 if (isAttachedToChart())
398 if (isAttachedToChart())
403 d_ptr->m_presenter->layout()->invalidate();
399 d_ptr->m_presenter->layout()->invalidate();
404 QGraphicsWidget::hideEvent(event);
400 QGraphicsWidget::hideEvent(event);
405 }
401 }
406 /*!
402 /*!
407 \internal \a event see QGraphicsWidget for details
403 \internal \a event see QGraphicsWidget for details
408 */
404 */
409 void QLegend::showEvent(QShowEvent *event)
405 void QLegend::showEvent(QShowEvent *event)
410 {
406 {
411 if (isAttachedToChart()) {
407 if (isAttachedToChart()) {
412 d_ptr->items()->setVisible(false);
408 d_ptr->items()->setVisible(false);
413 layout()->invalidate();
409 layout()->invalidate();
414 }
410 }
415 QGraphicsWidget::showEvent(event);
411 QGraphicsWidget::showEvent(event);
416 //layout activation will show the items
412 //layout activation will show the items
417 }
413 }
418
414
419 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
415 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
420
416
421 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q)
417 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q)
422 : q_ptr(q),
418 : q_ptr(q),
423 m_presenter(presenter),
419 m_presenter(presenter),
424 m_layout(new LegendLayout(q)),
420 m_layout(new LegendLayout(q)),
425 m_chart(chart),
421 m_chart(chart),
426 m_items(new QGraphicsItemGroup(q)),
422 m_items(new QGraphicsItemGroup(q)),
427 m_alignment(Qt::AlignTop),
423 m_alignment(Qt::AlignTop),
428 m_brush(QBrush()),
424 m_brush(QBrush()),
429 m_pen(QPen()),
425 m_pen(QPen()),
430 m_labelBrush(QBrush()),
426 m_labelBrush(QBrush()),
431 m_diameter(5),
427 m_diameter(5),
432 m_attachedToChart(true),
428 m_attachedToChart(true),
433 m_backgroundVisible(false)
429 m_backgroundVisible(false)
434 {
430 {
435 m_items->setHandlesChildEvents(false);
431 m_items->setHandlesChildEvents(false);
436 }
432 }
437
433
438 QLegendPrivate::~QLegendPrivate()
434 QLegendPrivate::~QLegendPrivate()
439 {
435 {
440
436
441 }
437 }
442
438
443 void QLegendPrivate::setOffset(const QPointF &offset)
439 void QLegendPrivate::setOffset(const QPointF &offset)
444 {
440 {
445 m_layout->setOffset(offset.x(), offset.y());
441 m_layout->setOffset(offset.x(), offset.y());
446 }
442 }
447
443
448 QPointF QLegendPrivate::offset() const
444 QPointF QLegendPrivate::offset() const
449 {
445 {
450 return m_layout->offset();
446 return m_layout->offset();
451 }
447 }
452
448
453 int QLegendPrivate::roundness(qreal size)
449 int QLegendPrivate::roundness(qreal size)
454 {
450 {
455 return 100 * m_diameter / int(size);
451 return 100 * m_diameter / int(size);
456 }
452 }
457
453
458 QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series)
454 QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series)
459 {
455 {
460 // Return all markers
456 // Return all markers
461 if (!series) {
457 if (!series) {
462 return m_markers;
458 return m_markers;
463 }
459 }
464
460
465 // Create filtered list
461 // Create filtered list
466 QList<QLegendMarker *> markers;
462 QList<QLegendMarker *> markers;
467 foreach (QLegendMarker *marker, m_markers) {
463 foreach (QLegendMarker *marker, m_markers) {
468 if (marker->series() == series) {
464 if (marker->series() == series) {
469 markers.append(marker);
465 markers.append(marker);
470 }
466 }
471 }
467 }
472 return markers;
468 return markers;
473 }
469 }
474
470
475 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series)
471 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series)
476 {
472 {
477 if (m_series.contains(series)) {
473 if (m_series.contains(series)) {
478 return;
474 return;
479 }
475 }
480
476
481 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
477 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
482 decorateMarkers(newMarkers);
478 decorateMarkers(newMarkers);
483 addMarkers(newMarkers);
479 addMarkers(newMarkers);
484
480
485 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
481 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
486 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
482 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
487
483
488 m_series.append(series);
484 m_series.append(series);
489 m_items->setVisible(false);
485 m_items->setVisible(false);
490 m_layout->invalidate();
486 m_layout->invalidate();
491 }
487 }
492
488
493 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
489 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
494 {
490 {
495 if (m_series.contains(series)) {
491 if (m_series.contains(series)) {
496 m_series.removeOne(series);
492 m_series.removeOne(series);
497 }
493 }
498
494
499 // Find out, which markers to remove
495 // Find out, which markers to remove
500 QList<QLegendMarker *> removed;
496 QList<QLegendMarker *> removed;
501 foreach (QLegendMarker *m, m_markers) {
497 foreach (QLegendMarker *m, m_markers) {
502 if (m->series() == series) {
498 if (m->series() == series) {
503 removed << m;
499 removed << m;
504 }
500 }
505 }
501 }
506 removeMarkers(removed);
502 removeMarkers(removed);
507
503
508 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
504 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
509 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
505 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
510
506
511 m_layout->invalidate();
507 m_layout->invalidate();
512 }
508 }
513
509
514 void QLegendPrivate::handleSeriesVisibleChanged()
510 void QLegendPrivate::handleSeriesVisibleChanged()
515 {
511 {
516 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
512 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
517 Q_ASSERT(series);
513 Q_ASSERT(series);
518
514
519 foreach (QLegendMarker *marker, m_markers) {
515 foreach (QLegendMarker *marker, m_markers) {
520 if (marker->series() == series) {
516 if (marker->series() == series) {
521 marker->setVisible(series->isVisible());
517 marker->setVisible(series->isVisible());
522 }
518 }
523 }
519 }
524 m_layout->invalidate();
520 m_layout->invalidate();
525 }
521 }
526
522
527 void QLegendPrivate::handleCountChanged()
523 void QLegendPrivate::handleCountChanged()
528 {
524 {
529 // Here we handle the changes in marker count.
525 // Here we handle the changes in marker count.
530 // Can happen for example when pieslice(s) have been added to or removed from pieseries.
526 // Can happen for example when pieslice(s) have been added to or removed from pieseries.
531
527
532 QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender());
528 QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender());
533 QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr);
529 QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr);
534
530
535 // Find out removed markers and created markers
531 // Find out removed markers and created markers
536 QList<QLegendMarker *> removedMarkers;
532 QList<QLegendMarker *> removedMarkers;
537 foreach (QLegendMarker *oldMarker, m_markers) {
533 foreach (QLegendMarker *oldMarker, m_markers) {
538 // we have marker, which is related to sender.
534 // we have marker, which is related to sender.
539 if (oldMarker->series() == series->q_ptr) {
535 if (oldMarker->series() == series->q_ptr) {
540 bool found = false;
536 bool found = false;
541 foreach(QLegendMarker *newMarker, createdMarkers) {
537 foreach(QLegendMarker *newMarker, createdMarkers) {
542 // New marker considered existing if:
538 // New marker considered existing if:
543 // - d_ptr->relatedObject() is same for both markers.
539 // - d_ptr->relatedObject() is same for both markers.
544 if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) {
540 if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) {
545 // Delete the new marker, since we already have existing marker, that might be connected on user side.
541 // Delete the new marker, since we already have existing marker, that might be connected on user side.
546 found = true;
542 found = true;
547 createdMarkers.removeOne(newMarker);
543 createdMarkers.removeOne(newMarker);
548 delete newMarker;
544 delete newMarker;
549 }
545 }
550 }
546 }
551 if (!found) {
547 if (!found) {
552 // No related object found for marker, add to removedMarkers list
548 // No related object found for marker, add to removedMarkers list
553 removedMarkers << oldMarker;
549 removedMarkers << oldMarker;
554 }
550 }
555 }
551 }
556 }
552 }
557
553
558 removeMarkers(removedMarkers);
554 removeMarkers(removedMarkers);
559 decorateMarkers(createdMarkers);
555 decorateMarkers(createdMarkers);
560 addMarkers(createdMarkers);
556 addMarkers(createdMarkers);
561
557
562 q_ptr->layout()->invalidate();
558 q_ptr->layout()->invalidate();
563 }
559 }
564
560
565 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers)
561 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers)
566 {
562 {
567 foreach (QLegendMarker *marker, markers) {
563 foreach (QLegendMarker *marker, markers) {
568 m_items->addToGroup(marker->d_ptr.data()->item());
564 m_items->addToGroup(marker->d_ptr.data()->item());
569 m_markers << marker;
565 m_markers << marker;
570 m_markerHash.insert(marker->d_ptr->item(), marker);
566 m_markerHash.insert(marker->d_ptr->item(), marker);
571 }
567 }
572 }
568 }
573
569
574 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers)
570 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers)
575 {
571 {
576 foreach (QLegendMarker *marker, markers) {
572 foreach (QLegendMarker *marker, markers) {
577 marker->d_ptr->item()->setVisible(false);
573 marker->d_ptr->item()->setVisible(false);
578 m_items->removeFromGroup(marker->d_ptr->item());
574 m_items->removeFromGroup(marker->d_ptr->item());
579 m_markers.removeOne(marker);
575 m_markers.removeOne(marker);
580 m_markerHash.remove(marker->d_ptr->item());
576 m_markerHash.remove(marker->d_ptr->item());
581 delete marker;
577 delete marker;
582 }
578 }
583 }
579 }
584
580
585 void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers)
581 void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers)
586 {
582 {
587 foreach (QLegendMarker *marker, markers) {
583 foreach (QLegendMarker *marker, markers) {
588 marker->setFont(m_font);
584 marker->setFont(m_font);
589 marker->setLabelBrush(m_labelBrush);
585 marker->setLabelBrush(m_labelBrush);
590 }
586 }
591 }
587 }
592
588
593
589
594 #include "moc_qlegend.cpp"
590 #include "moc_qlegend.cpp"
595 #include "moc_qlegend_p.cpp"
591 #include "moc_qlegend_p.cpp"
596
592
597 QTCOMMERCIALCHART_END_NAMESPACE
593 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,243 +1,273
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qlegendmarker.h"
21 #include "qlegendmarker.h"
22 #include "qlegendmarker_p.h"
22 #include "qlegendmarker_p.h"
23 #include "legendmarkeritem_p.h"
23 #include "legendmarkeritem_p.h"
24 #include "qlegend.h"
24 #include "qlegend.h"
25 #include "qlegend_p.h"
25 #include "qlegend_p.h"
26 #include "legendlayout_p.h"
26 #include "legendlayout_p.h"
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <QGraphicsSceneEvent>
28 #include <QGraphicsSceneEvent>
29 #include <QAbstractSeries>
29 #include <QAbstractSeries>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \class QLegendMarker
34 \class QLegendMarker
35 \brief LegendMarker object
35 \brief LegendMarker object
36 \mainclass
36 \mainclass
37
37
38 QLegendMarker is abstract object that can be used to access markers inside QLegend. Legend marker consists of two
38 QLegendMarker is abstract object that can be used to access markers inside QLegend. Legend marker consists of two
39 items: The colored box, which reflects the color of series and label, which is the name of series (or label of slice/barset
39 items: The colored box, which reflects the color of series and label, which is the name of series (or label of slice/barset
40 in case of pie or bar series)
40 in case of pie or bar series)
41 The QLegendMarker is always related to one series.
41 The QLegendMarker is always related to one series.
42
42
43 \image examples_percentbarchart_legend.png
43 \image examples_percentbarchart_legend.png
44
44
45 \sa QLegend
45 \sa QLegend
46 */
46 */
47 /*!
47 /*!
48 \enum QLegendMarker::LegendMarkerType
48 \enum QLegendMarker::LegendMarkerType
49
49
50 The type of the legendmarker object.
50 The type of the legendmarker object.
51
51
52 \value LegendMarkerTypeArea
52 \value LegendMarkerTypeArea
53 \value LegendMarkerTypeBar
53 \value LegendMarkerTypeBar
54 \value LegendMarkerTypePie
54 \value LegendMarkerTypePie
55 \value LegendMarkerTypeXY
55 \value LegendMarkerTypeXY
56 */
56 */
57
57
58 /*!
58 /*!
59 \fn virtual LegendMarkerType QLegendMarker::type() = 0;
59 \fn virtual LegendMarkerType QLegendMarker::type() = 0;
60 Returns the type of legendmarker. Type depends of the related series. LegendMarkerTypeXY is used for all QXYSeries derived
60 Returns the type of legendmarker. Type depends of the related series. LegendMarkerTypeXY is used for all QXYSeries derived
61 classes.
61 classes.
62 */
62 */
63
63
64 /*!
64 /*!
65 \fn virtual QAbstractSeries* QLegendMarker::series() = 0;
65 \fn virtual QAbstractSeries* QLegendMarker::series() = 0;
66 Returns pointer to series, which is related to this marker. Marker is always related to some series.
66 Returns pointer to series, which is related to this marker. Marker is always related to some series.
67 */
67 */
68
68
69 /*!
69 /*!
70 \fn void QLegendMarker::clicked();
70 \fn void QLegendMarker::clicked();
71 This signal is emitted, when marker is clicked with mouse.
71 This signal is emitted, when marker is clicked with mouse.
72 */
72 */
73
73
74 /*!
74 /*!
75 \fn void QLegendMarker::hovered(bool status);
75 \fn void QLegendMarker::hovered(bool status);
76 This signal is emitted, when mouse is hovered over marker. \a status is true, when mouse enters the marker
76 This signal is emitted, when mouse is hovered over marker. \a status is true, when mouse enters the marker
77 and false when it leaves the marker.
77 and false when it leaves the marker.
78 */
78 */
79
79
80 /*!
80 /*!
81 \fn void QLegendMarker::labelChanged()
82 This signal is emitted when the label of the legend marker has changed.
83 */
84
85 /*!
86 \fn void QLegendMarker::labelBrushChanged()
87 This signal is emitted when the label brush of the legend marker has changed.
88 */
89
90 /*!
91 \fn void QLegendMarker::fontChanged()
92 This signal is emitted when the (label) font of the legend marker has changed.
93 */
94
95 /*!
96 \fn void QLegendMarker::penChanged()
97 This signal is emitted when the pen of the legend marker has changed.
98 */
99
100 /*!
101 \fn void QLegendMarker::brushChanged()
102 This signal is emitted when the brush of the legend marker has changed.
103 */
104
105 /*!
106 \fn void QLegendMarker::visibleChanged()
107 This signal is emitted when the visibility of the legend marker has changed.
108 */
109
110 /*!
81 \property QLegendMarker::label
111 \property QLegendMarker::label
82 Label of the marker. This is the text that is shown in legend.
112 Label of the marker. This is the text that is shown in legend.
83 */
113 */
84
114
85 /*!
115 /*!
86 \property QLegendMarker::labelBrush
116 \property QLegendMarker::labelBrush
87 Brush of the label
117 Brush of the label
88 */
118 */
89
119
90 /*!
120 /*!
91 \property QLegendMarker::font
121 \property QLegendMarker::font
92 Font of the label
122 Font of the label
93 */
123 */
94
124
95 /*!
125 /*!
96 \property QLegendMarker::pen
126 \property QLegendMarker::pen
97 Pen of the marker. This is the outline of the colored square.
127 Pen of the marker. This is the outline of the colored square.
98 */
128 */
99
129
100 /*!
130 /*!
101 \property QLegendMarker::brush
131 \property QLegendMarker::brush
102 Brush of the marker. This is the inside of the colored square.
132 Brush of the marker. This is the inside of the colored square.
103 */
133 */
104
134
105 /*!
135 /*!
106 \property QLegendMarker::visible
136 \property QLegendMarker::visible
107 Visibility of the legend marker. Affects label and the colored square.
137 Visibility of the legend marker. Affects label and the colored square.
108 */
138 */
109
139
110
140
111 /*!
141 /*!
112 Constructor of marker
142 \internal
113 */
143 */
114 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
144 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
115 QObject(parent),
145 QObject(parent),
116 d_ptr(&d)
146 d_ptr(&d)
117 {
147 {
118 d_ptr->m_item->setVisible(d_ptr->series()->isVisible());
148 d_ptr->m_item->setVisible(d_ptr->series()->isVisible());
119 }
149 }
120
150
121 /*!
151 /*!
122 Destructor of marker
152 Destructor of marker
123 */
153 */
124 QLegendMarker::~QLegendMarker()
154 QLegendMarker::~QLegendMarker()
125 {
155 {
126 }
156 }
127
157
128 /*!
158 /*!
129 Returns the label of the marker.
159 Returns the label of the marker.
130 */
160 */
131 QString QLegendMarker::label() const
161 QString QLegendMarker::label() const
132 {
162 {
133 return d_ptr->m_item->label();
163 return d_ptr->m_item->label();
134 }
164 }
135
165
136 /*!
166 /*!
137 Sets the \a label of marker. Note that changing name of series will also change label of its marker.
167 Sets the \a label of marker. Note that changing name of series will also change label of its marker.
138 */
168 */
139 void QLegendMarker::setLabel(const QString &label)
169 void QLegendMarker::setLabel(const QString &label)
140 {
170 {
141 d_ptr->m_item->setLabel(label);
171 d_ptr->m_item->setLabel(label);
142 }
172 }
143 /*!
173 /*!
144 Returns the brush which is used to draw label.
174 Returns the brush which is used to draw label.
145 */
175 */
146 QBrush QLegendMarker::labelBrush() const
176 QBrush QLegendMarker::labelBrush() const
147 {
177 {
148 return d_ptr->m_item->labelBrush();
178 return d_ptr->m_item->labelBrush();
149 }
179 }
150
180
151 /*!
181 /*!
152 Sets the \a brush of label
182 Sets the \a brush of label
153 */
183 */
154 void QLegendMarker::setLabelBrush(const QBrush &brush)
184 void QLegendMarker::setLabelBrush(const QBrush &brush)
155 {
185 {
156 d_ptr->m_item->setLabelBrush(brush);
186 d_ptr->m_item->setLabelBrush(brush);
157 }
187 }
158
188
159 /*!
189 /*!
160 Retuns the font of label
190 Retuns the font of label
161 */
191 */
162 QFont QLegendMarker::font() const
192 QFont QLegendMarker::font() const
163 {
193 {
164 return d_ptr->m_item->font();
194 return d_ptr->m_item->font();
165 }
195 }
166
196
167 /*!
197 /*!
168 Sets the \a font of label
198 Sets the \a font of label
169 */
199 */
170 void QLegendMarker::setFont(const QFont &font)
200 void QLegendMarker::setFont(const QFont &font)
171 {
201 {
172 d_ptr->m_item->setFont(font);
202 d_ptr->m_item->setFont(font);
173 }
203 }
174
204
175 /*!
205 /*!
176 Returns the pen of marker item
206 Returns the pen of marker item
177 */
207 */
178 QPen QLegendMarker::pen() const
208 QPen QLegendMarker::pen() const
179 {
209 {
180 return d_ptr->m_item->pen();
210 return d_ptr->m_item->pen();
181 }
211 }
182
212
183 /*!
213 /*!
184 Sets the \a pen of marker item
214 Sets the \a pen of marker item
185 */
215 */
186 void QLegendMarker::setPen(const QPen &pen)
216 void QLegendMarker::setPen(const QPen &pen)
187 {
217 {
188 d_ptr->m_item->setPen(pen);
218 d_ptr->m_item->setPen(pen);
189 }
219 }
190
220
191 /*!
221 /*!
192 Returns the brush of marker item
222 Returns the brush of marker item
193 */
223 */
194 QBrush QLegendMarker::brush() const
224 QBrush QLegendMarker::brush() const
195 {
225 {
196 return d_ptr->m_item->brush();
226 return d_ptr->m_item->brush();
197 }
227 }
198
228
199 /*!
229 /*!
200 Sets the \a brush of marker item. Note that changing color of the series also changes this.
230 Sets the \a brush of marker item. Note that changing color of the series also changes this.
201 */
231 */
202 void QLegendMarker::setBrush(const QBrush &brush)
232 void QLegendMarker::setBrush(const QBrush &brush)
203 {
233 {
204 d_ptr->m_item->setBrush(brush);
234 d_ptr->m_item->setBrush(brush);
205 }
235 }
206
236
207 /*!
237 /*!
208 Returns visibility of the marker
238 Returns visibility of the marker
209 */
239 */
210 bool QLegendMarker::isVisible() const
240 bool QLegendMarker::isVisible() const
211 {
241 {
212 return d_ptr->m_item->isVisible();
242 return d_ptr->m_item->isVisible();
213 }
243 }
214
244
215 /*!
245 /*!
216 Sets markers visibility to \a visible
246 Sets markers visibility to \a visible
217 */
247 */
218 void QLegendMarker::setVisible(bool visible)
248 void QLegendMarker::setVisible(bool visible)
219 {
249 {
220 d_ptr->m_item->setVisible(visible);
250 d_ptr->m_item->setVisible(visible);
221 }
251 }
222
252
223 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
253 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
224 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) :
254 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) :
225 m_legend(legend),
255 m_legend(legend),
226 q_ptr(q)
256 q_ptr(q)
227 {
257 {
228 m_item = new LegendMarkerItem(this);
258 m_item = new LegendMarkerItem(this);
229 }
259 }
230
260
231 QLegendMarkerPrivate::~QLegendMarkerPrivate()
261 QLegendMarkerPrivate::~QLegendMarkerPrivate()
232 {
262 {
233 }
263 }
234
264
235 void QLegendMarkerPrivate::invalidateLegend()
265 void QLegendMarkerPrivate::invalidateLegend()
236 {
266 {
237 m_legend->d_ptr->m_layout->invalidate();
267 m_legend->d_ptr->m_layout->invalidate();
238 }
268 }
239
269
240 #include "moc_qlegendmarker.cpp"
270 #include "moc_qlegendmarker.cpp"
241 #include "moc_qlegendmarker_p.cpp"
271 #include "moc_qlegendmarker_p.cpp"
242
272
243 QTCOMMERCIALCHART_END_NAMESPACE
273 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,143 +1,143
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qpielegendmarker.h"
21 #include "qpielegendmarker.h"
22 #include "qpielegendmarker_p.h"
22 #include "qpielegendmarker_p.h"
23 #include <QPieSeries>
23 #include <QPieSeries>
24 #include <QPieSlice>
24 #include <QPieSlice>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QPieLegendMarker
29 \class QPieLegendMarker
30 \brief LegendMarker object
30 \brief LegendMarker object
31 \mainclass
31 \mainclass
32
32
33 QPieLegendMarker is related to QPieSeries. With QPieSeries, each slice of pie is related to one marker in QLegend.
33 QPieLegendMarker is related to QPieSeries. With QPieSeries, each slice of pie is related to one marker in QLegend.
34
34
35 \sa QLegend QPieSeries QPieSlice
35 \sa QLegend QPieSeries QPieSlice
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn virtual LegendMarkerType QPieLegendMarker::type()
39 \fn virtual LegendMarkerType QPieLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypePie
40 Returns QLegendMarker::LegendMarkerTypePie
41 */
41 */
42
42
43 /*!
43 /*!
44 Constructor
44 \internal
45 */
45 */
46 QPieLegendMarker::QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent) :
46 QPieLegendMarker::QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent) :
47 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
47 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
48 {
48 {
49 d_ptr->updated();
49 d_ptr->updated();
50 }
50 }
51
51
52 /*!
52 /*!
53 Destructor
53 Destructor
54 */
54 */
55 QPieLegendMarker::~QPieLegendMarker()
55 QPieLegendMarker::~QPieLegendMarker()
56 {
56 {
57 }
57 }
58
58
59 /*!
59 /*!
60 \internal
60 \internal
61 */
61 */
62 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
62 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
63 QLegendMarker(d, parent)
63 QLegendMarker(d, parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns the related series of marker.
68 Returns the related series of marker.
69 */
69 */
70 QPieSeries* QPieLegendMarker::series()
70 QPieSeries* QPieLegendMarker::series()
71 {
71 {
72 Q_D(QPieLegendMarker);
72 Q_D(QPieLegendMarker);
73 return d->m_series;
73 return d->m_series;
74 }
74 }
75
75
76 /*!
76 /*!
77 Returns the related slice of marker.
77 Returns the related slice of marker.
78 */
78 */
79 QPieSlice* QPieLegendMarker::slice()
79 QPieSlice* QPieLegendMarker::slice()
80 {
80 {
81 Q_D(QPieLegendMarker);
81 Q_D(QPieLegendMarker);
82 return d->m_slice;
82 return d->m_slice;
83 }
83 }
84
84
85 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86
86
87 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
87 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
88 QLegendMarkerPrivate(q,legend),
88 QLegendMarkerPrivate(q,legend),
89 q_ptr(q),
89 q_ptr(q),
90 m_series(series),
90 m_series(series),
91 m_slice(slice)
91 m_slice(slice)
92 {
92 {
93 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
93 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
94 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
94 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
95 QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
95 QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
96 }
96 }
97
97
98 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
98 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
99 {
99 {
100 }
100 }
101
101
102 QPieSeries* QPieLegendMarkerPrivate::series()
102 QPieSeries* QPieLegendMarkerPrivate::series()
103 {
103 {
104 return m_series;
104 return m_series;
105 }
105 }
106
106
107 QObject* QPieLegendMarkerPrivate::relatedObject()
107 QObject* QPieLegendMarkerPrivate::relatedObject()
108 {
108 {
109 return m_slice;
109 return m_slice;
110 }
110 }
111
111
112 void QPieLegendMarkerPrivate::updated()
112 void QPieLegendMarkerPrivate::updated()
113 {
113 {
114 bool labelChanged = false;
114 bool labelChanged = false;
115 bool brushChanged = false;
115 bool brushChanged = false;
116 bool penChanged = false;
116 bool penChanged = false;
117
117
118 if (m_item->pen() != m_slice->pen()) {
118 if (m_item->pen() != m_slice->pen()) {
119 m_item->setPen(m_slice->pen());
119 m_item->setPen(m_slice->pen());
120 penChanged = true;
120 penChanged = true;
121 }
121 }
122 if (m_item->brush() != m_slice->brush()) {
122 if (m_item->brush() != m_slice->brush()) {
123 m_item->setBrush(m_slice->brush());
123 m_item->setBrush(m_slice->brush());
124 brushChanged = true;
124 brushChanged = true;
125 }
125 }
126 if (m_item->label() != m_slice->label()) {
126 if (m_item->label() != m_slice->label()) {
127 m_item->setLabel(m_slice->label());
127 m_item->setLabel(m_slice->label());
128 labelChanged = true;
128 labelChanged = true;
129 }
129 }
130 invalidateLegend();
130 invalidateLegend();
131
131
132 if (labelChanged)
132 if (labelChanged)
133 emit q_ptr->labelChanged();
133 emit q_ptr->labelChanged();
134 if (brushChanged)
134 if (brushChanged)
135 emit q_ptr->brushChanged();
135 emit q_ptr->brushChanged();
136 if (penChanged)
136 if (penChanged)
137 emit q_ptr->penChanged();
137 emit q_ptr->penChanged();
138 }
138 }
139
139
140 #include "moc_qpielegendmarker.cpp"
140 #include "moc_qpielegendmarker.cpp"
141 #include "moc_qpielegendmarker_p.cpp"
141 #include "moc_qpielegendmarker_p.cpp"
142
142
143 QTCOMMERCIALCHART_END_NAMESPACE
143 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,134 +1,134
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qxylegendmarker.h"
21 #include "qxylegendmarker.h"
22 #include "qxylegendmarker_p.h"
22 #include "qxylegendmarker_p.h"
23 #include "qxyseries_p.h"
23 #include "qxyseries_p.h"
24 #include <QXYSeries>
24 #include <QXYSeries>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QXYLegendMarker
29 \class QXYLegendMarker
30 \brief QXYLegendMarker object
30 \brief QXYLegendMarker object
31 \mainclass
31 \mainclass
32
32
33 QXYLegendMarker is related to QXYSeries derived classes. Each marker is related to one series.
33 QXYLegendMarker is related to QXYSeries derived classes. Each marker is related to one series.
34
34
35 \sa QLegend QXYSeries QSplineSeries QScatterSeries QLineSeries
35 \sa QLegend QXYSeries QSplineSeries QScatterSeries QLineSeries
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn virtual LegendMarkerType QXYLegendMarker::type()
39 \fn virtual LegendMarkerType QXYLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypeXY
40 Returns QLegendMarker::LegendMarkerTypeXY
41 */
41 */
42
42
43 /*!
43 /*!
44 Constructor
44 \internal
45 */
45 */
46 QXYLegendMarker::QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent) :
46 QXYLegendMarker::QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent) :
47 QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent)
47 QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent)
48 {
48 {
49 d_ptr->updated();
49 d_ptr->updated();
50 }
50 }
51
51
52 /*!
52 /*!
53 Destructor
53 Destructor
54 */
54 */
55 QXYLegendMarker::~QXYLegendMarker()
55 QXYLegendMarker::~QXYLegendMarker()
56 {
56 {
57 }
57 }
58
58
59 /*!
59 /*!
60 \internal
60 \internal
61 */
61 */
62 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
62 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
63 QLegendMarker(d, parent)
63 QLegendMarker(d, parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns the related series
68 Returns the related series
69 */
69 */
70 QXYSeries* QXYLegendMarker::series()
70 QXYSeries* QXYLegendMarker::series()
71 {
71 {
72 Q_D(QXYLegendMarker);
72 Q_D(QXYLegendMarker);
73 return d->m_series;
73 return d->m_series;
74 }
74 }
75
75
76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77
77
78 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
78 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
79 QLegendMarkerPrivate(q,legend),
79 QLegendMarkerPrivate(q,legend),
80 q_ptr(q),
80 q_ptr(q),
81 m_series(series)
81 m_series(series)
82 {
82 {
83 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
83 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
84 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
84 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
85 }
85 }
86
86
87 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
87 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
88 {
88 {
89 }
89 }
90
90
91 QAbstractSeries* QXYLegendMarkerPrivate::series()
91 QAbstractSeries* QXYLegendMarkerPrivate::series()
92 {
92 {
93 return m_series;
93 return m_series;
94 }
94 }
95
95
96 QObject* QXYLegendMarkerPrivate::relatedObject()
96 QObject* QXYLegendMarkerPrivate::relatedObject()
97 {
97 {
98 return m_series;
98 return m_series;
99 }
99 }
100
100
101 void QXYLegendMarkerPrivate::updated()
101 void QXYLegendMarkerPrivate::updated()
102 {
102 {
103 bool labelChanged = false;
103 bool labelChanged = false;
104 bool brushChanged = false;
104 bool brushChanged = false;
105
105
106 if (m_item->label() != m_series->name()) {
106 if (m_item->label() != m_series->name()) {
107 m_item->setLabel(m_series->name());
107 m_item->setLabel(m_series->name());
108 labelChanged = true;
108 labelChanged = true;
109 }
109 }
110
110
111 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
111 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
112 if (m_item->brush() != m_series->brush()) {
112 if (m_item->brush() != m_series->brush()) {
113 m_item->setBrush(m_series->brush());
113 m_item->setBrush(m_series->brush());
114 brushChanged = true;
114 brushChanged = true;
115 }
115 }
116 } else {
116 } else {
117 if (m_item->brush().color() != m_series->pen().color()) {
117 if (m_item->brush().color() != m_series->pen().color()) {
118 m_item->setBrush(QBrush(m_series->pen().color()));
118 m_item->setBrush(QBrush(m_series->pen().color()));
119 brushChanged = true;
119 brushChanged = true;
120 }
120 }
121 }
121 }
122 invalidateLegend();
122 invalidateLegend();
123
123
124 if (labelChanged)
124 if (labelChanged)
125 emit q_ptr->labelChanged();
125 emit q_ptr->labelChanged();
126 if (brushChanged)
126 if (brushChanged)
127 emit q_ptr->brushChanged();
127 emit q_ptr->brushChanged();
128 }
128 }
129
129
130 #include "moc_qxylegendmarker.cpp"
130 #include "moc_qxylegendmarker.cpp"
131 #include "moc_qxylegendmarker_p.cpp"
131 #include "moc_qxylegendmarker_p.cpp"
132
132
133 QTCOMMERCIALCHART_END_NAMESPACE
133 QTCOMMERCIALCHART_END_NAMESPACE
134
134
General Comments 0
You need to be logged in to leave comments. Login now