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