##// END OF EJS Templates
Documented QLegend label properties
Tero Ahola -
r1529:02a3b8a210d3
parent child
Show More
@@ -1,844 +1,869
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
26
27 #include "legendmarker_p.h"
27 #include "legendmarker_p.h"
28 #include "qxyseries.h"
28 #include "qxyseries.h"
29 #include "qlineseries.h"
29 #include "qlineseries.h"
30 #include "qareaseries.h"
30 #include "qareaseries.h"
31 #include "qscatterseries.h"
31 #include "qscatterseries.h"
32 #include "qsplineseries.h"
32 #include "qsplineseries.h"
33 #include "qbarseries.h"
33 #include "qbarseries.h"
34 #include "qstackedbarseries.h"
34 #include "qstackedbarseries.h"
35 #include "qpercentbarseries.h"
35 #include "qpercentbarseries.h"
36 #include "qbarset.h"
36 #include "qbarset.h"
37 #include "qpieseries.h"
37 #include "qpieseries.h"
38 #include "qpieseries_p.h"
38 #include "qpieseries_p.h"
39 #include "qpieslice.h"
39 #include "qpieslice.h"
40 #include "chartpresenter_p.h"
40 #include "chartpresenter_p.h"
41 #include <QPainter>
41 #include <QPainter>
42 #include <QPen>
42 #include <QPen>
43 #include <QTimer>
43 #include <QTimer>
44
44
45 #include <QGraphicsSceneEvent>
45 #include <QGraphicsSceneEvent>
46
46
47 QTCOMMERCIALCHART_BEGIN_NAMESPACE
47 QTCOMMERCIALCHART_BEGIN_NAMESPACE
48
48
49 /*!
49 /*!
50 \class QLegend
50 \class QLegend
51 \brief Legend object
51 \brief Legend object
52 \mainclass
52 \mainclass
53
53
54 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
54 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
55 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
55 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
56 handle the drawing manually.
56 handle the drawing manually.
57 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
57 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
58
58
59 \image examples_percentbarchart_legend.png
59 \image examples_percentbarchart_legend.png
60
60
61 \sa QChart
61 \sa QChart
62 */
62 */
63 /*!
63 /*!
64 \qmlclass Legend QLegend
64 \qmlclass Legend QLegend
65 \brief Legend is part of QtCommercial Chart QML API.
65 \brief Legend is part of QtCommercial Chart QML API.
66
66
67 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
67 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
68 series have been changed. Legend is used via ChartView class. For example:
68 series have been changed. Legend is used via ChartView class. For example:
69 \code
69 \code
70 ChartView {
70 ChartView {
71 legend.visible: true
71 legend.visible: true
72 legend.alignment: Qt.AlignBottom
72 legend.alignment: Qt.AlignBottom
73 // Add a few series...
73 // Add a few series...
74 }
74 }
75 \endcode
75 \endcode
76
76
77 \image examples_percentbarchart_legend.png
77 \image examples_percentbarchart_legend.png
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QLegend::alignment
81 \property QLegend::alignment
82 \brief The alignment of the legend.
82 \brief The alignment of the legend.
83
83
84 Legend paints on the defined position in the chart. The following alignments are supported:
84 Legend paints on the defined position in the chart. The following alignments are supported:
85 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
85 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
86 */
86 */
87 /*!
87 /*!
88 \qmlproperty Qt.Alignment Legend::alignment
88 \qmlproperty Qt.Alignment Legend::alignment
89 \brief The alignment of the legend.
89 \brief The alignment of the legend.
90
90
91 Legend paints on the defined position in the chart. The following alignments are supported:
91 Legend paints on the defined position in the chart. The following alignments are supported:
92 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
92 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
93 */
93 */
94
94
95 /*!
95 /*!
96 \property QLegend::backgroundVisible
96 \property QLegend::backgroundVisible
97 Whether the legend background is visible or not.
97 Whether the legend background is visible or not.
98 */
98 */
99 /*!
99 /*!
100 \qmlproperty bool Legend::backgroundVisible
100 \qmlproperty bool Legend::backgroundVisible
101 Whether the legend background is visible or not.
101 Whether the legend background is visible or not.
102 */
102 */
103
103
104 /*!
104 /*!
105 \property QLegend::color
105 \property QLegend::color
106 The color of the legend, i.e. the background (brush) color. Note that if you change the color
106 The color of the legend, i.e. the background (brush) color. Note that if you change the color
107 of the legend, the style of the legend brush is set to Qt::SolidPattern.
107 of the legend, the style of the legend brush is set to Qt::SolidPattern.
108 */
108 */
109 /*!
109 /*!
110 \qmlproperty color Legend::color
110 \qmlproperty color Legend::color
111 The color of the legend, i.e. the background (brush) color.
111 The color of the legend, i.e. the background (brush) color.
112 */
112 */
113
113
114 /*!
114 /*!
115 \property QLegend::borderColor
115 \property QLegend::borderColor
116 The border color of the legend, i.e. the line color.
116 The border color of the legend, i.e. the line color.
117 */
117 */
118 /*!
118 /*!
119 \qmlproperty color Legend::borderColor
119 \qmlproperty color Legend::borderColor
120 The border color of the legend, i.e. the line color.
120 The border color of the legend, i.e. the line color.
121 */
121 */
122
122
123 /*!
123 /*!
124 \property QLegend::font
124 \property QLegend::font
125 The font of markers used by legend
125 The font of markers used by legend
126 */
126 */
127 /*!
127 /*!
128 \qmlproperty color Legend::font
128 \qmlproperty color Legend::font
129 The font of markers used by legend
129 The font of markers used by legend
130 */
130 */
131
131
132 /*!
132 /*!
133 \property QLegend::labelColor
134 The color of brush used to draw labels.
135 */
136 /*!
137 \qmlproperty color QLegend::labelColor
138 The color of brush used to draw labels.
139 */
140
141 /*!
133 \fn void QLegend::backgroundVisibleChanged(bool)
142 \fn void QLegend::backgroundVisibleChanged(bool)
134 The visibility of the legend background changed to \a visible.
143 The visibility of the legend background changed to \a visible.
135 */
144 */
136
145
137 /*!
146 /*!
138 \fn void QLegend::colorChanged(QColor)
147 \fn void QLegend::colorChanged(QColor)
139 The color of the legend background changed to \a color.
148 The color of the legend background changed to \a color.
140 */
149 */
141
150
142 /*!
151 /*!
143 \fn void QLegend::borderColorChanged(QColor)
152 \fn void QLegend::borderColorChanged(QColor)
144 The border color of the legend background changed to \a color.
153 The border color of the legend background changed to \a color.
145 */
154 */
146
155
147 /*!
156 /*!
148 \fn void QLegend::fontChanged(QFont)
157 \fn void QLegend::fontChanged(QFont)
149 The font of markers of the legend changed to \a font.
158 The font of markers of the legend changed to \a font.
150 */
159 */
151
160
152 /*!
161 /*!
162 \fn void QLegend::labelBrushChanged(QBrush brush)
163 This signal is emitted when the brush used to draw labels has changed to \a brush.
164 */
165
166 /*!
167 \fn void QLegend::labelColorChanged(QColor color)
168 This signal is emitted when the color of brush used to draw labels has changed to \a color.
169 */
170
171 /*!
153 \fn qreal QLegend::minWidth() const
172 \fn qreal QLegend::minWidth() const
154 Returns minimum width of the legend
173 Returns minimum width of the legend
155 */
174 */
156
175
157 /*!
176 /*!
158 \fn qreal QLegend::minHeight() const
177 \fn qreal QLegend::minHeight() const
159 Returns minimum height of the legend
178 Returns minimum height of the legend
160 */
179 */
161
180
162 /*!
181 /*!
163 Constructs the legend object and sets the parent to \a parent
182 Constructs the legend object and sets the parent to \a parent
164 */
183 */
165
184
166 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
185 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
167 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this))
186 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this))
168 {
187 {
169 setZValue(ChartPresenter::LegendZValue);
188 setZValue(ChartPresenter::LegendZValue);
170 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
189 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
171 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
190 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
172 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*)));
191 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*)));
173 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
192 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
174 }
193 }
175
194
176 /*!
195 /*!
177 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
196 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
178 */
197 */
179 QLegend::~QLegend()
198 QLegend::~QLegend()
180 {
199 {
181 }
200 }
182
201
183 /*!
202 /*!
184 \internal
203 \internal
185 */
204 */
186 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
205 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
187 {
206 {
188 Q_UNUSED(option)
207 Q_UNUSED(option)
189 Q_UNUSED(widget)
208 Q_UNUSED(widget)
190 if(!d_ptr->m_backgroundVisible) return;
209 if(!d_ptr->m_backgroundVisible) return;
191
210
192 painter->setOpacity(opacity());
211 painter->setOpacity(opacity());
193 painter->setPen(d_ptr->m_pen);
212 painter->setPen(d_ptr->m_pen);
194 painter->setBrush(d_ptr->m_brush);
213 painter->setBrush(d_ptr->m_brush);
195 painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height()));
214 painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height()));
196 }
215 }
197
216
198 /*!
217 /*!
199 \internal
218 \internal
200 */
219 */
201 QRectF QLegend::boundingRect() const
220 QRectF QLegend::boundingRect() const
202 {
221 {
203 return d_ptr->m_rect;
222 return d_ptr->m_rect;
204 }
223 }
205
224
206 /*!
225 /*!
207 Sets the \a brush of legend. Brush affects the background of legend.
226 Sets the \a brush of legend. Brush affects the background of legend.
208 */
227 */
209 void QLegend::setBrush(const QBrush &brush)
228 void QLegend::setBrush(const QBrush &brush)
210 {
229 {
211 if (d_ptr->m_brush != brush) {
230 if (d_ptr->m_brush != brush) {
212 d_ptr->m_brush = brush;
231 d_ptr->m_brush = brush;
213 update();
232 update();
214 }
233 }
215 }
234 }
216
235
217 /*!
236 /*!
218 Returns the brush used by legend.
237 Returns the brush used by legend.
219 */
238 */
220 QBrush QLegend::brush() const
239 QBrush QLegend::brush() const
221 {
240 {
222 return d_ptr->m_brush;
241 return d_ptr->m_brush;
223 }
242 }
224
243
225 void QLegend::setColor(QColor color)
244 void QLegend::setColor(QColor color)
226 {
245 {
227 QBrush b = d_ptr->m_brush;
246 QBrush b = d_ptr->m_brush;
228 if (b.style() != Qt::SolidPattern || b.color() != color) {
247 if (b.style() != Qt::SolidPattern || b.color() != color) {
229 b.setStyle(Qt::SolidPattern);
248 b.setStyle(Qt::SolidPattern);
230 b.setColor(color);
249 b.setColor(color);
231 setBrush(b);
250 setBrush(b);
232 emit colorChanged(color);
251 emit colorChanged(color);
233 }
252 }
234 }
253 }
235
254
236 QColor QLegend::color()
255 QColor QLegend::color()
237 {
256 {
238 return d_ptr->m_brush.color();
257 return d_ptr->m_brush.color();
239 }
258 }
240
259
241 /*!
260 /*!
242 Sets the \a pen of legend. Pen affects the legend borders.
261 Sets the \a pen of legend. Pen affects the legend borders.
243 */
262 */
244 void QLegend::setPen(const QPen &pen)
263 void QLegend::setPen(const QPen &pen)
245 {
264 {
246 if (d_ptr->m_pen != pen) {
265 if (d_ptr->m_pen != pen) {
247 d_ptr->m_pen = pen;
266 d_ptr->m_pen = pen;
248 update();
267 update();
249 }
268 }
250 }
269 }
251
270
252 /*!
271 /*!
253 Returns the pen used by legend
272 Returns the pen used by legend
254 */
273 */
255
274
256 QPen QLegend::pen() const
275 QPen QLegend::pen() const
257 {
276 {
258 return d_ptr->m_pen;
277 return d_ptr->m_pen;
259 }
278 }
260
279
261 void QLegend::setBorderColor(QColor color)
280 void QLegend::setBorderColor(QColor color)
262 {
281 {
263 QPen p = d_ptr->m_pen;
282 QPen p = d_ptr->m_pen;
264 if (p.color() != color) {
283 if (p.color() != color) {
265 p.setColor(color);
284 p.setColor(color);
266 setPen(p);
285 setPen(p);
267 emit borderColorChanged(color);
286 emit borderColorChanged(color);
268 }
287 }
269 }
288 }
270
289
271 QColor QLegend::borderColor()
290 QColor QLegend::borderColor()
272 {
291 {
273 return d_ptr->m_pen.color();
292 return d_ptr->m_pen.color();
274 }
293 }
275
294
276 void QLegend::setFont(const QFont &font)
295 void QLegend::setFont(const QFont &font)
277 {
296 {
278 if (d_ptr->m_font != font) {
297 if (d_ptr->m_font != font) {
279 d_ptr->setFont(font);
298 d_ptr->setFont(font);
280 emit fontChanged(font);
299 emit fontChanged(font);
281 }
300 }
282 }
301 }
283
302
284 QFont QLegend::font() const
303 QFont QLegend::font() const
285 {
304 {
286 return d_ptr->m_font;
305 return d_ptr->m_font;
287 }
306 }
288
307
308 /*!
309 Set brush used to draw labels to \a brush.
310 */
289 void QLegend::setLabelBrush(const QBrush &brush)
311 void QLegend::setLabelBrush(const QBrush &brush)
290 {
312 {
291 if (d_ptr->m_labelBrush != brush) {
313 if (d_ptr->m_labelBrush != brush) {
292 d_ptr->setLabelBrush(brush);
314 d_ptr->setLabelBrush(brush);
293 emit labelBrushChanged(brush);
315 emit labelBrushChanged(brush);
294 }
316 }
295 }
317 }
296
318
319 /*!
320 Brush used to draw labels.
321 */
297 QBrush QLegend::labelBrush() const
322 QBrush QLegend::labelBrush() const
298 {
323 {
299 return d_ptr->m_labelBrush;
324 return d_ptr->m_labelBrush;
300 }
325 }
301
326
302 void QLegend::setLabelColor(QColor color)
327 void QLegend::setLabelColor(QColor color)
303 {
328 {
304 QBrush b = d_ptr->m_labelBrush;
329 QBrush b = d_ptr->m_labelBrush;
305 if (b.style() != Qt::SolidPattern || b.color() != color) {
330 if (b.style() != Qt::SolidPattern || b.color() != color) {
306 b.setStyle(Qt::SolidPattern);
331 b.setStyle(Qt::SolidPattern);
307 b.setColor(color);
332 b.setColor(color);
308 setLabelBrush(b);
333 setLabelBrush(b);
309 emit labelColorChanged(color);
334 emit labelColorChanged(color);
310 }
335 }
311 }
336 }
312
337
313 QColor QLegend::labelColor() const
338 QColor QLegend::labelColor() const
314 {
339 {
315 return d_ptr->m_labelBrush.color();
340 return d_ptr->m_labelBrush.color();
316 }
341 }
317
342
318 void QLegend::setAlignment(Qt::Alignment alignment)
343 void QLegend::setAlignment(Qt::Alignment alignment)
319 {
344 {
320 if(d_ptr->m_alignment!=alignment) {
345 if(d_ptr->m_alignment!=alignment) {
321 d_ptr->m_alignment = alignment;
346 d_ptr->m_alignment = alignment;
322 d_ptr->updateLayout();
347 d_ptr->updateLayout();
323 }
348 }
324 }
349 }
325
350
326 Qt::Alignment QLegend::alignment() const
351 Qt::Alignment QLegend::alignment() const
327 {
352 {
328 return d_ptr->m_alignment;
353 return d_ptr->m_alignment;
329 }
354 }
330
355
331 /*!
356 /*!
332 Detaches the legend from chart. Chart won't change layout of the legend.
357 Detaches the legend from chart. Chart won't change layout of the legend.
333 */
358 */
334 void QLegend::detachFromChart()
359 void QLegend::detachFromChart()
335 {
360 {
336 d_ptr->m_attachedToChart = false;
361 d_ptr->m_attachedToChart = false;
337 }
362 }
338
363
339 /*!
364 /*!
340 Attaches the legend to chart. Chart may change layout of the legend.
365 Attaches the legend to chart. Chart may change layout of the legend.
341 */
366 */
342 void QLegend::attachToChart()
367 void QLegend::attachToChart()
343 {
368 {
344 d_ptr->attachToChart();
369 d_ptr->attachToChart();
345 }
370 }
346
371
347 /*!
372 /*!
348 Returns true, if legend is attached to chart.
373 Returns true, if legend is attached to chart.
349 */
374 */
350 bool QLegend::isAttachedToChart()
375 bool QLegend::isAttachedToChart()
351 {
376 {
352 return d_ptr->m_attachedToChart;
377 return d_ptr->m_attachedToChart;
353 }
378 }
354
379
355 /*!
380 /*!
356 Sets the visibility of legend background to \a visible
381 Sets the visibility of legend background to \a visible
357 */
382 */
358 void QLegend::setBackgroundVisible(bool visible)
383 void QLegend::setBackgroundVisible(bool visible)
359 {
384 {
360 if(d_ptr->m_backgroundVisible != visible) {
385 if(d_ptr->m_backgroundVisible != visible) {
361 d_ptr->m_backgroundVisible = visible;
386 d_ptr->m_backgroundVisible = visible;
362 update();
387 update();
363 emit backgroundVisibleChanged(visible);
388 emit backgroundVisibleChanged(visible);
364 }
389 }
365 }
390 }
366
391
367 /*!
392 /*!
368 Returns the visibility of legend background
393 Returns the visibility of legend background
369 */
394 */
370 bool QLegend::isBackgroundVisible() const
395 bool QLegend::isBackgroundVisible() const
371 {
396 {
372 return d_ptr->m_backgroundVisible;
397 return d_ptr->m_backgroundVisible;
373 }
398 }
374
399
375 /*!
400 /*!
376 \internal \a event see QGraphicsWidget for details
401 \internal \a event see QGraphicsWidget for details
377 */
402 */
378 void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event)
403 void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event)
379 {
404 {
380 const QRectF& rect = QRectF(QPoint(0,0),event->newSize());
405 const QRectF& rect = QRectF(QPoint(0,0),event->newSize());
381 QGraphicsWidget::resizeEvent(event);
406 QGraphicsWidget::resizeEvent(event);
382 if(d_ptr->m_rect != rect) {
407 if(d_ptr->m_rect != rect) {
383 d_ptr->m_rect = rect;
408 d_ptr->m_rect = rect;
384 d_ptr->updateLayout();
409 d_ptr->updateLayout();
385 }
410 }
386 }
411 }
387
412
388 /*!
413 /*!
389 \internal \a event see QGraphicsWidget for details
414 \internal \a event see QGraphicsWidget for details
390 */
415 */
391 void QLegend::hideEvent(QHideEvent *event)
416 void QLegend::hideEvent(QHideEvent *event)
392 {
417 {
393 QGraphicsWidget::hideEvent(event);
418 QGraphicsWidget::hideEvent(event);
394 setEnabled(false);
419 setEnabled(false);
395 d_ptr->updateLayout();
420 d_ptr->updateLayout();
396 }
421 }
397
422
398 /*!
423 /*!
399 \internal \a event see QGraphicsWidget for details
424 \internal \a event see QGraphicsWidget for details
400 */
425 */
401 void QLegend::showEvent(QShowEvent *event)
426 void QLegend::showEvent(QShowEvent *event)
402 {
427 {
403 QGraphicsWidget::showEvent(event);
428 QGraphicsWidget::showEvent(event);
404 setEnabled(true);
429 setEnabled(true);
405 d_ptr->updateLayout();
430 d_ptr->updateLayout();
406 }
431 }
407
432
408 qreal QLegend::minWidth() const
433 qreal QLegend::minWidth() const
409 {
434 {
410 return d_ptr->m_minWidth;
435 return d_ptr->m_minWidth;
411 }
436 }
412
437
413 qreal QLegend::minHeight() const
438 qreal QLegend::minHeight() const
414 {
439 {
415 return d_ptr->m_minHeight;
440 return d_ptr->m_minHeight;
416 }
441 }
417
442
418 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
443 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
419
444
420 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q):
445 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q):
421 q_ptr(q),
446 q_ptr(q),
422 m_presenter(presenter),
447 m_presenter(presenter),
423 m_chart(chart),
448 m_chart(chart),
424 m_markers(new QGraphicsItemGroup(q)),
449 m_markers(new QGraphicsItemGroup(q)),
425 m_alignment(Qt::AlignTop),
450 m_alignment(Qt::AlignTop),
426 m_brush(QBrush()),
451 m_brush(QBrush()),
427 m_pen(QPen()),
452 m_pen(QPen()),
428 m_labelBrush(QBrush()),
453 m_labelBrush(QBrush()),
429 m_offsetX(0),
454 m_offsetX(0),
430 m_offsetY(0),
455 m_offsetY(0),
431 m_minWidth(0),
456 m_minWidth(0),
432 m_minHeight(0),
457 m_minHeight(0),
433 m_width(0),
458 m_width(0),
434 m_height(0),
459 m_height(0),
435 m_diameter(5),
460 m_diameter(5),
436 m_attachedToChart(true),
461 m_attachedToChart(true),
437 m_backgroundVisible(false)
462 m_backgroundVisible(false)
438 {
463 {
439
464
440 }
465 }
441
466
442 QLegendPrivate::~QLegendPrivate()
467 QLegendPrivate::~QLegendPrivate()
443 {
468 {
444
469
445 }
470 }
446
471
447 void QLegendPrivate::setOffset(qreal x, qreal y)
472 void QLegendPrivate::setOffset(qreal x, qreal y)
448 {
473 {
449 bool scrollHorizontal = true;
474 bool scrollHorizontal = true;
450 switch(m_alignment) {
475 switch(m_alignment) {
451 case Qt::AlignTop:
476 case Qt::AlignTop:
452 case Qt::AlignBottom: {
477 case Qt::AlignBottom: {
453 scrollHorizontal = true;
478 scrollHorizontal = true;
454 break;
479 break;
455 }
480 }
456 case Qt::AlignLeft:
481 case Qt::AlignLeft:
457 case Qt::AlignRight: {
482 case Qt::AlignRight: {
458 scrollHorizontal = false;
483 scrollHorizontal = false;
459 break;
484 break;
460 }
485 }
461 }
486 }
462
487
463 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
488 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
464 if (!m_attachedToChart) {
489 if (!m_attachedToChart) {
465 scrollHorizontal = !scrollHorizontal;
490 scrollHorizontal = !scrollHorizontal;
466 }
491 }
467
492
468 // Limit offset between m_minOffset and m_maxOffset
493 // Limit offset between m_minOffset and m_maxOffset
469 if (scrollHorizontal) {
494 if (scrollHorizontal) {
470 if(m_width<=m_rect.width()) return;
495 if(m_width<=m_rect.width()) return;
471
496
472 if (x != m_offsetX) {
497 if (x != m_offsetX) {
473 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
498 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
474 m_markers->setPos(-m_offsetX,m_rect.top());
499 m_markers->setPos(-m_offsetX,m_rect.top());
475 }
500 }
476 } else {
501 } else {
477 if(m_height<=m_rect.height()) return;
502 if(m_height<=m_rect.height()) return;
478
503
479 if (y != m_offsetY) {
504 if (y != m_offsetY) {
480 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
505 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
481 m_markers->setPos(m_rect.left(),-m_offsetY);
506 m_markers->setPos(m_rect.left(),-m_offsetY);
482 }
507 }
483 }
508 }
484 }
509 }
485
510
486 QPointF QLegendPrivate::offset() const
511 QPointF QLegendPrivate::offset() const
487 {
512 {
488 return QPointF(m_offsetX,m_offsetY);
513 return QPointF(m_offsetX,m_offsetY);
489 }
514 }
490
515
491 void QLegendPrivate::updateLayout()
516 void QLegendPrivate::updateLayout()
492 {
517 {
493 if (!m_attachedToChart) {
518 if (!m_attachedToChart) {
494 updateDetachedLayout();
519 updateDetachedLayout();
495 return;
520 return;
496 }
521 }
497
522
498 m_offsetX=0;
523 m_offsetX=0;
499 QList<QGraphicsItem *> items = m_markers->childItems();
524 QList<QGraphicsItem *> items = m_markers->childItems();
500
525
501 if(items.isEmpty()) return;
526 if(items.isEmpty()) return;
502
527
503 m_minWidth=0;
528 m_minWidth=0;
504 m_minHeight=0;
529 m_minHeight=0;
505
530
506 switch(m_alignment) {
531 switch(m_alignment) {
507
532
508 case Qt::AlignTop:
533 case Qt::AlignTop:
509 case Qt::AlignBottom: {
534 case Qt::AlignBottom: {
510 QPointF point = m_rect.topLeft();
535 QPointF point = m_rect.topLeft();
511 m_width = 0;
536 m_width = 0;
512 foreach (QGraphicsItem *item, items) {
537 foreach (QGraphicsItem *item, items) {
513 if (item->isVisible()) {
538 if (item->isVisible()) {
514 item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2);
539 item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2);
515 const QRectF& rect = item->boundingRect();
540 const QRectF& rect = item->boundingRect();
516 qreal w = rect.width();
541 qreal w = rect.width();
517 m_minWidth=qMax(m_minWidth,w);
542 m_minWidth=qMax(m_minWidth,w);
518 m_minHeight=qMax(m_minHeight,rect.height());
543 m_minHeight=qMax(m_minHeight,rect.height());
519 m_width+=w;
544 m_width+=w;
520 point.setX(point.x() + w);
545 point.setX(point.x() + w);
521 }
546 }
522 }
547 }
523 if(m_width<m_rect.width()) {
548 if(m_width<m_rect.width()) {
524 m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top());
549 m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top());
525 }
550 }
526 else {
551 else {
527 m_markers->setPos(m_rect.topLeft());
552 m_markers->setPos(m_rect.topLeft());
528 }
553 }
529 m_height=m_minHeight;
554 m_height=m_minHeight;
530 }
555 }
531 break;
556 break;
532 case Qt::AlignLeft:
557 case Qt::AlignLeft:
533 case Qt::AlignRight: {
558 case Qt::AlignRight: {
534 QPointF point = m_rect.topLeft();
559 QPointF point = m_rect.topLeft();
535 m_height = 0;
560 m_height = 0;
536 foreach (QGraphicsItem *item, items) {
561 foreach (QGraphicsItem *item, items) {
537 if (item->isVisible()) {
562 if (item->isVisible()) {
538 item->setPos(point);
563 item->setPos(point);
539 const QRectF& rect = item->boundingRect();
564 const QRectF& rect = item->boundingRect();
540 qreal h = rect.height();
565 qreal h = rect.height();
541 m_minWidth=qMax(m_minWidth,rect.width());
566 m_minWidth=qMax(m_minWidth,rect.width());
542 m_minHeight=qMax(m_minHeight,h);
567 m_minHeight=qMax(m_minHeight,h);
543 m_height+=h;
568 m_height+=h;
544 point.setY(point.y() + h);
569 point.setY(point.y() + h);
545 }
570 }
546 }
571 }
547 if(m_height<m_rect.height()) {
572 if(m_height<m_rect.height()) {
548 m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2);
573 m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2);
549 }
574 }
550 else {
575 else {
551 m_markers->setPos(m_rect.topLeft());
576 m_markers->setPos(m_rect.topLeft());
552 }
577 }
553 m_width=m_minWidth;
578 m_width=m_minWidth;
554 }
579 }
555 break;
580 break;
556 }
581 }
557
582
558 m_minOffsetX = 0;
583 m_minOffsetX = 0;
559 m_minOffsetY = 0;
584 m_minOffsetY = 0;
560 m_maxOffsetX = m_width - m_rect.width();
585 m_maxOffsetX = m_width - m_rect.width();
561 m_maxOffsetY = m_height - m_rect.height();
586 m_maxOffsetY = m_height - m_rect.height();
562
587
563 m_presenter->updateLayout();
588 m_presenter->updateLayout();
564 }
589 }
565
590
566 void QLegendPrivate::updateDetachedLayout()
591 void QLegendPrivate::updateDetachedLayout()
567 {
592 {
568 // Detached layout is different.
593 // Detached layout is different.
569 // In detached mode legend may have multiple rows and columns, so layout calculations
594 // In detached mode legend may have multiple rows and columns, so layout calculations
570 // differ a log from attached mode.
595 // differ a log from attached mode.
571 // Also the scrolling logic is bit different.
596 // Also the scrolling logic is bit different.
572 m_offsetX=0;
597 m_offsetX=0;
573 m_offsetY=0;
598 m_offsetY=0;
574 QList<QGraphicsItem *> items = m_markers->childItems();
599 QList<QGraphicsItem *> items = m_markers->childItems();
575
600
576 if(items.isEmpty()) return;
601 if(items.isEmpty()) return;
577
602
578 m_minWidth = 0;
603 m_minWidth = 0;
579 m_minHeight = 0;
604 m_minHeight = 0;
580
605
581 switch (m_alignment) {
606 switch (m_alignment) {
582 case Qt::AlignTop: {
607 case Qt::AlignTop: {
583 QPointF point = m_rect.topLeft();
608 QPointF point = m_rect.topLeft();
584 m_width = 0;
609 m_width = 0;
585 m_height = 0;
610 m_height = 0;
586 for (int i=0; i<items.count(); i++) {
611 for (int i=0; i<items.count(); i++) {
587 QGraphicsItem *item = items.at(i);
612 QGraphicsItem *item = items.at(i);
588 if (item->isVisible()) {
613 if (item->isVisible()) {
589 const QRectF& rect = item->boundingRect();
614 const QRectF& rect = item->boundingRect();
590 qreal w = rect.width();
615 qreal w = rect.width();
591 qreal h = rect.height();
616 qreal h = rect.height();
592 m_minWidth = qMax(m_minWidth,w);
617 m_minWidth = qMax(m_minWidth,w);
593 m_minHeight = qMax(m_minHeight,rect.height());
618 m_minHeight = qMax(m_minHeight,rect.height());
594 m_height = qMax(m_height,h);
619 m_height = qMax(m_height,h);
595 item->setPos(point.x(),point.y());
620 item->setPos(point.x(),point.y());
596 point.setX(point.x() + w);
621 point.setX(point.x() + w);
597 if (point.x() + w > m_rect.topLeft().x() + m_rect.width()) {
622 if (point.x() + w > m_rect.topLeft().x() + m_rect.width()) {
598 // Next item would go off rect.
623 // Next item would go off rect.
599 point.setX(m_rect.topLeft().x());
624 point.setX(m_rect.topLeft().x());
600 point.setY(point.y() + h);
625 point.setY(point.y() + h);
601 if (i+1 < items.count()) {
626 if (i+1 < items.count()) {
602 m_height += h;
627 m_height += h;
603 }
628 }
604 }
629 }
605 }
630 }
606 }
631 }
607 m_markers->setPos(m_rect.topLeft());
632 m_markers->setPos(m_rect.topLeft());
608 m_width = m_minWidth;
633 m_width = m_minWidth;
609
634
610 m_minOffsetX = 0;
635 m_minOffsetX = 0;
611 m_minOffsetY = 0;
636 m_minOffsetY = 0;
612 m_maxOffsetX = m_width - m_rect.width();
637 m_maxOffsetX = m_width - m_rect.width();
613 m_maxOffsetY = m_height - m_rect.height();
638 m_maxOffsetY = m_height - m_rect.height();
614 }
639 }
615 break;
640 break;
616 case Qt::AlignBottom: {
641 case Qt::AlignBottom: {
617 QPointF point = m_rect.bottomLeft();
642 QPointF point = m_rect.bottomLeft();
618 m_width = 0;
643 m_width = 0;
619 m_height = 0;
644 m_height = 0;
620 for (int i=0; i<items.count(); i++) {
645 for (int i=0; i<items.count(); i++) {
621 QGraphicsItem *item = items.at(i);
646 QGraphicsItem *item = items.at(i);
622 if (item->isVisible()) {
647 if (item->isVisible()) {
623 const QRectF& rect = item->boundingRect();
648 const QRectF& rect = item->boundingRect();
624 qreal w = rect.width();
649 qreal w = rect.width();
625 qreal h = rect.height();
650 qreal h = rect.height();
626 m_minWidth = qMax(m_minWidth,w);
651 m_minWidth = qMax(m_minWidth,w);
627 m_minHeight = qMax(m_minHeight,rect.height());
652 m_minHeight = qMax(m_minHeight,rect.height());
628 m_height = qMax(m_height,h);
653 m_height = qMax(m_height,h);
629 item->setPos(point.x(),point.y() - h);
654 item->setPos(point.x(),point.y() - h);
630 point.setX(point.x() + w);
655 point.setX(point.x() + w);
631 if (point.x() + w > m_rect.bottomLeft().x() + m_rect.width()) {
656 if (point.x() + w > m_rect.bottomLeft().x() + m_rect.width()) {
632 // Next item would go off rect.
657 // Next item would go off rect.
633 point.setX(m_rect.bottomLeft().x());
658 point.setX(m_rect.bottomLeft().x());
634 point.setY(point.y() - h);
659 point.setY(point.y() - h);
635 if (i+1 < items.count()) {
660 if (i+1 < items.count()) {
636 m_height += h;
661 m_height += h;
637 }
662 }
638 }
663 }
639 }
664 }
640 }
665 }
641 m_markers->setPos(m_rect.topLeft());
666 m_markers->setPos(m_rect.topLeft());
642 m_width = m_minWidth;
667 m_width = m_minWidth;
643
668
644 m_minOffsetX = 0;
669 m_minOffsetX = 0;
645 m_minOffsetY = qMin(m_rect.topLeft().y(), m_rect.topLeft().y() - m_height + m_rect.height());
670 m_minOffsetY = qMin(m_rect.topLeft().y(), m_rect.topLeft().y() - m_height + m_rect.height());
646 m_maxOffsetX = m_width - m_rect.width();
671 m_maxOffsetX = m_width - m_rect.width();
647 m_maxOffsetY = 0;
672 m_maxOffsetY = 0;
648 }
673 }
649 break;
674 break;
650 case Qt::AlignLeft: {
675 case Qt::AlignLeft: {
651 QPointF point = m_rect.topLeft();
676 QPointF point = m_rect.topLeft();
652 m_width = 0;
677 m_width = 0;
653 m_height = 0;
678 m_height = 0;
654 qreal maxWidth = 0;
679 qreal maxWidth = 0;
655 for (int i=0; i<items.count(); i++) {
680 for (int i=0; i<items.count(); i++) {
656 QGraphicsItem *item = items.at(i);
681 QGraphicsItem *item = items.at(i);
657 if (item->isVisible()) {
682 if (item->isVisible()) {
658 const QRectF& rect = item->boundingRect();
683 const QRectF& rect = item->boundingRect();
659 qreal w = rect.width();
684 qreal w = rect.width();
660 qreal h = rect.height();
685 qreal h = rect.height();
661 m_minWidth = qMax(m_minWidth,rect.width());
686 m_minWidth = qMax(m_minWidth,rect.width());
662 m_minHeight = qMax(m_minHeight,h);
687 m_minHeight = qMax(m_minHeight,h);
663 maxWidth = qMax(maxWidth,w);
688 maxWidth = qMax(maxWidth,w);
664 item->setPos(point.x(),point.y());
689 item->setPos(point.x(),point.y());
665 point.setY(point.y() + h);
690 point.setY(point.y() + h);
666 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
691 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
667 // Next item would go off rect.
692 // Next item would go off rect.
668 point.setX(point.x() + maxWidth);
693 point.setX(point.x() + maxWidth);
669 point.setY(m_rect.topLeft().y());
694 point.setY(m_rect.topLeft().y());
670 if (i+1 < items.count()) {
695 if (i+1 < items.count()) {
671 m_width += maxWidth;
696 m_width += maxWidth;
672 maxWidth = 0;
697 maxWidth = 0;
673 }
698 }
674 }
699 }
675 }
700 }
676 }
701 }
677 m_width += maxWidth;
702 m_width += maxWidth;
678 m_markers->setPos(m_rect.topLeft());
703 m_markers->setPos(m_rect.topLeft());
679 m_height = m_minHeight;
704 m_height = m_minHeight;
680
705
681 m_minOffsetX = 0;
706 m_minOffsetX = 0;
682 m_minOffsetY = 0;
707 m_minOffsetY = 0;
683 m_maxOffsetX = m_width - m_rect.width();
708 m_maxOffsetX = m_width - m_rect.width();
684 m_maxOffsetY = m_height - m_rect.height();
709 m_maxOffsetY = m_height - m_rect.height();
685 }
710 }
686 break;
711 break;
687 case Qt::AlignRight: {
712 case Qt::AlignRight: {
688 QPointF point = m_rect.topRight();
713 QPointF point = m_rect.topRight();
689 m_width = 0;
714 m_width = 0;
690 m_height = 0;
715 m_height = 0;
691 qreal maxWidth = 0;
716 qreal maxWidth = 0;
692 for (int i=0; i<items.count(); i++) {
717 for (int i=0; i<items.count(); i++) {
693 QGraphicsItem *item = items.at(i);
718 QGraphicsItem *item = items.at(i);
694 if (item->isVisible()) {
719 if (item->isVisible()) {
695 const QRectF& rect = item->boundingRect();
720 const QRectF& rect = item->boundingRect();
696 qreal w = rect.width();
721 qreal w = rect.width();
697 qreal h = rect.height();
722 qreal h = rect.height();
698 m_minWidth = qMax(m_minWidth,rect.width());
723 m_minWidth = qMax(m_minWidth,rect.width());
699 m_minHeight = qMax(m_minHeight,h);
724 m_minHeight = qMax(m_minHeight,h);
700 maxWidth = qMax(maxWidth,w);
725 maxWidth = qMax(maxWidth,w);
701 item->setPos(point.x() - w,point.y());
726 item->setPos(point.x() - w,point.y());
702 point.setY(point.y() + h);
727 point.setY(point.y() + h);
703 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
728 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
704 // Next item would go off rect.
729 // Next item would go off rect.
705 point.setX(point.x() - maxWidth);
730 point.setX(point.x() - maxWidth);
706 point.setY(m_rect.topLeft().y());
731 point.setY(m_rect.topLeft().y());
707 if (i+1 < items.count()) {
732 if (i+1 < items.count()) {
708 m_width += maxWidth;
733 m_width += maxWidth;
709 maxWidth = 0;
734 maxWidth = 0;
710 }
735 }
711 }
736 }
712 }
737 }
713 }
738 }
714 m_width += maxWidth;
739 m_width += maxWidth;
715 m_markers->setPos(m_rect.topLeft());
740 m_markers->setPos(m_rect.topLeft());
716 m_height = m_minHeight;
741 m_height = m_minHeight;
717
742
718 m_minOffsetX = qMin(m_rect.topLeft().x(), m_rect.topLeft().x() - m_width + m_rect.width());
743 m_minOffsetX = qMin(m_rect.topLeft().x(), m_rect.topLeft().x() - m_width + m_rect.width());
719 m_minOffsetY = 0;
744 m_minOffsetY = 0;
720 m_maxOffsetX = 0;
745 m_maxOffsetX = 0;
721 m_maxOffsetY = m_height - m_rect.height();
746 m_maxOffsetY = m_height - m_rect.height();
722 }
747 }
723 break;
748 break;
724 default:
749 default:
725 break;
750 break;
726 }
751 }
727 }
752 }
728
753
729 void QLegendPrivate::attachToChart()
754 void QLegendPrivate::attachToChart()
730 {
755 {
731 m_attachedToChart = true;
756 m_attachedToChart = true;
732 q_ptr->setParent(m_chart);
757 q_ptr->setParent(m_chart);
733 }
758 }
734
759
735 int QLegendPrivate::roundness(qreal size)
760 int QLegendPrivate::roundness(qreal size)
736 {
761 {
737 return 100*m_diameter/int(size);
762 return 100*m_diameter/int(size);
738 }
763 }
739
764
740 void QLegendPrivate::setFont(const QFont &font)
765 void QLegendPrivate::setFont(const QFont &font)
741 {
766 {
742 m_font = font;
767 m_font = font;
743 QList<QGraphicsItem *> items = m_markers->childItems();
768 QList<QGraphicsItem *> items = m_markers->childItems();
744
769
745 foreach (QGraphicsItem *markers, items) {
770 foreach (QGraphicsItem *markers, items) {
746 LegendMarker *marker = static_cast<LegendMarker*>(markers);
771 LegendMarker *marker = static_cast<LegendMarker*>(markers);
747 marker->setFont(m_font);
772 marker->setFont(m_font);
748 }
773 }
749 updateLayout();
774 updateLayout();
750 }
775 }
751
776
752 void QLegendPrivate::setLabelBrush(const QBrush &brush)
777 void QLegendPrivate::setLabelBrush(const QBrush &brush)
753 {
778 {
754 m_labelBrush = brush;
779 m_labelBrush = brush;
755 QList<QGraphicsItem *> items = m_markers->childItems();
780 QList<QGraphicsItem *> items = m_markers->childItems();
756
781
757 foreach (QGraphicsItem *markers, items) {
782 foreach (QGraphicsItem *markers, items) {
758 LegendMarker *marker = static_cast<LegendMarker*>(markers);
783 LegendMarker *marker = static_cast<LegendMarker*>(markers);
759 marker->setLabelBrush(m_labelBrush);
784 marker->setLabelBrush(m_labelBrush);
760 }
785 }
761 updateLayout();
786 updateLayout();
762 }
787 }
763
788
764 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
789 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
765 {
790 {
766 Q_UNUSED(domain)
791 Q_UNUSED(domain)
767
792
768 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
793 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
769 foreach(LegendMarker* marker, markers) {
794 foreach(LegendMarker* marker, markers) {
770 marker->setFont(m_font);
795 marker->setFont(m_font);
771 marker->setLabelBrush(m_labelBrush);
796 marker->setLabelBrush(m_labelBrush);
772 m_markers->addToGroup(marker);
797 m_markers->addToGroup(marker);
773 }
798 }
774
799
775 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
800 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
776
801
777 if(series->type() == QAbstractSeries::SeriesTypePie) {
802 if(series->type() == QAbstractSeries::SeriesTypePie) {
778 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
803 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
779 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
804 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
780 QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
805 QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
781 }
806 }
782
807
783 updateLayout();
808 updateLayout();
784 }
809 }
785
810
786 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
811 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
787 {
812 {
788 QList<QGraphicsItem *> items = m_markers->childItems();
813 QList<QGraphicsItem *> items = m_markers->childItems();
789
814
790 foreach (QGraphicsItem *markers, items) {
815 foreach (QGraphicsItem *markers, items) {
791 LegendMarker *marker = static_cast<LegendMarker*>(markers);
816 LegendMarker *marker = static_cast<LegendMarker*>(markers);
792 if (marker->series() == series) {
817 if (marker->series() == series) {
793 delete marker;
818 delete marker;
794 }
819 }
795 }
820 }
796
821
797 if(series->type() == QAbstractSeries::SeriesTypePie)
822 if(series->type() == QAbstractSeries::SeriesTypePie)
798 {
823 {
799 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
824 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
800 QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
825 QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
801 QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
826 QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
802 }
827 }
803
828
804 updateLayout();
829 updateLayout();
805 }
830 }
806
831
807 void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series)
832 void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series)
808 {
833 {
809 // TODO: find out which markers are are added or removed. Update them
834 // TODO: find out which markers are are added or removed. Update them
810 // TODO: better implementation
835 // TODO: better implementation
811 handleSeriesRemoved(series);
836 handleSeriesRemoved(series);
812 Domain domain;
837 Domain domain;
813 handleSeriesAdded(series, &domain);
838 handleSeriesAdded(series, &domain);
814 }
839 }
815
840
816 void QLegendPrivate::handleUpdatePieSeries()
841 void QLegendPrivate::handleUpdatePieSeries()
817 {
842 {
818 //TODO: reimplement to be optimal
843 //TODO: reimplement to be optimal
819 QPieSeries* series = qobject_cast<QPieSeries *> (sender());
844 QPieSeries* series = qobject_cast<QPieSeries *> (sender());
820 Q_ASSERT(series);
845 Q_ASSERT(series);
821 handleSeriesRemoved(series);
846 handleSeriesRemoved(series);
822 handleSeriesAdded(series, 0);
847 handleSeriesAdded(series, 0);
823 }
848 }
824
849
825 void QLegendPrivate::handleSeriesVisibleChanged()
850 void QLegendPrivate::handleSeriesVisibleChanged()
826 {
851 {
827 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
852 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
828 QList<QGraphicsItem *> items = m_markers->childItems();
853 QList<QGraphicsItem *> items = m_markers->childItems();
829
854
830 foreach (QGraphicsItem *markers, items) {
855 foreach (QGraphicsItem *markers, items) {
831 LegendMarker *marker = static_cast<LegendMarker*>(markers);
856 LegendMarker *marker = static_cast<LegendMarker*>(markers);
832 if (marker->series() == series) {
857 if (marker->series() == series) {
833 marker->setVisible(!marker->isVisible());
858 marker->setVisible(!marker->isVisible());
834 }
859 }
835 }
860 }
836
861
837 updateLayout();
862 updateLayout();
838 }
863 }
839
864
840
865
841 #include "moc_qlegend.cpp"
866 #include "moc_qlegend.cpp"
842 #include "moc_qlegend_p.cpp"
867 #include "moc_qlegend_p.cpp"
843
868
844 QTCOMMERCIALCHART_END_NAMESPACE
869 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,779 +1,779
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 "qpieslice.h"
21 #include "qpieslice.h"
22 #include "qpieslice_p.h"
22 #include "qpieslice_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QPieSlice
27 \class QPieSlice
28 \brief Defines a slice in pie series.
28 \brief Defines a slice in pie series.
29
29
30 This object defines the properties of a single slice in a QPieSeries.
30 This object defines the properties of a single slice in a QPieSeries.
31
31
32 In addition to the obvious value and label properties the user can also control
32 In addition to the obvious value and label properties the user can also control
33 the visual appearance of a slice. By modifying the visual appearance also means that
33 the visual appearance of a slice. By modifying the visual appearance also means that
34 the user is overriding the default appearance set by the theme.
34 the user is overriding the default appearance set by the theme.
35
35
36 Note that if the user has customized slices and theme is changed all customizations will be lost.
36 Note that if the user has customized slices and theme is changed all customizations will be lost.
37
37
38 To enable user interaction with the pie some basic signals are provided about clicking and hovering.
38 To enable user interaction with the pie some basic signals are provided about clicking and hovering.
39 */
39 */
40
40
41 /*!
41 /*!
42 \qmlclass PieSlice QPieSlice
42 \qmlclass PieSlice QPieSlice
43 PieSlice defines the properties of a single slice in a PieSeries. The element should be used
43 PieSlice defines the properties of a single slice in a PieSeries. The element should be used
44 as a child for a PieSeries. For example:
44 as a child for a PieSeries. For example:
45 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
45 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
46
46
47 An alternative (dynamic) method for adding slices to a PieSeries is using PieSeries.append
47 An alternative (dynamic) method for adding slices to a PieSeries is using PieSeries.append
48 method.
48 method.
49 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 4
49 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 4
50
50
51 In that case you may want to use PieSeries.at or PieSeries.find to access the properties of
51 In that case you may want to use PieSeries.at or PieSeries.find to access the properties of
52 an individual PieSlice instance.
52 an individual PieSlice instance.
53 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 5
53 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 5
54 \sa PieSeries
54 \sa PieSeries
55 */
55 */
56
56
57 /*!
57 /*!
58 \enum QPieSlice::LabelPosition
58 \enum QPieSlice::LabelPosition
59
59
60 This enum describes the position of the slice label.
60 This enum describes the position of the slice label.
61
61
62 \value LabelOutside Label is outside the slice with an arm.
62 \value LabelOutside Label is outside the slice with an arm.
63 \value LabelInside Label is centered inside the slice.
63 \value LabelInside Label is centered inside the slice.
64
64
65 */
65 */
66
66
67 /*!
67 /*!
68 \property QPieSlice::label
68 \property QPieSlice::label
69 Label of the slice.
69 Label of the slice.
70 \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor
70 \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor
71 */
71 */
72 /*!
72 /*!
73 \qmlproperty string PieSlice::label
73 \qmlproperty string PieSlice::label
74 Label (text) of the slice.
74 Label (text) of the slice.
75 */
75 */
76
76
77 /*!
77 /*!
78 \fn void QPieSlice::labelChanged()
78 \fn void QPieSlice::labelChanged()
79 This signal emitted when the slice label has been changed.
79 This signal emitted when the slice label has been changed.
80 \sa label
80 \sa label
81 */
81 */
82 /*!
82 /*!
83 \qmlsignal PieSlice::labelChanged()
83 \qmlsignal PieSlice::labelChanged()
84 This signal emitted when the slice label has been changed.
84 This signal emitted when the slice label has been changed.
85 \sa label
85 \sa label
86 */
86 */
87
87
88 /*!
88 /*!
89 \property QPieSlice::value
89 \property QPieSlice::value
90 Value of the slice.
90 Value of the slice.
91 Note that if users sets a negative value it is converted to a positive value.
91 Note that if users sets a negative value it is converted to a positive value.
92 \sa percentage(), QPieSeries::sum()
92 \sa percentage(), QPieSeries::sum()
93 */
93 */
94 /*!
94 /*!
95 \qmlproperty real PieSlice::value
95 \qmlproperty real PieSlice::value
96 Value of the slice. Note that if users sets a negative value it is converted to a positive value.
96 Value of the slice. Note that if users sets a negative value it is converted to a positive value.
97 */
97 */
98
98
99 /*!
99 /*!
100 \fn void QPieSlice::valueChanged()
100 \fn void QPieSlice::valueChanged()
101 This signal is emitted when the slice value changes.
101 This signal is emitted when the slice value changes.
102 \sa value
102 \sa value
103 */
103 */
104 /*!
104 /*!
105 \qmlsignal PieSlice::valueChanged()
105 \qmlsignal PieSlice::valueChanged()
106 This signal is emitted when the slice value changes.
106 This signal is emitted when the slice value changes.
107 \sa value
107 \sa value
108 */
108 */
109
109
110 /*!
110 /*!
111 \property QPieSlice::labelVisible
111 \property QPieSlice::labelVisible
112 Defines the visibility of slice label. By default the label is not visible.
112 Defines the visibility of slice label. By default the label is not visible.
113 \sa label, labelBrush, labelFont, labelArmLengthFactor
113 \sa label, labelBrush, labelFont, labelArmLengthFactor
114 */
114 */
115 /*!
115 /*!
116 \qmlproperty bool PieSlice::labelVisible
116 \qmlproperty bool PieSlice::labelVisible
117 Defines the visibility of slice label. By default the label is not visible.
117 Defines the visibility of slice label. By default the label is not visible.
118 */
118 */
119
119
120 /*!
120 /*!
121 \fn void QPieSlice::labelVisibleChanged()
121 \fn void QPieSlice::labelVisibleChanged()
122 This signal emitted when visibility of the slice label has changed.
122 This signal emitted when visibility of the slice label has changed.
123 \sa labelVisible
123 \sa labelVisible
124 */
124 */
125 /*!
125 /*!
126 \qmlsignal PieSlice::labelVisibleChanged()
126 \qmlsignal PieSlice::labelVisibleChanged()
127 This signal emitted when visibility of the slice label has changed.
127 This signal emitted when visibility of the slice label has changed.
128 \sa labelVisible
128 \sa labelVisible
129 */
129 */
130
130
131 /*!
131 /*!
132 \property QPieSlice::exploded
132 \property QPieSlice::exploded
133 If set to true the slice is "exploded" away from the pie.
133 If set to true the slice is "exploded" away from the pie.
134 \sa explodeDistanceFactor
134 \sa explodeDistanceFactor
135 */
135 */
136 /*!
136 /*!
137 \qmlproperty bool PieSlice::exploded
137 \qmlproperty bool PieSlice::exploded
138 If set to true the slice is "exploded" away from the pie.
138 If set to true the slice is "exploded" away from the pie.
139 \sa explodeDistanceFactor
139 \sa explodeDistanceFactor
140 */
140 */
141
141
142 /*!
142 /*!
143 \property QPieSlice::pen
143 \property QPieSlice::pen
144 Pen used to draw the slice border.
144 Pen used to draw the slice border.
145 */
145 */
146
146
147 /*!
147 /*!
148 \fn void QPieSlice::penChanged()
148 \fn void QPieSlice::penChanged()
149 This signal is emitted when the pen of the slice has changed.
149 This signal is emitted when the pen of the slice has changed.
150 \sa pen
150 \sa pen
151 */
151 */
152
152
153 /*!
153 /*!
154 \property QPieSlice::borderColor
154 \property QPieSlice::borderColor
155 Color used to draw the slice border.
155 Color used to draw the slice border.
156 This is a convenience property for modifying the slice pen.
156 This is a convenience property for modifying the slice pen.
157 \sa pen, borderWidth
157 \sa pen, borderWidth
158 */
158 */
159 /*!
159 /*!
160 \qmlproperty color PieSlice::borderColor
160 \qmlproperty color PieSlice::borderColor
161 Color used to draw the slice border (pen color).
161 Color used to draw the slice border (pen color).
162 \sa borderWidth
162 \sa borderWidth
163 */
163 */
164
164
165 /*!
165 /*!
166 \fn void QPieSlice::borderColorChanged()
166 \fn void QPieSlice::borderColorChanged()
167 This signal is emitted when slice border color changes.
167 This signal is emitted when slice border color changes.
168 \sa pen, borderColor
168 \sa pen, borderColor
169 */
169 */
170 /*!
170 /*!
171 \qmlsignal PieSlice::borderColorChanged()
171 \qmlsignal PieSlice::borderColorChanged()
172 This signal is emitted when slice border color changes.
172 This signal is emitted when slice border color changes.
173 \sa borderColor
173 \sa borderColor
174 */
174 */
175
175
176 /*!
176 /*!
177 \property QPieSlice::borderWidth
177 \property QPieSlice::borderWidth
178 Width of the slice border.
178 Width of the slice border.
179 This is a convenience property for modifying the slice pen.
179 This is a convenience property for modifying the slice pen.
180 \sa pen, borderColor
180 \sa pen, borderColor
181 */
181 */
182 /*!
182 /*!
183 \qmlproperty int PieSlice::borderWidth
183 \qmlproperty int PieSlice::borderWidth
184 Width of the slice border.
184 Width of the slice border.
185 This is a convenience property for modifying the slice pen.
185 This is a convenience property for modifying the slice pen.
186 \sa borderColor
186 \sa borderColor
187 */
187 */
188
188
189 /*!
189 /*!
190 \fn void QPieSlice::borderWidthChanged()
190 \fn void QPieSlice::borderWidthChanged()
191 This signal is emitted when slice border width changes.
191 This signal is emitted when slice border width changes.
192 \sa pen, borderWidth
192 \sa pen, borderWidth
193 */
193 */
194 /*!
194 /*!
195 \qmlsignal PieSlice::borderWidthChanged()
195 \qmlsignal PieSlice::borderWidthChanged()
196 This signal is emitted when slice border width changes.
196 This signal is emitted when slice border width changes.
197 \sa borderWidth
197 \sa borderWidth
198 */
198 */
199
199
200 /*!
200 /*!
201 \property QPieSlice::brush
201 \property QPieSlice::brush
202 Brush used to draw the slice.
202 Brush used to draw the slice.
203 */
203 */
204
204
205 /*!
205 /*!
206 \fn void QPieSlice::brushChanged()
206 \fn void QPieSlice::brushChanged()
207 This signal is emitted when the brush of the slice has changed.
207 This signal is emitted when the brush of the slice has changed.
208 \sa brush
208 \sa brush
209 */
209 */
210
210
211 /*!
211 /*!
212 \property QPieSlice::color
212 \property QPieSlice::color
213 Fill (brush) color of the slice.
213 Fill (brush) color of the slice.
214 This is a convenience property for modifying the slice brush.
214 This is a convenience property for modifying the slice brush.
215 \sa brush
215 \sa brush
216 */
216 */
217 /*!
217 /*!
218 \qmlproperty color PieSlice::color
218 \qmlproperty color PieSlice::color
219 Fill (brush) color of the slice.
219 Fill (brush) color of the slice.
220 */
220 */
221
221
222 /*!
222 /*!
223 \fn void QPieSlice::colorChanged()
223 \fn void QPieSlice::colorChanged()
224 This signal is emitted when slice color changes.
224 This signal is emitted when slice color changes.
225 \sa brush
225 \sa brush
226 */
226 */
227 /*!
227 /*!
228 \qmlsignal PieSlice::colorChanged()
228 \qmlsignal PieSlice::colorChanged()
229 This signal is emitted when slice color changes.
229 This signal is emitted when slice color changes.
230 */
230 */
231
231
232 /*!
232 /*!
233 \property QPieSlice::labelBrush
233 \property QPieSlice::labelBrush
234 Brush used to draw label and label arm of the slice.
234 Brush used to draw label and label arm of the slice.
235 \sa label, labelVisible, labelFont, labelArmLengthFactor
235 \sa label, labelVisible, labelFont, labelArmLengthFactor
236 */
236 */
237
237
238 /*!
238 /*!
239 \fn void QPieSlice::labelBrushChanged()
239 \fn void QPieSlice::labelBrushChanged()
240 This signal is emitted when the label pen of the slice has changed.
240 This signal is emitted when the label brush of the slice has changed.
241 \sa labelBrush
241 \sa labelBrush
242 */
242 */
243
243
244 /*!
244 /*!
245 \property QPieSlice::labelColor
245 \property QPieSlice::labelColor
246 Color used to draw the slice label.
246 Color used to draw the slice label.
247 This is a convenience property for modifying the slice label brush.
247 This is a convenience property for modifying the slice label brush.
248 \sa labelBrush
248 \sa labelBrush
249 */
249 */
250 /*!
250 /*!
251 \qmlproperty color PieSlice::labelColor
251 \qmlproperty color PieSlice::labelColor
252 Color used to draw the slice label.
252 Color used to draw the slice label.
253 */
253 */
254
254
255 /*!
255 /*!
256 \fn void QPieSlice::labelColorChanged()
256 \fn void QPieSlice::labelColorChanged()
257 This signal is emitted when slice label color changes.
257 This signal is emitted when slice label color changes.
258 \sa labelColor
258 \sa labelColor
259 */
259 */
260 /*!
260 /*!
261 \qmlsignal PieSlice::labelColorChanged()
261 \qmlsignal PieSlice::labelColorChanged()
262 This signal is emitted when slice label color changes.
262 This signal is emitted when slice label color changes.
263 \sa labelColor
263 \sa labelColor
264 */
264 */
265
265
266 /*!
266 /*!
267 \property QPieSlice::labelFont
267 \property QPieSlice::labelFont
268 Font used for drawing label text.
268 Font used for drawing label text.
269 \sa label, labelVisible, labelArmLengthFactor
269 \sa label, labelVisible, labelArmLengthFactor
270 */
270 */
271
271
272 /*!
272 /*!
273 \fn void QPieSlice::labelFontChanged()
273 \fn void QPieSlice::labelFontChanged()
274 This signal is emitted when the label font of the slice has changed.
274 This signal is emitted when the label font of the slice has changed.
275 \sa labelFont
275 \sa labelFont
276 */
276 */
277
277
278 /*!
278 /*!
279 \qmlproperty Font PieSlice::labelFont
279 \qmlproperty Font PieSlice::labelFont
280
280
281 Defines the font used for slice label.
281 Defines the font used for slice label.
282
282
283 See the \l {Font} {QML Font Element} for detailed documentation.
283 See the \l {Font} {QML Font Element} for detailed documentation.
284
284
285 \sa labelVisible, labelPosition
285 \sa labelVisible, labelPosition
286 */
286 */
287
287
288 /*!
288 /*!
289 \property QPieSlice::labelPosition
289 \property QPieSlice::labelPosition
290 Position of the slice label.
290 Position of the slice label.
291 \sa label, labelVisible
291 \sa label, labelVisible
292 */
292 */
293 /*!
293 /*!
294 \qmlproperty LabelPosition PieSlice::labelPosition
294 \qmlproperty LabelPosition PieSlice::labelPosition
295 Position of the slice label. One of PieSlice.LabelOutside or PieSlice.LabelInside.
295 Position of the slice label. One of PieSlice.LabelOutside or PieSlice.LabelInside.
296 \sa labelVisible
296 \sa labelVisible
297 */
297 */
298
298
299 /*!
299 /*!
300 \property QPieSlice::labelArmLengthFactor
300 \property QPieSlice::labelArmLengthFactor
301 Defines the length of the label arm.
301 Defines the length of the label arm.
302 The factor is relative to pie radius. For example:
302 The factor is relative to pie radius. For example:
303 1.0 means the length is the same as the radius.
303 1.0 means the length is the same as the radius.
304 0.5 means the length is half of the radius.
304 0.5 means the length is half of the radius.
305 By default the arm length is 0.15
305 By default the arm length is 0.15
306 \sa label, labelVisible, labelBrush, labelFont
306 \sa label, labelVisible, labelBrush, labelFont
307 */
307 */
308 /*!
308 /*!
309 \qmlproperty real PieSlice::labelArmLengthFactor
309 \qmlproperty real PieSlice::labelArmLengthFactor
310 Defines the length of the label arm.
310 Defines the length of the label arm.
311 The factor is relative to pie radius. For example:
311 The factor is relative to pie radius. For example:
312 1.0 means the length is the same as the radius.
312 1.0 means the length is the same as the radius.
313 0.5 means the length is half of the radius.
313 0.5 means the length is half of the radius.
314 By default the arm length is 0.15
314 By default the arm length is 0.15
315 \sa labelVisible
315 \sa labelVisible
316 */
316 */
317
317
318 /*!
318 /*!
319 \property QPieSlice::explodeDistanceFactor
319 \property QPieSlice::explodeDistanceFactor
320 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
320 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
321 The factor is relative to pie radius. For example:
321 The factor is relative to pie radius. For example:
322 1.0 means the distance is the same as the radius.
322 1.0 means the distance is the same as the radius.
323 0.5 means the distance is half of the radius.
323 0.5 means the distance is half of the radius.
324 By default the distance is is 0.15
324 By default the distance is is 0.15
325 \sa exploded
325 \sa exploded
326 */
326 */
327 /*!
327 /*!
328 \qmlproperty real PieSlice::explodeDistanceFactor
328 \qmlproperty real PieSlice::explodeDistanceFactor
329 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
329 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
330 The factor is relative to pie radius. For example:
330 The factor is relative to pie radius. For example:
331 1.0 means the distance is the same as the radius.
331 1.0 means the distance is the same as the radius.
332 0.5 means the distance is half of the radius.
332 0.5 means the distance is half of the radius.
333 By default the distance is is 0.15
333 By default the distance is is 0.15
334 \sa exploded
334 \sa exploded
335 */
335 */
336
336
337 /*!
337 /*!
338 \property QPieSlice::percentage
338 \property QPieSlice::percentage
339 Percentage of the slice compared to the sum of all slices in the series.
339 Percentage of the slice compared to the sum of all slices in the series.
340 The actual value ranges from 0.0 to 1.0.
340 The actual value ranges from 0.0 to 1.0.
341 Updated automatically once the slice is added to the series.
341 Updated automatically once the slice is added to the series.
342 \sa value, QPieSeries::sum
342 \sa value, QPieSeries::sum
343 */
343 */
344 /*!
344 /*!
345 \qmlproperty real PieSlice::percentage
345 \qmlproperty real PieSlice::percentage
346 Percentage of the slice compared to the sum of all slices in the series.
346 Percentage of the slice compared to the sum of all slices in the series.
347 The actual value ranges from 0.0 to 1.0.
347 The actual value ranges from 0.0 to 1.0.
348 Updated automatically once the slice is added to the series.
348 Updated automatically once the slice is added to the series.
349 */
349 */
350
350
351 /*!
351 /*!
352 \fn void QPieSlice::percentageChanged()
352 \fn void QPieSlice::percentageChanged()
353 This signal is emitted when the percentage of the slice has changed.
353 This signal is emitted when the percentage of the slice has changed.
354 \sa percentage
354 \sa percentage
355 */
355 */
356 /*!
356 /*!
357 \qmlsignal void PieSlice::percentageChanged()
357 \qmlsignal void PieSlice::percentageChanged()
358 This signal is emitted when the percentage of the slice has changed.
358 This signal is emitted when the percentage of the slice has changed.
359 \sa percentage
359 \sa percentage
360 */
360 */
361
361
362 /*!
362 /*!
363 \property QPieSlice::startAngle
363 \property QPieSlice::startAngle
364 Defines the starting angle of this slice in the series it belongs to.
364 Defines the starting angle of this slice in the series it belongs to.
365 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
365 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
366 Updated automatically once the slice is added to the series.
366 Updated automatically once the slice is added to the series.
367 */
367 */
368 /*!
368 /*!
369 \qmlproperty real PieSlice::startAngle
369 \qmlproperty real PieSlice::startAngle
370 Defines the starting angle of this slice in the series it belongs to.
370 Defines the starting angle of this slice in the series it belongs to.
371 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
371 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
372 Updated automatically once the slice is added to the series.
372 Updated automatically once the slice is added to the series.
373 */
373 */
374
374
375 /*!
375 /*!
376 \fn void QPieSlice::startAngleChanged()
376 \fn void QPieSlice::startAngleChanged()
377 This signal is emitted when the starting angle f the slice has changed.
377 This signal is emitted when the starting angle f the slice has changed.
378 \sa startAngle
378 \sa startAngle
379 */
379 */
380 /*!
380 /*!
381 \qmlsignal PieSlice::startAngleChanged()
381 \qmlsignal PieSlice::startAngleChanged()
382 This signal is emitted when the starting angle f the slice has changed.
382 This signal is emitted when the starting angle f the slice has changed.
383 \sa startAngle
383 \sa startAngle
384 */
384 */
385
385
386 /*!
386 /*!
387 \property QPieSlice::angleSpan
387 \property QPieSlice::angleSpan
388 Span of the slice in degrees.
388 Span of the slice in degrees.
389 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
389 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
390 Updated automatically once the slice is added to the series.
390 Updated automatically once the slice is added to the series.
391 */
391 */
392 /*!
392 /*!
393 \qmlproperty real PieSlice::angleSpan
393 \qmlproperty real PieSlice::angleSpan
394 Span of the slice in degrees.
394 Span of the slice in degrees.
395 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
395 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
396 Updated automatically once the slice is added to the series.
396 Updated automatically once the slice is added to the series.
397 */
397 */
398
398
399 /*!
399 /*!
400 \fn void QPieSlice::angleSpanChanged()
400 \fn void QPieSlice::angleSpanChanged()
401 This signal is emitted when the angle span of the slice has changed.
401 This signal is emitted when the angle span of the slice has changed.
402 \sa angleSpan
402 \sa angleSpan
403 */
403 */
404 /*!
404 /*!
405 \qmlsignal PieSlice::angleSpanChanged()
405 \qmlsignal PieSlice::angleSpanChanged()
406 This signal is emitted when the angle span of the slice has changed.
406 This signal is emitted when the angle span of the slice has changed.
407 \sa angleSpan
407 \sa angleSpan
408 */
408 */
409
409
410 /*!
410 /*!
411 \fn void QPieSlice::clicked()
411 \fn void QPieSlice::clicked()
412 This signal is emitted when user has clicked the slice.
412 This signal is emitted when user has clicked the slice.
413 \sa QPieSeries::clicked()
413 \sa QPieSeries::clicked()
414 */
414 */
415 /*!
415 /*!
416 \qmlsignal PieSlice::onClicked()
416 \qmlsignal PieSlice::onClicked()
417 This signal is emitted when user has clicked the slice.
417 This signal is emitted when user has clicked the slice.
418 */
418 */
419
419
420 /*!
420 /*!
421 \fn void QPieSlice::hovered(bool state)
421 \fn void QPieSlice::hovered(bool state)
422 This signal is emitted when user has hovered over or away from the slice.
422 This signal is emitted when user has hovered over or away from the slice.
423 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
423 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
424 \sa QPieSeries::hovered()
424 \sa QPieSeries::hovered()
425 */
425 */
426 /*!
426 /*!
427 \qmlsignal PieSlice::onHovered(bool state)
427 \qmlsignal PieSlice::onHovered(bool state)
428 This signal is emitted when user has hovered over or away from the slice.
428 This signal is emitted when user has hovered over or away from the slice.
429 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
429 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
430 */
430 */
431
431
432 /*!
432 /*!
433 Constructs an empty slice with a \a parent.
433 Constructs an empty slice with a \a parent.
434 \sa QPieSeries::append(), QPieSeries::insert()
434 \sa QPieSeries::append(), QPieSeries::insert()
435 */
435 */
436 QPieSlice::QPieSlice(QObject *parent)
436 QPieSlice::QPieSlice(QObject *parent)
437 :QObject(parent),
437 :QObject(parent),
438 d_ptr(new QPieSlicePrivate(this))
438 d_ptr(new QPieSlicePrivate(this))
439 {
439 {
440
440
441 }
441 }
442
442
443 /*!
443 /*!
444 Constructs an empty slice with given \a value, \a label and a \a parent.
444 Constructs an empty slice with given \a value, \a label and a \a parent.
445 \sa QPieSeries::append(), QPieSeries::insert()
445 \sa QPieSeries::append(), QPieSeries::insert()
446 */
446 */
447 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
447 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
448 :QObject(parent),
448 :QObject(parent),
449 d_ptr(new QPieSlicePrivate(this))
449 d_ptr(new QPieSlicePrivate(this))
450 {
450 {
451 setValue(value);
451 setValue(value);
452 setLabel(label);
452 setLabel(label);
453 }
453 }
454
454
455 /*!
455 /*!
456 Destroys the slice.
456 Destroys the slice.
457 User should not delete the slice if it has been added to the series.
457 User should not delete the slice if it has been added to the series.
458 */
458 */
459 QPieSlice::~QPieSlice()
459 QPieSlice::~QPieSlice()
460 {
460 {
461
461
462 }
462 }
463
463
464 void QPieSlice::setLabel(QString label)
464 void QPieSlice::setLabel(QString label)
465 {
465 {
466 if (d_ptr->m_data.m_labelText != label) {
466 if (d_ptr->m_data.m_labelText != label) {
467 d_ptr->m_data.m_labelText = label;
467 d_ptr->m_data.m_labelText = label;
468 emit labelChanged();
468 emit labelChanged();
469 }
469 }
470 }
470 }
471
471
472 QString QPieSlice::label() const
472 QString QPieSlice::label() const
473 {
473 {
474 return d_ptr->m_data.m_labelText;
474 return d_ptr->m_data.m_labelText;
475 }
475 }
476
476
477 void QPieSlice::setValue(qreal value)
477 void QPieSlice::setValue(qreal value)
478 {
478 {
479 value = qAbs(value); // negative values not allowed
479 value = qAbs(value); // negative values not allowed
480 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
480 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
481 d_ptr->m_data.m_value = value;
481 d_ptr->m_data.m_value = value;
482 emit valueChanged();
482 emit valueChanged();
483 }
483 }
484 }
484 }
485
485
486 qreal QPieSlice::value() const
486 qreal QPieSlice::value() const
487 {
487 {
488 return d_ptr->m_data.m_value;
488 return d_ptr->m_data.m_value;
489 }
489 }
490
490
491 void QPieSlice::setLabelVisible(bool visible)
491 void QPieSlice::setLabelVisible(bool visible)
492 {
492 {
493 if (d_ptr->m_data.m_isLabelVisible != visible) {
493 if (d_ptr->m_data.m_isLabelVisible != visible) {
494 d_ptr->m_data.m_isLabelVisible = visible;
494 d_ptr->m_data.m_isLabelVisible = visible;
495 emit labelVisibleChanged();
495 emit labelVisibleChanged();
496 }
496 }
497 }
497 }
498
498
499 bool QPieSlice::isLabelVisible() const
499 bool QPieSlice::isLabelVisible() const
500 {
500 {
501 return d_ptr->m_data.m_isLabelVisible;
501 return d_ptr->m_data.m_isLabelVisible;
502 }
502 }
503
503
504 void QPieSlice::setExploded(bool exploded)
504 void QPieSlice::setExploded(bool exploded)
505 {
505 {
506 if (d_ptr->m_data.m_isExploded != exploded) {
506 if (d_ptr->m_data.m_isExploded != exploded) {
507 d_ptr->m_data.m_isExploded = exploded;
507 d_ptr->m_data.m_isExploded = exploded;
508 emit d_ptr->explodedChanged();
508 emit d_ptr->explodedChanged();
509 }
509 }
510 }
510 }
511
511
512 QPieSlice::LabelPosition QPieSlice::labelPosition()
512 QPieSlice::LabelPosition QPieSlice::labelPosition()
513 {
513 {
514 return d_ptr->m_data.m_labelPosition;
514 return d_ptr->m_data.m_labelPosition;
515 }
515 }
516
516
517 void QPieSlice::setLabelPosition(LabelPosition position)
517 void QPieSlice::setLabelPosition(LabelPosition position)
518 {
518 {
519 if (d_ptr->m_data.m_labelPosition != position) {
519 if (d_ptr->m_data.m_labelPosition != position) {
520 d_ptr->m_data.m_labelPosition = position;
520 d_ptr->m_data.m_labelPosition = position;
521 emit d_ptr->labelPositionChanged();
521 emit d_ptr->labelPositionChanged();
522 }
522 }
523 }
523 }
524
524
525 bool QPieSlice::isExploded() const
525 bool QPieSlice::isExploded() const
526 {
526 {
527 return d_ptr->m_data.m_isExploded;
527 return d_ptr->m_data.m_isExploded;
528 }
528 }
529
529
530 void QPieSlice::setPen(const QPen &pen)
530 void QPieSlice::setPen(const QPen &pen)
531 {
531 {
532 d_ptr->setPen(pen, false);
532 d_ptr->setPen(pen, false);
533 }
533 }
534
534
535 QPen QPieSlice::pen() const
535 QPen QPieSlice::pen() const
536 {
536 {
537 return d_ptr->m_data.m_slicePen;
537 return d_ptr->m_data.m_slicePen;
538 }
538 }
539
539
540 QColor QPieSlice::borderColor()
540 QColor QPieSlice::borderColor()
541 {
541 {
542 return pen().color();
542 return pen().color();
543 }
543 }
544
544
545 void QPieSlice::setBorderColor(QColor color)
545 void QPieSlice::setBorderColor(QColor color)
546 {
546 {
547 QPen p = pen();
547 QPen p = pen();
548 if (color != p.color()) {
548 if (color != p.color()) {
549 p.setColor(color);
549 p.setColor(color);
550 setPen(p);
550 setPen(p);
551 }
551 }
552 }
552 }
553
553
554 int QPieSlice::borderWidth()
554 int QPieSlice::borderWidth()
555 {
555 {
556 return pen().width();
556 return pen().width();
557 }
557 }
558
558
559 void QPieSlice::setBorderWidth(int width)
559 void QPieSlice::setBorderWidth(int width)
560 {
560 {
561 QPen p = pen();
561 QPen p = pen();
562 if (width != p.width()) {
562 if (width != p.width()) {
563 p.setWidth(width);
563 p.setWidth(width);
564 setPen(p);
564 setPen(p);
565 }
565 }
566 }
566 }
567
567
568 void QPieSlice::setBrush(const QBrush &brush)
568 void QPieSlice::setBrush(const QBrush &brush)
569 {
569 {
570 d_ptr->setBrush(brush, false);
570 d_ptr->setBrush(brush, false);
571 }
571 }
572
572
573 QBrush QPieSlice::brush() const
573 QBrush QPieSlice::brush() const
574 {
574 {
575 return d_ptr->m_data.m_sliceBrush;
575 return d_ptr->m_data.m_sliceBrush;
576 }
576 }
577
577
578 QColor QPieSlice::color()
578 QColor QPieSlice::color()
579 {
579 {
580 return brush().color();
580 return brush().color();
581 }
581 }
582
582
583 void QPieSlice::setColor(QColor color)
583 void QPieSlice::setColor(QColor color)
584 {
584 {
585 QBrush b = brush();
585 QBrush b = brush();
586 if (color != b.color()) {
586 if (color != b.color()) {
587 b.setColor(color);
587 b.setColor(color);
588 setBrush(b);
588 setBrush(b);
589 }
589 }
590 }
590 }
591
591
592 void QPieSlice::setLabelBrush(const QBrush &brush)
592 void QPieSlice::setLabelBrush(const QBrush &brush)
593 {
593 {
594 d_ptr->setLabelBrush(brush, false);
594 d_ptr->setLabelBrush(brush, false);
595 }
595 }
596
596
597 QBrush QPieSlice::labelBrush() const
597 QBrush QPieSlice::labelBrush() const
598 {
598 {
599 return d_ptr->m_data.m_labelBrush;
599 return d_ptr->m_data.m_labelBrush;
600 }
600 }
601
601
602 QColor QPieSlice::labelColor()
602 QColor QPieSlice::labelColor()
603 {
603 {
604 return labelBrush().color();
604 return labelBrush().color();
605 }
605 }
606
606
607 void QPieSlice::setLabelColor(QColor color)
607 void QPieSlice::setLabelColor(QColor color)
608 {
608 {
609 QBrush b = labelBrush();
609 QBrush b = labelBrush();
610 if (color != b.color()) {
610 if (color != b.color()) {
611 b.setColor(color);
611 b.setColor(color);
612 setLabelBrush(b);
612 setLabelBrush(b);
613 }
613 }
614 }
614 }
615
615
616 void QPieSlice::setLabelFont(const QFont &font)
616 void QPieSlice::setLabelFont(const QFont &font)
617 {
617 {
618 d_ptr->setLabelFont(font, false);
618 d_ptr->setLabelFont(font, false);
619 }
619 }
620
620
621 QFont QPieSlice::labelFont() const
621 QFont QPieSlice::labelFont() const
622 {
622 {
623 return d_ptr->m_data.m_labelFont;
623 return d_ptr->m_data.m_labelFont;
624 }
624 }
625
625
626 void QPieSlice::setLabelArmLengthFactor(qreal factor)
626 void QPieSlice::setLabelArmLengthFactor(qreal factor)
627 {
627 {
628 if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) {
628 if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) {
629 d_ptr->m_data.m_labelArmLengthFactor = factor;
629 d_ptr->m_data.m_labelArmLengthFactor = factor;
630 emit d_ptr->labelArmLengthFactorChanged();
630 emit d_ptr->labelArmLengthFactorChanged();
631 }
631 }
632 }
632 }
633
633
634 qreal QPieSlice::labelArmLengthFactor() const
634 qreal QPieSlice::labelArmLengthFactor() const
635 {
635 {
636 return d_ptr->m_data.m_labelArmLengthFactor;
636 return d_ptr->m_data.m_labelArmLengthFactor;
637 }
637 }
638
638
639 void QPieSlice::setExplodeDistanceFactor(qreal factor)
639 void QPieSlice::setExplodeDistanceFactor(qreal factor)
640 {
640 {
641 if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) {
641 if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) {
642 d_ptr->m_data.m_explodeDistanceFactor = factor;
642 d_ptr->m_data.m_explodeDistanceFactor = factor;
643 emit d_ptr->explodeDistanceFactorChanged();
643 emit d_ptr->explodeDistanceFactorChanged();
644 }
644 }
645 }
645 }
646
646
647 qreal QPieSlice::explodeDistanceFactor() const
647 qreal QPieSlice::explodeDistanceFactor() const
648 {
648 {
649 return d_ptr->m_data.m_explodeDistanceFactor;
649 return d_ptr->m_data.m_explodeDistanceFactor;
650 }
650 }
651
651
652 qreal QPieSlice::percentage() const
652 qreal QPieSlice::percentage() const
653 {
653 {
654 return d_ptr->m_data.m_percentage;
654 return d_ptr->m_data.m_percentage;
655 }
655 }
656
656
657 qreal QPieSlice::startAngle() const
657 qreal QPieSlice::startAngle() const
658 {
658 {
659 return d_ptr->m_data.m_startAngle;
659 return d_ptr->m_data.m_startAngle;
660 }
660 }
661
661
662 qreal QPieSlice::angleSpan() const
662 qreal QPieSlice::angleSpan() const
663 {
663 {
664 return d_ptr->m_data.m_angleSpan;
664 return d_ptr->m_data.m_angleSpan;
665 }
665 }
666
666
667 /*!
667 /*!
668 Returns the series that this slice belongs to.
668 Returns the series that this slice belongs to.
669
669
670 \sa QPieSeries::append()
670 \sa QPieSeries::append()
671 */
671 */
672 QPieSeries *QPieSlice::series() const
672 QPieSeries *QPieSlice::series() const
673 {
673 {
674 return d_ptr->m_series;
674 return d_ptr->m_series;
675 }
675 }
676
676
677 QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent)
677 QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent)
678 :QObject(parent),
678 :QObject(parent),
679 q_ptr(parent),
679 q_ptr(parent),
680 m_series(0)
680 m_series(0)
681 {
681 {
682
682
683 }
683 }
684
684
685 QPieSlicePrivate::~QPieSlicePrivate()
685 QPieSlicePrivate::~QPieSlicePrivate()
686 {
686 {
687
687
688 }
688 }
689
689
690 QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice)
690 QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice)
691 {
691 {
692 return slice->d_func();
692 return slice->d_func();
693 }
693 }
694
694
695 void QPieSlicePrivate::setPen(const QPen &pen, bool themed)
695 void QPieSlicePrivate::setPen(const QPen &pen, bool themed)
696 {
696 {
697 if (m_data.m_slicePen != pen) {
697 if (m_data.m_slicePen != pen) {
698
698
699 QPen oldPen = m_data.m_slicePen;
699 QPen oldPen = m_data.m_slicePen;
700
700
701 m_data.m_slicePen = pen;
701 m_data.m_slicePen = pen;
702 m_data.m_slicePen.setThemed(themed);
702 m_data.m_slicePen.setThemed(themed);
703
703
704 emit q_ptr->penChanged();
704 emit q_ptr->penChanged();
705 if (oldPen.color() != pen.color())
705 if (oldPen.color() != pen.color())
706 emit q_ptr->borderColorChanged();
706 emit q_ptr->borderColorChanged();
707 if (oldPen.width() != pen.width())
707 if (oldPen.width() != pen.width())
708 emit q_ptr->borderWidthChanged();
708 emit q_ptr->borderWidthChanged();
709 }
709 }
710 }
710 }
711
711
712 void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed)
712 void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed)
713 {
713 {
714 if (m_data.m_sliceBrush != brush) {
714 if (m_data.m_sliceBrush != brush) {
715
715
716 QBrush oldBrush = m_data.m_sliceBrush;
716 QBrush oldBrush = m_data.m_sliceBrush;
717
717
718 m_data.m_sliceBrush = brush;
718 m_data.m_sliceBrush = brush;
719 m_data.m_sliceBrush.setThemed(themed);
719 m_data.m_sliceBrush.setThemed(themed);
720
720
721 emit q_ptr->brushChanged();
721 emit q_ptr->brushChanged();
722 if (oldBrush.color() != brush.color())
722 if (oldBrush.color() != brush.color())
723 emit q_ptr->colorChanged();
723 emit q_ptr->colorChanged();
724 }
724 }
725 }
725 }
726
726
727 void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed)
727 void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed)
728 {
728 {
729 if (m_data.m_labelBrush != brush) {
729 if (m_data.m_labelBrush != brush) {
730
730
731 QBrush oldBrush = m_data.m_labelBrush;
731 QBrush oldBrush = m_data.m_labelBrush;
732
732
733 m_data.m_labelBrush = brush;
733 m_data.m_labelBrush = brush;
734 m_data.m_labelBrush.setThemed(themed);
734 m_data.m_labelBrush.setThemed(themed);
735
735
736 emit q_ptr->labelBrushChanged();
736 emit q_ptr->labelBrushChanged();
737 if (oldBrush.color() != brush.color())
737 if (oldBrush.color() != brush.color())
738 emit q_ptr->labelColorChanged();
738 emit q_ptr->labelColorChanged();
739 }
739 }
740 }
740 }
741
741
742 void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed)
742 void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed)
743 {
743 {
744 if (m_data.m_labelFont != font) {
744 if (m_data.m_labelFont != font) {
745 m_data.m_labelFont = font;
745 m_data.m_labelFont = font;
746 m_data.m_labelFont.setThemed(themed);
746 m_data.m_labelFont.setThemed(themed);
747 emit q_ptr->labelFontChanged();
747 emit q_ptr->labelFontChanged();
748 }
748 }
749 }
749 }
750
750
751 void QPieSlicePrivate::setPercentage(qreal percentage)
751 void QPieSlicePrivate::setPercentage(qreal percentage)
752 {
752 {
753 if (!qFuzzyIsNull(m_data.m_percentage - percentage)) {
753 if (!qFuzzyIsNull(m_data.m_percentage - percentage)) {
754 m_data.m_percentage = percentage;
754 m_data.m_percentage = percentage;
755 emit q_ptr->percentageChanged();
755 emit q_ptr->percentageChanged();
756 }
756 }
757 }
757 }
758
758
759 void QPieSlicePrivate::setStartAngle(qreal angle)
759 void QPieSlicePrivate::setStartAngle(qreal angle)
760 {
760 {
761 if (!qFuzzyIsNull(m_data.m_startAngle - angle)) {
761 if (!qFuzzyIsNull(m_data.m_startAngle - angle)) {
762 m_data.m_startAngle = angle;
762 m_data.m_startAngle = angle;
763 emit q_ptr->startAngleChanged();
763 emit q_ptr->startAngleChanged();
764 }
764 }
765 }
765 }
766
766
767 void QPieSlicePrivate::setAngleSpan(qreal span)
767 void QPieSlicePrivate::setAngleSpan(qreal span)
768 {
768 {
769 if (!qFuzzyIsNull(m_data.m_angleSpan - span)) {
769 if (!qFuzzyIsNull(m_data.m_angleSpan - span)) {
770 m_data.m_angleSpan = span;
770 m_data.m_angleSpan = span;
771 emit q_ptr->angleSpanChanged();
771 emit q_ptr->angleSpanChanged();
772 }
772 }
773 }
773 }
774
774
775 QTCOMMERCIALCHART_END_NAMESPACE
775 QTCOMMERCIALCHART_END_NAMESPACE
776
776
777 QTCOMMERCIALCHART_USE_NAMESPACE
777 QTCOMMERCIALCHART_USE_NAMESPACE
778 #include "moc_qpieslice.cpp"
778 #include "moc_qpieslice.cpp"
779 #include "moc_qpieslice_p.cpp"
779 #include "moc_qpieslice_p.cpp"
General Comments 0
You need to be logged in to leave comments. Login now