##// END OF EJS Templates
Review corrections for pie
Jani Honkonen -
r386:fe666a26d3fa
parent child
Show More
@@ -1,38 +1,38
1 #include <QtGui/QApplication>
1 #include <QtGui/QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartglobal.h>
3 #include <qchartglobal.h>
4 #include <qchartview.h>
4 #include <qchartview.h>
5 #include <qpieseries.h>
5 #include <qpieseries.h>
6 #include <qpieslice.h>
6 #include <qpieslice.h>
7
7
8 QTCOMMERCIALCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
9
9
10 int main(int argc, char *argv[])
10 int main(int argc, char *argv[])
11 {
11 {
12 QApplication a(argc, argv);
12 QApplication a(argc, argv);
13
13
14 QMainWindow window;
14 QMainWindow window;
15
15
16 QChartView* chartView = new QChartView(&window);
16 QChartView* chartView = new QChartView(&window);
17
17
18 //! [1]
18 //! [1]
19 QPieSeries *series = new QPieSeries();
19 QPieSeries *series = new QPieSeries();
20 series->add(1, "Slice 1");
20 series->add(1, "Slice 1");
21 series->add(2, "Slice 2");
21 series->add(2, "Slice 2");
22 series->add(3, "Slice 3");
22 series->add(3, "Slice 3");
23 series->add(4, "Slice 4");
23 series->add(4, "Slice 4");
24 series->add(5, "Slice 5");
24 series->add(5, "Slice 5");
25 chartView->addSeries(series);
25 chartView->addSeries(series);
26 //! [1]
26 //! [1]
27
27
28 //! [2]
28 //! [2]
29 series->enableHoverHighlight(true);
29 series->setHoverHighlighting();
30 series->enableClickExplodes(true);
30 series->setClickExplodes();
31 //! [2]
31 //! [2]
32
32
33 window.setCentralWidget(chartView);
33 window.setCentralWidget(chartView);
34 window.resize(600, 600);
34 window.resize(600, 600);
35 window.show();
35 window.show();
36
36
37 return a.exec();
37 return a.exec();
38 }
38 }
@@ -1,521 +1,516
1 #include "qpieseries.h"
1 #include "qpieseries.h"
2 #include "qpieslice.h"
2 #include "qpieslice.h"
3 #include <QDebug>
3 #include <QDebug>
4
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7
7
8 /*!
8 /*!
9 \class QPieSeries::ChangeSet
9 \class QPieSeries::ChangeSet
10 \brief Defines the changes in the series.
10 \brief Defines the changes in the series.
11
11
12 Contains the changes that have occurred in the series. Lists of added, changed and removed slices.
12 Contains the changes that have occurred in the series. Lists of added, changed and removed slices.
13
13
14 \sa QPieSeries::changed()
14 \sa QPieSeries::changed()
15 */
15 */
16
16
17 /*!
17 /*!
18 \internal
18 \internal
19 */
19 */
20 void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice)
20 void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice)
21 {
21 {
22 if (!m_added.contains(slice))
22 if (!m_added.contains(slice))
23 m_added << slice;
23 m_added << slice;
24 }
24 }
25
25
26 /*!
26 /*!
27 \internal
27 \internal
28 */
28 */
29 void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices)
29 void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices)
30 {
30 {
31 foreach (QPieSlice* s, slices)
31 foreach (QPieSlice* s, slices)
32 appendAdded(s);
32 appendAdded(s);
33 }
33 }
34
34
35 /*!
35 /*!
36 \internal
36 \internal
37 */
37 */
38 void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice)
38 void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice)
39 {
39 {
40 if (!m_changed.contains(slice))
40 if (!m_changed.contains(slice))
41 m_changed << slice;
41 m_changed << slice;
42 }
42 }
43
43
44 /*!
44 /*!
45 \internal
45 \internal
46 */
46 */
47 void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice)
47 void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice)
48 {
48 {
49 if (!m_removed.contains(slice))
49 if (!m_removed.contains(slice))
50 m_removed << slice;
50 m_removed << slice;
51 }
51 }
52
52
53 /*!
53 /*!
54 Returns a list of slices that have been added to the series.
54 Returns a list of slices that have been added to the series.
55 \sa QPieSeries::changed()
55 \sa QPieSeries::changed()
56 */
56 */
57 QList<QPieSlice*> QPieSeries::ChangeSet::added() const
57 QList<QPieSlice*> QPieSeries::ChangeSet::added() const
58 {
58 {
59 return m_added;
59 return m_added;
60 }
60 }
61
61
62 /*!
62 /*!
63 Returns a list of slices that have been changed in the series.
63 Returns a list of slices that have been changed in the series.
64 \sa QPieSeries::changed()
64 \sa QPieSeries::changed()
65 */
65 */
66 QList<QPieSlice*> QPieSeries::ChangeSet::changed() const
66 QList<QPieSlice*> QPieSeries::ChangeSet::changed() const
67 {
67 {
68 return m_changed;
68 return m_changed;
69 }
69 }
70
70
71 /*!
71 /*!
72 Returns a list of slices that have been removed from the series.
72 Returns a list of slices that have been removed from the series.
73 \sa QPieSeries::changed()
73 \sa QPieSeries::changed()
74 */
74 */
75 QList<QPieSlice*> QPieSeries::ChangeSet::removed() const
75 QList<QPieSlice*> QPieSeries::ChangeSet::removed() const
76 {
76 {
77 return m_removed;
77 return m_removed;
78 }
78 }
79
79
80
80
81 /*!
81 /*!
82 Returns true if there are no added/changed or removed slices in the change set.
82 Returns true if there are no added/changed or removed slices in the change set.
83 */
83 */
84 bool QPieSeries::ChangeSet::isEmpty() const
84 bool QPieSeries::ChangeSet::isEmpty() const
85 {
85 {
86 if (m_added.count() || m_changed.count() || m_removed.count())
86 if (m_added.count() || m_changed.count() || m_removed.count())
87 return false;
87 return false;
88 return true;
88 return true;
89 }
89 }
90
90
91 /*!
91 /*!
92 \enum QPieSeries::PiePosition
92 \enum QPieSeries::PiePosition
93
93
94 This enum describes pie position within its bounding rectangle
94 This enum describes pie position within its bounding rectangle
95
95
96 \value PiePositionMaximized
96 \value PiePositionMaximized
97 \value PiePositionTopLeft
97 \value PiePositionTopLeft
98 \value PiePositionTopRight
98 \value PiePositionTopRight
99 \value PiePositionBottomLeft
99 \value PiePositionBottomLeft
100 \value PiePositionBottomRight
100 \value PiePositionBottomRight
101 */
101 */
102
102
103 /*!
103 /*!
104 \class QPieSeries
104 \class QPieSeries
105 \brief Pie series API for QtCommercial Charts
105 \brief Pie series API for QtCommercial Charts
106
106
107 The pie series defines a pie chart which consists of pie slices which are QPieSlice objects.
107 The pie series defines a pie chart which consists of pie slices which are QPieSlice objects.
108 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
108 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
109 The actual slice size (span) is determined by that relative value.
109 The actual slice size is determined by that relative value.
110
110
111 By default the pie is defined as full but it can be a partial pie.
111 By default the pie is defined as a full pie but it can be a partial pie.
112 This can be done by setting a starting angle and angle span to the series.
112 This can be done by setting a starting angle and angle span to the series.
113
113
114 Example on how to create a chart with pie series:
114 To help with the most common user interaction scenarions there some convenience functions.
115 \snippet ../example/piechart/main.cpp 1
115 Like exploding a slice when clicked and higlighting when user hovers over a slice.
116
117 To help with the most common user intercation scenarions there some convenience functions. Specifically
118 exploding and higlighting:
119 \snippet ../example/piechart/main.cpp 2
120
121 */
116 */
122
117
123 /*!
118 /*!
124 Constructs a series object which is a child of \a parent.
119 Constructs a series object which is a child of \a parent.
125 */
120 */
126 QPieSeries::QPieSeries(QObject *parent) :
121 QPieSeries::QPieSeries(QObject *parent) :
127 QSeries(parent),
122 QSeries(parent),
128 m_sizeFactor(1.0),
123 m_sizeFactor(1.0),
129 m_position(PiePositionMaximized),
124 m_position(PiePositionMaximized),
130 m_pieStartAngle(0),
125 m_pieStartAngle(0),
131 m_pieAngleSpan(360)
126 m_pieAngleSpan(360)
132 {
127 {
133
128
134 }
129 }
135
130
136 /*!
131 /*!
137 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
132 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
138 */
133 */
139 QPieSeries::~QPieSeries()
134 QPieSeries::~QPieSeries()
140 {
135 {
141
136
142 }
137 }
143
138
144 /*!
139 /*!
145 Returns QChartSeries::SeriesTypePie.
140 Returns QChartSeries::SeriesTypePie.
146 */
141 */
147 QSeries::QSeriesType QPieSeries::type() const
142 QSeries::QSeriesType QPieSeries::type() const
148 {
143 {
149 return QSeries::SeriesTypePie;
144 return QSeries::SeriesTypePie;
150 }
145 }
151
146
152 /*!
147 /*!
153 Sets an array of \a slices to the series replacing the existing slices.
148 Sets an array of \a slices to the series replacing the existing slices.
154 Slice ownership is passed to the series.
149 Slice ownership is passed to the series.
155 */
150 */
156 void QPieSeries::replace(QList<QPieSlice*> slices)
151 void QPieSeries::replace(QList<QPieSlice*> slices)
157 {
152 {
158 clear();
153 clear();
159 add(slices);
154 add(slices);
160 }
155 }
161
156
162 /*!
157 /*!
163 Adds an array of \a slices to the series.
158 Adds an array of \a slices to the series.
164 Slice ownership is passed to the series.
159 Slice ownership is passed to the series.
165 */
160 */
166 void QPieSeries::add(QList<QPieSlice*> slices)
161 void QPieSeries::add(QList<QPieSlice*> slices)
167 {
162 {
168 ChangeSet changeSet;
163 ChangeSet changeSet;
169 foreach (QPieSlice* s, slices) {
164 foreach (QPieSlice* s, slices) {
170 s->setParent(this);
165 s->setParent(this);
171 m_slices << s;
166 m_slices << s;
172 changeSet.appendAdded(s);
167 changeSet.appendAdded(s);
173 }
168 }
174
169
175 updateDerivativeData();
170 updateDerivativeData();
176
171
177 foreach (QPieSlice* s, slices) {
172 foreach (QPieSlice* s, slices) {
178 connect(s, SIGNAL(changed()), this, SLOT(sliceChanged()));
173 connect(s, SIGNAL(changed()), this, SLOT(sliceChanged()));
179 connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked()));
174 connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked()));
180 connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
175 connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
181 connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
176 connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
182 }
177 }
183
178
184 emit changed(changeSet);
179 emit changed(changeSet);
185 }
180 }
186
181
187 /*!
182 /*!
188 Adds a single \a slice to the series.
183 Adds a single \a slice to the series.
189 Slice ownership is passed to the series.
184 Slice ownership is passed to the series.
190 */
185 */
191 void QPieSeries::add(QPieSlice* slice)
186 void QPieSeries::add(QPieSlice* slice)
192 {
187 {
193 add(QList<QPieSlice*>() << slice);
188 add(QList<QPieSlice*>() << slice);
194 }
189 }
195
190
196
191
197 /*!
192 /*!
198 Adds a single slice to the series with give \a value and \a name.
193 Adds a single slice to the series with give \a value and \a name.
199 Slice ownership is passed to the series.
194 Slice ownership is passed to the series.
200 */
195 */
201 QPieSlice* QPieSeries::add(qreal value, QString name)
196 QPieSlice* QPieSeries::add(qreal value, QString name)
202 {
197 {
203 QPieSlice* slice = new QPieSlice(value, name);
198 QPieSlice* slice = new QPieSlice(value, name);
204 add(slice);
199 add(slice);
205 return slice;
200 return slice;
206 }
201 }
207
202
208 /*!
203 /*!
209 Removes a single \a slice from the series and deletes the slice.
204 Removes a single \a slice from the series and deletes the slice.
210
205
211 Do not reference this pointer after this call.
206 Do not reference this pointer after this call.
212 */
207 */
213 void QPieSeries::remove(QPieSlice* slice)
208 void QPieSeries::remove(QPieSlice* slice)
214 {
209 {
215 if (!m_slices.removeOne(slice)) {
210 if (!m_slices.removeOne(slice)) {
216 Q_ASSERT(0); // TODO: how should this be reported?
211 Q_ASSERT(0); // TODO: how should this be reported?
217 return;
212 return;
218 }
213 }
219
214
220 ChangeSet changeSet;
215 ChangeSet changeSet;
221 changeSet.appendRemoved(slice);
216 changeSet.appendRemoved(slice);
222 emit changed(changeSet);
217 emit changed(changeSet);
223
218
224 delete slice;
219 delete slice;
225 slice = NULL;
220 slice = NULL;
226
221
227 updateDerivativeData();
222 updateDerivativeData();
228 }
223 }
229
224
230 /*!
225 /*!
231 Clears all slices from the series.
226 Clears all slices from the series.
232 */
227 */
233 void QPieSeries::clear()
228 void QPieSeries::clear()
234 {
229 {
235 if (m_slices.count() == 0)
230 if (m_slices.count() == 0)
236 return;
231 return;
237
232
238 ChangeSet changeSet;
233 ChangeSet changeSet;
239 foreach (QPieSlice* s, m_slices) {
234 foreach (QPieSlice* s, m_slices) {
240 changeSet.appendRemoved(s);
235 changeSet.appendRemoved(s);
241 m_slices.removeOne(s);
236 m_slices.removeOne(s);
242 delete s;
237 delete s;
243 }
238 }
244 emit changed(changeSet);
239 emit changed(changeSet);
245 updateDerivativeData();
240 updateDerivativeData();
246 }
241 }
247
242
248 /*!
243 /*!
249 Counts the number of the slices in this series.
244 Counts the number of the slices in this series.
250 */
245 */
251 int QPieSeries::count() const
246 int QPieSeries::count() const
252 {
247 {
253 return m_slices.count();
248 return m_slices.count();
254 }
249 }
255
250
256 /*!
251 /*!
257 Returns a list of slices that belong to this series.
252 Returns a list of slices that belong to this series.
258 */
253 */
259 QList<QPieSlice*> QPieSeries::slices() const
254 QList<QPieSlice*> QPieSeries::slices() const
260 {
255 {
261 return m_slices;
256 return m_slices;
262 }
257 }
263
258
264 /*!
259 /*!
265 Sets the size \a factor of the pie. 1.0 is the default value.
260 Sets the size \a factor of the pie. 1.0 is the default value.
266 Note that the pie will not grow beyond its absolute maximum size.
261 Note that the pie will not grow beyond its absolute maximum size.
267 In practice its use is to make the pie appear smaller.
262 In practice its use is to make the pie appear smaller.
268 \sa sizeFactor()
263 \sa sizeFactor()
269 */
264 */
270 void QPieSeries::setSizeFactor(qreal factor)
265 void QPieSeries::setSizeFactor(qreal factor)
271 {
266 {
272 if (factor < 0.0)
267 if (factor < 0.0)
273 return;
268 return;
274
269
275 if (m_sizeFactor != factor) {
270 if (m_sizeFactor != factor) {
276 m_sizeFactor = factor;
271 m_sizeFactor = factor;
277 emit sizeFactorChanged();
272 emit sizeFactorChanged();
278 }
273 }
279 }
274 }
280
275
281 /*!
276 /*!
282 Gets the size factor of the pie.
277 Gets the size factor of the pie.
283 \sa setSizeFactor()
278 \sa setSizeFactor()
284 */
279 */
285 qreal QPieSeries::sizeFactor() const
280 qreal QPieSeries::sizeFactor() const
286 {
281 {
287 return m_sizeFactor;
282 return m_sizeFactor;
288 }
283 }
289
284
290 /*!
285 /*!
291 Sets the \a position of the pie within its bounding rectangle.
286 Sets the \a position of the pie within its bounding rectangle.
292 \sa PiePosition, position()
287 \sa PiePosition, position()
293 */
288 */
294 void QPieSeries::setPosition(PiePosition position)
289 void QPieSeries::setPosition(PiePosition position)
295 {
290 {
296 if (m_position != position) {
291 if (m_position != position) {
297 m_position = position;
292 m_position = position;
298 emit positionChanged();
293 emit positionChanged();
299 }
294 }
300 }
295 }
301
296
302 /*!
297 /*!
303 Gets the position of the pie within its bounding rectangle.
298 Gets the position of the pie within its bounding rectangle.
304 \sa PiePosition, setPosition()
299 \sa PiePosition, setPosition()
305 */
300 */
306 QPieSeries::PiePosition QPieSeries::position() const
301 QPieSeries::PiePosition QPieSeries::position() const
307 {
302 {
308 return m_position;
303 return m_position;
309 }
304 }
310
305
311
306
312 /*!
307 /*!
313 Sets the \a startAngle and \a angleSpan of this series.
308 Sets the \a startAngle and \a angleSpan of this series.
314
309
315 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
310 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
316 */
311 */
317 void QPieSeries::setSpan(qreal startAngle, qreal angleSpan)
312 void QPieSeries::setSpan(qreal startAngle, qreal angleSpan)
318 {
313 {
319 if (startAngle >= 0 && startAngle < 360 &&
314 if (startAngle >= 0 && startAngle < 360 &&
320 angleSpan > 0 && angleSpan <= 360) {
315 angleSpan > 0 && angleSpan <= 360) {
321 m_pieStartAngle = startAngle;
316 m_pieStartAngle = startAngle;
322 m_pieAngleSpan = angleSpan;
317 m_pieAngleSpan = angleSpan;
323 updateDerivativeData();
318 updateDerivativeData();
324 }
319 }
325 }
320 }
326
321
327 /*!
322 /*!
328 Sets the all the slice labels \a visible or invisible.
323 Sets the all the slice labels \a visible or invisible.
329
324
330 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
325 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
331 */
326 */
332 void QPieSeries::setLabelsVisible(bool visible)
327 void QPieSeries::setLabelsVisible(bool visible)
333 {
328 {
334 foreach (QPieSlice* s, m_slices)
329 foreach (QPieSlice* s, m_slices)
335 s->setLabelVisible(visible);
330 s->setLabelVisible(visible);
336 }
331 }
337
332
338 /*!
333 /*!
339 Convenience method for exploding a slice when user clicks the pie. Set \a enable to true to
334 Convenience method for exploding a slice when user clicks the pie. Set \a enable to true to
340 explode slices by clicking.
335 explode slices by clicking.
341
336
342 \sa QPieSlice::isExploded(), QPieSlice::setExploded(), QPieSlice::setExplodeDistance()
337 \sa QPieSlice::isExploded(), QPieSlice::setExploded(), QPieSlice::setExplodeDistance()
343 */
338 */
344 void QPieSeries::enableClickExplodes(bool enable)
339 void QPieSeries::setClickExplodes(bool enable)
345 {
340 {
346 if (enable)
341 if (enable)
347 connect(this, SIGNAL(clicked(QPieSlice*)), this, SLOT(toggleExploded(QPieSlice*)));
342 connect(this, SIGNAL(clicked(QPieSlice*)), this, SLOT(toggleExploded(QPieSlice*)));
348 else
343 else
349 disconnect(this, SLOT(toggleExploded(QPieSlice*)));
344 disconnect(this, SLOT(toggleExploded(QPieSlice*)));
350 }
345 }
351
346
352 /*!
347 /*!
353 Convenience method for highlighting a slice when user hovers over the slice.
348 Convenience method for highlighting a slice when user hovers over the slice.
354 It changes the slice color to be lighter and shows the label of the slice.
349 It changes the slice color to be lighter and shows the label of the slice.
355 Set \a enable to true to highlight a slice when user hovers on top of it.
350 Set \a enable to true to highlight a slice when user hovers on top of it.
356
351
357 \sa QPieSlice::isExploded(), QPieSlice::setExploded()
352 \sa QPieSlice::isExploded(), QPieSlice::setExploded()
358 */
353 */
359
354
360 void QPieSeries::enableHoverHighlight(bool enable)
355 void QPieSeries::setHoverHighlighting(bool enable)
361 {
356 {
362 if (enable) {
357 if (enable) {
363 connect(this, SIGNAL(hoverEnter(QPieSlice*)), this, SLOT(highlightOn(QPieSlice*)));
358 connect(this, SIGNAL(hoverEnter(QPieSlice*)), this, SLOT(highlightOn(QPieSlice*)));
364 connect(this, SIGNAL(hoverLeave(QPieSlice*)), this, SLOT(highlightOff(QPieSlice*)));
359 connect(this, SIGNAL(hoverLeave(QPieSlice*)), this, SLOT(highlightOff(QPieSlice*)));
365 } else {
360 } else {
366 disconnect(this, SLOT(hoverEnter(QPieSlice*)));
361 disconnect(this, SLOT(hoverEnter(QPieSlice*)));
367 disconnect(this, SLOT(hoverLeave(QPieSlice*)));
362 disconnect(this, SLOT(hoverLeave(QPieSlice*)));
368 }
363 }
369 }
364 }
370
365
371 /*!
366 /*!
372 \fn void QPieSeries::changed(const QPieSeries::ChangeSet& changeSet)
367 \fn void QPieSeries::changed(const QPieSeries::ChangeSet& changeSet)
373
368
374 This signal emitted when something has changed in the series.
369 This signal emitted when something has changed in the series.
375 The \a changeSet contains the details of which slices have been added, changed or removed.
370 The \a changeSet contains the details of which slices have been added, changed or removed.
376
371
377 \sa QPieSeries::ChangeSet, QPieSlice::changed()
372 \sa QPieSeries::ChangeSet, QPieSlice::changed()
378 */
373 */
379
374
380 /*!
375 /*!
381 \fn void QPieSeries::clicked(QPieSlice* slice)
376 \fn void QPieSeries::clicked(QPieSlice* slice)
382
377
383 This signal is emitted when a \a slice has been clicked.
378 This signal is emitted when a \a slice has been clicked.
384
379
385 \sa QPieSlice::clicked()
380 \sa QPieSlice::clicked()
386 */
381 */
387
382
388 /*!
383 /*!
389 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
384 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
390
385
391 This signal is emitted when user has hovered over a \a slice.
386 This signal is emitted when user has hovered over a \a slice.
392
387
393 \sa QPieSlice::hoverEnter()
388 \sa QPieSlice::hoverEnter()
394 */
389 */
395
390
396 /*!
391 /*!
397 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
392 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
398
393
399 This signal is emitted when user has hovered away from a \a slice.
394 This signal is emitted when user has hovered away from a \a slice.
400
395
401 \sa QPieSlice::hoverLeave()
396 \sa QPieSlice::hoverLeave()
402 */
397 */
403
398
404 /*!
399 /*!
405 \fn void QPieSeries::sizeFactorChanged()
400 \fn void QPieSeries::sizeFactorChanged()
406
401
407 This signal is emitted when size factor has been changed.
402 This signal is emitted when size factor has been changed.
408
403
409 \sa sizeFactor(), setSizeFactor()
404 \sa sizeFactor(), setSizeFactor()
410 */
405 */
411
406
412 /*!
407 /*!
413 \fn void QPieSeries::positionChanged()
408 \fn void QPieSeries::positionChanged()
414
409
415 This signal is emitted when position of the pie has been changed.
410 This signal is emitted when position of the pie has been changed.
416
411
417 \sa position(), setPosition()
412 \sa position(), setPosition()
418 */
413 */
419
414
420 void QPieSeries::sliceChanged()
415 void QPieSeries::sliceChanged()
421 {
416 {
422 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
417 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
423 Q_ASSERT(m_slices.contains(slice));
418 Q_ASSERT(m_slices.contains(slice));
424
419
425 ChangeSet changeSet;
420 ChangeSet changeSet;
426 changeSet.appendChanged(slice);
421 changeSet.appendChanged(slice);
427 emit changed(changeSet);
422 emit changed(changeSet);
428
423
429 updateDerivativeData();
424 updateDerivativeData();
430 }
425 }
431
426
432 void QPieSeries::sliceClicked()
427 void QPieSeries::sliceClicked()
433 {
428 {
434 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
429 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
435 Q_ASSERT(m_slices.contains(slice));
430 Q_ASSERT(m_slices.contains(slice));
436 emit clicked(slice);
431 emit clicked(slice);
437 }
432 }
438
433
439 void QPieSeries::sliceHoverEnter()
434 void QPieSeries::sliceHoverEnter()
440 {
435 {
441 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
436 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
442 Q_ASSERT(m_slices.contains(slice));
437 Q_ASSERT(m_slices.contains(slice));
443 emit hoverEnter(slice);
438 emit hoverEnter(slice);
444 }
439 }
445
440
446 void QPieSeries::sliceHoverLeave()
441 void QPieSeries::sliceHoverLeave()
447 {
442 {
448 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
443 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
449 Q_ASSERT(m_slices.contains(slice));
444 Q_ASSERT(m_slices.contains(slice));
450 emit hoverLeave(slice);
445 emit hoverLeave(slice);
451 }
446 }
452
447
453 void QPieSeries::toggleExploded(QPieSlice* slice)
448 void QPieSeries::toggleExploded(QPieSlice* slice)
454 {
449 {
455 Q_ASSERT(slice);
450 Q_ASSERT(slice);
456 slice->setExploded(!slice->isExploded());
451 slice->setExploded(!slice->isExploded());
457 }
452 }
458
453
459 void QPieSeries::highlightOn(QPieSlice* slice)
454 void QPieSeries::highlightOn(QPieSlice* slice)
460 {
455 {
461 Q_ASSERT(slice);
456 Q_ASSERT(slice);
462 QColor c = slice->brush().color().lighter();
457 QColor c = slice->brush().color().lighter();
463 slice->setBrush(c);
458 slice->setBrush(c);
464 slice->setLabelVisible(true);
459 slice->setLabelVisible(true);
465 }
460 }
466
461
467 void QPieSeries::highlightOff(QPieSlice* slice)
462 void QPieSeries::highlightOff(QPieSlice* slice)
468 {
463 {
469 Q_ASSERT(slice);
464 Q_ASSERT(slice);
470 QColor c = slice->brush().color().darker(150);
465 QColor c = slice->brush().color().darker(150);
471 slice->setBrush(c);
466 slice->setBrush(c);
472 slice->setLabelVisible(false);
467 slice->setLabelVisible(false);
473 }
468 }
474
469
475 void QPieSeries::updateDerivativeData()
470 void QPieSeries::updateDerivativeData()
476 {
471 {
477 m_total = 0;
472 m_total = 0;
478
473
479 // nothing to do?
474 // nothing to do?
480 if (m_slices.count() == 0)
475 if (m_slices.count() == 0)
481 return;
476 return;
482
477
483 // calculate total
478 // calculate total
484 foreach (QPieSlice* s, m_slices)
479 foreach (QPieSlice* s, m_slices)
485 m_total += s->value();
480 m_total += s->value();
486
481
487 // we must have some values
482 // we must have some values
488 Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this?
483 Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this?
489
484
490 // update slice attributes
485 // update slice attributes
491 qreal sliceAngle = m_pieStartAngle;
486 qreal sliceAngle = m_pieStartAngle;
492 foreach (QPieSlice* s, m_slices) {
487 foreach (QPieSlice* s, m_slices) {
493
488
494 bool changed = false;
489 bool changed = false;
495
490
496 qreal percentage = s->value() / m_total;
491 qreal percentage = s->value() / m_total;
497 if (s->m_percentage != percentage) {
492 if (s->m_percentage != percentage) {
498 s->m_percentage = percentage;
493 s->m_percentage = percentage;
499 changed = true;
494 changed = true;
500 }
495 }
501
496
502 qreal sliceSpan = m_pieAngleSpan * percentage;
497 qreal sliceSpan = m_pieAngleSpan * percentage;
503 if (s->m_angleSpan != sliceSpan) {
498 if (s->m_angleSpan != sliceSpan) {
504 s->m_angleSpan = sliceSpan;
499 s->m_angleSpan = sliceSpan;
505 changed = true;
500 changed = true;
506 }
501 }
507
502
508 if (s->m_startAngle != sliceAngle) {
503 if (s->m_startAngle != sliceAngle) {
509 s->m_startAngle = sliceAngle;
504 s->m_startAngle = sliceAngle;
510 changed = true;
505 changed = true;
511 }
506 }
512 sliceAngle += sliceSpan;
507 sliceAngle += sliceSpan;
513
508
514 if (changed)
509 if (changed)
515 emit s->changed();
510 emit s->changed();
516 }
511 }
517 }
512 }
518
513
519 #include "moc_qpieseries.cpp"
514 #include "moc_qpieseries.cpp"
520
515
521 QTCOMMERCIALCHART_END_NAMESPACE
516 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,132 +1,129
1 #ifndef PIESERIES_H
1 #ifndef PIESERIES_H
2 #define PIESERIES_H
2 #define PIESERIES_H
3
3
4 #include "qseries.h"
4 #include "qseries.h"
5 #include <QObject>
5 #include <QObject>
6 #include <QRectF>
6 #include <QRectF>
7 #include <QColor>
7 #include <QColor>
8 #include <QPen>
8 #include <QPen>
9 #include <QBrush>
9 #include <QBrush>
10 #include <QSignalMapper>
10 #include <QSignalMapper>
11
11
12 class QGraphicsObject;
12 class QGraphicsObject;
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14 class PiePresenter;
14 class PiePresenter;
15 class PieSlice;
15 class PieSlice;
16 class QPieSlice;
16 class QPieSlice;
17
17
18 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QSeries
18 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QSeries
19 {
19 {
20 Q_OBJECT
20 Q_OBJECT
21
21
22 public:
22 public:
23 enum PiePosition {
23 enum PiePosition {
24 PiePositionMaximized = 0,
24 PiePositionMaximized = 0,
25 PiePositionTopLeft,
25 PiePositionTopLeft,
26 PiePositionTopRight,
26 PiePositionTopRight,
27 PiePositionBottomLeft,
27 PiePositionBottomLeft,
28 PiePositionBottomRight
28 PiePositionBottomRight
29 };
29 };
30
30
31 class ChangeSet
31 class ChangeSet
32 {
32 {
33 public:
33 public:
34
34
35 // TODO: these should not really be exposed to the public API
35 // TODO: these should not really be exposed to the public API
36 void appendAdded(QPieSlice* slice);
36 void appendAdded(QPieSlice* slice);
37 void appendAdded(QList<QPieSlice*> slices);
37 void appendAdded(QList<QPieSlice*> slices);
38 void appendChanged(QPieSlice* slice);
38 void appendChanged(QPieSlice* slice);
39 void appendRemoved(QPieSlice* slice);
39 void appendRemoved(QPieSlice* slice);
40
40
41 QList<QPieSlice*> added() const;
41 QList<QPieSlice*> added() const;
42 QList<QPieSlice*> changed() const;
42 QList<QPieSlice*> changed() const;
43 QList<QPieSlice*> removed() const;
43 QList<QPieSlice*> removed() const;
44
44
45 bool isEmpty() const;
45 bool isEmpty() const;
46
46
47 private:
47 private:
48 QList<QPieSlice*> m_added;
48 QList<QPieSlice*> m_added;
49 QList<QPieSlice*> m_changed;
49 QList<QPieSlice*> m_changed;
50 QList<QPieSlice*> m_removed;
50 QList<QPieSlice*> m_removed;
51 };
51 };
52
52
53 public:
53 public:
54 QPieSeries(QObject *parent = 0);
54 QPieSeries(QObject *parent = 0);
55 virtual ~QPieSeries();
55 virtual ~QPieSeries();
56
56
57 public: // from QChartSeries
57 public: // from QChartSeries
58 QSeriesType type() const;
58 QSeriesType type() const;
59
59
60 public:
60 public:
61 void replace(QList<QPieSlice*> slices);
61 void replace(QList<QPieSlice*> slices);
62 void add(QList<QPieSlice*> slices);
62 void add(QList<QPieSlice*> slices);
63 void add(QPieSlice* slice);
63 void add(QPieSlice* slice);
64 QPieSlice* add(qreal value, QString name);
64 QPieSlice* add(qreal value, QString name);
65 void remove(QPieSlice* slice);
65 void remove(QPieSlice* slice);
66 void clear();
66 void clear();
67
67
68 int count() const;
68 int count() const;
69
70 QList<QPieSlice*> slices() const;
69 QList<QPieSlice*> slices() const;
71
70
72 void setSizeFactor(qreal sizeFactor);
71 void setSizeFactor(qreal sizeFactor);
73 qreal sizeFactor() const;
72 qreal sizeFactor() const;
74
75 void setPosition(PiePosition position);
73 void setPosition(PiePosition position);
76 PiePosition position() const;
74 PiePosition position() const;
77
78 void setSpan(qreal startAngle, qreal angleSpan);
75 void setSpan(qreal startAngle, qreal angleSpan);
79
76
80 void setLabelsVisible(bool visible);
77 void setLabelsVisible(bool visible = true);
81 void enableClickExplodes(bool enable);
78 void setClickExplodes(bool enable = true);
82 void enableHoverHighlight(bool enable);
79 void setHoverHighlighting(bool enable = true);
83
80
84 // TODO: find slices?
81 // TODO: find slices?
85 // QList<QPieSlice*> findByValue(qreal value);
82 // QList<QPieSlice*> findByValue(qreal value);
86 // ...
83 // ...
87
84
88 // TODO: sorting slices?
85 // TODO: sorting slices?
89 // void sort(QPieSeries::SortByValue|label|??)
86 // void sort(QPieSeries::SortByValue|label|??)
90
87
91 // TODO: general graphics customization
88 // TODO: general graphics customization
92 // setDrawStyle(2d|3d)
89 // setDrawStyle(2d|3d)
93 // setDropShadows(bool)
90 // setDropShadows(bool)
94
91
95 Q_SIGNALS:
92 Q_SIGNALS:
96 void changed(const QPieSeries::ChangeSet& changeSet);
93 void changed(const QPieSeries::ChangeSet& changeSet);
97 void clicked(QPieSlice* slice);
94 void clicked(QPieSlice* slice);
98 void hoverEnter(QPieSlice* slice);
95 void hoverEnter(QPieSlice* slice);
99 void hoverLeave(QPieSlice* slice);
96 void hoverLeave(QPieSlice* slice);
100 void sizeFactorChanged();
97 void sizeFactorChanged();
101 void positionChanged();
98 void positionChanged();
102
99
103 private Q_SLOTS: // TODO: should be private and not visible in the interface at all
100 private Q_SLOTS: // TODO: should be private and not visible in the interface at all
104 void sliceChanged();
101 void sliceChanged();
105 void sliceClicked();
102 void sliceClicked();
106 void sliceHoverEnter();
103 void sliceHoverEnter();
107 void sliceHoverLeave();
104 void sliceHoverLeave();
108 void toggleExploded(QPieSlice* slice);
105 void toggleExploded(QPieSlice* slice);
109 void highlightOn(QPieSlice* slice);
106 void highlightOn(QPieSlice* slice);
110 void highlightOff(QPieSlice* slice);
107 void highlightOff(QPieSlice* slice);
111
108
112 private:
109 private:
113 void updateDerivativeData();
110 void updateDerivativeData();
114
111
115 private:
112 private:
116 Q_DISABLE_COPY(QPieSeries)
113 Q_DISABLE_COPY(QPieSeries)
117
114
118 // TODO: use PIML
115 // TODO: use PIML
119 friend class PiePresenter;
116 friend class PiePresenter;
120 friend class PieSlice;
117 friend class PieSlice;
121
118
122 QList<QPieSlice*> m_slices;
119 QList<QPieSlice*> m_slices;
123 qreal m_sizeFactor;
120 qreal m_sizeFactor;
124 PiePosition m_position;
121 PiePosition m_position;
125 qreal m_total;
122 qreal m_total;
126 qreal m_pieStartAngle;
123 qreal m_pieStartAngle;
127 qreal m_pieAngleSpan;
124 qreal m_pieAngleSpan;
128 };
125 };
129
126
130 QTCOMMERCIALCHART_END_NAMESPACE
127 QTCOMMERCIALCHART_END_NAMESPACE
131
128
132 #endif // PIESERIES_H
129 #endif // PIESERIES_H
@@ -1,375 +1,376
1 #include "qpieslice.h"
1 #include "qpieslice.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 #define DEFAULT_PEN_COLOR Qt::black
5 #define DEFAULT_PEN_COLOR Qt::black
6 #define DEFAULT_BRUSH_COLOR Qt::white
6 #define DEFAULT_BRUSH_COLOR Qt::white
7 #define DEFAULT_LABEL_ARM_LENGTH 40
7 #define DEFAULT_LABEL_ARM_LENGTH 40
8 #define DEFAULT_EXPOLODE_DISTANCE 20
8 #define DEFAULT_EXPOLODE_DISTANCE 20
9
9
10 /*!
10 /*!
11 \class QPieSlice
11 \class QPieSlice
12 \brief Defines a slice in pie series.
12 \brief Defines a slice in pie series.
13
13
14 Holds all the data of a single slice in a QPieSeries and provides the means
14 Holds all the data of a single slice in a QPieSeries and provides the means
15 to modify slice data and customize the visual appearance of the slice.
15 to modify slice data and customize the visual appearance of the slice.
16
16
17 It also provides the means to customize user interaction with the slice by
17 It also provides the means to customize user interaction with the slice by
18 providing signals for clicking and hover events.
18 providing signals for clicking and hover events.
19 */
19 */
20
20
21 /*!
21 /*!
22 \property QPieSlice::label
22 \property QPieSlice::label
23
23
24 Label of the slice.
24 Label of the slice.
25 */
25 */
26
26
27 /*!
27 /*!
28 \property QPieSlice::value
28 \property QPieSlice::value
29
29
30 Value of the slice.
30 Value of the slice.
31 */
31 */
32
32
33 /*!
33 /*!
34 Constructs an empty slice with a \a parent.
34 Constructs an empty slice with a \a parent.
35
35
36 Note that QPieSeries takes ownership of the slice when it is set/added.
36 Note that QPieSeries takes ownership of the slice when it is set/added.
37
37
38 \sa QPieSeries::replace(), QPieSeries::add()
38 \sa QPieSeries::replace(), QPieSeries::add()
39 */
39 */
40 QPieSlice::QPieSlice(QObject *parent)
40 QPieSlice::QPieSlice(QObject *parent)
41 :QObject(parent),
41 :QObject(parent),
42 m_value(0),
42 m_value(0),
43 m_isLabelVisible(false),
43 m_isLabelVisible(false),
44 m_isExploded(false),
44 m_isExploded(false),
45 m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE),
45 m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE),
46 m_percentage(0),
46 m_percentage(0),
47 m_startAngle(0),
47 m_startAngle(0),
48 m_angleSpan(0),
48 m_angleSpan(0),
49 m_pen(DEFAULT_PEN_COLOR),
49 m_pen(DEFAULT_PEN_COLOR),
50 m_brush(DEFAULT_BRUSH_COLOR),
50 m_brush(DEFAULT_BRUSH_COLOR),
51 m_labelPen(DEFAULT_PEN_COLOR),
51 m_labelPen(DEFAULT_PEN_COLOR),
52 m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH)
52 m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH)
53 {
53 {
54
54
55 }
55 }
56
56
57 /*!
57 /*!
58 Constructs an empty slice with given \a value, \a label and a \a parent.
58 Constructs an empty slice with given \a value, \a label and a \a parent.
59 Note that QPieSeries takes ownership of the slice when it is set/added.
59 Note that QPieSeries takes ownership of the slice when it is set/added.
60 \sa QPieSeries::replace(), QPieSeries::add()
60 \sa QPieSeries::replace(), QPieSeries::add()
61 */
61 */
62 QPieSlice::QPieSlice(qreal value, QString label, QObject *parent)
62 QPieSlice::QPieSlice(qreal value, QString label, QObject *parent)
63 :QObject(parent),
63 :QObject(parent),
64 m_value(value),
64 m_value(value),
65 m_label(label),
65 m_label(label),
66 m_isLabelVisible(false),
66 m_isLabelVisible(false),
67 m_isExploded(false),
67 m_isExploded(false),
68 m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE),
68 m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE),
69 m_percentage(0),
69 m_percentage(0),
70 m_startAngle(0),
70 m_startAngle(0),
71 m_angleSpan(0),
71 m_angleSpan(0),
72 m_pen(DEFAULT_PEN_COLOR),
72 m_pen(DEFAULT_PEN_COLOR),
73 m_brush(DEFAULT_BRUSH_COLOR),
73 m_brush(DEFAULT_BRUSH_COLOR),
74 m_labelPen(DEFAULT_PEN_COLOR),
74 m_labelPen(DEFAULT_PEN_COLOR),
75 m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH)
75 m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH)
76 {
76 {
77
77
78 }
78 }
79
79
80 /*!
80 /*!
81 Destroys the slice.
81 Destroys the slice.
82 User should not delete the slice if it has been added to the series.
82 User should not delete the slice if it has been added to the series.
83 */
83 */
84 QPieSlice::~QPieSlice()
84 QPieSlice::~QPieSlice()
85 {
85 {
86
86
87 }
87 }
88
88
89 /*!
89 /*!
90 Gets the value of the slice.
90 Gets the value of the slice.
91 Note that all values in the series
91 Note that all values in the series
92 \sa setValue()
92 \sa setValue()
93 */
93 */
94 qreal QPieSlice::value() const
94 qreal QPieSlice::value() const
95 {
95 {
96 return m_value;
96 return m_value;
97 }
97 }
98
98
99 /*!
99 /*!
100 Gets the label of the slice.
100 Gets the label of the slice.
101 \sa setLabel()
101 \sa setLabel()
102 */
102 */
103 QString QPieSlice::label() const
103 QString QPieSlice::label() const
104 {
104 {
105 return m_label;
105 return m_label;
106 }
106 }
107
107
108 /*!
108 /*!
109 Returns true if label is set as visible.
109 Returns true if label is set as visible.
110 \sa setLabelVisible()
110 \sa setLabelVisible()
111 */
111 */
112 bool QPieSlice::isLabelVisible() const
112 bool QPieSlice::isLabelVisible() const
113 {
113 {
114 return m_isLabelVisible;
114 return m_isLabelVisible;
115 }
115 }
116
116
117 /*!
117 /*!
118 Returns true if slice is exloded from the pie.
118 Returns true if slice is exloded from the pie.
119 \sa setExploded()
119 \sa setExploded()
120 */
120 */
121 bool QPieSlice::isExploded() const
121 bool QPieSlice::isExploded() const
122 {
122 {
123 return m_isExploded;
123 return m_isExploded;
124 }
124 }
125
125
126 /*!
126 /*!
127 Returns the explosion distance of the slice.
127 Returns the explosion distance of the slice.
128 Default value is 20.
128 Default value is 20.
129 \sa setExplodeDistance()
129 \sa setExplodeDistance()
130 */
130 */
131 qreal QPieSlice::explodeDistance() const
131 qreal QPieSlice::explodeDistance() const
132 {
132 {
133 return m_explodeDistance;
133 return m_explodeDistance;
134 }
134 }
135
135
136 /*!
136 /*!
137 Returns the percentage of this slice compared to all slices in the same series.
137 Returns the percentage of this slice compared to all slices in the same series.
138 The returned value ranges from 0 to 1.0.
138
139
139 Updated internally after the slice is added to the series.
140 Updated internally after the slice is added to the series.
140 */
141 */
141 qreal QPieSlice::percentage() const
142 qreal QPieSlice::percentage() const
142 {
143 {
143 return m_percentage;
144 return m_percentage;
144 }
145 }
145
146
146 /*!
147 /*!
147 Returns the starting angle of this slice in the series it belongs to.
148 Returns the starting angle of this slice in the series it belongs to.
148
149
149 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
150 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
150
151
151 Updated internally after the slice is added to the series.
152 Updated internally after the slice is added to the series.
152 */
153 */
153 qreal QPieSlice::startAngle() const
154 qreal QPieSlice::startAngle() const
154 {
155 {
155 return m_startAngle;
156 return m_startAngle;
156 }
157 }
157
158
158 /*!
159 /*!
159 Returns the end angle of this slice in the series it belongs to.
160 Returns the end angle of this slice in the series it belongs to.
160
161
161 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
162 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
162
163
163 Updated internally after the slice is added to the series.
164 Updated internally after the slice is added to the series.
164 */
165 */
165 qreal QPieSlice::endAngle() const
166 qreal QPieSlice::endAngle() const
166 {
167 {
167 return m_startAngle + m_angleSpan;
168 return m_startAngle + m_angleSpan;
168 }
169 }
169
170
170 /*!
171 /*!
171 Returns the pen used to draw this slice.
172 Returns the pen used to draw this slice.
172 \sa setPen()
173 \sa setPen()
173 */
174 */
174 QPen QPieSlice::pen() const
175 QPen QPieSlice::pen() const
175 {
176 {
176 return m_pen;
177 return m_pen;
177 }
178 }
178
179
179 /*!
180 /*!
180 Returns the brush used to draw this slice.
181 Returns the brush used to draw this slice.
181 \sa setBrush()
182 \sa setBrush()
182 */
183 */
183 QBrush QPieSlice::brush() const
184 QBrush QPieSlice::brush() const
184 {
185 {
185 return m_brush;
186 return m_brush;
186 }
187 }
187
188
188 /*!
189 /*!
189 Returns the pen used to draw label in this slice.
190 Returns the pen used to draw label in this slice.
190 \sa setLabelPen()
191 \sa setLabelPen()
191 */
192 */
192 QPen QPieSlice::labelPen() const
193 QPen QPieSlice::labelPen() const
193 {
194 {
194 return m_labelPen;
195 return m_labelPen;
195 }
196 }
196
197
197 /*!
198 /*!
198 Returns the font used to draw label in this slice.
199 Returns the font used to draw label in this slice.
199 \sa setLabelFont()
200 \sa setLabelFont()
200 */
201 */
201 QFont QPieSlice::labelFont() const
202 QFont QPieSlice::labelFont() const
202 {
203 {
203 return m_labelFont;
204 return m_labelFont;
204 }
205 }
205
206
206 /*!
207 /*!
207 Returns the label arm lenght used in this slice.
208 Returns the label arm lenght used in this slice.
208 Default value is 40 pixels.
209 Default value is 40 pixels.
209 \sa setLabelArmLength()
210 \sa setLabelArmLength()
210 */
211 */
211 qreal QPieSlice::labelArmLength() const
212 qreal QPieSlice::labelArmLength() const
212 {
213 {
213 return m_labelArmLength;
214 return m_labelArmLength;
214 }
215 }
215
216
216 /*!
217 /*!
217 \fn void QPieSlice::clicked()
218 \fn void QPieSlice::clicked()
218
219
219 This signal is emitted when user has clicked the slice.
220 This signal is emitted when user has clicked the slice.
220
221
221 \sa QPieSeries::clicked()
222 \sa QPieSeries::clicked()
222 */
223 */
223
224
224 /*!
225 /*!
225 \fn void QPieSlice::hoverEnter()
226 \fn void QPieSlice::hoverEnter()
226
227
227 This signal is emitted when user has hovered over the slice.
228 This signal is emitted when user has hovered over the slice.
228
229
229 \sa QPieSeries::hoverEnter()
230 \sa QPieSeries::hoverEnter()
230 */
231 */
231
232
232 /*!
233 /*!
233 \fn void QPieSlice::hoverLeave()
234 \fn void QPieSlice::hoverLeave()
234
235
235 This signal is emitted when user has hovered away from the slice.
236 This signal is emitted when user has hovered away from the slice.
236
237
237 \sa QPieSeries::hoverLeave()
238 \sa QPieSeries::hoverLeave()
238 */
239 */
239
240
240 /*!
241 /*!
241 \fn void QPieSlice::changed()
242 \fn void QPieSlice::changed()
242
243
243 This signal emitted when something has changed in the slice.
244 This signal emitted when something has changed in the slice.
244
245
245 \sa QPieSeries::changed()
246 \sa QPieSeries::changed()
246 */
247 */
247
248
248 /*!
249 /*!
249 Sets the value of this slice.
250 Sets the value of this slice.
250 \sa value()
251 \sa value()
251 */
252 */
252 void QPieSlice::setValue(qreal value)
253 void QPieSlice::setValue(qreal value)
253 {
254 {
254 if (m_value != value) {
255 if (m_value != value) {
255 m_value = value;
256 m_value = value;
256 emit changed();
257 emit changed();
257 }
258 }
258 }
259 }
259
260
260 /*!
261 /*!
261 Sets the \a label of the slice.
262 Sets the \a label of the slice.
262 \sa label()
263 \sa label()
263 */
264 */
264 void QPieSlice::setLabel(QString label)
265 void QPieSlice::setLabel(QString label)
265 {
266 {
266 if (m_label != label) {
267 if (m_label != label) {
267 m_label = label;
268 m_label = label;
268 emit changed();
269 emit changed();
269 }
270 }
270 }
271 }
271
272
272 /*!
273 /*!
273 Sets the label \a visible in this slice.
274 Sets the label \a visible in this slice.
274 \sa isLabelVisible(), QPieSeries::setLabelsVisible()
275 \sa isLabelVisible(), QPieSeries::setLabelsVisible()
275 */
276 */
276 void QPieSlice::setLabelVisible(bool visible)
277 void QPieSlice::setLabelVisible(bool visible)
277 {
278 {
278 if (m_isLabelVisible != visible) {
279 if (m_isLabelVisible != visible) {
279 m_isLabelVisible = visible;
280 m_isLabelVisible = visible;
280 emit changed();
281 emit changed();
281 }
282 }
282 }
283 }
283
284
284 /*!
285 /*!
285 Sets this slice \a exploded.
286 Sets this slice \a exploded.
286 \sa isExploded(), setExplodeDistance(), QPieSeries::enableClickExplodes()
287 \sa isExploded(), setExplodeDistance(), QPieSeries::setClickExplodes()
287 */
288 */
288 void QPieSlice::setExploded(bool exploded)
289 void QPieSlice::setExploded(bool exploded)
289 {
290 {
290 if (m_isExploded != exploded) {
291 if (m_isExploded != exploded) {
291 m_isExploded = exploded;
292 m_isExploded = exploded;
292 emit changed();
293 emit changed();
293 }
294 }
294 }
295 }
295
296
296 /*!
297 /*!
297 Sets the explosion \a distance of this slice.
298 Sets the explosion \a distance of this slice.
298 It is the distance the slice is moved away from the pie center.
299 It is the distance the slice is moved away from the pie center.
299 \sa explodeDistance(), isExploded(), QPieSeries::enableClickExplodes()
300 \sa explodeDistance(), isExploded(), QPieSeries::setClickExplodes()
300 */
301 */
301 void QPieSlice::setExplodeDistance(qreal distance)
302 void QPieSlice::setExplodeDistance(qreal distance)
302 {
303 {
303 if (m_explodeDistance != distance) {
304 if (m_explodeDistance != distance) {
304 m_explodeDistance = distance;
305 m_explodeDistance = distance;
305 emit changed();
306 emit changed();
306 }
307 }
307 }
308 }
308
309
309 /*!
310 /*!
310 Sets the \a pen used to draw this slice.
311 Sets the \a pen used to draw this slice.
311 Note that applying a theme will override this.
312 Note that applying a theme will override this.
312 \sa pen()
313 \sa pen()
313 */
314 */
314 void QPieSlice::setPen(QPen pen)
315 void QPieSlice::setPen(QPen pen)
315 {
316 {
316 if (m_pen != pen) {
317 if (m_pen != pen) {
317 m_pen = pen;
318 m_pen = pen;
318 emit changed();
319 emit changed();
319 }
320 }
320 }
321 }
321
322
322 /*!
323 /*!
323 Sets the \a brush used to draw this slice.
324 Sets the \a brush used to draw this slice.
324 Note that applying a theme will override this.
325 Note that applying a theme will override this.
325 \sa brush()
326 \sa brush()
326 */
327 */
327 void QPieSlice::setBrush(QBrush brush)
328 void QPieSlice::setBrush(QBrush brush)
328 {
329 {
329 if (m_brush != brush) {
330 if (m_brush != brush) {
330 m_brush = brush;
331 m_brush = brush;
331 emit changed();
332 emit changed();
332 }
333 }
333 }
334 }
334
335
335 /*!
336 /*!
336 Sets the \a pen used to draw the label in this slice.
337 Sets the \a pen used to draw the label in this slice.
337 Note that applying a theme will override this.
338 Note that applying a theme will override this.
338 \sa labelPen()
339 \sa labelPen()
339 */
340 */
340 void QPieSlice::setLabelPen(QPen pen)
341 void QPieSlice::setLabelPen(QPen pen)
341 {
342 {
342 if (m_labelPen != pen) {
343 if (m_labelPen != pen) {
343 m_labelPen = pen;
344 m_labelPen = pen;
344 emit changed();
345 emit changed();
345 }
346 }
346 }
347 }
347
348
348 /*!
349 /*!
349 Sets the \a font used to draw the label in this slice.
350 Sets the \a font used to draw the label in this slice.
350 Note that applying a theme will override this.
351 Note that applying a theme will override this.
351 \sa labelFont()
352 \sa labelFont()
352 */
353 */
353 void QPieSlice::setLabelFont(QFont font)
354 void QPieSlice::setLabelFont(QFont font)
354 {
355 {
355 if (m_labelFont != font) {
356 if (m_labelFont != font) {
356 m_labelFont = font;
357 m_labelFont = font;
357 emit changed();
358 emit changed();
358 }
359 }
359 }
360 }
360
361
361 /*!
362 /*!
362 Sets the label arm \a length used to draw the label in this slice.
363 Sets the label arm \a length used to draw the label in this slice.
363 \sa labelArmLength()
364 \sa labelArmLength()
364 */
365 */
365 void QPieSlice::setLabelArmLength(qreal length)
366 void QPieSlice::setLabelArmLength(qreal length)
366 {
367 {
367 if (m_labelArmLength != length) {
368 if (m_labelArmLength != length) {
368 m_labelArmLength = length;
369 m_labelArmLength = length;
369 emit changed();
370 emit changed();
370 }
371 }
371 }
372 }
372
373
373 #include "moc_qpieslice.cpp"
374 #include "moc_qpieslice.cpp"
374
375
375 QTCOMMERCIALCHART_END_NAMESPACE
376 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now