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