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