##// END OF EJS Templates
Removed a few signals from QPieSeries API
Tero Ahola -
r1482:57681a863659
parent child
Show More
@@ -1,215 +1,216
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 "piechartitem_p.h"
22 22 #include "piesliceitem_p.h"
23 23 #include "qpieslice.h"
24 24 #include "qpieslice_p.h"
25 25 #include "qpieseries.h"
26 26 #include "qpieseries_p.h"
27 27 #include "chartpresenter_p.h"
28 28 #include "chartdataset_p.h"
29 29 #include "chartanimator_p.h"
30 30 #include <QPainter>
31 31 #include <QTimer>
32 32
33 33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 34
35 35 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter)
36 36 :ChartItem(presenter),
37 37 m_series(series)
38 38 {
39 39 Q_ASSERT(series);
40 40
41 QPieSeriesPrivate *p = QPieSeriesPrivate::fromSeries(series);
41 42 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
42 43 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
43 44 connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
44 connect(series, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout()));
45 connect(series, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout()));
46 connect(series, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout()));
47 connect(QPieSeriesPrivate::fromSeries(series), SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout()));
45 connect(p, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout()));
46 connect(p, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout()));
47 connect(p, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout()));
48 connect(p, SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout()));
48 49
49 50 // Note: the following does not affect as long as the item does not have anything to paint
50 51 setZValue(ChartPresenter::PieSeriesZValue);
51 52
52 53 // Note: will not create slice items until we have a proper rectangle to draw on.
53 54 }
54 55
55 56 PieChartItem::~PieChartItem()
56 57 {
57 58 // slices deleted automatically through QGraphicsItem
58 59 }
59 60
60 61 void PieChartItem::handleGeometryChanged(const QRectF& rect)
61 62 {
62 63 prepareGeometryChange();
63 64 m_rect = rect;
64 65 updateLayout();
65 66
66 67 // This is for delayed initialization of the slice items during startup.
67 68 // It ensures that startup animation originates from the correct position.
68 69 if (m_sliceItems.isEmpty())
69 70 handleSlicesAdded(m_series->slices());
70 71 }
71 72
72 73 void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
73 74 {
74 75 Q_UNUSED(minX);
75 76 Q_UNUSED(maxX);
76 77 Q_UNUSED(minY);
77 78 Q_UNUSED(maxY);
78 79 // does not apply to pie
79 80 }
80 81
81 82 void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount)
82 83 {
83 84 Q_UNUSED(min);
84 85 Q_UNUSED(max);
85 86 Q_UNUSED(tickXCount);
86 87 // does not apply to pie
87 88 }
88 89
89 90 void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount)
90 91 {
91 92 Q_UNUSED(min);
92 93 Q_UNUSED(max);
93 94 Q_UNUSED(tickYCount);
94 95 // does not apply to pie
95 96 }
96 97
97 98 void PieChartItem::updateLayout()
98 99 {
99 100 // find pie center coordinates
100 101 m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->horizontalPosition()));
101 102 m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->verticalPosition()));
102 103
103 104 // find maximum radius for pie
104 105 m_pieRadius = m_rect.height() / 2;
105 106 if (m_rect.width() < m_rect.height())
106 107 m_pieRadius = m_rect.width() / 2;
107 108
108 109 // apply size factor
109 110 m_pieRadius *= m_series->pieSize();
110 111
111 112 // set layouts for existing slice items
112 113 foreach (QPieSlice* slice, m_series->slices()) {
113 114 PieSliceItem *sliceItem = m_sliceItems.value(slice);
114 115 if (sliceItem) {
115 116 PieSliceData sliceData = updateSliceGeometry(slice);
116 117 if (animator())
117 118 animator()->updateAnimation(this, sliceItem, sliceData);
118 119 else
119 120 sliceItem->setLayout(sliceData);
120 121 }
121 122 }
122 123
123 124 update();
124 125 }
125 126
126 127 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
127 128 {
128 129 // delay creating slice items until there is a proper rectangle
129 130 if (!m_rect.isValid() && m_sliceItems.isEmpty())
130 131 return;
131 132
132 133 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
133 134
134 135 bool startupAnimation = m_sliceItems.isEmpty();
135 136
136 137 foreach (QPieSlice *slice, slices) {
137 138 PieSliceItem* sliceItem = new PieSliceItem(this);
138 139 m_sliceItems.insert(slice, sliceItem);
139 140
140 141 // Note: do need to connect to slice valueChanged() etc.
141 142 // This is handled through calculatedDataChanged signal.
142 143 connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged()));
143 144 connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged()));
144 145 connect(slice, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged()));
145 146 connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged()));
146 147 connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged()));
147 148 connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged()));
148 149 connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged()));
149 150 connect(slice, SIGNAL(labelPositionChanged()), this, SLOT(handleSliceChanged()));
150 151 connect(slice, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged()));
151 152 connect(slice, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged()));
152 153
153 154 connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked()));
154 155 connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool)));
155 156
156 157 PieSliceData sliceData = updateSliceGeometry(slice);
157 158 if (animator())
158 159 animator()->addAnimation(this, sliceItem, sliceData, startupAnimation);
159 160 else
160 161 sliceItem->setLayout(sliceData);
161 162 }
162 163 }
163 164
164 165 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
165 166 {
166 167 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
167 168
168 169 foreach (QPieSlice *slice, slices) {
169 170
170 171 PieSliceItem *sliceItem = m_sliceItems.value(slice);
171 172
172 173 // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created
173 174 if (!sliceItem)
174 175 continue;
175 176
176 177 m_sliceItems.remove(slice);
177 178
178 179 if (animator())
179 180 animator()->removeAnimation(this, sliceItem); // animator deletes the PieSliceItem
180 181 else
181 182 delete sliceItem;
182 183 }
183 184 }
184 185
185 186 void PieChartItem::handleSliceChanged()
186 187 {
187 188 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
188 189 Q_ASSERT(m_sliceItems.contains(slice));
189 190
190 191 PieSliceItem *sliceItem = m_sliceItems.value(slice);
191 192 PieSliceData sliceData = updateSliceGeometry(slice);
192 193 if (animator())
193 194 animator()->updateAnimation(this, sliceItem, sliceData);
194 195 else
195 196 sliceItem->setLayout(sliceData);
196 197
197 198 update();
198 199 }
199 200
200 201 void PieChartItem::handleSeriesVisibleChanged()
201 202 {
202 203 setVisible(m_series->isVisible());
203 204 }
204 205
205 206 PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice)
206 207 {
207 208 PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data;
208 209 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
209 210 sliceData.m_radius = m_pieRadius;
210 211 return sliceData;
211 212 }
212 213
213 214 #include "moc_piechartitem_p.cpp"
214 215
215 216 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,672 +1,632
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 "qpieseries.h"
22 22 #include "qpieseries_p.h"
23 23 #include "qpieslice.h"
24 24 #include "qpieslice_p.h"
25 25 #include "pieslicedata_p.h"
26 26 #include "chartdataset_p.h"
27 27 #include "charttheme_p.h"
28 28 #include "chartanimator_p.h"
29 29 #include "legendmarker_p.h"
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 /*!
34 34 \class QPieSeries
35 35 \brief Pie series API for QtCommercial Charts
36 36
37 37 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
38 38 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
39 39 The actual slice size is determined by that relative value.
40 40
41 41 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
42 42 These relate to the actual chart rectangle.
43 43
44 44 By default the pie is defined as a full pie but it can also be a partial pie.
45 45 This can be done by setting a starting angle and angle span to the series.
46 46 Full pie is 360 degrees where 0 is at 12 a'clock.
47 47
48 48 See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
49 49 \image examples_piechart.png
50 50 */
51 51
52 52 /*!
53 53 \property QPieSeries::horizontalPosition
54 54 \brief Defines the horizontal position of the pie.
55 55
56 56 The value is a relative value to the chart rectangle where:
57 57
58 58 \list
59 59 \o 0.0 is the absolute left.
60 60 \o 1.0 is the absolute right.
61 61 \endlist
62 62
63 63 Default value is 0.5 (center).
64 64
65 65 \sa verticalPosition
66 66 */
67 67
68 68 /*!
69 \fn void QPieSeries::horizontalPositionChanged()
70
71 Emitted then the horizontal position of the pie has changed.
72
73 \sa horizontalPosition
74 */
75
76 /*!
77 69 \property QPieSeries::verticalPosition
78 70 \brief Defines the vertical position of the pie.
79 71
80 72 The value is a relative value to the chart rectangle where:
81 73
82 74 \list
83 75 \o 0.0 is the absolute top.
84 76 \o 1.0 is the absolute bottom.
85 77 \endlist
86 78
87 79 Default value is 0.5 (center).
88 80
89 81 \sa horizontalPosition
90 82 */
91 83
92 84 /*!
93 \fn void QPieSeries::verticalPositionChanged()
94
95 Emitted then the vertical position of the pie has changed.
96
97 \sa verticalPosition
98 */
99
100 /*!
101 85 \property QPieSeries::size
102 86 \brief Defines the pie size.
103 87
104 88 The value is a relative value to the chart rectangle where:
105 89
106 90 \list
107 91 \o 0.0 is the minimum size (pie not drawn).
108 92 \o 1.0 is the maximum size that can fit the chart.
109 93 \endlist
110 94
111 95 Default value is 0.7.
112 96 */
113 97
114 98 /*!
115 \fn void QPieSeries::pieSizeChanged()
116
117 Emitted when the pie size has changed.
118
119 \sa size
120 */
121
122 /*!
123 99 \property QPieSeries::startAngle
124 100 \brief Defines the starting angle of the pie.
125 101
126 102 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
127 103
128 104 Default is value is 0.
129 105 */
130 106
131 107 /*!
132 \fn void QPieSeries::pieStartAngleChanged()
133
134 Emitted when the starting angle of the pie has changed.
135
136 \sa startAngle
137 */
138
139 /*!
140 108 \property QPieSeries::endAngle
141 109 \brief Defines the ending angle of the pie.
142 110
143 111 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
144 112
145 113 Default is value is 360.
146 114 */
147 115
148 116 /*!
149 \fn void QPieSeries::pieEndAngleChanged()
150
151 Emitted when the ending angle of the pie has changed.
152
153 \sa endAngle
154 */
155
156 /*!
157 117 \property QPieSeries::count
158 118
159 119 Number of slices in the series.
160 120 */
161 121
162 122 /*!
163 123 \fn void QPieSeries::countChanged()
164 124
165 125 Emitted when the slice count has changed.
166 126
167 127 \sa count
168 128 */
169 129
170 130 /*!
171 131 \property QPieSeries::sum
172 132
173 133 Sum of all slices.
174 134
175 135 The series keeps track of the sum of all slices it holds.
176 136 */
177 137
178 138 /*!
179 139 \fn void QPieSeries::sumChanged()
180 140
181 141 Emitted when the sum of all slices has changed.
182 142
183 143 \sa sum
184 144 */
185 145
186 146 /*!
187 147 \fn void QPieSeries::added(QList<QPieSlice*> slices)
188 148
189 149 This signal is emitted when \a slices have been added to the series.
190 150
191 151 \sa append(), insert()
192 152 */
193 153
194 154 /*!
195 155 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
196 156
197 157 This signal is emitted when \a slices have been removed from the series.
198 158
199 159 \sa remove()
200 160 */
201 161
202 162 /*!
203 163 \fn void QPieSeries::clicked(QPieSlice* slice)
204 164
205 165 This signal is emitted when a \a slice has been clicked.
206 166
207 167 \sa QPieSlice::clicked()
208 168 */
209 169
210 170 /*!
211 171 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
212 172
213 173 This signal is emitted when user has hovered over or away from the \a slice.
214 174
215 175 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
216 176
217 177 \sa QPieSlice::hovered()
218 178 */
219 179
220 180 /*!
221 181 Constructs a series object which is a child of \a parent.
222 182 */
223 183 QPieSeries::QPieSeries(QObject *parent) :
224 184 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
225 185 {
226 186
227 187 }
228 188
229 189 /*!
230 190 Destroys the series and its slices.
231 191 */
232 192 QPieSeries::~QPieSeries()
233 193 {
234 194 // NOTE: d_prt destroyed by QObject
235 195 }
236 196
237 197 /*!
238 198 Returns QChartSeries::SeriesTypePie.
239 199 */
240 200 QAbstractSeries::SeriesType QPieSeries::type() const
241 201 {
242 202 return QAbstractSeries::SeriesTypePie;
243 203 }
244 204
245 205 /*!
246 206 Appends a single \a slice to the series.
247 207 Slice ownership is passed to the series.
248 208
249 209 Returns true if append was succesfull.
250 210 */
251 211 bool QPieSeries::append(QPieSlice* slice)
252 212 {
253 213 return append(QList<QPieSlice*>() << slice);
254 214 }
255 215
256 216 /*!
257 217 Appends an array of \a slices to the series.
258 218 Slice ownership is passed to the series.
259 219
260 220 Returns true if append was successfull.
261 221 */
262 222 bool QPieSeries::append(QList<QPieSlice*> slices)
263 223 {
264 224 Q_D(QPieSeries);
265 225
266 226 if (slices.count() == 0)
267 227 return false;
268 228
269 229 foreach (QPieSlice* s, slices) {
270 230 if (!s || d->m_slices.contains(s))
271 231 return false;
272 232 if (s->series()) // already added to some series
273 233 return false;
274 234 }
275 235
276 236 foreach (QPieSlice* s, slices) {
277 237 s->setParent(this);
278 238 QPieSlicePrivate::fromSlice(s)->m_series = this;
279 239 d->m_slices << s;
280 240 }
281 241
282 242 d->updateDerivativeData();
283 243
284 244 foreach (QPieSlice* s, slices) {
285 245 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
286 246 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
287 247 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
288 248 }
289 249
290 250 emit added(slices);
291 251 emit countChanged();
292 252
293 253 return true;
294 254 }
295 255
296 256 /*!
297 257 Appends a single \a slice to the series and returns a reference to the series.
298 258 Slice ownership is passed to the series.
299 259 */
300 260 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
301 261 {
302 262 append(slice);
303 263 return *this;
304 264 }
305 265
306 266
307 267 /*!
308 268 Appends a single slice to the series with give \a value and \a label.
309 269 Slice ownership is passed to the series.
310 270 */
311 271 QPieSlice* QPieSeries::append(QString label, qreal value)
312 272 {
313 273 QPieSlice* slice = new QPieSlice(label, value);
314 274 append(slice);
315 275 return slice;
316 276 }
317 277
318 278 /*!
319 279 Inserts a single \a slice to the series before the slice at \a index position.
320 280 Slice ownership is passed to the series.
321 281
322 282 Returns true if insert was successfull.
323 283 */
324 284 bool QPieSeries::insert(int index, QPieSlice* slice)
325 285 {
326 286 Q_D(QPieSeries);
327 287
328 288 if (index < 0 || index > d->m_slices.count())
329 289 return false;
330 290
331 291 if (!slice || d->m_slices.contains(slice))
332 292 return false;
333 293
334 294 if (slice->series()) // already added to some series
335 295 return false;
336 296
337 297 slice->setParent(this);
338 298 QPieSlicePrivate::fromSlice(slice)->m_series = this;
339 299 d->m_slices.insert(index, slice);
340 300
341 301 d->updateDerivativeData();
342 302
343 303 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
344 304 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
345 305 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
346 306
347 307 emit added(QList<QPieSlice*>() << slice);
348 308 emit countChanged();
349 309
350 310 return true;
351 311 }
352 312
353 313 /*!
354 314 Removes a single \a slice from the series and deletes the slice.
355 315
356 316 Do not reference the pointer after this call.
357 317
358 318 Returns true if remove was successfull.
359 319 */
360 320 bool QPieSeries::remove(QPieSlice* slice)
361 321 {
362 322 Q_D(QPieSeries);
363 323
364 324 if (!d->m_slices.removeOne(slice))
365 325 return false;
366 326
367 327 d->updateDerivativeData();
368 328
369 329 emit removed(QList<QPieSlice*>() << slice);
370 330 emit countChanged();
371 331
372 332 delete slice;
373 333 slice = 0;
374 334
375 335 return true;
376 336 }
377 337
378 338 /*!
379 339 Clears all slices from the series.
380 340 */
381 341 void QPieSeries::clear()
382 342 {
383 343 Q_D(QPieSeries);
384 344 if (d->m_slices.count() == 0)
385 345 return;
386 346
387 347 QList<QPieSlice*> slices = d->m_slices;
388 348 foreach (QPieSlice* s, d->m_slices) {
389 349 d->m_slices.removeOne(s);
390 350 delete s;
391 351 }
392 352
393 353 d->updateDerivativeData();
394 354
395 355 emit removed(slices);
396 356 emit countChanged();
397 357 }
398 358
399 359 /*!
400 360 Returns a list of slices that belong to this series.
401 361 */
402 362 QList<QPieSlice*> QPieSeries::slices() const
403 363 {
404 364 Q_D(const QPieSeries);
405 365 return d->m_slices;
406 366 }
407 367
408 368 /*!
409 369 returns the number of the slices in this series.
410 370 */
411 371 int QPieSeries::count() const
412 372 {
413 373 Q_D(const QPieSeries);
414 374 return d->m_slices.count();
415 375 }
416 376
417 377 /*!
418 378 Returns true is the series is empty.
419 379 */
420 380 bool QPieSeries::isEmpty() const
421 381 {
422 382 Q_D(const QPieSeries);
423 383 return d->m_slices.isEmpty();
424 384 }
425 385
426 386 /*!
427 387 Returns the sum of all slice values in this series.
428 388
429 389 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
430 390 */
431 391 qreal QPieSeries::sum() const
432 392 {
433 393 Q_D(const QPieSeries);
434 394 return d->m_sum;
435 395 }
436 396
437 397 void QPieSeries::setHorizontalPosition(qreal relativePosition)
438 398 {
439 399 Q_D(QPieSeries);
440 400
441 401 if (relativePosition < 0.0)
442 402 relativePosition = 0.0;
443 403 if (relativePosition > 1.0)
444 404 relativePosition = 1.0;
445 405
446 406 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
447 407 d->m_pieRelativeHorPos = relativePosition;
448 emit horizontalPositionChanged();
408 emit d->horizontalPositionChanged();
449 409 }
450 410 }
451 411
452 412 qreal QPieSeries::horizontalPosition() const
453 413 {
454 414 Q_D(const QPieSeries);
455 415 return d->m_pieRelativeHorPos;
456 416 }
457 417
458 418 void QPieSeries::setVerticalPosition(qreal relativePosition)
459 419 {
460 420 Q_D(QPieSeries);
461 421
462 422 if (relativePosition < 0.0)
463 423 relativePosition = 0.0;
464 424 if (relativePosition > 1.0)
465 425 relativePosition = 1.0;
466 426
467 427 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
468 428 d->m_pieRelativeVerPos = relativePosition;
469 emit verticalPositionChanged();
429 emit d->verticalPositionChanged();
470 430 }
471 431 }
472 432
473 433 qreal QPieSeries::verticalPosition() const
474 434 {
475 435 Q_D(const QPieSeries);
476 436 return d->m_pieRelativeVerPos;
477 437 }
478 438
479 439 void QPieSeries::setPieSize(qreal relativeSize)
480 440 {
481 441 Q_D(QPieSeries);
482 442
483 443 if (relativeSize < 0.0)
484 444 relativeSize = 0.0;
485 445 if (relativeSize > 1.0)
486 446 relativeSize = 1.0;
487 447
488 448 if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) {
489 449 d->m_pieRelativeSize = relativeSize;
490 emit pieSizeChanged();
450 emit d->pieSizeChanged();
491 451 }
492 452 }
493 453
494 454 qreal QPieSeries::pieSize() const
495 455 {
496 456 Q_D(const QPieSeries);
497 457 return d->m_pieRelativeSize;
498 458 }
499 459
500 460
501 461 void QPieSeries::setPieStartAngle(qreal angle)
502 462 {
503 463 Q_D(QPieSeries);
504 464 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
505 465 return;
506 466 d->m_pieStartAngle = angle;
507 467 d->updateDerivativeData();
508 emit pieStartAngleChanged();
468 emit d->pieStartAngleChanged();
509 469 }
510 470
511 471 qreal QPieSeries::pieStartAngle() const
512 472 {
513 473 Q_D(const QPieSeries);
514 474 return d->m_pieStartAngle;
515 475 }
516 476
517 477 /*!
518 478 Sets the end angle of the pie.
519 479
520 480 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
521 481
522 482 \a angle must be greater than start angle.
523 483
524 484 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
525 485 */
526 486 void QPieSeries::setPieEndAngle(qreal angle)
527 487 {
528 488 Q_D(QPieSeries);
529 489 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
530 490 return;
531 491 d->m_pieEndAngle = angle;
532 492 d->updateDerivativeData();
533 emit pieEndAngleChanged();
493 emit d->pieEndAngleChanged();
534 494 }
535 495
536 496 /*!
537 497 Returns the end angle of the pie.
538 498
539 499 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
540 500
541 501 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
542 502 */
543 503 qreal QPieSeries::pieEndAngle() const
544 504 {
545 505 Q_D(const QPieSeries);
546 506 return d->m_pieEndAngle;
547 507 }
548 508
549 509 /*!
550 510 Sets the all the slice labels \a visible or invisible.
551 511
552 512 Note that this affects only the current slices in the series.
553 513 If user adds a new slice the default label visibility is false.
554 514
555 515 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
556 516 */
557 517 void QPieSeries::setLabelsVisible(bool visible)
558 518 {
559 519 Q_D(QPieSeries);
560 520 foreach (QPieSlice* s, d->m_slices)
561 521 s->setLabelVisible(visible);
562 522 }
563 523
564 524 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
565 525
566 526
567 527 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
568 528 QAbstractSeriesPrivate(parent),
569 529 m_pieRelativeHorPos(0.5),
570 530 m_pieRelativeVerPos(0.5),
571 531 m_pieRelativeSize(0.7),
572 532 m_pieStartAngle(0),
573 533 m_pieEndAngle(360),
574 534 m_sum(0)
575 535 {
576 536 }
577 537
578 538 QPieSeriesPrivate::~QPieSeriesPrivate()
579 539 {
580 540 }
581 541
582 542 void QPieSeriesPrivate::updateDerivativeData()
583 543 {
584 544 // calculate sum of all slices
585 545 qreal sum = 0;
586 546 foreach (QPieSlice* s, m_slices)
587 547 sum += s->value();
588 548
589 549 if (!qFuzzyIsNull(m_sum - sum)) {
590 550 m_sum = sum;
591 551 emit q_func()->sumChanged();
592 552 }
593 553
594 554 // nothing to show..
595 555 if (qFuzzyIsNull(m_sum))
596 556 return;
597 557
598 558 // update slice attributes
599 559 qreal sliceAngle = m_pieStartAngle;
600 560 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
601 561 QVector<QPieSlice*> changed;
602 562 foreach (QPieSlice* s, m_slices) {
603 563 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
604 564 d->setPercentage(s->value() / m_sum);
605 565 d->setStartAngle(sliceAngle);
606 566 d->setAngleSpan(pieSpan * s->percentage());
607 567 sliceAngle += s->angleSpan();
608 568 }
609 569
610 570
611 571 emit calculatedDataChanged();
612 572 }
613 573
614 574 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
615 575 {
616 576 return series->d_func();
617 577 }
618 578
619 579 void QPieSeriesPrivate::sliceValueChanged()
620 580 {
621 581 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
622 582 updateDerivativeData();
623 583 }
624 584
625 585 void QPieSeriesPrivate::sliceClicked()
626 586 {
627 587 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
628 588 Q_ASSERT(m_slices.contains(slice));
629 589 Q_Q(QPieSeries);
630 590 emit q->clicked(slice);
631 591 }
632 592
633 593 void QPieSeriesPrivate::sliceHovered(bool state)
634 594 {
635 595 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
636 596 Q_ASSERT(m_slices.contains(slice));
637 597 Q_Q(QPieSeries);
638 598 emit q->hovered(slice, state);
639 599 }
640 600
641 601 void QPieSeriesPrivate::scaleDomain(Domain& domain)
642 602 {
643 603 Q_UNUSED(domain);
644 604 // does not apply to pie
645 605 }
646 606
647 607 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
648 608 {
649 609 Q_Q(QPieSeries);
650 610 PieChartItem* pie = new PieChartItem(q,presenter);
651 611 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
652 612 presenter->animator()->addAnimation(pie);
653 613 }
654 614 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
655 615 return pie;
656 616 }
657 617
658 618 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
659 619 {
660 620 Q_Q(QPieSeries);
661 621 QList<LegendMarker*> markers;
662 622 foreach(QPieSlice* slice, q->slices()) {
663 623 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
664 624 markers << marker;
665 625 }
666 626 return markers;
667 627 }
668 628
669 629 #include "moc_qpieseries.cpp"
670 630 #include "moc_qpieseries_p.cpp"
671 631
672 632 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,101 +1,96
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 #ifndef PIESERIES_H
22 22 #define PIESERIES_H
23 23
24 24 #include <qabstractseries.h>
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27 class QPieSeriesPrivate;
28 28 class QPieSlice;
29 29
30 30 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries
31 31 {
32 32 Q_OBJECT
33 Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition NOTIFY horizontalPositionChanged)
34 Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition NOTIFY verticalPositionChanged)
35 Q_PROPERTY(qreal size READ pieSize WRITE setPieSize NOTIFY pieSizeChanged)
36 Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle NOTIFY pieStartAngleChanged)
37 Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle NOTIFY pieEndAngleChanged)
33 Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition)
34 Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition)
35 Q_PROPERTY(qreal size READ pieSize WRITE setPieSize)
36 Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle)
37 Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle)
38 38 Q_PROPERTY(int count READ count NOTIFY countChanged)
39 39 Q_PROPERTY(qreal sum READ sum NOTIFY sumChanged)
40 40
41 41 public:
42 42 explicit QPieSeries(QObject *parent = 0);
43 43 virtual ~QPieSeries();
44 44
45 45 QAbstractSeries::SeriesType type() const;
46 46
47 47 bool append(QPieSlice* slice);
48 48 bool append(QList<QPieSlice*> slices);
49 49 QPieSeries& operator << (QPieSlice* slice);
50 50 QPieSlice* append(QString label, qreal value);
51 51
52 52 bool insert(int index, QPieSlice* slice);
53 53
54 54 bool remove(QPieSlice* slice);
55 55 void clear();
56 56
57 57 QList<QPieSlice*> slices() const;
58 58 int count() const;
59 59
60 60 bool isEmpty() const;
61 61
62 62 qreal sum() const;
63 63
64 64 void setHorizontalPosition(qreal relativePosition);
65 65 qreal horizontalPosition() const;
66 66
67 67 void setVerticalPosition(qreal relativePosition);
68 68 qreal verticalPosition() const;
69 69
70 70 void setPieSize(qreal relativeSize);
71 71 qreal pieSize() const;
72 72
73 73 void setPieStartAngle(qreal startAngle);
74 74 qreal pieStartAngle() const;
75 75
76 76 void setPieEndAngle(qreal endAngle);
77 77 qreal pieEndAngle() const;
78 78
79 79 void setLabelsVisible(bool visible = true);
80 80
81 81 Q_SIGNALS:
82 82 void added(QList<QPieSlice*> slices);
83 83 void removed(QList<QPieSlice*> slices);
84 84 void clicked(QPieSlice* slice);
85 85 void hovered(QPieSlice* slice, bool state);
86 86 void countChanged();
87 87 void sumChanged();
88 void pieSizeChanged();
89 void pieStartAngleChanged();
90 void pieEndAngleChanged();
91 void horizontalPositionChanged();
92 void verticalPositionChanged();
93 88
94 89 private:
95 90 Q_DECLARE_PRIVATE(QPieSeries)
96 91 Q_DISABLE_COPY(QPieSeries)
97 92 };
98 93
99 94 QTCOMMERCIALCHART_END_NAMESPACE
100 95
101 96 #endif // PIESERIES_H
@@ -1,79 +1,84
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 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QPIESERIES_P_H
31 31 #define QPIESERIES_P_H
32 32
33 33 #include "qpieseries.h"
34 34 #include "qabstractseries_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37 class QLegendPrivate;
38 38
39 39 class QPieSeriesPrivate : public QAbstractSeriesPrivate
40 40 {
41 41 Q_OBJECT
42 42
43 43 public:
44 44 QPieSeriesPrivate(QPieSeries *parent);
45 45 ~QPieSeriesPrivate();
46 46
47 47 void scaleDomain(Domain& domain);
48 48 Chart* createGraphics(ChartPresenter *presenter);
49 49 QList<LegendMarker*> createLegendMarker(QLegend *legend);
50 50
51 51 void updateDerivativeData();
52 52
53 53 static QPieSeriesPrivate* fromSeries(QPieSeries *series);
54 54
55 55 signals:
56 56 void calculatedDataChanged();
57 void pieSizeChanged();
58 void pieStartAngleChanged();
59 void pieEndAngleChanged();
60 void horizontalPositionChanged();
61 void verticalPositionChanged();
57 62
58 63 public Q_SLOTS:
59 64 void sliceValueChanged();
60 65 void sliceClicked();
61 66 void sliceHovered(bool state);
62 67
63 68 private:
64 69 QList<QPieSlice*> m_slices;
65 70 qreal m_pieRelativeHorPos;
66 71 qreal m_pieRelativeVerPos;
67 72 qreal m_pieRelativeSize;
68 73 qreal m_pieStartAngle;
69 74 qreal m_pieEndAngle;
70 75 qreal m_sum;
71 76
72 77 private:
73 78 friend class QLegendPrivate;
74 79 Q_DECLARE_PUBLIC(QPieSeries)
75 80 };
76 81
77 82 QTCOMMERCIALCHART_END_NAMESPACE
78 83
79 84 #endif // QPIESERIES_P_H
@@ -1,563 +1,555
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 <QtTest/QtTest>
22 22 #include <qchartview.h>
23 23 #include <qchart.h>
24 24 #include <qpieseries.h>
25 25 #include <qpieslice.h>
26 26 #include <qpiemodelmapper.h>
27 27 #include <QStandardItemModel>
28 28 #include <tst_definitions.h>
29 29
30 30 QTCOMMERCIALCHART_USE_NAMESPACE
31 31
32 32 Q_DECLARE_METATYPE(QPieSlice*)
33 33 Q_DECLARE_METATYPE(QList<QPieSlice*>)
34 34
35 35 class tst_qpieseries : public QObject
36 36 {
37 37 Q_OBJECT
38 38
39 39 public slots:
40 40 void initTestCase();
41 41 void cleanupTestCase();
42 42 void init();
43 43 void cleanup();
44 44
45 45 private slots:
46 46 void properties();
47 47 void append();
48 48 void appendAnimated();
49 49 void insert();
50 50 void insertAnimated();
51 51 void remove();
52 52 void removeAnimated();
53 53 void calculatedValues();
54 54 void clickedSignal();
55 55 void hoverSignal();
56 56 void sliceSeries();
57 57
58 58 private:
59 59 void verifyCalculatedData(const QPieSeries &series, bool *ok);
60 60
61 61 private:
62 62 QChartView *m_view;
63 63 QPieSeries *m_series;
64 64 };
65 65
66 66 void tst_qpieseries::initTestCase()
67 67 {
68 68 qRegisterMetaType<QPieSlice*>("QPieSlice*");
69 69 qRegisterMetaType<QList<QPieSlice*> >("QList<QPieSlice*>");
70 70 }
71 71
72 72 void tst_qpieseries::cleanupTestCase()
73 73 {
74 74 }
75 75
76 76 void tst_qpieseries::init()
77 77 {
78 78 m_view = new QChartView();
79 79 m_series = new QPieSeries(m_view);
80 80 }
81 81
82 82 void tst_qpieseries::cleanup()
83 83 {
84 84 delete m_view;
85 85 m_view = 0;
86 86 m_series = 0;
87 87 }
88 88
89 89 void tst_qpieseries::properties()
90 90 {
91 91 QSignalSpy countSpy(m_series, SIGNAL(countChanged()));
92 92 QSignalSpy sumSpy(m_series, SIGNAL(sumChanged()));
93 QSignalSpy sizeSpy(m_series, SIGNAL(pieSizeChanged()));
94 QSignalSpy startAngleSpy(m_series, SIGNAL(pieStartAngleChanged()));
95 QSignalSpy endAngleSpy(m_series, SIGNAL(pieEndAngleChanged()));
96 QSignalSpy horPosSpy(m_series, SIGNAL(horizontalPositionChanged()));
97 QSignalSpy verPosSpy(m_series, SIGNAL(verticalPositionChanged()));
98 93
99 94 QVERIFY(m_series->type() == QAbstractSeries::SeriesTypePie);
100 95 QVERIFY(m_series->count() == 0);
101 96 QVERIFY(m_series->isEmpty());
102 97 QCOMPARE(m_series->sum(), 0.0);
103 98 QCOMPARE(m_series->horizontalPosition(), 0.5);
104 99 QCOMPARE(m_series->verticalPosition(), 0.5);
105 100 QCOMPARE(m_series->pieSize(), 0.7);
106 101 QCOMPARE(m_series->pieStartAngle(), 0.0);
107 102 QCOMPARE(m_series->pieEndAngle(), 360.0);
108 103
109 104 m_series->append("s1", 1);
110 105 m_series->append("s2", 1);
111 106 m_series->append("s3", 1);
112 107 m_series->insert(1, new QPieSlice("s4", 1));
113 108 m_series->remove(m_series->slices().first());
114 109 QCOMPARE(m_series->count(), 3);
115 110 QCOMPARE(m_series->sum(), 3.0);
116 111 m_series->clear();
117 112 QCOMPARE(m_series->count(), 0);
118 113 QCOMPARE(m_series->sum(), 0.0);
119 114 QCOMPARE(countSpy.count(), 6);
120 115 QCOMPARE(sumSpy.count(), 6);
121 116
122 117 m_series->setPieSize(-1.0);
123 118 QCOMPARE(m_series->pieSize(), 0.0);
124 119 m_series->setPieSize(0.0);
125 120 m_series->setPieSize(0.9);
126 121 m_series->setPieSize(2.0);
127 122 QCOMPARE(m_series->pieSize(), 1.0);
128 QCOMPARE(sizeSpy.count(), 3);
129 123
130 124 m_series->setPieStartAngle(0);
131 125 m_series->setPieStartAngle(-180);
132 126 m_series->setPieStartAngle(180);
133 QCOMPARE(startAngleSpy.count(), 2);
127 QCOMPARE(m_series->pieStartAngle(), 180.0);
134 128
135 129 m_series->setPieEndAngle(360);
136 130 m_series->setPieEndAngle(-180);
137 131 m_series->setPieEndAngle(180);
138 QCOMPARE(endAngleSpy.count(), 2);
132 QCOMPARE(m_series->pieEndAngle(), 180.0);
139 133
140 134 m_series->setHorizontalPosition(0.5);
141 135 m_series->setHorizontalPosition(-1.0);
142 136 QCOMPARE(m_series->horizontalPosition(), 0.0);
143 137 m_series->setHorizontalPosition(1.0);
144 138 m_series->setHorizontalPosition(2.0);
145 139 QCOMPARE(m_series->horizontalPosition(), 1.0);
146 QCOMPARE(horPosSpy.count(), 2);
147 140
148 141 m_series->setVerticalPosition(0.5);
149 142 m_series->setVerticalPosition(-1.0);
150 143 QCOMPARE(m_series->verticalPosition(), 0.0);
151 144 m_series->setVerticalPosition(1.0);
152 145 m_series->setVerticalPosition(2.0);
153 146 QCOMPARE(m_series->verticalPosition(), 1.0);
154 QCOMPARE(verPosSpy.count(), 2);
155 147 }
156 148
157 149 void tst_qpieseries::append()
158 150 {
159 151 m_view->chart()->addSeries(m_series);
160 152 QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>)));
161 153
162 154 // append pointer
163 155 QPieSlice *slice1 = 0;
164 156 QVERIFY(!m_series->append(slice1));
165 157 slice1 = new QPieSlice("slice 1", 1);
166 158 QVERIFY(m_series->append(slice1));
167 159 QVERIFY(!m_series->append(slice1));
168 160 QCOMPARE(m_series->count(), 1);
169 161 QCOMPARE(addedSpy.count(), 1);
170 162 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
171 163 QCOMPARE(added.count(), 1);
172 164 QCOMPARE(added.first(), slice1);
173 165
174 166 // try to append same slice to another series
175 167 QPieSeries series2;
176 168 QVERIFY(!series2.append(slice1));
177 169
178 170 // append pointer list
179 171 QList<QPieSlice *> list;
180 172 QVERIFY(!m_series->append(list));
181 173 list << (QPieSlice *) 0;
182 174 QVERIFY(!m_series->append(list));
183 175 list.clear();
184 176 list << new QPieSlice("slice 2", 2);
185 177 list << new QPieSlice("slice 3", 3);
186 178 QVERIFY(m_series->append(list));
187 179 QVERIFY(!m_series->append(list));
188 180 QCOMPARE(m_series->count(), 3);
189 181 QCOMPARE(addedSpy.count(), 2);
190 182 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
191 183 QCOMPARE(added.count(), 2);
192 184 QCOMPARE(added, list);
193 185
194 186 // append operator
195 187 QPieSlice *slice4 = new QPieSlice("slice 4", 4);
196 188 *m_series << slice4;
197 189 *m_series << slice1; // fails because already added
198 190 QCOMPARE(m_series->count(), 4);
199 191 QCOMPARE(addedSpy.count(), 3);
200 192 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0));
201 193 QCOMPARE(added.count(), 1);
202 194 QCOMPARE(added.first(), slice4);
203 195
204 196 // append with params
205 197 QPieSlice *slice5 = m_series->append("slice 5", 5);
206 198 QVERIFY(slice5 != 0);
207 199 QCOMPARE(slice5->value(), 5.0);
208 200 QCOMPARE(slice5->label(), QString("slice 5"));
209 201 QCOMPARE(m_series->count(), 5);
210 202 QCOMPARE(addedSpy.count(), 4);
211 203 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
212 204 QCOMPARE(added.count(), 1);
213 205 QCOMPARE(added.first(), slice5);
214 206
215 207 // check slices
216 208 QVERIFY(!m_series->isEmpty());
217 209 for (int i=0; i<m_series->count(); i++) {
218 210 QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1);
219 211 QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1));
220 212 }
221 213 }
222 214
223 215 void tst_qpieseries::appendAnimated()
224 216 {
225 217 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
226 218 }
227 219
228 220 void tst_qpieseries::insert()
229 221 {
230 222 m_view->chart()->addSeries(m_series);
231 223 QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>)));
232 224
233 225 // insert one slice
234 226 QPieSlice *slice1 = 0;
235 227 QVERIFY(!m_series->insert(0, slice1));
236 228 slice1 = new QPieSlice("slice 1", 1);
237 229 QVERIFY(!m_series->insert(-1, slice1));
238 230 QVERIFY(!m_series->insert(5, slice1));
239 231 QVERIFY(m_series->insert(0, slice1));
240 232 QVERIFY(!m_series->insert(0, slice1));
241 233 QCOMPARE(m_series->count(), 1);
242 234 QCOMPARE(addedSpy.count(), 1);
243 235 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
244 236 QCOMPARE(added.count(), 1);
245 237 QCOMPARE(added.first(), slice1);
246 238
247 239 // try to insert same slice to another series
248 240 QPieSeries series2;
249 241 QVERIFY(!series2.insert(0, slice1));
250 242
251 243 // add some more slices
252 244 QPieSlice *slice2 = m_series->append("slice 2", 2);
253 245 QPieSlice *slice4 = m_series->append("slice 4", 4);
254 246 QCOMPARE(m_series->count(), 3);
255 247 QCOMPARE(addedSpy.count(), 3);
256 248 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
257 249 QCOMPARE(added.count(), 1);
258 250 QCOMPARE(added.first(), slice2);
259 251 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0));
260 252 QCOMPARE(added.count(), 1);
261 253 QCOMPARE(added.first(), slice4);
262 254
263 255 // insert between slices
264 256 QPieSlice *slice3 = new QPieSlice("slice 3", 3);
265 257 m_series->insert(2, slice3);
266 258 QCOMPARE(m_series->count(), 4);
267 259 QCOMPARE(addedSpy.count(), 4);
268 260 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
269 261 QCOMPARE(added.count(), 1);
270 262 QCOMPARE(added.first(), slice3);
271 263
272 264 // check slices
273 265 for (int i=0; i<m_series->count(); i++) {
274 266 QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1);
275 267 QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1));
276 268 }
277 269 }
278 270
279 271 void tst_qpieseries::insertAnimated()
280 272 {
281 273 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
282 274 }
283 275
284 276 void tst_qpieseries::remove()
285 277 {
286 278 m_view->chart()->addSeries(m_series);
287 279 QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>)));
288 280
289 281 // add some slices
290 282 QPieSlice *slice1 = m_series->append("slice 1", 1);
291 283 QPieSlice *slice2 = m_series->append("slice 2", 2);
292 284 QPieSlice *slice3 = m_series->append("slice 3", 3);
293 285 QSignalSpy spy1(slice1, SIGNAL(destroyed()));
294 286 QSignalSpy spy2(slice2, SIGNAL(destroyed()));
295 287 QSignalSpy spy3(slice3, SIGNAL(destroyed()));
296 288 QCOMPARE(m_series->count(), 3);
297 289
298 290 // null pointer remove
299 291 QVERIFY(!m_series->remove(0));
300 292
301 293 // remove first
302 294 QVERIFY(m_series->remove(slice1));
303 295 QVERIFY(!m_series->remove(slice1));
304 296 QCOMPARE(m_series->count(), 2);
305 297 QCOMPARE(m_series->slices().at(0)->label(), slice2->label());
306 298 QCOMPARE(removedSpy.count(), 1);
307 299 QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0));
308 300 QCOMPARE(removed.count(), 1);
309 301 QCOMPARE(removed.first(), slice1);
310 302
311 303 // remove all
312 304 m_series->clear();
313 305 QVERIFY(m_series->isEmpty());
314 306 QVERIFY(m_series->slices().isEmpty());
315 307 QCOMPARE(m_series->count(), 0);
316 308 QCOMPARE(removedSpy.count(), 2);
317 309 removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0));
318 310 QCOMPARE(removed.count(), 2);
319 311 QCOMPARE(removed.first(), slice2);
320 312 QCOMPARE(removed.last(), slice3);
321 313
322 314 // check that slices were actually destroyed
323 315 TRY_COMPARE(spy1.count(), 1);
324 316 TRY_COMPARE(spy2.count(), 1);
325 317 TRY_COMPARE(spy3.count(), 1);
326 318 }
327 319
328 320 void tst_qpieseries::removeAnimated()
329 321 {
330 322 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
331 323 }
332 324
333 325 void tst_qpieseries::calculatedValues()
334 326 {
335 327 m_view->chart()->addSeries(m_series);
336 328
337 329 QPieSlice *slice1 = new QPieSlice("slice 1", 1);
338 330 QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged()));
339 331 QSignalSpy startAngleSpy(slice1, SIGNAL(startAngleChanged()));
340 332 QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged()));
341 333
342 334 // add a slice
343 335 m_series->append(slice1);
344 336 bool ok;
345 337 verifyCalculatedData(*m_series, &ok);
346 338 if (!ok)
347 339 return;
348 340 QCOMPARE(percentageSpy.count(), 1);
349 341 QCOMPARE(startAngleSpy.count(), 0);
350 342 QCOMPARE(angleSpanSpy.count(), 1);
351 343
352 344 // add some more slices
353 345 QList<QPieSlice *> list;
354 346 list << new QPieSlice("slice 2", 2);
355 347 list << new QPieSlice("slice 3", 3);
356 348 m_series->append(list);
357 349 verifyCalculatedData(*m_series, &ok);
358 350 if (!ok)
359 351 return;
360 352 QCOMPARE(percentageSpy.count(), 2);
361 353 QCOMPARE(startAngleSpy.count(), 0);
362 354 QCOMPARE(angleSpanSpy.count(), 2);
363 355
364 356 // remove a slice
365 357 m_series->remove(list.first()); // remove slice 2
366 358 verifyCalculatedData(*m_series, &ok);
367 359 if (!ok)
368 360 return;
369 361 QCOMPARE(percentageSpy.count(), 3);
370 362 QCOMPARE(startAngleSpy.count(), 0);
371 363 QCOMPARE(angleSpanSpy.count(), 3);
372 364
373 365 // insert a slice
374 366 m_series->insert(0, new QPieSlice("Slice 4", 4));
375 367 verifyCalculatedData(*m_series, &ok);
376 368 if (!ok)
377 369 return;
378 370 QCOMPARE(percentageSpy.count(), 4);
379 371 QCOMPARE(startAngleSpy.count(), 1);
380 372 QCOMPARE(angleSpanSpy.count(), 4);
381 373
382 374 // modify pie angles
383 375 m_series->setPieStartAngle(-90);
384 376 m_series->setPieEndAngle(90);
385 377 verifyCalculatedData(*m_series, &ok);
386 378 if (!ok)
387 379 return;
388 380 QCOMPARE(percentageSpy.count(), 4);
389 381 QCOMPARE(startAngleSpy.count(), 3);
390 382 QCOMPARE(angleSpanSpy.count(), 6);
391 383
392 384 // clear all
393 385 m_series->clear();
394 386 verifyCalculatedData(*m_series, &ok);
395 387 if (!ok)
396 388 return;
397 389 QCOMPARE(percentageSpy.count(), 4);
398 390 QCOMPARE(startAngleSpy.count(), 3);
399 391 QCOMPARE(angleSpanSpy.count(), 6);
400 392 }
401 393
402 394 void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok)
403 395 {
404 396 *ok = false;
405 397
406 398 qreal sum = 0;
407 399 foreach (const QPieSlice *slice, series.slices())
408 400 sum += slice->value();
409 401 QCOMPARE(series.sum(), sum);
410 402
411 403 qreal startAngle = series.pieStartAngle();
412 404 qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle();
413 405 foreach (const QPieSlice *slice, series.slices()) {
414 406 qreal ratio = slice->value() / sum;
415 407 qreal sliceSpan = pieAngleSpan * ratio;
416 408 QCOMPARE(slice->startAngle(), startAngle);
417 409 QCOMPARE(slice->angleSpan(), sliceSpan);
418 410 QCOMPARE(slice->percentage(), ratio);
419 411 startAngle += sliceSpan;
420 412 }
421 413
422 414 if (!series.isEmpty())
423 415 QCOMPARE(series.slices().last()->startAngle() + series.slices().last()->angleSpan(), series.pieEndAngle());
424 416
425 417 *ok = true;
426 418 }
427 419
428 420
429 421 void tst_qpieseries::clickedSignal()
430 422 {
431 423 // add some slices
432 424 QPieSlice *s1 = m_series->append("slice 1", 1);
433 425 QPieSlice *s2 = m_series->append("slice 2", 1);
434 426 QPieSlice *s3 = m_series->append("slice 3", 1);
435 427 QPieSlice *s4 = m_series->append("slice 4", 1);
436 428 QSignalSpy clickSpy(m_series, SIGNAL(clicked(QPieSlice*)));
437 429
438 430 // add series to the chart
439 431 m_view->chart()->legend()->setVisible(false);
440 432 m_view->resize(200, 200);
441 433 m_view->chart()->addSeries(m_series);
442 434 m_view->show();
443 435 QTest::qWaitForWindowShown(m_view);
444 436
445 437 // if you devide the chart in four equal tiles these
446 438 // are the center points of those tiles
447 439 QPoint p1(90.25, 90);
448 440 QPoint p2(150, 90);
449 441 QPoint p3(90, 150);
450 442 QPoint p4(150, 150);
451 443
452 444 QPoint center(120, 120);
453 445
454 446 m_series->setPieSize(1.0);
455 447 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
456 448 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
457 449 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
458 450 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
459 451 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
460 452 TRY_COMPARE(clickSpy.count(), 5); // all hit
461 453 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s4);
462 454 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s1);
463 455 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3);
464 456 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s2);
465 457 clickSpy.clear();
466 458
467 459 m_series->setPieSize(0.5);
468 460 m_series->setVerticalPosition(0.25);
469 461 m_series->setHorizontalPosition(0.25);
470 462 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); // hits
471 463 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
472 464 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
473 465 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
474 466 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
475 467 TRY_COMPARE(clickSpy.count(), 1);
476 468 clickSpy.clear();
477 469
478 470 m_series->setVerticalPosition(0.25);
479 471 m_series->setHorizontalPosition(0.75);
480 472 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
481 473 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); // hits
482 474 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
483 475 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
484 476 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
485 477 TRY_COMPARE(clickSpy.count(), 1);
486 478 clickSpy.clear();
487 479
488 480 m_series->setVerticalPosition(0.75);
489 481 m_series->setHorizontalPosition(0.25);
490 482 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
491 483 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
492 484 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); // hits
493 485 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
494 486 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
495 487 TRY_COMPARE(clickSpy.count(), 1);
496 488 clickSpy.clear();
497 489
498 490 m_series->setVerticalPosition(0.75);
499 491 m_series->setHorizontalPosition(0.75);
500 492 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
501 493 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
502 494 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
503 495 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); // hits
504 496 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
505 497 TRY_COMPARE(clickSpy.count(), 1);
506 498 clickSpy.clear();
507 499 }
508 500
509 501 void tst_qpieseries::hoverSignal()
510 502 {
511 503 // add some slices
512 504 m_series->setPieSize(1.0);
513 505 QPieSlice *s1 = m_series->append("slice 1", 1);
514 506 m_series->append("slice 2", 2);
515 507 m_series->append("slice 3", 3);
516 508
517 509 // add series to the chart
518 510 m_view->chart()->legend()->setVisible(false);
519 511 m_view->resize(200, 200);
520 512 m_view->chart()->addSeries(m_series);
521 513 m_view->show();
522 514 QTest::qWaitForWindowShown(m_view);
523 515
524 516 // first move to right top corner
525 517 QTest::mouseMove(m_view->viewport(), QPoint(200, 0));
526 518 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
527 519
528 520 // move inside the slice
529 521 // pie rectangle: QRectF(60,60 121x121)
530 522 QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool)));
531 523 QTest::mouseMove(m_view->viewport(), QPoint(139, 85));
532 524 TRY_COMPARE(hoverSpy.count(), 1);
533 525 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1);
534 526 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true);
535 527
536 528 // move outside the slice
537 529 QTest::mouseMove(m_view->viewport(), QPoint(200, 0));
538 530 TRY_COMPARE(hoverSpy.count(), 2);
539 531 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1);
540 532 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false);
541 533 }
542 534
543 535 void tst_qpieseries::sliceSeries()
544 536 {
545 537 QPieSlice *slice = new QPieSlice();
546 538 QVERIFY(!slice->series());
547 539 delete slice;
548 540
549 541 slice = new QPieSlice(m_series);
550 542 QVERIFY(!slice->series());
551 543
552 544 m_series->append(slice);
553 545 QCOMPARE(slice->series(), m_series);
554 546
555 547 slice = new QPieSlice();
556 548 m_series->insert(0, slice);
557 549 QCOMPARE(slice->series(), m_series);
558 550 }
559 551
560 552 QTEST_MAIN(tst_qpieseries)
561 553
562 554 #include "tst_qpieseries.moc"
563 555
@@ -1,173 +1,168
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 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 Flow {
25 25 id: flow
26 26 spacing: 5
27 27 flow: Flow.TopToBottom
28 28 property variant series
29 29
30 30 onSeriesChanged: {
31 31 if (series && series.name == "pie") {
32 32 seriesConnections.target = series;
33 33 sliceConnections.target = series.at(0);
34 34 } else {
35 35 seriesConnections.target = null;
36 36 sliceConnections.target = null;
37 37 }
38 38 }
39 39
40 40 Connections {
41 41 id: seriesConnections
42 42 target: null
43 43 onVisibleChanged: console.log("series.onVisibleChanged: " + series.visible);
44 onHorizontalPositionChanged:console.log("series.onHorizontalPositionChanged: " + series.horizontalPosition);
45 onVerticalPositionChanged: console.log("series.onVerticalPositionChanged: " + series.verticalPosition);
46 onSizeChanged: console.log("series.onSizeChanged: " + series.size);
47 onStartAngleChanged: console.log("series.onStartAngleChanged: " + series.startAngle);
48 onEndAngleChanged: console.log("series.onEndAngleChanged: " + series.endAngle);
49 44 onCountChanged: console.log("series.onCountChanged: " + series.count);
50 45 onSumChanged: console.log("series.onSumChanged: " + series.sum);
51 46 }
52 47
53 48 Connections {
54 49 id: sliceConnections
55 50 target: null
56 51 onValueChanged: console.log("slice.onValueChanged: " + series.at(0).value);
57 52 onLabelVisibleChanged: console.log("slice.onLabelVisibleChanged: " + series.at(0).labelVisible);
58 53 onLabelPositionChanged: console.log("slice.onLabelPositionChanged: " + series.at(0).labelPosition);
59 54 onExplodedChanged: console.log("slice.onExplodedChanged: " + series.at(0).exploded);
60 55 onPenChanged: console.log("slice.onPenChanged: " + series.at(0).pen);
61 56 onBorderColorChanged: console.log("slice.onBorderColorChanged: " + series.at(0).borderColor);
62 57 onBorderWidthChanged: console.log("slice.onBorderWidthChanged: " + series.at(0).borderWidth);
63 58 onBrushChanged: console.log("slice.onBrushChanged: " + series.at(0).brush);
64 59 onColorChanged: console.log("slice.onColorChanged: " + series.at(0).color);
65 60 onLabelColorChanged: console.log("slice.onLabelColorChanged: " + series.at(0).labelColor);
66 61 onLabelBrushChanged: console.log("slice.onLabelBrushChanged: " + series.at(0).labelBrush);
67 62 onLabelFontChanged: console.log("slice.onLabelFontChanged: " + series.at(0).labelFont);
68 63 onLabelArmLengthFactorChanged: console.log("slice.onLabelArmLengthFactorChanged: " + series.at(0).labelArmLengthFactor);
69 64 onExplodeDistanceFactorChanged: console.log("slice.onExplodeDistanceFactorChanged: " + series.at(0).explodeDistanceFactor);
70 65 onPercentageChanged: console.log("slice.onPercentageChanged: " + series.at(0).percentage);
71 66 onStartAngleChanged: console.log("slice.onStartAngleChanged: " + series.at(0).startAngle);
72 67 onAngleSpanChanged: console.log("slice.onAngleSpanChanged: " + series.at(0).angleSpan);
73 68 onClicked: console.log("slice.onClicked");
74 69 onHovered: console.log("slice.onHovered: " + state);
75 70 }
76 71
77 72 Button {
78 73 text: "visible"
79 74 onClicked: series.visible = !series.visible;
80 75 }
81 76 Button {
82 77 text: "series hpos +"
83 78 onClicked: series.horizontalPosition += 0.1;
84 79 }
85 80 Button {
86 81 text: "series hpos -"
87 82 onClicked: series.horizontalPosition -= 0.1;
88 83 }
89 84 Button {
90 85 text: "series vpos +"
91 86 onClicked: series.verticalPosition += 0.1;
92 87 }
93 88 Button {
94 89 text: "series vpos -"
95 90 onClicked: series.verticalPosition -= 0.1;
96 91 }
97 92 Button {
98 93 text: "series size +"
99 94 onClicked: series.size += 0.1;
100 95 }
101 96 Button {
102 97 text: "series size -"
103 98 onClicked: series.size -= 0.1;
104 99 }
105 100 Button {
106 101 text: "series start angle +"
107 102 onClicked: series.startAngle += 1.1;
108 103 }
109 104 Button {
110 105 text: "series start angle -"
111 106 onClicked: series.startAngle -= 1.1;
112 107 }
113 108 Button {
114 109 text: "series end angle +"
115 110 onClicked: series.endAngle += 1.1;
116 111 }
117 112 Button {
118 113 text: "series end angle -"
119 114 onClicked: series.endAngle -= 1.1;
120 115 }
121 116 Button {
122 117 text: "slice color"
123 118 onClicked: series.at(0).color = main.nextColor();
124 119 }
125 120 Button {
126 121 text: "slice border color"
127 122 onClicked: series.at(0).borderColor = main.nextColor();
128 123 }
129 124 Button {
130 125 text: "slice border width +"
131 126 onClicked: series.at(0).borderWidth++;
132 127 }
133 128 Button {
134 129 text: "slice border width -"
135 130 onClicked: series.at(0).borderWidth--;
136 131 }
137 132 Button {
138 133 text: "slice label visible"
139 134 onClicked: series.at(0).labelVisible = !series.at(0).labelVisible;
140 135 }
141 136 Button {
142 137 text: "slice label position inside"
143 138 onClicked: series.at(0).labelPosition = PieSlice.LabelInside;
144 139 }
145 140 Button {
146 141 text: "slice label position outside"
147 142 onClicked: series.at(0).labelPosition = PieSlice.LabelOutside;
148 143 }
149 144 Button {
150 145 text: "slice label arm len +"
151 146 onClicked: series.at(0).labelArmLengthFactor += 0.1;
152 147 }
153 148 Button {
154 149 text: "slice label arm len -"
155 150 onClicked: series.at(0).labelArmLengthFactor -= 0.1;
156 151 }
157 152 Button {
158 153 text: "slice label color"
159 154 onClicked: series.at(0).labelColor = main.nextColor();
160 155 }
161 156 Button {
162 157 text: "slice exploded"
163 158 onClicked: series.at(0).exploded = !series.at(0).exploded;
164 159 }
165 160 Button {
166 161 text: "slice explode dist +"
167 162 onClicked: series.at(0).explodeDistanceFactor += 0.1;
168 163 }
169 164 Button {
170 165 text: "slice explode dist -"
171 166 onClicked: series.at(0).explodeDistanceFactor -= 0.1;
172 167 }
173 168 }
General Comments 0
You need to be logged in to leave comments. Login now