@@ -1,751 +1,702 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qpieseries.h" |
|
21 | #include "qpieseries.h" | |
22 | #include "qpieseriesprivate_p.h" |
|
22 | #include "qpieseriesprivate_p.h" | |
23 | #include "qpieslice.h" |
|
23 | #include "qpieslice.h" | |
24 | #include "pieslicedata_p.h" |
|
24 | #include "pieslicedata_p.h" | |
25 | #include <QAbstractItemModel> |
|
25 | #include <QAbstractItemModel> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) |
|
30 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) | |
31 | :QObject(parent), |
|
31 | :QObject(parent), | |
32 | q_ptr(parent), |
|
32 | q_ptr(parent), | |
33 | m_pieRelativeHorPos(0.5), |
|
33 | m_pieRelativeHorPos(0.5), | |
34 | m_pieRelativeVerPos(0.5), |
|
34 | m_pieRelativeVerPos(0.5), | |
35 | m_pieRelativeSize(0.7), |
|
35 | m_pieRelativeSize(0.7), | |
36 | m_pieStartAngle(0), |
|
36 | m_pieStartAngle(0), | |
37 | m_pieEndAngle(360), |
|
37 | m_pieEndAngle(360), | |
38 | m_total(0), |
|
38 | m_total(0), | |
39 | m_mapValues(0), |
|
39 | m_mapValues(0), | |
40 | m_mapLabels(0), |
|
40 | m_mapLabels(0), | |
41 | m_mapOrientation(Qt::Horizontal) |
|
41 | m_mapOrientation(Qt::Horizontal) | |
42 | { |
|
42 | { | |
43 |
|
43 | |||
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
46 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
47 | { |
|
47 | { | |
48 |
|
48 | |||
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void QPieSeriesPrivate::updateDerivativeData() |
|
51 | void QPieSeriesPrivate::updateDerivativeData() | |
52 | { |
|
52 | { | |
53 | m_total = 0; |
|
53 | m_total = 0; | |
54 |
|
54 | |||
55 | // nothing to do? |
|
55 | // nothing to do? | |
56 | if (m_slices.count() == 0) |
|
56 | if (m_slices.count() == 0) | |
57 | return; |
|
57 | return; | |
58 |
|
58 | |||
59 | // calculate total |
|
59 | // calculate total | |
60 | foreach (QPieSlice* s, m_slices) |
|
60 | foreach (QPieSlice* s, m_slices) | |
61 | m_total += s->value(); |
|
61 | m_total += s->value(); | |
62 |
|
62 | |||
63 | // nothing to show.. |
|
63 | // nothing to show.. | |
64 | if (qFuzzyIsNull(m_total)) |
|
64 | if (qFuzzyIsNull(m_total)) | |
65 | return; |
|
65 | return; | |
66 |
|
66 | |||
67 | // update slice attributes |
|
67 | // update slice attributes | |
68 | qreal sliceAngle = m_pieStartAngle; |
|
68 | qreal sliceAngle = m_pieStartAngle; | |
69 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
69 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
70 | QVector<QPieSlice*> changed; |
|
70 | QVector<QPieSlice*> changed; | |
71 | foreach (QPieSlice* s, m_slices) { |
|
71 | foreach (QPieSlice* s, m_slices) { | |
72 |
|
72 | |||
73 | PieSliceData data = PieSliceData::data(s); |
|
73 | PieSliceData data = PieSliceData::data(s); | |
74 | data.m_percentage = s->value() / m_total; |
|
74 | data.m_percentage = s->value() / m_total; | |
75 | data.m_angleSpan = pieSpan * data.m_percentage; |
|
75 | data.m_angleSpan = pieSpan * data.m_percentage; | |
76 | data.m_startAngle = sliceAngle; |
|
76 | data.m_startAngle = sliceAngle; | |
77 | sliceAngle += data.m_angleSpan; |
|
77 | sliceAngle += data.m_angleSpan; | |
78 |
|
78 | |||
79 | if (PieSliceData::data(s) != data) { |
|
79 | if (PieSliceData::data(s) != data) { | |
80 | PieSliceData::data(s) = data; |
|
80 | PieSliceData::data(s) = data; | |
81 | changed << s; |
|
81 | changed << s; | |
82 | } |
|
82 | } | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | // emit signals |
|
85 | // emit signals | |
86 | foreach (QPieSlice* s, changed) |
|
86 | foreach (QPieSlice* s, changed) | |
87 | PieSliceData::data(s).emitChangedSignal(s); |
|
87 | PieSliceData::data(s).emitChangedSignal(s); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void QPieSeriesPrivate::sliceChanged() |
|
90 | void QPieSeriesPrivate::sliceChanged() | |
91 | { |
|
91 | { | |
92 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
92 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
93 | updateDerivativeData(); |
|
93 | updateDerivativeData(); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons) |
|
96 | void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons) | |
97 | { |
|
97 | { | |
98 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
98 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
99 | Q_ASSERT(m_slices.contains(slice)); |
|
99 | Q_ASSERT(m_slices.contains(slice)); | |
100 | Q_Q(QPieSeries); |
|
100 | Q_Q(QPieSeries); | |
101 | emit q->clicked(slice, buttons); |
|
101 | emit q->clicked(slice, buttons); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void QPieSeriesPrivate::sliceHoverEnter() |
|
104 | void QPieSeriesPrivate::sliceHoverEnter() | |
105 | { |
|
105 | { | |
106 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
106 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
107 | Q_ASSERT(m_slices.contains(slice)); |
|
107 | Q_ASSERT(m_slices.contains(slice)); | |
108 | Q_Q(QPieSeries); |
|
108 | Q_Q(QPieSeries); | |
109 | emit q->hoverEnter(slice); |
|
109 | emit q->hoverEnter(slice); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void QPieSeriesPrivate::sliceHoverLeave() |
|
112 | void QPieSeriesPrivate::sliceHoverLeave() | |
113 | { |
|
113 | { | |
114 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
114 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
115 | Q_ASSERT(m_slices.contains(slice)); |
|
115 | Q_ASSERT(m_slices.contains(slice)); | |
116 | Q_Q(QPieSeries); |
|
116 | Q_Q(QPieSeries); | |
117 | emit q->hoverLeave(slice); |
|
117 | emit q->hoverLeave(slice); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
120 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
121 | { |
|
121 | { | |
122 | Q_UNUSED(bottomRight) |
|
122 | Q_UNUSED(bottomRight) | |
123 | Q_Q(QPieSeries); |
|
123 | Q_Q(QPieSeries); | |
124 |
|
124 | |||
125 | if (m_mapOrientation == Qt::Vertical) |
|
125 | if (m_mapOrientation == Qt::Vertical) | |
126 | { |
|
126 | { | |
127 | if (topLeft.column() == m_mapValues) |
|
127 | if (topLeft.column() == m_mapValues) | |
128 | if (m_mapValues == m_mapLabels) |
|
128 | if (m_mapValues == m_mapLabels) | |
129 | { |
|
129 | { | |
130 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
130 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
131 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
131 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
132 | } |
|
132 | } | |
133 | else |
|
133 | else | |
134 | { |
|
134 | { | |
135 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
135 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
136 | } |
|
136 | } | |
137 | else if (topLeft.column() == m_mapLabels) |
|
137 | else if (topLeft.column() == m_mapLabels) | |
138 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
138 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
139 | } |
|
139 | } | |
140 | else |
|
140 | else | |
141 | { |
|
141 | { | |
142 | if (topLeft.row() == m_mapValues) |
|
142 | if (topLeft.row() == m_mapValues) | |
143 | if (m_mapValues == m_mapLabels) |
|
143 | if (m_mapValues == m_mapLabels) | |
144 | { |
|
144 | { | |
145 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
145 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
146 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
146 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
147 | } |
|
147 | } | |
148 | else |
|
148 | else | |
149 | { |
|
149 | { | |
150 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
150 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
151 | } |
|
151 | } | |
152 | else if (topLeft.row() == m_mapLabels) |
|
152 | else if (topLeft.row() == m_mapLabels) | |
153 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
153 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
154 | } |
|
154 | } | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) |
|
157 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | |
158 | { |
|
158 | { | |
159 | Q_UNUSED(parent) |
|
159 | Q_UNUSED(parent) | |
160 | Q_UNUSED(end) |
|
160 | Q_UNUSED(end) | |
161 | Q_Q(QPieSeries); |
|
161 | Q_Q(QPieSeries); | |
162 |
|
162 | |||
163 | QPieSlice* newSlice = new QPieSlice; |
|
163 | QPieSlice* newSlice = new QPieSlice; | |
164 | newSlice->setLabelVisible(true); |
|
164 | newSlice->setLabelVisible(true); | |
165 | if (m_mapOrientation == Qt::Vertical) |
|
165 | if (m_mapOrientation == Qt::Vertical) | |
166 | { |
|
166 | { | |
167 | newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); |
|
167 | newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); | |
168 | newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); |
|
168 | newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); | |
169 | } |
|
169 | } | |
170 | else |
|
170 | else | |
171 | { |
|
171 | { | |
172 | newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); |
|
172 | newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); | |
173 | newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); |
|
173 | newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | q->insert(start, newSlice); |
|
176 | q->insert(start, newSlice); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) |
|
179 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
180 | { |
|
180 | { | |
181 | Q_UNUSED(parent) |
|
181 | Q_UNUSED(parent) | |
182 | Q_UNUSED(end) |
|
182 | Q_UNUSED(end) | |
183 | Q_Q(QPieSeries); |
|
183 | Q_Q(QPieSeries); | |
184 | q->remove(m_slices.at(start)); |
|
184 | q->remove(m_slices.at(start)); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min) |
|
187 | bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min) | |
188 | { |
|
188 | { | |
189 | // Remove rounding errors |
|
189 | // Remove rounding errors | |
190 | qreal roundedValue = newValue; |
|
190 | qreal roundedValue = newValue; | |
191 | if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue)) |
|
191 | if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue)) | |
192 | roundedValue = 0.0; |
|
192 | roundedValue = 0.0; | |
193 | else if (qFuzzyCompare(newValue, max)) |
|
193 | else if (qFuzzyCompare(newValue, max)) | |
194 | roundedValue = max; |
|
194 | roundedValue = max; | |
195 | else if (qFuzzyCompare(newValue, min)) |
|
195 | else if (qFuzzyCompare(newValue, min)) | |
196 | roundedValue = min; |
|
196 | roundedValue = min; | |
197 |
|
197 | |||
198 | // Check if the position is valid after removing the rounding errors |
|
198 | // Check if the position is valid after removing the rounding errors | |
199 | if (roundedValue < min || roundedValue > max) { |
|
199 | if (roundedValue < min || roundedValue > max) { | |
200 | qWarning("QPieSeries: Illegal value"); |
|
200 | qWarning("QPieSeries: Illegal value"); | |
201 | return false; |
|
201 | return false; | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | if (!qFuzzyIsNull(value - roundedValue)) { |
|
204 | if (!qFuzzyIsNull(value - roundedValue)) { | |
205 | value = roundedValue; |
|
205 | value = roundedValue; | |
206 | return true; |
|
206 | return true; | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | // The change was so small it is considered a rounding error |
|
209 | // The change was so small it is considered a rounding error | |
210 | return false; |
|
210 | return false; | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 |
|
213 | |||
214 |
|
214 | |||
215 | /*! |
|
215 | /*! | |
216 | \class QPieSeries |
|
216 | \class QPieSeries | |
217 | \brief Pie series API for QtCommercial Charts |
|
217 | \brief Pie series API for QtCommercial Charts | |
218 |
|
218 | |||
219 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. |
|
219 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. | |
220 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
220 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
221 | The actual slice size is determined by that relative value. |
|
221 | The actual slice size is determined by that relative value. | |
222 |
|
222 | |||
223 | By default the pie is defined as a full pie but it can be a partial pie. |
|
223 | By default the pie is defined as a full pie but it can be a partial pie. | |
224 | This can be done by setting a starting angle and angle span to the series. |
|
224 | This can be done by setting a starting angle and angle span to the series. | |
225 | */ |
|
225 | */ | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
228 | \property QPieSeries::horizontalPosition |
|
228 | \property QPieSeries::horizontalPosition | |
229 |
\brief |
|
229 | \brief Defines the horizontal position of the pie. | |
230 |
|
230 | |||
231 | By default horizontal position is 0.5 (center). |
|
231 | The value is a relative value to the chart rectangle where: | |
|
232 | ||||
|
233 | \list | |||
|
234 | \o 0.0 is the absolute left. | |||
|
235 | \o 1.0 is the absolute right. | |||
|
236 | \endlist | |||
|
237 | ||||
|
238 | Default value is 0.5 (center). | |||
232 | */ |
|
239 | */ | |
233 |
|
240 | |||
234 | /*! |
|
241 | /*! | |
235 | \property QPieSeries::verticalPosition |
|
242 | \property QPieSeries::verticalPosition | |
236 |
\brief |
|
243 | \brief Defines the vertical position of the pie. | |
|
244 | ||||
|
245 | The value is a relative value to the chart rectangle where: | |||
|
246 | ||||
|
247 | \list | |||
|
248 | \o 0.0 is the absolute top. | |||
|
249 | \o 1.0 is the absolute bottom. | |||
|
250 | \endlist | |||
237 |
|
251 | |||
238 |
|
|
252 | Default value is 0.5 (center). | |
239 | */ |
|
253 | */ | |
240 |
|
254 | |||
241 | /*! |
|
255 | /*! | |
242 | \property QPieSeries::size |
|
256 | \property QPieSeries::size | |
243 |
\brief |
|
257 | \brief Defines the pie size. | |
244 |
|
258 | |||
245 | By default size is 0.7. |
|
259 | The value is a relative value to the chart rectangle where: | |
|
260 | ||||
|
261 | \list | |||
|
262 | \o 0.0 is the minumum size (pie not drawn). | |||
|
263 | \o 1.0 is the maximum size that can fit the chart. | |||
|
264 | \endlist | |||
|
265 | ||||
|
266 | Default value is 0.7. | |||
246 | */ |
|
267 | */ | |
247 |
|
268 | |||
248 | /*! |
|
269 | /*! | |
249 | \property QPieSeries::startAngle |
|
270 | \property QPieSeries::startAngle | |
250 |
\brief |
|
271 | \brief Defines the starting angle of the pie. | |
251 |
|
272 | |||
252 | Starting angle of the pie. Default is 0. |
|
273 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
253 | */ |
|
|||
254 |
|
|
274 | ||
|
275 | Default is value is 0. | |||
|
276 | */ | |||
255 |
|
277 | |||
256 | /*! |
|
278 | /*! | |
257 | \property QPieSeries::endAngle |
|
279 | \property QPieSeries::endAngle | |
258 |
\brief |
|
280 | \brief Defines the ending angle of the pie. | |
259 |
|
281 | |||
260 | Ending angle of the pie. Default is 360. |
|
282 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
261 | */ |
|
|||
262 |
|
|
283 | ||
|
284 | Default is value is 360. | |||
|
285 | */ | |||
263 |
|
286 | |||
264 |
|
287 | |||
265 | /*! |
|
288 | /*! | |
266 | Constructs a series object which is a child of \a parent. |
|
289 | Constructs a series object which is a child of \a parent. | |
267 | */ |
|
290 | */ | |
268 | QPieSeries::QPieSeries(QObject *parent) : |
|
291 | QPieSeries::QPieSeries(QObject *parent) : | |
269 | QSeries(parent), |
|
292 | QSeries(parent), | |
270 | d_ptr(new QPieSeriesPrivate(this)) |
|
293 | d_ptr(new QPieSeriesPrivate(this)) | |
271 | { |
|
294 | { | |
272 |
|
295 | |||
273 | } |
|
296 | } | |
274 |
|
297 | |||
275 | /*! |
|
298 | /*! | |
276 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. |
|
299 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. | |
277 | */ |
|
300 | */ | |
278 | QPieSeries::~QPieSeries() |
|
301 | QPieSeries::~QPieSeries() | |
279 | { |
|
302 | { | |
280 | // NOTE: d_prt destroyed by QObject |
|
303 | // NOTE: d_prt destroyed by QObject | |
281 | } |
|
304 | } | |
282 |
|
305 | |||
283 | /*! |
|
306 | /*! | |
284 | Returns QChartSeries::SeriesTypePie. |
|
307 | Returns QChartSeries::SeriesTypePie. | |
285 | */ |
|
308 | */ | |
286 | QSeries::QSeriesType QPieSeries::type() const |
|
309 | QSeries::QSeriesType QPieSeries::type() const | |
287 | { |
|
310 | { | |
288 | return QSeries::SeriesTypePie; |
|
311 | return QSeries::SeriesTypePie; | |
289 | } |
|
312 | } | |
290 |
|
313 | |||
291 | /*! |
|
314 | /*! | |
292 | Sets an array of \a slices to the series replacing the existing slices. |
|
315 | Sets an array of \a slices to the series replacing the existing slices. | |
293 | Slice ownership is passed to the series. |
|
316 | Slice ownership is passed to the series. | |
294 | */ |
|
317 | */ | |
295 | void QPieSeries::replace(QList<QPieSlice*> slices) |
|
318 | void QPieSeries::replace(QList<QPieSlice*> slices) | |
296 | { |
|
319 | { | |
297 | clear(); |
|
320 | clear(); | |
298 | append(slices); |
|
321 | append(slices); | |
299 | } |
|
322 | } | |
300 |
|
323 | |||
301 | /*! |
|
324 | /*! | |
302 | Adds an array of \a slices to the series. |
|
325 | Adds an array of \a slices to the series. | |
303 | Slice ownership is passed to the series. |
|
326 | Slice ownership is passed to the series. | |
304 | */ |
|
327 | */ | |
305 | void QPieSeries::append(QList<QPieSlice*> slices) |
|
328 | void QPieSeries::append(QList<QPieSlice*> slices) | |
306 | { |
|
329 | { | |
307 | Q_D(QPieSeries); |
|
330 | Q_D(QPieSeries); | |
308 |
|
331 | |||
309 | foreach (QPieSlice* s, slices) { |
|
332 | foreach (QPieSlice* s, slices) { | |
310 | s->setParent(this); |
|
333 | s->setParent(this); | |
311 | d->m_slices << s; |
|
334 | d->m_slices << s; | |
312 | } |
|
335 | } | |
313 |
|
336 | |||
314 | d->updateDerivativeData(); |
|
337 | d->updateDerivativeData(); | |
315 |
|
338 | |||
316 | foreach (QPieSlice* s, slices) { |
|
339 | foreach (QPieSlice* s, slices) { | |
317 | connect(s, SIGNAL(changed()), d, SLOT(sliceChanged())); |
|
340 | connect(s, SIGNAL(changed()), d, SLOT(sliceChanged())); | |
318 | connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); |
|
341 | connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); | |
319 | connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); |
|
342 | connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | |
320 | connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); |
|
343 | connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | |
321 | } |
|
344 | } | |
322 |
|
345 | |||
323 | emit added(slices); |
|
346 | emit added(slices); | |
324 | } |
|
347 | } | |
325 |
|
348 | |||
326 | /*! |
|
349 | /*! | |
327 | Adds a single \a slice to the series. |
|
350 | Adds a single \a slice to the series. | |
328 | Slice ownership is passed to the series. |
|
351 | Slice ownership is passed to the series. | |
329 | */ |
|
352 | */ | |
330 | void QPieSeries::append(QPieSlice* slice) |
|
353 | void QPieSeries::append(QPieSlice* slice) | |
331 | { |
|
354 | { | |
332 | append(QList<QPieSlice*>() << slice); |
|
355 | append(QList<QPieSlice*>() << slice); | |
333 | } |
|
356 | } | |
334 |
|
357 | |||
335 | /*! |
|
358 | /*! | |
336 | Adds a single \a slice to the series and returns a reference to the series. |
|
359 | Adds a single \a slice to the series and returns a reference to the series. | |
337 | Slice ownership is passed to the series. |
|
360 | Slice ownership is passed to the series. | |
338 | */ |
|
361 | */ | |
339 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) |
|
362 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | |
340 | { |
|
363 | { | |
341 | append(slice); |
|
364 | append(slice); | |
342 | return *this; |
|
365 | return *this; | |
343 | } |
|
366 | } | |
344 |
|
367 | |||
345 |
|
368 | |||
346 | /*! |
|
369 | /*! | |
347 | Appends a single slice to the series with give \a value and \a name. |
|
370 | Appends a single slice to the series with give \a value and \a name. | |
348 | Slice ownership is passed to the series. |
|
371 | Slice ownership is passed to the series. | |
349 | */ |
|
372 | */ | |
350 | QPieSlice* QPieSeries::append(qreal value, QString name) |
|
373 | QPieSlice* QPieSeries::append(qreal value, QString name) | |
351 | { |
|
374 | { | |
352 | QPieSlice* slice = new QPieSlice(value, name); |
|
375 | QPieSlice* slice = new QPieSlice(value, name); | |
353 | append(slice); |
|
376 | append(slice); | |
354 | return slice; |
|
377 | return slice; | |
355 | } |
|
378 | } | |
356 |
|
379 | |||
357 | /*! |
|
380 | /*! | |
358 | Inserts a single \a slice to the series before the slice at \a index position. |
|
381 | Inserts a single \a slice to the series before the slice at \a index position. | |
359 | Slice ownership is passed to the series. |
|
382 | Slice ownership is passed to the series. | |
360 | */ |
|
383 | */ | |
361 | void QPieSeries::insert(int index, QPieSlice* slice) |
|
384 | void QPieSeries::insert(int index, QPieSlice* slice) | |
362 | { |
|
385 | { | |
363 | Q_D(QPieSeries); |
|
386 | Q_D(QPieSeries); | |
364 | Q_ASSERT(index <= d->m_slices.count()); |
|
387 | Q_ASSERT(index <= d->m_slices.count()); | |
365 | slice->setParent(this); |
|
388 | slice->setParent(this); | |
366 | d->m_slices.insert(index, slice); |
|
389 | d->m_slices.insert(index, slice); | |
367 |
|
390 | |||
368 | d->updateDerivativeData(); |
|
391 | d->updateDerivativeData(); | |
369 |
|
392 | |||
370 | connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged())); |
|
393 | connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged())); | |
371 | connect(slice, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); |
|
394 | connect(slice, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); | |
372 | connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); |
|
395 | connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | |
373 | connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); |
|
396 | connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | |
374 |
|
397 | |||
375 | emit added(QList<QPieSlice*>() << slice); |
|
398 | emit added(QList<QPieSlice*>() << slice); | |
376 | } |
|
399 | } | |
377 |
|
400 | |||
378 | /*! |
|
401 | /*! | |
379 | Removes a single \a slice from the series and deletes the slice. |
|
402 | Removes a single \a slice from the series and deletes the slice. | |
380 |
|
403 | |||
381 | Do not reference this pointer after this call. |
|
404 | Do not reference this pointer after this call. | |
382 | */ |
|
405 | */ | |
383 | void QPieSeries::remove(QPieSlice* slice) |
|
406 | void QPieSeries::remove(QPieSlice* slice) | |
384 | { |
|
407 | { | |
385 | Q_D(QPieSeries); |
|
408 | Q_D(QPieSeries); | |
386 | if (!d->m_slices.removeOne(slice)) { |
|
409 | if (!d->m_slices.removeOne(slice)) { | |
387 | Q_ASSERT(0); // TODO: how should this be reported? |
|
410 | Q_ASSERT(0); // TODO: how should this be reported? | |
388 | return; |
|
411 | return; | |
389 | } |
|
412 | } | |
390 |
|
413 | |||
391 | d->updateDerivativeData(); |
|
414 | d->updateDerivativeData(); | |
392 |
|
415 | |||
393 | emit removed(QList<QPieSlice*>() << slice); |
|
416 | emit removed(QList<QPieSlice*>() << slice); | |
394 |
|
417 | |||
395 | delete slice; |
|
418 | delete slice; | |
396 | slice = 0; |
|
419 | slice = 0; | |
397 | } |
|
420 | } | |
398 |
|
421 | |||
399 | /*! |
|
422 | /*! | |
400 | Clears all slices from the series. |
|
423 | Clears all slices from the series. | |
401 | */ |
|
424 | */ | |
402 | void QPieSeries::clear() |
|
425 | void QPieSeries::clear() | |
403 | { |
|
426 | { | |
404 | Q_D(QPieSeries); |
|
427 | Q_D(QPieSeries); | |
405 | if (d->m_slices.count() == 0) |
|
428 | if (d->m_slices.count() == 0) | |
406 | return; |
|
429 | return; | |
407 |
|
430 | |||
408 | QList<QPieSlice*> slices = d->m_slices; |
|
431 | QList<QPieSlice*> slices = d->m_slices; | |
409 | foreach (QPieSlice* s, d->m_slices) { |
|
432 | foreach (QPieSlice* s, d->m_slices) { | |
410 | d->m_slices.removeOne(s); |
|
433 | d->m_slices.removeOne(s); | |
411 | delete s; |
|
434 | delete s; | |
412 | } |
|
435 | } | |
413 |
|
436 | |||
414 | d->updateDerivativeData(); |
|
437 | d->updateDerivativeData(); | |
415 |
|
438 | |||
416 | emit removed(slices); |
|
439 | emit removed(slices); | |
417 | } |
|
440 | } | |
418 |
|
441 | |||
419 | /*! |
|
442 | /*! | |
420 | Counts the number of the slices in this series. |
|
443 | Counts the number of the slices in this series. | |
421 | */ |
|
444 | */ | |
422 | int QPieSeries::count() const |
|
445 | int QPieSeries::count() const | |
423 | { |
|
446 | { | |
424 | Q_D(const QPieSeries); |
|
447 | Q_D(const QPieSeries); | |
425 | return d->m_slices.count(); |
|
448 | return d->m_slices.count(); | |
426 | } |
|
449 | } | |
427 |
|
450 | |||
428 | /*! |
|
451 | /*! | |
429 | Returns true is the series is empty. |
|
452 | Returns true is the series is empty. | |
430 | */ |
|
453 | */ | |
431 | bool QPieSeries::isEmpty() const |
|
454 | bool QPieSeries::isEmpty() const | |
432 | { |
|
455 | { | |
433 | Q_D(const QPieSeries); |
|
456 | Q_D(const QPieSeries); | |
434 | return d->m_slices.isEmpty(); |
|
457 | return d->m_slices.isEmpty(); | |
435 | } |
|
458 | } | |
436 |
|
459 | |||
437 | /*! |
|
460 | /*! | |
438 | Returns a list of slices that belong to this series. |
|
461 | Returns a list of slices that belong to this series. | |
439 | */ |
|
462 | */ | |
440 | QList<QPieSlice*> QPieSeries::slices() const |
|
463 | QList<QPieSlice*> QPieSeries::slices() const | |
441 | { |
|
464 | { | |
442 | Q_D(const QPieSeries); |
|
465 | Q_D(const QPieSeries); | |
443 | return d->m_slices; |
|
466 | return d->m_slices; | |
444 | } |
|
467 | } | |
445 |
|
468 | |||
446 | /*! |
|
|||
447 | Sets the horizontal center position of the pie to \a relativePosition. If \a relativePosition is |
|
|||
448 | set to 0.0 the pie is drawn on the left side of the chart and if it's set to 1.0 the pie is |
|
|||
449 | drawn on right side of the chart. The default value 0.5 puts the pie in the middle. |
|
|||
450 |
|
||||
451 | \sa setHorizontalPosition(), setPieSize() |
|
|||
452 | */ |
|
|||
453 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
469 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
454 | { |
|
470 | { | |
455 | Q_D(QPieSeries); |
|
471 | Q_D(QPieSeries); | |
456 | if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0)) |
|
472 | if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0)) | |
457 | emit piePositionChanged(); |
|
473 | emit piePositionChanged(); | |
458 | } |
|
474 | } | |
459 |
|
475 | |||
460 | /*! |
|
|||
461 | Sets the vertical center position of the pie to \a relativePosition. If \a relativePosition is |
|
|||
462 | set to 0.0 the pie is drawn on the top of the chart and if it's set to 1.0 the pie is drawn |
|
|||
463 | on bottom of the chart. The default value 0.5 puts the pie in the middle. |
|
|||
464 |
|
||||
465 | \sa verticalPosition(), setPieSize() |
|
|||
466 | */ |
|
|||
467 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
476 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
468 | { |
|
477 | { | |
469 | Q_D(QPieSeries); |
|
478 | Q_D(QPieSeries); | |
470 | if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0)) |
|
479 | if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0)) | |
471 | emit piePositionChanged(); |
|
480 | emit piePositionChanged(); | |
472 | } |
|
481 | } | |
473 |
|
482 | |||
474 | /*! |
|
|||
475 | Gets the horizontal position of the pie. |
|
|||
476 |
|
||||
477 | The returned value is relative to the chart rectangle where: |
|
|||
478 |
|
||||
479 | 0.0 means the absolute left. |
|
|||
480 | 1.0 means the absolute right. |
|
|||
481 |
|
||||
482 | By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle. |
|
|||
483 |
|
||||
484 | \sa verticalPosition(), setPieSize() |
|
|||
485 | */ |
|
|||
486 | qreal QPieSeries::horizontalPosition() const |
|
483 | qreal QPieSeries::horizontalPosition() const | |
487 | { |
|
484 | { | |
488 | Q_D(const QPieSeries); |
|
485 | Q_D(const QPieSeries); | |
489 | return d->m_pieRelativeHorPos; |
|
486 | return d->m_pieRelativeHorPos; | |
490 | } |
|
487 | } | |
491 |
|
488 | |||
492 | /*! |
|
|||
493 | Gets the vertical position position of the pie. |
|
|||
494 |
|
||||
495 | The returned value is relative to the chart rectangle where: |
|
|||
496 |
|
||||
497 | 0.0 means the absolute top. |
|
|||
498 | 1.0 means the absolute bottom. |
|
|||
499 |
|
||||
500 | By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle. |
|
|||
501 |
|
||||
502 | \sa horizontalPosition(), setPieSize() |
|
|||
503 | */ |
|
|||
504 | qreal QPieSeries::verticalPosition() const |
|
489 | qreal QPieSeries::verticalPosition() const | |
505 | { |
|
490 | { | |
506 | Q_D(const QPieSeries); |
|
491 | Q_D(const QPieSeries); | |
507 | return d->m_pieRelativeVerPos; |
|
492 | return d->m_pieRelativeVerPos; | |
508 | } |
|
493 | } | |
509 |
|
494 | |||
510 | /*! |
|
|||
511 | Sets the relative size of the pie. |
|
|||
512 |
|
||||
513 | The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle. |
|
|||
514 |
|
||||
515 | Default value is 0.7. |
|
|||
516 |
|
||||
517 | \sa pieSize(), verticalPosition(), horizontalPosition() |
|
|||
518 | */ |
|
|||
519 | void QPieSeries::setPieSize(qreal relativeSize) |
|
495 | void QPieSeries::setPieSize(qreal relativeSize) | |
520 | { |
|
496 | { | |
521 | Q_D(QPieSeries); |
|
497 | Q_D(QPieSeries); | |
522 | if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0)) |
|
498 | if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0)) | |
523 | emit pieSizeChanged(); |
|
499 | emit pieSizeChanged(); | |
524 | } |
|
500 | } | |
525 |
|
501 | |||
526 | /*! |
|
|||
527 | Gets the relative size of the pie. |
|
|||
528 |
|
||||
529 | The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle. |
|
|||
530 |
|
||||
531 | Default value is 0.7. |
|
|||
532 |
|
||||
533 | \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() |
|
|||
534 | */ |
|
|||
535 | qreal QPieSeries::pieSize() const |
|
502 | qreal QPieSeries::pieSize() const | |
536 | { |
|
503 | { | |
537 | Q_D(const QPieSeries); |
|
504 | Q_D(const QPieSeries); | |
538 | return d->m_pieRelativeSize; |
|
505 | return d->m_pieRelativeSize; | |
539 | } |
|
506 | } | |
540 |
|
507 | |||
541 |
|
508 | |||
542 | /*! |
|
|||
543 | Sets the end angle of the pie. |
|
|||
544 |
|
||||
545 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
|||
546 |
|
||||
547 | \a angle must be less than pie end angle. Default value is 0. |
|
|||
548 |
|
||||
549 | \sa pieStartAngle(), pieEndAngle(), setPieEndAngle() |
|
|||
550 | */ |
|
|||
551 | void QPieSeries::setPieStartAngle(qreal angle) |
|
509 | void QPieSeries::setPieStartAngle(qreal angle) | |
552 | { |
|
510 | { | |
553 | Q_D(QPieSeries); |
|
511 | Q_D(QPieSeries); | |
554 | if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle)) |
|
512 | if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle)) | |
555 | d->updateDerivativeData(); |
|
513 | d->updateDerivativeData(); | |
556 | } |
|
514 | } | |
557 |
|
515 | |||
558 | /*! |
|
|||
559 | Gets the start angle of the pie. |
|
|||
560 |
|
||||
561 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360. |
|
|||
562 |
|
||||
563 | \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle() |
|
|||
564 | */ |
|
|||
565 | qreal QPieSeries::pieStartAngle() const |
|
516 | qreal QPieSeries::pieStartAngle() const | |
566 | { |
|
517 | { | |
567 | Q_D(const QPieSeries); |
|
518 | Q_D(const QPieSeries); | |
568 | return d->m_pieStartAngle; |
|
519 | return d->m_pieStartAngle; | |
569 | } |
|
520 | } | |
570 |
|
521 | |||
571 | /*! |
|
522 | /*! | |
572 | Sets the end angle of the pie. |
|
523 | Sets the end angle of the pie. | |
573 |
|
524 | |||
574 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
525 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
575 |
|
526 | |||
576 | \a angle must be greater than start angle. |
|
527 | \a angle must be greater than start angle. | |
577 |
|
528 | |||
578 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
529 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
579 | */ |
|
530 | */ | |
580 | void QPieSeries::setPieEndAngle(qreal angle) |
|
531 | void QPieSeries::setPieEndAngle(qreal angle) | |
581 | { |
|
532 | { | |
582 | Q_D(QPieSeries); |
|
533 | Q_D(QPieSeries); | |
583 |
|
534 | |||
584 | if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle)) |
|
535 | if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle)) | |
585 | d->updateDerivativeData(); |
|
536 | d->updateDerivativeData(); | |
586 | } |
|
537 | } | |
587 |
|
538 | |||
588 | /*! |
|
539 | /*! | |
589 | Returns the end angle of the pie. |
|
540 | Returns the end angle of the pie. | |
590 |
|
541 | |||
591 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
542 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
592 |
|
543 | |||
593 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
544 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
594 | */ |
|
545 | */ | |
595 | qreal QPieSeries::pieEndAngle() const |
|
546 | qreal QPieSeries::pieEndAngle() const | |
596 | { |
|
547 | { | |
597 | Q_D(const QPieSeries); |
|
548 | Q_D(const QPieSeries); | |
598 | return d->m_pieEndAngle; |
|
549 | return d->m_pieEndAngle; | |
599 | } |
|
550 | } | |
600 |
|
551 | |||
601 | /*! |
|
552 | /*! | |
602 | Sets the all the slice labels \a visible or invisible. |
|
553 | Sets the all the slice labels \a visible or invisible. | |
603 |
|
554 | |||
604 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
555 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
605 | */ |
|
556 | */ | |
606 | void QPieSeries::setLabelsVisible(bool visible) |
|
557 | void QPieSeries::setLabelsVisible(bool visible) | |
607 | { |
|
558 | { | |
608 | Q_D(QPieSeries); |
|
559 | Q_D(QPieSeries); | |
609 | foreach (QPieSlice* s, d->m_slices) |
|
560 | foreach (QPieSlice* s, d->m_slices) | |
610 | s->setLabelVisible(visible); |
|
561 | s->setLabelVisible(visible); | |
611 | } |
|
562 | } | |
612 |
|
563 | |||
613 | /*! |
|
564 | /*! | |
614 | Returns the sum of all slice values in this series. |
|
565 | Returns the sum of all slice values in this series. | |
615 |
|
566 | |||
616 | \sa QPieSlice::value(), QPieSlice::setValue() |
|
567 | \sa QPieSlice::value(), QPieSlice::setValue() | |
617 | */ |
|
568 | */ | |
618 | qreal QPieSeries::total() const |
|
569 | qreal QPieSeries::total() const | |
619 | { |
|
570 | { | |
620 | Q_D(const QPieSeries); |
|
571 | Q_D(const QPieSeries); | |
621 | return d->m_total; |
|
572 | return d->m_total; | |
622 | } |
|
573 | } | |
623 |
|
574 | |||
624 | /*! |
|
575 | /*! | |
625 | \fn void QPieSeries::clicked(QPieSlice* slice, Qt::MouseButtons buttons) |
|
576 | \fn void QPieSeries::clicked(QPieSlice* slice, Qt::MouseButtons buttons) | |
626 |
|
577 | |||
627 | This signal is emitted when a \a slice has been clicked with mouse \a buttons. |
|
578 | This signal is emitted when a \a slice has been clicked with mouse \a buttons. | |
628 |
|
579 | |||
629 | \sa QPieSlice::clicked() |
|
580 | \sa QPieSlice::clicked() | |
630 | */ |
|
581 | */ | |
631 |
|
582 | |||
632 | /*! |
|
583 | /*! | |
633 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) |
|
584 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) | |
634 |
|
585 | |||
635 | This signal is emitted when user has hovered over a \a slice. |
|
586 | This signal is emitted when user has hovered over a \a slice. | |
636 |
|
587 | |||
637 | \sa QPieSlice::hoverEnter() |
|
588 | \sa QPieSlice::hoverEnter() | |
638 | */ |
|
589 | */ | |
639 |
|
590 | |||
640 | /*! |
|
591 | /*! | |
641 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) |
|
592 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) | |
642 |
|
593 | |||
643 | This signal is emitted when user has hovered away from a \a slice. |
|
594 | This signal is emitted when user has hovered away from a \a slice. | |
644 |
|
595 | |||
645 | \sa QPieSlice::hoverLeave() |
|
596 | \sa QPieSlice::hoverLeave() | |
646 | */ |
|
597 | */ | |
647 |
|
598 | |||
648 | /*! |
|
599 | /*! | |
649 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
600 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
650 |
|
601 | |||
651 | This signal is emitted when \a slices has been added to the series. |
|
602 | This signal is emitted when \a slices has been added to the series. | |
652 |
|
603 | |||
653 | \sa append(), insert() |
|
604 | \sa append(), insert() | |
654 | */ |
|
605 | */ | |
655 |
|
606 | |||
656 | /*! |
|
607 | /*! | |
657 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
608 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
658 |
|
609 | |||
659 | This signal is emitted when \a slices has been removed from the series. |
|
610 | This signal is emitted when \a slices has been removed from the series. | |
660 |
|
611 | |||
661 | \sa remove(), clear() |
|
612 | \sa remove(), clear() | |
662 | */ |
|
613 | */ | |
663 |
|
614 | |||
664 | /*! |
|
615 | /*! | |
665 | \fn void QPieSeries::piePositionChanged() |
|
616 | \fn void QPieSeries::piePositionChanged() | |
666 |
|
617 | |||
667 | This signal is emitted when pie position has changed. |
|
618 | This signal is emitted when pie position has changed. | |
668 |
|
619 | |||
669 | \sa verticalPosition(), setVerticalPosition(), horizontalPosition(), setHorizontalPosition() |
|
620 | \sa verticalPosition(), setVerticalPosition(), horizontalPosition(), setHorizontalPosition() | |
670 | */ |
|
621 | */ | |
671 |
|
622 | |||
672 | /*! |
|
623 | /*! | |
673 | \fn void QPieSeries::pieSizeChanged() |
|
624 | \fn void QPieSeries::pieSizeChanged() | |
674 |
|
625 | |||
675 | This signal is emitted when pie size has changed. |
|
626 | This signal is emitted when pie size has changed. | |
676 |
|
627 | |||
677 | \sa pieSize(), setPieSize() |
|
628 | \sa pieSize(), setPieSize() | |
678 | */ |
|
629 | */ | |
679 |
|
630 | |||
680 | /*! |
|
631 | /*! | |
681 | \fn bool QPieSeries::setModel(QAbstractItemModel *model) |
|
632 | \fn bool QPieSeries::setModel(QAbstractItemModel *model) | |
682 | Sets the \a model to be used as a data source |
|
633 | Sets the \a model to be used as a data source | |
683 | */ |
|
634 | */ | |
684 | bool QPieSeries::setModel(QAbstractItemModel* model) |
|
635 | bool QPieSeries::setModel(QAbstractItemModel* model) | |
685 | { |
|
636 | { | |
686 | Q_D(QPieSeries); |
|
637 | Q_D(QPieSeries); | |
687 | // disconnect signals from old model |
|
638 | // disconnect signals from old model | |
688 | if(m_model) |
|
639 | if(m_model) | |
689 | { |
|
640 | { | |
690 | disconnect(m_model, 0, this, 0); |
|
641 | disconnect(m_model, 0, this, 0); | |
691 | d->m_mapValues = -1; |
|
642 | d->m_mapValues = -1; | |
692 | d->m_mapLabels = -1; |
|
643 | d->m_mapLabels = -1; | |
693 | d->m_mapOrientation = Qt::Vertical; |
|
644 | d->m_mapOrientation = Qt::Vertical; | |
694 | } |
|
645 | } | |
695 |
|
646 | |||
696 | // set new model |
|
647 | // set new model | |
697 | if(model) |
|
648 | if(model) | |
698 | { |
|
649 | { | |
699 | m_model = model; |
|
650 | m_model = model; | |
700 | return true; |
|
651 | return true; | |
701 | } |
|
652 | } | |
702 | else |
|
653 | else | |
703 | { |
|
654 | { | |
704 | m_model = 0; |
|
655 | m_model = 0; | |
705 | return false; |
|
656 | return false; | |
706 | } |
|
657 | } | |
707 | } |
|
658 | } | |
708 |
|
659 | |||
709 | /*! |
|
660 | /*! | |
710 | \fn bool QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) |
|
661 | \fn bool QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | |
711 | Sets column/row specified by \a modelValuesLine to be used as a list of pie slice values for the pie. |
|
662 | Sets column/row specified by \a modelValuesLine to be used as a list of pie slice values for the pie. | |
712 | Parameter \a modelValuesLine indicates the column/row where the values for the pie slices are located in the model. |
|
663 | Parameter \a modelValuesLine indicates the column/row where the values for the pie slices are located in the model. | |
713 | Parameter \a modelLabelsLine indicates the column/row where the labels for the pie slices are located in the model. |
|
664 | Parameter \a modelLabelsLine indicates the column/row where the labels for the pie slices are located in the model. | |
714 | The \a orientation paramater specifies whether the data is in columns or in rows. |
|
665 | The \a orientation paramater specifies whether the data is in columns or in rows. | |
715 | */ |
|
666 | */ | |
716 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) |
|
667 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | |
717 | { |
|
668 | { | |
718 | Q_D(QPieSeries); |
|
669 | Q_D(QPieSeries); | |
719 |
|
670 | |||
720 | if (m_model == 0) |
|
671 | if (m_model == 0) | |
721 | return; |
|
672 | return; | |
722 |
|
673 | |||
723 | d->m_mapValues = modelValuesLine; |
|
674 | d->m_mapValues = modelValuesLine; | |
724 | d->m_mapLabels = modelLabelsLine; |
|
675 | d->m_mapLabels = modelLabelsLine; | |
725 | d->m_mapOrientation = orientation; |
|
676 | d->m_mapOrientation = orientation; | |
726 |
|
677 | |||
727 | // connect the signals |
|
678 | // connect the signals | |
728 | if (d->m_mapOrientation == Qt::Vertical) { |
|
679 | if (d->m_mapOrientation == Qt::Vertical) { | |
729 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
680 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
730 | connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
681 | connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
731 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
682 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
732 | } else { |
|
683 | } else { | |
733 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
684 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
734 | connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
685 | connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
735 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
686 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
736 | } |
|
687 | } | |
737 |
|
688 | |||
738 | // create the initial slices set |
|
689 | // create the initial slices set | |
739 | if (d->m_mapOrientation == Qt::Vertical) { |
|
690 | if (d->m_mapOrientation == Qt::Vertical) { | |
740 | for (int i = 0; i < m_model->rowCount(); i++) |
|
691 | for (int i = 0; i < m_model->rowCount(); i++) | |
741 | append(m_model->data(m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); |
|
692 | append(m_model->data(m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); | |
742 | } else { |
|
693 | } else { | |
743 | for (int i = 0; i < m_model->columnCount(); i++) |
|
694 | for (int i = 0; i < m_model->columnCount(); i++) | |
744 | append(m_model->data(m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); |
|
695 | append(m_model->data(m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); | |
745 | } |
|
696 | } | |
746 | } |
|
697 | } | |
747 |
|
698 | |||
748 | #include "moc_qpieseries.cpp" |
|
699 | #include "moc_qpieseries.cpp" | |
749 | #include "moc_qpieseriesprivate_p.cpp" |
|
700 | #include "moc_qpieseriesprivate_p.cpp" | |
750 |
|
701 | |||
751 | QTCOMMERCIALCHART_END_NAMESPACE |
|
702 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,401 +1,407 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qpieslice.h" |
|
21 | #include "qpieslice.h" | |
22 | #include "pieslicedata_p.h" |
|
22 | #include "pieslicedata_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QPieSlice |
|
27 | \class QPieSlice | |
28 | \brief Defines a slice in pie series. |
|
28 | \brief Defines a slice in pie series. | |
29 |
|
29 | |||
30 | Holds all the data of a single slice in a QPieSeries and provides the means |
|
30 | Holds all the data of a single slice in a QPieSeries and provides the means | |
31 | to modify slice data and customize the visual appearance of the slice. |
|
31 | to modify slice data and customize the visual appearance of the slice. | |
32 |
|
32 | |||
33 | It also provides the means to customize user interaction with the slice by |
|
33 | It also provides the means to customize user interaction with the slice by | |
34 | providing signals for clicking and hover events. |
|
34 | providing signals for clicking and hover events. | |
35 | */ |
|
35 | */ | |
36 |
|
36 | |||
37 | /*! |
|
37 | /*! | |
38 | \property QPieSlice::label |
|
38 | \property QPieSlice::label | |
39 |
|
39 | |||
40 | Label of the slice. |
|
40 | Label of the slice. | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \property QPieSlice::value |
|
44 | \property QPieSlice::value | |
45 |
|
45 | |||
46 | Value of the slice. |
|
46 | Value of the slice. | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | Constructs an empty slice with a \a parent. |
|
50 | Constructs an empty slice with a \a parent. | |
51 |
|
51 | |||
52 | Note that QPieSeries takes ownership of the slice when it is set/added. |
|
52 | Note that QPieSeries takes ownership of the slice when it is set/added. | |
53 |
|
53 | |||
54 | \sa QPieSeries::replace(), QPieSeries::append() |
|
54 | \sa QPieSeries::replace(), QPieSeries::append() | |
55 | */ |
|
55 | */ | |
56 | QPieSlice::QPieSlice(QObject *parent) |
|
56 | QPieSlice::QPieSlice(QObject *parent) | |
57 | :QObject(parent), |
|
57 | :QObject(parent), | |
58 | d(new PieSliceData()) |
|
58 | d(new PieSliceData()) | |
59 | { |
|
59 | { | |
60 |
|
60 | |||
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | Constructs an empty slice with given \a value, \a label and a \a parent. |
|
64 | Constructs an empty slice with given \a value, \a label and a \a parent. | |
65 | Note that QPieSeries takes ownership of the slice when it is set/added. |
|
65 | Note that QPieSeries takes ownership of the slice when it is set/added. | |
66 | \sa QPieSeries::replace(), QPieSeries::append() |
|
66 | \sa QPieSeries::replace(), QPieSeries::append() | |
67 | */ |
|
67 | */ | |
68 | QPieSlice::QPieSlice(qreal value, QString label, QObject *parent) |
|
68 | QPieSlice::QPieSlice(qreal value, QString label, QObject *parent) | |
69 | :QObject(parent), |
|
69 | :QObject(parent), | |
70 | d(new PieSliceData()) |
|
70 | d(new PieSliceData()) | |
71 | { |
|
71 | { | |
72 | d->m_value = value; |
|
72 | d->m_value = value; | |
73 | d->m_labelText = label; |
|
73 | d->m_labelText = label; | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | Destroys the slice. |
|
77 | Destroys the slice. | |
78 | User should not delete the slice if it has been added to the series. |
|
78 | User should not delete the slice if it has been added to the series. | |
79 | */ |
|
79 | */ | |
80 | QPieSlice::~QPieSlice() |
|
80 | QPieSlice::~QPieSlice() | |
81 | { |
|
81 | { | |
82 | delete d; |
|
82 | delete d; | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | Gets the value of the slice. |
|
86 | Gets the value of the slice. | |
87 | Note that all values in the series |
|
87 | Note that all values in the series | |
88 | \sa setValue() |
|
88 | \sa setValue() | |
89 | */ |
|
89 | */ | |
90 | qreal QPieSlice::value() const |
|
90 | qreal QPieSlice::value() const | |
91 | { |
|
91 | { | |
92 | return d->m_value; |
|
92 | return d->m_value; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | Gets the label of the slice. |
|
96 | Gets the label of the slice. | |
97 | \sa setLabel() |
|
97 | \sa setLabel() | |
98 | */ |
|
98 | */ | |
99 | QString QPieSlice::label() const |
|
99 | QString QPieSlice::label() const | |
100 | { |
|
100 | { | |
101 | return d->m_labelText; |
|
101 | return d->m_labelText; | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | Returns true if label is set as visible. |
|
105 | Returns true if label is set as visible. | |
106 | \sa setLabelVisible() |
|
106 | \sa setLabelVisible() | |
107 | */ |
|
107 | */ | |
108 | bool QPieSlice::isLabelVisible() const |
|
108 | bool QPieSlice::isLabelVisible() const | |
109 | { |
|
109 | { | |
110 | return d->m_isLabelVisible; |
|
110 | return d->m_isLabelVisible; | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | /*! |
|
113 | /*! | |
114 | Returns true if slice is exloded from the pie. |
|
114 | Returns true if slice is exloded from the pie. | |
115 | \sa setExploded(), setExplodeDistanceFactor() |
|
115 | \sa setExploded(), setExplodeDistanceFactor() | |
116 | */ |
|
116 | */ | |
117 | bool QPieSlice::isExploded() const |
|
117 | bool QPieSlice::isExploded() const | |
118 | { |
|
118 | { | |
119 | return d->m_isExploded; |
|
119 | return d->m_isExploded; | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | Returns the explode distance factor. |
|
123 | Returns the explode distance factor. | |
124 |
|
124 | |||
125 | The factor is relative to pie radius. For example: |
|
125 | The factor is relative to pie radius. For example: | |
126 | 1.0 means the distance is the same as the radius. |
|
126 | 1.0 means the distance is the same as the radius. | |
127 | 0.5 means the distance is half of the radius. |
|
127 | 0.5 means the distance is half of the radius. | |
128 |
|
128 | |||
129 | Default value is 0.15. |
|
129 | Default value is 0.15. | |
130 |
|
130 | |||
131 | \sa setExplodeDistanceFactor() |
|
131 | \sa setExplodeDistanceFactor() | |
132 | */ |
|
132 | */ | |
133 | qreal QPieSlice::explodeDistanceFactor() const |
|
133 | qreal QPieSlice::explodeDistanceFactor() const | |
134 | { |
|
134 | { | |
135 | return d->m_explodeDistanceFactor; |
|
135 | return d->m_explodeDistanceFactor; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | Returns the percentage of this slice compared to all slices in the same series. |
|
139 | Returns the percentage of this slice compared to all slices in the same series. | |
140 | The returned value ranges from 0 to 1.0. |
|
140 | The returned value ranges from 0 to 1.0. | |
141 |
|
141 | |||
142 | Updated internally after the slice is added to the series. |
|
142 | Updated internally after the slice is added to the series. | |
143 | */ |
|
143 | */ | |
144 | qreal QPieSlice::percentage() const |
|
144 | qreal QPieSlice::percentage() const | |
145 | { |
|
145 | { | |
146 | return d->m_percentage; |
|
146 | return d->m_percentage; | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | Returns the starting angle of this slice in the series it belongs to. |
|
150 | Returns the starting angle of this slice in the series it belongs to. | |
151 |
|
151 | |||
152 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
152 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
153 |
|
153 | |||
154 | Updated internally after the slice is added to the series. |
|
154 | Updated internally after the slice is added to the series. | |
155 | */ |
|
155 | */ | |
156 | qreal QPieSlice::startAngle() const |
|
156 | qreal QPieSlice::startAngle() const | |
157 | { |
|
157 | { | |
158 | return d->m_startAngle; |
|
158 | return d->m_startAngle; | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | Returns the end angle of this slice in the series it belongs to. |
|
162 | Returns the end angle of this slice in the series it belongs to. | |
163 |
|
163 | |||
164 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
164 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
165 |
|
165 | |||
166 | Updated internally after the slice is added to the series. |
|
166 | Updated internally after the slice is added to the series. | |
167 | */ |
|
167 | */ | |
168 | qreal QPieSlice::endAngle() const |
|
168 | qreal QPieSlice::endAngle() const | |
169 | { |
|
169 | { | |
170 | return d->m_startAngle + d->m_angleSpan; |
|
170 | return d->m_startAngle + d->m_angleSpan; | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | Returns the pen used to draw this slice. |
|
174 | Returns the pen used to draw this slice. | |
175 | \sa setPen() |
|
175 | \sa setPen() | |
176 | */ |
|
176 | */ | |
177 | QPen QPieSlice::pen() const |
|
177 | QPen QPieSlice::pen() const | |
178 | { |
|
178 | { | |
179 | return d->m_slicePen; |
|
179 | return d->m_slicePen; | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | /*! |
|
182 | /*! | |
183 | Returns the brush used to draw this slice. |
|
183 | Returns the brush used to draw this slice. | |
184 | \sa setBrush() |
|
184 | \sa setBrush() | |
185 | */ |
|
185 | */ | |
186 | QBrush QPieSlice::brush() const |
|
186 | QBrush QPieSlice::brush() const | |
187 | { |
|
187 | { | |
188 | return d->m_sliceBrush; |
|
188 | return d->m_sliceBrush; | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | Returns the pen used to draw the label in this slice. |
|
192 | Returns the pen used to draw the label in this slice. | |
193 | \sa setLabelPen() |
|
193 | \sa setLabelPen() | |
194 | */ |
|
194 | */ | |
195 | QPen QPieSlice::labelPen() const |
|
195 | QPen QPieSlice::labelPen() const | |
196 | { |
|
196 | { | |
197 | return d->m_labelPen; |
|
197 | return d->m_labelPen; | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Returns the font used to draw label in this slice. |
|
201 | Returns the font used to draw label in this slice. | |
202 | \sa setLabelFont() |
|
202 | \sa setLabelFont() | |
203 | */ |
|
203 | */ | |
204 | QFont QPieSlice::labelFont() const |
|
204 | QFont QPieSlice::labelFont() const | |
205 | { |
|
205 | { | |
206 | return d->m_labelFont; |
|
206 | return d->m_labelFont; | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | Gets the label arm length factor. |
|
210 | Gets the label arm length factor. | |
211 |
|
211 | |||
212 | The factor is relative to pie radius. For example: |
|
212 | The factor is relative to pie radius. For example: | |
213 | 1.0 means the length is the same as the radius. |
|
213 | 1.0 means the length is the same as the radius. | |
214 | 0.5 means the length is half of the radius. |
|
214 | 0.5 means the length is half of the radius. | |
215 |
|
215 | |||
216 | Default value is 0.15 |
|
216 | Default value is 0.15 | |
217 |
|
217 | |||
218 | \sa setLabelArmLengthFactor() |
|
218 | \sa setLabelArmLengthFactor() | |
219 | */ |
|
219 | */ | |
220 | qreal QPieSlice::labelArmLengthFactor() const |
|
220 | qreal QPieSlice::labelArmLengthFactor() const | |
221 | { |
|
221 | { | |
222 | return d->m_labelArmLengthFactor; |
|
222 | return d->m_labelArmLengthFactor; | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | /*! |
|
225 | /*! | |
226 | \fn void QPieSlice::clicked(Qt::MouseButtons buttons) |
|
226 | \fn void QPieSlice::clicked(Qt::MouseButtons buttons) | |
227 |
|
227 | |||
228 | This signal is emitted when user has clicked the slice. |
|
228 | This signal is emitted when user has clicked the slice. | |
229 | Parameter \a buttons hold the information about the clicked mouse buttons. |
|
229 | Parameter \a buttons hold the information about the clicked mouse buttons. | |
230 |
|
230 | |||
231 | \sa QPieSeries::clicked() |
|
231 | \sa QPieSeries::clicked() | |
232 | */ |
|
232 | */ | |
233 |
|
233 | |||
234 | /*! |
|
234 | /*! | |
235 | \fn void QPieSlice::hoverEnter() |
|
235 | \fn void QPieSlice::hoverEnter() | |
236 |
|
236 | |||
237 | This signal is emitted when user has hovered over the slice. |
|
237 | This signal is emitted when user has hovered over the slice. | |
238 |
|
238 | |||
239 | \sa QPieSeries::hoverEnter() |
|
239 | \sa QPieSeries::hoverEnter() | |
240 | */ |
|
240 | */ | |
241 |
|
241 | |||
242 | /*! |
|
242 | /*! | |
243 | \fn void QPieSlice::hoverLeave() |
|
243 | \fn void QPieSlice::hoverLeave() | |
244 |
|
244 | |||
245 | This signal is emitted when user has hovered away from the slice. |
|
245 | This signal is emitted when user has hovered away from the slice. | |
246 |
|
246 | |||
247 | \sa QPieSeries::hoverLeave() |
|
247 | \sa QPieSeries::hoverLeave() | |
248 | */ |
|
248 | */ | |
249 |
|
249 | |||
250 | /*! |
|
250 | /*! | |
251 | \fn void QPieSlice::changed() |
|
251 | \fn void QPieSlice::changed() | |
252 |
|
252 | |||
253 | This signal emitted when something has changed in the slice. |
|
253 | This signal emitted when something has changed in the slice. | |
254 | */ |
|
254 | */ | |
255 |
|
255 | |||
256 | /*! |
|
256 | /*! | |
|
257 | \fn void QPieSlice::selected() | |||
|
258 | ||||
|
259 | This signal emitted when this slice has been clicked in the legend. | |||
|
260 | */ | |||
|
261 | ||||
|
262 | /*! | |||
257 | Sets the \a value of this slice. |
|
263 | Sets the \a value of this slice. | |
258 | \sa value() |
|
264 | \sa value() | |
259 | */ |
|
265 | */ | |
260 | void QPieSlice::setValue(qreal value) |
|
266 | void QPieSlice::setValue(qreal value) | |
261 | { |
|
267 | { | |
262 | if (!qFuzzyIsNull(d->m_value - value)) { |
|
268 | if (!qFuzzyIsNull(d->m_value - value)) { | |
263 | d->m_value = value; |
|
269 | d->m_value = value; | |
264 | emit changed(); |
|
270 | emit changed(); | |
265 | } |
|
271 | } | |
266 | } |
|
272 | } | |
267 |
|
273 | |||
268 | /*! |
|
274 | /*! | |
269 | Sets the \a label of the slice. |
|
275 | Sets the \a label of the slice. | |
270 | \sa label() |
|
276 | \sa label() | |
271 | */ |
|
277 | */ | |
272 | void QPieSlice::setLabel(QString label) |
|
278 | void QPieSlice::setLabel(QString label) | |
273 | { |
|
279 | { | |
274 | if (d->m_labelText != label) { |
|
280 | if (d->m_labelText != label) { | |
275 | d->m_labelText = label; |
|
281 | d->m_labelText = label; | |
276 | emit changed(); |
|
282 | emit changed(); | |
277 | } |
|
283 | } | |
278 | } |
|
284 | } | |
279 |
|
285 | |||
280 | /*! |
|
286 | /*! | |
281 | Sets the label \a visible in this slice. |
|
287 | Sets the label \a visible in this slice. | |
282 | \sa isLabelVisible(), QPieSeries::setLabelsVisible() |
|
288 | \sa isLabelVisible(), QPieSeries::setLabelsVisible() | |
283 | */ |
|
289 | */ | |
284 | void QPieSlice::setLabelVisible(bool visible) |
|
290 | void QPieSlice::setLabelVisible(bool visible) | |
285 | { |
|
291 | { | |
286 | if (d->m_isLabelVisible != visible) { |
|
292 | if (d->m_isLabelVisible != visible) { | |
287 | d->m_isLabelVisible = visible; |
|
293 | d->m_isLabelVisible = visible; | |
288 | emit changed(); |
|
294 | emit changed(); | |
289 | } |
|
295 | } | |
290 | } |
|
296 | } | |
291 |
|
297 | |||
292 | /*! |
|
298 | /*! | |
293 | Sets this slice \a exploded. |
|
299 | Sets this slice \a exploded. | |
294 | \sa isExploded(), explodeDistanceFactor() |
|
300 | \sa isExploded(), explodeDistanceFactor() | |
295 | */ |
|
301 | */ | |
296 | void QPieSlice::setExploded(bool exploded) |
|
302 | void QPieSlice::setExploded(bool exploded) | |
297 | { |
|
303 | { | |
298 | if (d->m_isExploded != exploded) { |
|
304 | if (d->m_isExploded != exploded) { | |
299 | d->m_isExploded = exploded; |
|
305 | d->m_isExploded = exploded; | |
300 | emit changed(); |
|
306 | emit changed(); | |
301 | } |
|
307 | } | |
302 | } |
|
308 | } | |
303 |
|
309 | |||
304 | /*! |
|
310 | /*! | |
305 | Sets the explode distance \a factor. |
|
311 | Sets the explode distance \a factor. | |
306 |
|
312 | |||
307 | The factor is relative to pie radius. For example: |
|
313 | The factor is relative to pie radius. For example: | |
308 | 1.0 means the distance is the same as the radius. |
|
314 | 1.0 means the distance is the same as the radius. | |
309 | 0.5 means the distance is half of the radius. |
|
315 | 0.5 means the distance is half of the radius. | |
310 |
|
316 | |||
311 | Default value is 0.15 |
|
317 | Default value is 0.15 | |
312 |
|
318 | |||
313 | \sa explodeDistanceFactor() |
|
319 | \sa explodeDistanceFactor() | |
314 | */ |
|
320 | */ | |
315 | void QPieSlice::setExplodeDistanceFactor(qreal factor) |
|
321 | void QPieSlice::setExplodeDistanceFactor(qreal factor) | |
316 | { |
|
322 | { | |
317 | if (!qFuzzyIsNull(d->m_explodeDistanceFactor - factor)) { |
|
323 | if (!qFuzzyIsNull(d->m_explodeDistanceFactor - factor)) { | |
318 | d->m_explodeDistanceFactor = factor; |
|
324 | d->m_explodeDistanceFactor = factor; | |
319 | emit changed(); |
|
325 | emit changed(); | |
320 | } |
|
326 | } | |
321 | } |
|
327 | } | |
322 |
|
328 | |||
323 | /*! |
|
329 | /*! | |
324 | Sets the \a pen used to draw this slice. |
|
330 | Sets the \a pen used to draw this slice. | |
325 | Note that applying a theme will override this. |
|
331 | Note that applying a theme will override this. | |
326 | \sa pen() |
|
332 | \sa pen() | |
327 | */ |
|
333 | */ | |
328 | void QPieSlice::setPen(const QPen &pen) |
|
334 | void QPieSlice::setPen(const QPen &pen) | |
329 | { |
|
335 | { | |
330 | if (d->m_slicePen != pen) { |
|
336 | if (d->m_slicePen != pen) { | |
331 | d->m_slicePen = pen; |
|
337 | d->m_slicePen = pen; | |
332 | d->m_slicePen.setThemed(false); |
|
338 | d->m_slicePen.setThemed(false); | |
333 | emit changed(); |
|
339 | emit changed(); | |
334 | } |
|
340 | } | |
335 | } |
|
341 | } | |
336 |
|
342 | |||
337 | /*! |
|
343 | /*! | |
338 | Sets the \a brush used to draw this slice. |
|
344 | Sets the \a brush used to draw this slice. | |
339 | Note that applying a theme will override this. |
|
345 | Note that applying a theme will override this. | |
340 | \sa brush() |
|
346 | \sa brush() | |
341 | */ |
|
347 | */ | |
342 | void QPieSlice::setBrush(const QBrush &brush) |
|
348 | void QPieSlice::setBrush(const QBrush &brush) | |
343 | { |
|
349 | { | |
344 | if (d->m_sliceBrush != brush) { |
|
350 | if (d->m_sliceBrush != brush) { | |
345 | d->m_sliceBrush = brush; |
|
351 | d->m_sliceBrush = brush; | |
346 | d->m_sliceBrush.setThemed(false); |
|
352 | d->m_sliceBrush.setThemed(false); | |
347 | emit changed(); |
|
353 | emit changed(); | |
348 | } |
|
354 | } | |
349 | } |
|
355 | } | |
350 |
|
356 | |||
351 | /*! |
|
357 | /*! | |
352 | Sets the \a pen used to draw the label in this slice. |
|
358 | Sets the \a pen used to draw the label in this slice. | |
353 | Note that applying a theme will override this. |
|
359 | Note that applying a theme will override this. | |
354 | \sa labelPen() |
|
360 | \sa labelPen() | |
355 | */ |
|
361 | */ | |
356 | void QPieSlice::setLabelPen(const QPen &pen) |
|
362 | void QPieSlice::setLabelPen(const QPen &pen) | |
357 | { |
|
363 | { | |
358 | if (d->m_labelPen != pen) { |
|
364 | if (d->m_labelPen != pen) { | |
359 | d->m_labelPen = pen; |
|
365 | d->m_labelPen = pen; | |
360 | d->m_labelPen.setThemed(false); |
|
366 | d->m_labelPen.setThemed(false); | |
361 | emit changed(); |
|
367 | emit changed(); | |
362 | } |
|
368 | } | |
363 | } |
|
369 | } | |
364 |
|
370 | |||
365 | /*! |
|
371 | /*! | |
366 | Sets the \a font used to draw the label in this slice. |
|
372 | Sets the \a font used to draw the label in this slice. | |
367 | Note that applying a theme will override this. |
|
373 | Note that applying a theme will override this. | |
368 | \sa labelFont() |
|
374 | \sa labelFont() | |
369 | */ |
|
375 | */ | |
370 | void QPieSlice::setLabelFont(const QFont &font) |
|
376 | void QPieSlice::setLabelFont(const QFont &font) | |
371 | { |
|
377 | { | |
372 | if (d->m_labelFont != font) { |
|
378 | if (d->m_labelFont != font) { | |
373 | d->m_labelFont = font; |
|
379 | d->m_labelFont = font; | |
374 | d->m_labelFont.setThemed(false); |
|
380 | d->m_labelFont.setThemed(false); | |
375 | emit changed(); |
|
381 | emit changed(); | |
376 | } |
|
382 | } | |
377 | } |
|
383 | } | |
378 |
|
384 | |||
379 | /*! |
|
385 | /*! | |
380 | Sets the label arm length \a factor. |
|
386 | Sets the label arm length \a factor. | |
381 |
|
387 | |||
382 | The factor is relative to pie radius. For example: |
|
388 | The factor is relative to pie radius. For example: | |
383 | 1.0 means the length is the same as the radius. |
|
389 | 1.0 means the length is the same as the radius. | |
384 | 0.5 means the length is half of the radius. |
|
390 | 0.5 means the length is half of the radius. | |
385 |
|
391 | |||
386 | Default value is 0.15 |
|
392 | Default value is 0.15 | |
387 |
|
393 | |||
388 | \sa labelArmLengthFactor() |
|
394 | \sa labelArmLengthFactor() | |
389 | */ |
|
395 | */ | |
390 | void QPieSlice::setLabelArmLengthFactor(qreal factor) |
|
396 | void QPieSlice::setLabelArmLengthFactor(qreal factor) | |
391 | { |
|
397 | { | |
392 | if (!qFuzzyIsNull(d->m_labelArmLengthFactor - factor)) { |
|
398 | if (!qFuzzyIsNull(d->m_labelArmLengthFactor - factor)) { | |
393 | d->m_labelArmLengthFactor = factor; |
|
399 | d->m_labelArmLengthFactor = factor; | |
394 | emit changed(); |
|
400 | emit changed(); | |
395 | } |
|
401 | } | |
396 | } |
|
402 | } | |
397 |
|
403 | |||
398 | QTCOMMERCIALCHART_END_NAMESPACE |
|
404 | QTCOMMERCIALCHART_END_NAMESPACE | |
399 |
|
405 | |||
400 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
406 | QTCOMMERCIALCHART_USE_NAMESPACE | |
401 | #include "moc_qpieslice.cpp" |
|
407 | #include "moc_qpieslice.cpp" |
General Comments 0
You need to be logged in to leave comments.
Login now