@@ -1,20 +1,22 | |||||
1 | #include "customslice.h" |
|
1 | #include "customslice.h" | |
2 |
|
2 | |||
3 | CustomSlice::CustomSlice(qreal value, QObject* parent) |
|
3 | CustomSlice::CustomSlice(qreal value, QObject* parent) | |
4 | :QPieSlice(parent) |
|
4 | :QPieSlice(parent) | |
5 | { |
|
5 | { | |
6 | setValue(value); |
|
6 | setValue(value); | |
|
7 | setLabelVisible(true); | |||
|
8 | setExploded(true); | |||
7 | connect(this, SIGNAL(changed()), this, SLOT(updateLabel())); |
|
9 | connect(this, SIGNAL(changed()), this, SLOT(updateLabel())); | |
8 | connect(this, SIGNAL(hoverEnter()), this, SLOT(toggleExploded())); |
|
10 | connect(this, SIGNAL(hoverEnter()), this, SLOT(toggleExploded())); | |
9 | connect(this, SIGNAL(hoverLeave()), this, SLOT(toggleExploded())); |
|
11 | connect(this, SIGNAL(hoverLeave()), this, SLOT(toggleExploded())); | |
10 | } |
|
12 | } | |
11 |
|
13 | |||
12 | void CustomSlice::updateLabel() |
|
14 | void CustomSlice::updateLabel() | |
13 | { |
|
15 | { | |
14 | setLabel(QString::number(this->percentage())); |
|
16 | setLabel(QString::number(this->percentage()*100) + "%"); | |
15 | } |
|
17 | } | |
16 |
|
18 | |||
17 | void CustomSlice::toggleExploded() |
|
19 | void CustomSlice::toggleExploded() | |
18 | { |
|
20 | { | |
19 | setExploded(!isExploded()); |
|
21 | setExploded(!isExploded()); | |
20 | } |
|
22 | } |
@@ -1,306 +1,308 | |||||
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 | void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice) |
|
10 | void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice) | |
11 | { |
|
11 | { | |
12 | if (!m_added.contains(slice)) |
|
12 | if (!m_added.contains(slice)) | |
13 | m_added << slice; |
|
13 | m_added << slice; | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices) |
|
16 | void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices) | |
17 | { |
|
17 | { | |
18 | foreach (QPieSlice* s, slices) |
|
18 | foreach (QPieSlice* s, slices) | |
19 | appendAdded(s); |
|
19 | appendAdded(s); | |
20 | } |
|
20 | } | |
21 |
|
21 | |||
22 | void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice) |
|
22 | void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice) | |
23 | { |
|
23 | { | |
24 | if (!m_changed.contains(slice)) |
|
24 | if (!m_changed.contains(slice)) | |
25 | m_changed << slice; |
|
25 | m_changed << slice; | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice) |
|
28 | void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice) | |
29 | { |
|
29 | { | |
30 | if (!m_removed.contains(slice)) |
|
30 | if (!m_removed.contains(slice)) | |
31 | m_removed << slice; |
|
31 | m_removed << slice; | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QList<QPieSlice*> QPieSeries::ChangeSet::added() const |
|
34 | QList<QPieSlice*> QPieSeries::ChangeSet::added() const | |
35 | { |
|
35 | { | |
36 | return m_added; |
|
36 | return m_added; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | QList<QPieSlice*> QPieSeries::ChangeSet::changed() const |
|
39 | QList<QPieSlice*> QPieSeries::ChangeSet::changed() const | |
40 | { |
|
40 | { | |
41 | return m_changed; |
|
41 | return m_changed; | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | QList<QPieSlice*> QPieSeries::ChangeSet::removed() const |
|
44 | QList<QPieSlice*> QPieSeries::ChangeSet::removed() const | |
45 | { |
|
45 | { | |
46 | return m_removed; |
|
46 | return m_removed; | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | bool QPieSeries::ChangeSet::isEmpty() const |
|
49 | bool QPieSeries::ChangeSet::isEmpty() const | |
50 | { |
|
50 | { | |
51 | if (m_added.count() || m_changed.count() || m_removed.count()) |
|
51 | if (m_added.count() || m_changed.count() || m_removed.count()) | |
52 | return false; |
|
52 | return false; | |
53 | return true; |
|
53 | return true; | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | QPieSeries::QPieSeries(QObject *parent) : |
|
57 | QPieSeries::QPieSeries(QObject *parent) : | |
58 | QChartSeries(parent), |
|
58 | QChartSeries(parent), | |
59 | m_sizeFactor(1.0), |
|
59 | m_sizeFactor(1.0), | |
60 | m_position(PiePositionMaximized), |
|
60 | m_position(PiePositionMaximized), | |
61 | m_pieStartAngle(0), |
|
61 | m_pieStartAngle(0), | |
62 | m_pieSpan(360) |
|
62 | m_pieSpan(360) | |
63 | { |
|
63 | { | |
64 |
|
64 | |||
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | QPieSeries::~QPieSeries() |
|
67 | QPieSeries::~QPieSeries() | |
68 | { |
|
68 | { | |
69 |
|
69 | |||
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | bool QPieSeries::setData(QList<qreal> data) |
|
72 | bool QPieSeries::setData(QList<qreal> data) | |
73 | { |
|
73 | { | |
74 | // TODO: remove this function |
|
74 | // TODO: remove this function | |
75 | QList<QPieSlice*> slices; |
|
75 | QList<QPieSlice*> slices; | |
76 | foreach (qreal value, data) |
|
76 | foreach (qreal value, data) | |
77 | slices << new QPieSlice(value, QString::number(value)); |
|
77 | slices << new QPieSlice(value, QString::number(value)); | |
78 | set(slices); |
|
78 | set(slices); | |
79 | return true; |
|
79 | return true; | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void QPieSeries::set(QList<QPieSlice*> slices) |
|
82 | void QPieSeries::set(QList<QPieSlice*> slices) | |
83 | { |
|
83 | { | |
84 | clear(); |
|
84 | clear(); | |
85 | add(slices); |
|
85 | add(slices); | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | void QPieSeries::add(QList<QPieSlice*> slices) |
|
88 | void QPieSeries::add(QList<QPieSlice*> slices) | |
89 | { |
|
89 | { | |
90 | ChangeSet changeSet; |
|
90 | ChangeSet changeSet; | |
91 | foreach (QPieSlice* s, slices) { |
|
91 | foreach (QPieSlice* s, slices) { | |
92 | s->setParent(this); |
|
92 | s->setParent(this); | |
93 | m_slices << s; |
|
93 | m_slices << s; | |
94 | changeSet.appendAdded(s); |
|
94 | changeSet.appendAdded(s); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | updateDerivativeData(); |
|
97 | updateDerivativeData(); | |
98 |
|
98 | |||
99 | foreach (QPieSlice* s, slices) { |
|
99 | foreach (QPieSlice* s, slices) { | |
100 | connect(s, SIGNAL(changed()), this, SLOT(sliceChanged())); |
|
100 | connect(s, SIGNAL(changed()), this, SLOT(sliceChanged())); | |
101 | connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked())); |
|
101 | connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked())); | |
102 | connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter())); |
|
102 | connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter())); | |
103 | connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave())); |
|
103 | connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave())); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | emit changed(changeSet); |
|
106 | emit changed(changeSet); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void QPieSeries::add(QPieSlice* slice) |
|
109 | void QPieSeries::add(QPieSlice* slice) | |
110 | { |
|
110 | { | |
111 | add(QList<QPieSlice*>() << slice); |
|
111 | add(QList<QPieSlice*>() << slice); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | QPieSlice* QPieSeries::add(qreal value, QString name) |
|
114 | QPieSlice* QPieSeries::add(qreal value, QString name) | |
115 | { |
|
115 | { | |
116 | QPieSlice* slice = new QPieSlice(value, name); |
|
116 | QPieSlice* slice = new QPieSlice(value, name); | |
117 | add(slice); |
|
117 | add(slice); | |
118 | return slice; |
|
118 | return slice; | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void QPieSeries::remove(QPieSlice* slice) |
|
121 | void QPieSeries::remove(QPieSlice* slice) | |
122 | { |
|
122 | { | |
123 | if (!m_slices.removeOne(slice)) { |
|
123 | if (!m_slices.removeOne(slice)) { | |
124 | Q_ASSERT(0); // TODO: how should this be reported? |
|
124 | Q_ASSERT(0); // TODO: how should this be reported? | |
125 | return; |
|
125 | return; | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | ChangeSet changeSet; |
|
128 | ChangeSet changeSet; | |
129 | changeSet.appendRemoved(slice); |
|
129 | changeSet.appendRemoved(slice); | |
130 | emit changed(changeSet); |
|
130 | emit changed(changeSet); | |
131 |
|
131 | |||
132 | delete slice; |
|
132 | delete slice; | |
133 | slice = NULL; |
|
133 | slice = NULL; | |
134 |
|
134 | |||
135 | updateDerivativeData(); |
|
135 | updateDerivativeData(); | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | void QPieSeries::clear() |
|
138 | void QPieSeries::clear() | |
139 | { |
|
139 | { | |
140 | if (m_slices.count() == 0) |
|
140 | if (m_slices.count() == 0) | |
141 | return; |
|
141 | return; | |
142 |
|
142 | |||
143 | ChangeSet changeSet; |
|
143 | ChangeSet changeSet; | |
144 | foreach (QPieSlice* s, m_slices) { |
|
144 | foreach (QPieSlice* s, m_slices) { | |
145 | changeSet.appendRemoved(s); |
|
145 | changeSet.appendRemoved(s); | |
146 | m_slices.removeOne(s); |
|
146 | m_slices.removeOne(s); | |
147 | delete s; |
|
147 | delete s; | |
148 | } |
|
148 | } | |
149 | emit changed(changeSet); |
|
149 | emit changed(changeSet); | |
150 | updateDerivativeData(); |
|
150 | updateDerivativeData(); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | void QPieSeries::setSizeFactor(qreal factor) |
|
153 | void QPieSeries::setSizeFactor(qreal factor) | |
154 | { |
|
154 | { | |
155 | if (factor < 0.0) |
|
155 | if (factor < 0.0) | |
156 | return; |
|
156 | return; | |
157 |
|
157 | |||
158 | if (m_sizeFactor != factor) { |
|
158 | if (m_sizeFactor != factor) { | |
159 | m_sizeFactor = factor; |
|
159 | m_sizeFactor = factor; | |
160 | emit sizeFactorChanged(); |
|
160 | emit sizeFactorChanged(); | |
161 | } |
|
161 | } | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | void QPieSeries::setPosition(PiePosition position) |
|
164 | void QPieSeries::setPosition(PiePosition position) | |
165 | { |
|
165 | { | |
166 | if (m_position != position) { |
|
166 | if (m_position != position) { | |
167 | m_position = position; |
|
167 | m_position = position; | |
168 | emit positionChanged(); |
|
168 | emit positionChanged(); | |
169 | } |
|
169 | } | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | void QPieSeries::setSpan(qreal startAngle, qreal span) |
|
172 | void QPieSeries::setSpan(qreal startAngle, qreal span) | |
173 | { |
|
173 | { | |
174 | if (startAngle >= 0 && startAngle < 360 && |
|
174 | if (startAngle >= 0 && startAngle < 360 && | |
175 | span > 0 && span <= 360) { |
|
175 | span > 0 && span <= 360) { | |
176 | m_pieStartAngle = startAngle; |
|
176 | m_pieStartAngle = startAngle; | |
177 | m_pieSpan = span; |
|
177 | m_pieSpan = span; | |
178 | updateDerivativeData(); |
|
178 | updateDerivativeData(); | |
179 | } |
|
179 | } | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | void QPieSeries::setLabelsVisible(bool visible) |
|
182 | void QPieSeries::setLabelsVisible(bool visible) | |
183 | { |
|
183 | { | |
184 | foreach (QPieSlice* s, m_slices) |
|
184 | foreach (QPieSlice* s, m_slices) | |
185 | s->setLabelVisible(visible); |
|
185 | s->setLabelVisible(visible); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | void QPieSeries::enableClickExplodes(bool enable) |
|
188 | void QPieSeries::enableClickExplodes(bool enable) | |
189 | { |
|
189 | { | |
190 | if (enable) |
|
190 | if (enable) | |
191 | connect(this, SIGNAL(clicked(QPieSlice*)), this, SLOT(toggleExploded(QPieSlice*))); |
|
191 | connect(this, SIGNAL(clicked(QPieSlice*)), this, SLOT(toggleExploded(QPieSlice*))); | |
192 | else |
|
192 | else | |
193 | disconnect(this, SLOT(toggleExploded(QPieSlice*))); |
|
193 | disconnect(this, SLOT(toggleExploded(QPieSlice*))); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void QPieSeries::enableHoverHighlight(bool enable) |
|
196 | void QPieSeries::enableHoverHighlight(bool enable) | |
197 | { |
|
197 | { | |
198 | if (enable) { |
|
198 | if (enable) { | |
199 | connect(this, SIGNAL(hoverEnter(QPieSlice*)), this, SLOT(highlightOn(QPieSlice*))); |
|
199 | connect(this, SIGNAL(hoverEnter(QPieSlice*)), this, SLOT(highlightOn(QPieSlice*))); | |
200 | connect(this, SIGNAL(hoverLeave(QPieSlice*)), this, SLOT(highlightOff(QPieSlice*))); |
|
200 | connect(this, SIGNAL(hoverLeave(QPieSlice*)), this, SLOT(highlightOff(QPieSlice*))); | |
201 | } else { |
|
201 | } else { | |
202 | disconnect(this, SLOT(hoverEnter(QPieSlice*))); |
|
202 | disconnect(this, SLOT(hoverEnter(QPieSlice*))); | |
203 | disconnect(this, SLOT(hoverLeave(QPieSlice*))); |
|
203 | disconnect(this, SLOT(hoverLeave(QPieSlice*))); | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | void QPieSeries::sliceChanged() |
|
207 | void QPieSeries::sliceChanged() | |
208 | { |
|
208 | { | |
209 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
209 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
210 | Q_ASSERT(m_slices.contains(slice)); |
|
210 | Q_ASSERT(m_slices.contains(slice)); | |
211 |
|
211 | |||
212 | ChangeSet changeSet; |
|
212 | ChangeSet changeSet; | |
213 | changeSet.appendChanged(slice); |
|
213 | changeSet.appendChanged(slice); | |
214 | emit changed(changeSet); |
|
214 | emit changed(changeSet); | |
215 |
|
215 | |||
216 | updateDerivativeData(); |
|
216 | updateDerivativeData(); | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | void QPieSeries::sliceClicked() |
|
219 | void QPieSeries::sliceClicked() | |
220 | { |
|
220 | { | |
221 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
221 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
222 | Q_ASSERT(m_slices.contains(slice)); |
|
222 | Q_ASSERT(m_slices.contains(slice)); | |
223 | emit clicked(slice); |
|
223 | emit clicked(slice); | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | void QPieSeries::sliceHoverEnter() |
|
226 | void QPieSeries::sliceHoverEnter() | |
227 | { |
|
227 | { | |
228 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
228 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
229 | Q_ASSERT(m_slices.contains(slice)); |
|
229 | Q_ASSERT(m_slices.contains(slice)); | |
230 | emit hoverEnter(slice); |
|
230 | emit hoverEnter(slice); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | void QPieSeries::sliceHoverLeave() |
|
233 | void QPieSeries::sliceHoverLeave() | |
234 | { |
|
234 | { | |
235 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
235 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
236 | Q_ASSERT(m_slices.contains(slice)); |
|
236 | Q_ASSERT(m_slices.contains(slice)); | |
237 | emit hoverLeave(slice); |
|
237 | emit hoverLeave(slice); | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | void QPieSeries::toggleExploded(QPieSlice* slice) |
|
240 | void QPieSeries::toggleExploded(QPieSlice* slice) | |
241 | { |
|
241 | { | |
242 | Q_ASSERT(slice); |
|
242 | Q_ASSERT(slice); | |
243 | slice->setExploded(!slice->isExploded()); |
|
243 | slice->setExploded(!slice->isExploded()); | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | void QPieSeries::highlightOn(QPieSlice* slice) |
|
246 | void QPieSeries::highlightOn(QPieSlice* slice) | |
247 | { |
|
247 | { | |
248 | Q_ASSERT(slice); |
|
248 | Q_ASSERT(slice); | |
249 | QColor c = slice->brush().color().lighter(); |
|
249 | QColor c = slice->brush().color().lighter(); | |
250 | slice->setBrush(c); |
|
250 | slice->setBrush(c); | |
|
251 | slice->setLabelVisible(true); | |||
251 | } |
|
252 | } | |
252 |
|
253 | |||
253 | void QPieSeries::highlightOff(QPieSlice* slice) |
|
254 | void QPieSeries::highlightOff(QPieSlice* slice) | |
254 | { |
|
255 | { | |
255 | Q_ASSERT(slice); |
|
256 | Q_ASSERT(slice); | |
256 | QColor c = slice->brush().color().darker(150); |
|
257 | QColor c = slice->brush().color().darker(150); | |
257 | slice->setBrush(c); |
|
258 | slice->setBrush(c); | |
|
259 | slice->setLabelVisible(false); | |||
258 | } |
|
260 | } | |
259 |
|
261 | |||
260 | void QPieSeries::updateDerivativeData() |
|
262 | void QPieSeries::updateDerivativeData() | |
261 | { |
|
263 | { | |
262 | m_total = 0; |
|
264 | m_total = 0; | |
263 |
|
265 | |||
264 | // nothing to do? |
|
266 | // nothing to do? | |
265 | if (m_slices.count() == 0) |
|
267 | if (m_slices.count() == 0) | |
266 | return; |
|
268 | return; | |
267 |
|
269 | |||
268 | // calculate total |
|
270 | // calculate total | |
269 | foreach (QPieSlice* s, m_slices) |
|
271 | foreach (QPieSlice* s, m_slices) | |
270 | m_total += s->value(); |
|
272 | m_total += s->value(); | |
271 |
|
273 | |||
272 | // we must have some values |
|
274 | // we must have some values | |
273 | Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this? |
|
275 | Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this? | |
274 |
|
276 | |||
275 | // update slice attributes |
|
277 | // update slice attributes | |
276 | qreal sliceAngle = m_pieStartAngle; |
|
278 | qreal sliceAngle = m_pieStartAngle; | |
277 | foreach (QPieSlice* s, m_slices) { |
|
279 | foreach (QPieSlice* s, m_slices) { | |
278 |
|
280 | |||
279 | bool changed = false; |
|
281 | bool changed = false; | |
280 |
|
282 | |||
281 | qreal percentage = s->value() / m_total; |
|
283 | qreal percentage = s->value() / m_total; | |
282 | if (s->m_percentage != percentage) { |
|
284 | if (s->m_percentage != percentage) { | |
283 | s->m_percentage = percentage; |
|
285 | s->m_percentage = percentage; | |
284 | changed = true; |
|
286 | changed = true; | |
285 | } |
|
287 | } | |
286 |
|
288 | |||
287 | qreal sliceSpan = m_pieSpan * percentage; |
|
289 | qreal sliceSpan = m_pieSpan * percentage; | |
288 | if (s->m_angleSpan != sliceSpan) { |
|
290 | if (s->m_angleSpan != sliceSpan) { | |
289 | s->m_angleSpan = sliceSpan; |
|
291 | s->m_angleSpan = sliceSpan; | |
290 | changed = true; |
|
292 | changed = true; | |
291 | } |
|
293 | } | |
292 |
|
294 | |||
293 | if (s->m_angle != sliceAngle) { |
|
295 | if (s->m_angle != sliceAngle) { | |
294 | s->m_angle = sliceAngle; |
|
296 | s->m_angle = sliceAngle; | |
295 | changed = true; |
|
297 | changed = true; | |
296 | } |
|
298 | } | |
297 | sliceAngle += sliceSpan; |
|
299 | sliceAngle += sliceSpan; | |
298 |
|
300 | |||
299 | if (changed) |
|
301 | if (changed) | |
300 | emit s->changed(); |
|
302 | emit s->changed(); | |
301 | } |
|
303 | } | |
302 | } |
|
304 | } | |
303 |
|
305 | |||
304 | #include "moc_qpieseries.cpp" |
|
306 | #include "moc_qpieseries.cpp" | |
305 |
|
307 | |||
306 | QTCOMMERCIALCHART_END_NAMESPACE |
|
308 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,197 +1,197 | |||||
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 50 |
|
7 | #define DEFAULT_LABEL_ARM_LENGTH 50 | |
8 | #define DEFAULT_EXPOLODE_DISTANCE 20 |
|
8 | #define DEFAULT_EXPOLODE_DISTANCE 20 | |
9 |
|
9 | |||
10 | QPieSlice::QPieSlice(QObject *parent) |
|
10 | QPieSlice::QPieSlice(QObject *parent) | |
11 | :QObject(parent), |
|
11 | :QObject(parent), | |
12 | m_value(0), |
|
12 | m_value(0), | |
13 |
m_isLabelVisible( |
|
13 | m_isLabelVisible(false), | |
14 | m_isExploded(false), |
|
14 | m_isExploded(false), | |
15 | m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE), |
|
15 | m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE), | |
16 | m_percentage(0), |
|
16 | m_percentage(0), | |
17 | m_angle(0), |
|
17 | m_angle(0), | |
18 | m_angleSpan(0), |
|
18 | m_angleSpan(0), | |
19 | m_pen(DEFAULT_PEN_COLOR), |
|
19 | m_pen(DEFAULT_PEN_COLOR), | |
20 | m_brush(DEFAULT_BRUSH_COLOR), |
|
20 | m_brush(DEFAULT_BRUSH_COLOR), | |
21 | m_labelPen(DEFAULT_PEN_COLOR), |
|
21 | m_labelPen(DEFAULT_PEN_COLOR), | |
22 | m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH) |
|
22 | m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH) | |
23 | { |
|
23 | { | |
24 |
|
24 | |||
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | QPieSlice::QPieSlice(qreal value, QString label, bool labelVisible, QObject *parent) |
|
27 | QPieSlice::QPieSlice(qreal value, QString label, bool labelVisible, QObject *parent) | |
28 | :QObject(parent), |
|
28 | :QObject(parent), | |
29 | m_value(value), |
|
29 | m_value(value), | |
30 | m_label(label), |
|
30 | m_label(label), | |
31 | m_isLabelVisible(labelVisible), |
|
31 | m_isLabelVisible(labelVisible), | |
32 | m_isExploded(false), |
|
32 | m_isExploded(false), | |
33 | m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE), |
|
33 | m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE), | |
34 | m_percentage(0), |
|
34 | m_percentage(0), | |
35 | m_angle(0), |
|
35 | m_angle(0), | |
36 | m_angleSpan(0), |
|
36 | m_angleSpan(0), | |
37 | m_pen(DEFAULT_PEN_COLOR), |
|
37 | m_pen(DEFAULT_PEN_COLOR), | |
38 | m_brush(DEFAULT_BRUSH_COLOR), |
|
38 | m_brush(DEFAULT_BRUSH_COLOR), | |
39 | m_labelPen(DEFAULT_PEN_COLOR), |
|
39 | m_labelPen(DEFAULT_PEN_COLOR), | |
40 | m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH) |
|
40 | m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH) | |
41 | { |
|
41 | { | |
42 |
|
42 | |||
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | QPieSlice::~QPieSlice() |
|
45 | QPieSlice::~QPieSlice() | |
46 | { |
|
46 | { | |
47 |
|
47 | |||
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | qreal QPieSlice::value() const |
|
50 | qreal QPieSlice::value() const | |
51 | { |
|
51 | { | |
52 | return m_value; |
|
52 | return m_value; | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | QString QPieSlice::label() const |
|
55 | QString QPieSlice::label() const | |
56 | { |
|
56 | { | |
57 | return m_label; |
|
57 | return m_label; | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | bool QPieSlice::isLabelVisible() const |
|
60 | bool QPieSlice::isLabelVisible() const | |
61 | { |
|
61 | { | |
62 | return m_isLabelVisible; |
|
62 | return m_isLabelVisible; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | bool QPieSlice::isExploded() const |
|
65 | bool QPieSlice::isExploded() const | |
66 | { |
|
66 | { | |
67 | return m_isExploded; |
|
67 | return m_isExploded; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | qreal QPieSlice::explodeDistance() const |
|
70 | qreal QPieSlice::explodeDistance() const | |
71 | { |
|
71 | { | |
72 | return m_explodeDistance; |
|
72 | return m_explodeDistance; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | qreal QPieSlice::percentage() const |
|
75 | qreal QPieSlice::percentage() const | |
76 | { |
|
76 | { | |
77 | return m_percentage; |
|
77 | return m_percentage; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | qreal QPieSlice::angle() const |
|
80 | qreal QPieSlice::angle() const | |
81 | { |
|
81 | { | |
82 | return m_angle; |
|
82 | return m_angle; | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | qreal QPieSlice::angleSpan() const |
|
85 | qreal QPieSlice::angleSpan() const | |
86 | { |
|
86 | { | |
87 | return m_angleSpan; |
|
87 | return m_angleSpan; | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | QPen QPieSlice::pen() const |
|
90 | QPen QPieSlice::pen() const | |
91 | { |
|
91 | { | |
92 | return m_pen; |
|
92 | return m_pen; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | QBrush QPieSlice::brush() const |
|
95 | QBrush QPieSlice::brush() const | |
96 | { |
|
96 | { | |
97 | return m_brush; |
|
97 | return m_brush; | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | QPen QPieSlice::labelPen() const |
|
100 | QPen QPieSlice::labelPen() const | |
101 | { |
|
101 | { | |
102 | return m_labelPen; |
|
102 | return m_labelPen; | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | QFont QPieSlice::labelFont() const |
|
105 | QFont QPieSlice::labelFont() const | |
106 | { |
|
106 | { | |
107 | return m_labelFont; |
|
107 | return m_labelFont; | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | qreal QPieSlice::labelArmLength() const |
|
110 | qreal QPieSlice::labelArmLength() const | |
111 | { |
|
111 | { | |
112 | return m_labelArmLength; |
|
112 | return m_labelArmLength; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void QPieSlice::setValue(qreal value) |
|
115 | void QPieSlice::setValue(qreal value) | |
116 | { |
|
116 | { | |
117 | if (m_value != value) { |
|
117 | if (m_value != value) { | |
118 | m_value = value; |
|
118 | m_value = value; | |
119 | emit changed(); |
|
119 | emit changed(); | |
120 | } |
|
120 | } | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void QPieSlice::setLabel(QString label) |
|
123 | void QPieSlice::setLabel(QString label) | |
124 | { |
|
124 | { | |
125 | if (m_label != label) { |
|
125 | if (m_label != label) { | |
126 | m_label = label; |
|
126 | m_label = label; | |
127 | emit changed(); |
|
127 | emit changed(); | |
128 | } |
|
128 | } | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | void QPieSlice::setLabelVisible(bool visible) |
|
131 | void QPieSlice::setLabelVisible(bool visible) | |
132 | { |
|
132 | { | |
133 | if (m_isLabelVisible != visible) { |
|
133 | if (m_isLabelVisible != visible) { | |
134 | m_isLabelVisible = visible; |
|
134 | m_isLabelVisible = visible; | |
135 | emit changed(); |
|
135 | emit changed(); | |
136 | } |
|
136 | } | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | void QPieSlice::setExploded(bool exploded) |
|
139 | void QPieSlice::setExploded(bool exploded) | |
140 | { |
|
140 | { | |
141 | if (m_isExploded != exploded) { |
|
141 | if (m_isExploded != exploded) { | |
142 | m_isExploded = exploded; |
|
142 | m_isExploded = exploded; | |
143 | emit changed(); |
|
143 | emit changed(); | |
144 | } |
|
144 | } | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | void QPieSlice::setExplodeDistance(qreal distance) |
|
147 | void QPieSlice::setExplodeDistance(qreal distance) | |
148 | { |
|
148 | { | |
149 | if (m_explodeDistance != distance) { |
|
149 | if (m_explodeDistance != distance) { | |
150 | m_explodeDistance = distance; |
|
150 | m_explodeDistance = distance; | |
151 | emit changed(); |
|
151 | emit changed(); | |
152 | } |
|
152 | } | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void QPieSlice::setPen(QPen pen) |
|
155 | void QPieSlice::setPen(QPen pen) | |
156 | { |
|
156 | { | |
157 | if (m_pen != pen) { |
|
157 | if (m_pen != pen) { | |
158 | m_pen = pen; |
|
158 | m_pen = pen; | |
159 | emit changed(); |
|
159 | emit changed(); | |
160 | } |
|
160 | } | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | void QPieSlice::setBrush(QBrush brush) |
|
163 | void QPieSlice::setBrush(QBrush brush) | |
164 | { |
|
164 | { | |
165 | if (m_brush != brush) { |
|
165 | if (m_brush != brush) { | |
166 | m_brush = brush; |
|
166 | m_brush = brush; | |
167 | emit changed(); |
|
167 | emit changed(); | |
168 | } |
|
168 | } | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | void QPieSlice::setLabelFont(QFont font) |
|
171 | void QPieSlice::setLabelFont(QFont font) | |
172 | { |
|
172 | { | |
173 | if (m_labelFont != font) { |
|
173 | if (m_labelFont != font) { | |
174 | m_labelFont = font; |
|
174 | m_labelFont = font; | |
175 | emit changed(); |
|
175 | emit changed(); | |
176 | } |
|
176 | } | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | void QPieSlice::setLabelPen(QPen pen) |
|
179 | void QPieSlice::setLabelPen(QPen pen) | |
180 | { |
|
180 | { | |
181 | if (m_labelPen != pen) { |
|
181 | if (m_labelPen != pen) { | |
182 | m_labelPen = pen; |
|
182 | m_labelPen = pen; | |
183 | emit changed(); |
|
183 | emit changed(); | |
184 | } |
|
184 | } | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | void QPieSlice::setLabelArmLength(qreal len) |
|
187 | void QPieSlice::setLabelArmLength(qreal len) | |
188 | { |
|
188 | { | |
189 | if (m_labelArmLength != len) { |
|
189 | if (m_labelArmLength != len) { | |
190 | m_labelArmLength = len; |
|
190 | m_labelArmLength = len; | |
191 | emit changed(); |
|
191 | emit changed(); | |
192 | } |
|
192 | } | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | #include "moc_qpieslice.cpp" |
|
195 | #include "moc_qpieslice.cpp" | |
196 |
|
196 | |||
197 | QTCOMMERCIALCHART_END_NAMESPACE |
|
197 | 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 /*NOTIFY dataYChanged*/) |
|
15 | Q_PROPERTY(QString label READ label WRITE setLabel /*NOTIFY dataYChanged*/) | |
16 | Q_PROPERTY(qreal value READ value WRITE setValue /*NOTIFY dataXChanged*/) |
|
16 | Q_PROPERTY(qreal value READ value WRITE setValue /*NOTIFY dataXChanged*/) | |
17 |
|
17 | |||
18 | public: |
|
18 | public: | |
19 | QPieSlice(QObject *parent = 0); |
|
19 | QPieSlice(QObject *parent = 0); | |
20 |
QPieSlice(qreal value, QString label, bool labelVisible = |
|
20 | QPieSlice(qreal value, QString label, bool labelVisible = false, 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