##// END OF EJS Templates
Refactoring QPieSlice private implementation. Removes the useless QPieSlicePrivate layer and uses PieSliceData directly.
Jani Honkonen -
r818:5bf1dbd3a89a
parent child
Show More
@@ -213,6 +213,7 void ChartTheme::decorate(QScatterSeries* series, int index,bool force)
213 213
214 214 void ChartTheme::decorate(QPieSeries* series, int index, bool force)
215 215 {
216
216 217 for (int i(0); i < series->slices().count(); i++) {
217 218
218 219 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
@@ -221,8 +222,8 void ChartTheme::decorate(QPieSeries* series, int index, bool force)
221 222 qreal pos = (qreal) (i + 1) / (qreal) series->count();
222 223 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
223 224
224 QPieSlice::DataPtr s = series->slices().at(i)->data_ptr();
225 PieSliceData data = s->m_data;
225 QPieSlice *s = series->slices().at(i);
226 PieSliceData data = *s->data_ptr();
226 227
227 228 if (data.m_slicePen.isThemed() || force) {
228 229 data.m_slicePen = penColor;
@@ -244,9 +245,9 void ChartTheme::decorate(QPieSeries* series, int index, bool force)
244 245 data.m_labelFont.setThemed(true);
245 246 }
246 247
247 if (s->m_data != data) {
248 s->m_data = data;
249 emit s->changed();
248 if (*s->data_ptr() != data) {
249 *s->data_ptr() = data;
250 emit s->data_ptr()->emitChangedSignal(s);
250 251 }
251 252 }
252 253 }
@@ -11,7 +11,6 PRIVATE_HEADERS += \
11 11 $$PWD/pieslicedata_p.h \
12 12 $$PWD/piechartitem_p.h \
13 13 $$PWD/piesliceitem_p.h \
14 $$PWD/qpiesliceprivate_p.h \
15 14 $$PWD/qpieseriesprivate_p.h
16 15
17 16 PUBLIC_HEADERS += \
@@ -21,7 +21,6
21 21 #include "piechartitem_p.h"
22 22 #include "piesliceitem_p.h"
23 23 #include "qpieslice.h"
24 #include "qpiesliceprivate_p.h"
25 24 #include "qpieseries.h"
26 25 #include "chartpresenter_p.h"
27 26 #include "chartdataset_p.h"
@@ -147,7 +146,8 void PieChartItem::calculatePieLayout()
147 146
148 147 PieSliceData PieChartItem::sliceData(QPieSlice *slice)
149 148 {
150 PieSliceData sliceData = slice->data_ptr()->m_data;
149 // TODO: This function is kid of useless now. Refactor.
150 PieSliceData sliceData = *slice->data_ptr();
151 151 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
152 152 sliceData.m_radius = m_pieRadius;
153 153 return sliceData;
@@ -21,7 +21,8
21 21 #ifndef PIESLICEDATA_P_H
22 22 #define PIESLICEDATA_P_H
23 23
24 #include <qchartglobal.h>
24 #include "qchartglobal.h"
25 #include "qpieslice.h"
25 26 #include <QPen>
26 27 #include <QBrush>
27 28 #include <QDebug>
@@ -104,6 +105,11 public:
104 105 return false;
105 106 }
106 107
108 void emitChangedSignal(QPieSlice *s)
109 {
110 emit s->changed();
111 }
112
107 113 qreal m_value;
108 114
109 115 Themed<QPen> m_slicePen;
@@ -24,7 +24,7
24 24 #include "qchartglobal.h"
25 25 #include "charttheme_p.h"
26 26 #include "qpieseries.h"
27 #include "qpiesliceprivate_p.h"
27 #include "pieslicedata_p.h"
28 28 #include <QGraphicsItem>
29 29 #include <QRectF>
30 30 #include <QColor>
@@ -19,8 +19,9
19 19 ****************************************************************************/
20 20
21 21 #include "qpieseries.h"
22 #include "qpiesliceprivate_p.h"
23 22 #include "qpieseriesprivate_p.h"
23 #include "qpieslice.h"
24 #include "pieslicedata_p.h"
24 25 #include <QDebug>
25 26
26 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -68,21 +69,21 void QPieSeriesPrivate::updateDerivativeData()
68 69 QVector<QPieSlice*> changed;
69 70 foreach (QPieSlice* s, m_slices) {
70 71
71 PieSliceData data = s->data_ptr()->m_data;
72 PieSliceData data = *s->data_ptr();
72 73 data.m_percentage = s->value() / m_total;
73 74 data.m_angleSpan = pieSpan * data.m_percentage;
74 75 data.m_startAngle = sliceAngle;
75 76 sliceAngle += data.m_angleSpan;
76 77
77 if (s->data_ptr()->m_data != data) {
78 s->data_ptr()->m_data = data;
78 if (*s->data_ptr() != data) {
79 *s->data_ptr() = data;
79 80 changed << s;
80 81 }
81 82 }
82 83
83 84 // emit signals
84 85 foreach (QPieSlice* s, changed)
85 emit s->data_ptr()->changed();
86 s->data_ptr()->emitChangedSignal(s);
86 87 }
87 88
88 89 void QPieSeriesPrivate::sliceChanged()
@@ -89,10 +89,6 private:
89 89 QPieSeriesPrivate * const d_ptr;
90 90 Q_DECLARE_PRIVATE(QPieSeries)
91 91 Q_DISABLE_COPY(QPieSeries)
92
93 public:
94 typedef QPieSeriesPrivate * const DataPtr;
95 inline DataPtr &data_ptr() { return d_ptr; }
96 92 };
97 93
98 94 QTCOMMERCIALCHART_END_NAMESPACE
@@ -19,9 +19,7
19 19 ****************************************************************************/
20 20
21 21 #include "qpieslice.h"
22 #include "qpiesliceprivate_p.h"
23 #include "qpieseries.h"
24 #include "qpieseriesprivate_p.h"
22 #include "pieslicedata_p.h"
25 23
26 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 25
@@ -57,7 +55,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
57 55 */
58 56 QPieSlice::QPieSlice(QObject *parent)
59 57 :QObject(parent),
60 d_ptr(new QPieSlicePrivate(this))
58 d(new PieSliceData())
61 59 {
62 60
63 61 }
@@ -69,11 +67,10 QPieSlice::QPieSlice(QObject *parent)
69 67 */
70 68 QPieSlice::QPieSlice(qreal value, QString label, QObject *parent)
71 69 :QObject(parent),
72 d_ptr(new QPieSlicePrivate(this))
70 d(new PieSliceData())
73 71 {
74 Q_D(QPieSlice);
75 d->m_data.m_value = value;
76 d->m_data.m_labelText = label;
72 d->m_value = value;
73 d->m_labelText = label;
77 74 }
78 75
79 76 /*!
@@ -82,7 +79,7 QPieSlice::QPieSlice(qreal value, QString label, QObject *parent)
82 79 */
83 80 QPieSlice::~QPieSlice()
84 81 {
85 delete d_ptr;
82 delete d;
86 83 }
87 84
88 85 /*!
@@ -92,8 +89,7 QPieSlice::~QPieSlice()
92 89 */
93 90 qreal QPieSlice::value() const
94 91 {
95 Q_D(const QPieSlice);
96 return d->m_data.m_value;
92 return d->m_value;
97 93 }
98 94
99 95 /*!
@@ -101,9 +97,8 qreal QPieSlice::value() const
101 97 \sa setLabel()
102 98 */
103 99 QString QPieSlice::label() const
104 {
105 Q_D(const QPieSlice);
106 return d->m_data.m_labelText;
100 {
101 return d->m_labelText;
107 102 }
108 103
109 104 /*!
@@ -112,8 +107,7 QString QPieSlice::label() const
112 107 */
113 108 bool QPieSlice::isLabelVisible() const
114 109 {
115 Q_D(const QPieSlice);
116 return d->m_data.m_isLabelVisible;
110 return d->m_isLabelVisible;
117 111 }
118 112
119 113 /*!
@@ -122,8 +116,7 bool QPieSlice::isLabelVisible() const
122 116 */
123 117 bool QPieSlice::isExploded() const
124 118 {
125 Q_D(const QPieSlice);
126 return d->m_data.m_isExploded;
119 return d->m_isExploded;
127 120 }
128 121
129 122 /*!
@@ -139,8 +132,7 bool QPieSlice::isExploded() const
139 132 */
140 133 qreal QPieSlice::explodeDistanceFactor() const
141 134 {
142 Q_D(const QPieSlice);
143 return d->m_data.m_explodeDistanceFactor;
135 return d->m_explodeDistanceFactor;
144 136 }
145 137
146 138 /*!
@@ -151,8 +143,7 qreal QPieSlice::explodeDistanceFactor() const
151 143 */
152 144 qreal QPieSlice::percentage() const
153 145 {
154 Q_D(const QPieSlice);
155 return d->m_data.m_percentage;
146 return d->m_percentage;
156 147 }
157 148
158 149 /*!
@@ -164,8 +155,7 qreal QPieSlice::percentage() const
164 155 */
165 156 qreal QPieSlice::startAngle() const
166 157 {
167 Q_D(const QPieSlice);
168 return d->m_data.m_startAngle;
158 return d->m_startAngle;
169 159 }
170 160
171 161 /*!
@@ -177,8 +167,7 qreal QPieSlice::startAngle() const
177 167 */
178 168 qreal QPieSlice::endAngle() const
179 169 {
180 Q_D(const QPieSlice);
181 return d->m_data.m_startAngle + d->m_data.m_angleSpan;
170 return d->m_startAngle + d->m_angleSpan;
182 171 }
183 172
184 173 /*!
@@ -187,8 +176,7 qreal QPieSlice::endAngle() const
187 176 */
188 177 QPen QPieSlice::pen() const
189 178 {
190 Q_D(const QPieSlice);
191 return d->m_data.m_slicePen;
179 return d->m_slicePen;
192 180 }
193 181
194 182 /*!
@@ -197,8 +185,7 QPen QPieSlice::pen() const
197 185 */
198 186 QBrush QPieSlice::brush() const
199 187 {
200 Q_D(const QPieSlice);
201 return d->m_data.m_sliceBrush;
188 return d->m_sliceBrush;
202 189 }
203 190
204 191 /*!
@@ -207,8 +194,7 QBrush QPieSlice::brush() const
207 194 */
208 195 QPen QPieSlice::labelPen() const
209 196 {
210 Q_D(const QPieSlice);
211 return d->m_data.m_labelPen;
197 return d->m_labelPen;
212 198 }
213 199
214 200 /*!
@@ -217,8 +203,7 QPen QPieSlice::labelPen() const
217 203 */
218 204 QFont QPieSlice::labelFont() const
219 205 {
220 Q_D(const QPieSlice);
221 return d->m_data.m_labelFont;
206 return d->m_labelFont;
222 207 }
223 208
224 209 /*!
@@ -234,8 +219,7 QFont QPieSlice::labelFont() const
234 219 */
235 220 qreal QPieSlice::labelArmLengthFactor() const
236 221 {
237 Q_D(const QPieSlice);
238 return d->m_data.m_labelArmLengthFactor;
222 return d->m_labelArmLengthFactor;
239 223 }
240 224
241 225 /*!
@@ -276,15 +260,9 qreal QPieSlice::labelArmLengthFactor() const
276 260 */
277 261 void QPieSlice::setValue(qreal value)
278 262 {
279 Q_D(QPieSlice);
280 if (!qFuzzyIsNull(d->m_data.m_value - value)) {
281 d->m_data.m_value = value;
282
283 QPieSeries *series = qobject_cast<QPieSeries*>(parent());
284 if (series)
285 series->data_ptr()->updateDerivativeData(); // will emit changed()
286 else
287 emit changed();
263 if (!qFuzzyIsNull(d->m_value - value)) {
264 d->m_value = value;
265 emit changed();
288 266 }
289 267 }
290 268
@@ -294,9 +272,8 void QPieSlice::setValue(qreal value)
294 272 */
295 273 void QPieSlice::setLabel(QString label)
296 274 {
297 Q_D(QPieSlice);
298 if (d->m_data.m_labelText != label) {
299 d->m_data.m_labelText = label;
275 if (d->m_labelText != label) {
276 d->m_labelText = label;
300 277 emit changed();
301 278 }
302 279 }
@@ -307,9 +284,8 void QPieSlice::setLabel(QString label)
307 284 */
308 285 void QPieSlice::setLabelVisible(bool visible)
309 286 {
310 Q_D(QPieSlice);
311 if (d->m_data.m_isLabelVisible != visible) {
312 d->m_data.m_isLabelVisible = visible;
287 if (d->m_isLabelVisible != visible) {
288 d->m_isLabelVisible = visible;
313 289 emit changed();
314 290 }
315 291 }
@@ -320,9 +296,8 void QPieSlice::setLabelVisible(bool visible)
320 296 */
321 297 void QPieSlice::setExploded(bool exploded)
322 298 {
323 Q_D(QPieSlice);
324 if (d->m_data.m_isExploded != exploded) {
325 d->m_data.m_isExploded = exploded;
299 if (d->m_isExploded != exploded) {
300 d->m_isExploded = exploded;
326 301 emit changed();
327 302 }
328 303 }
@@ -340,9 +315,8 void QPieSlice::setExploded(bool exploded)
340 315 */
341 316 void QPieSlice::setExplodeDistanceFactor(qreal factor)
342 317 {
343 Q_D(QPieSlice);
344 if (!qFuzzyIsNull(d->m_data.m_explodeDistanceFactor - factor)) {
345 d->m_data.m_explodeDistanceFactor = factor;
318 if (!qFuzzyIsNull(d->m_explodeDistanceFactor - factor)) {
319 d->m_explodeDistanceFactor = factor;
346 320 emit changed();
347 321 }
348 322 }
@@ -354,10 +328,9 void QPieSlice::setExplodeDistanceFactor(qreal factor)
354 328 */
355 329 void QPieSlice::setPen(const QPen &pen)
356 330 {
357 Q_D(QPieSlice);
358 if (d->m_data.m_slicePen != pen) {
359 d->m_data.m_slicePen = pen;
360 d->m_data.m_slicePen.setThemed(false);
331 if (d->m_slicePen != pen) {
332 d->m_slicePen = pen;
333 d->m_slicePen.setThemed(false);
361 334 emit changed();
362 335 }
363 336 }
@@ -369,10 +342,9 void QPieSlice::setPen(const QPen &pen)
369 342 */
370 343 void QPieSlice::setBrush(const QBrush &brush)
371 344 {
372 Q_D(QPieSlice);
373 if (d->m_data.m_sliceBrush != brush) {
374 d->m_data.m_sliceBrush = brush;
375 d->m_data.m_sliceBrush.setThemed(false);
345 if (d->m_sliceBrush != brush) {
346 d->m_sliceBrush = brush;
347 d->m_sliceBrush.setThemed(false);
376 348 emit changed();
377 349 }
378 350 }
@@ -384,10 +356,9 void QPieSlice::setBrush(const QBrush &brush)
384 356 */
385 357 void QPieSlice::setLabelPen(const QPen &pen)
386 358 {
387 Q_D(QPieSlice);
388 if (d->m_data.m_labelPen != pen) {
389 d->m_data.m_labelPen = pen;
390 d->m_data.m_labelPen.setThemed(false);
359 if (d->m_labelPen != pen) {
360 d->m_labelPen = pen;
361 d->m_labelPen.setThemed(false);
391 362 emit changed();
392 363 }
393 364 }
@@ -399,10 +370,9 void QPieSlice::setLabelPen(const QPen &pen)
399 370 */
400 371 void QPieSlice::setLabelFont(const QFont &font)
401 372 {
402 Q_D(QPieSlice);
403 if (d->m_data.m_labelFont != font) {
404 d->m_data.m_labelFont = font;
405 d->m_data.m_labelFont.setThemed(false);
373 if (d->m_labelFont != font) {
374 d->m_labelFont = font;
375 d->m_labelFont.setThemed(false);
406 376 emit changed();
407 377 }
408 378 }
@@ -420,14 +390,12 void QPieSlice::setLabelFont(const QFont &font)
420 390 */
421 391 void QPieSlice::setLabelArmLengthFactor(qreal factor)
422 392 {
423 Q_D(QPieSlice);
424 if (!qFuzzyIsNull(d->m_data.m_labelArmLengthFactor - factor)) {
425 d->m_data.m_labelArmLengthFactor = factor;
393 if (!qFuzzyIsNull(d->m_labelArmLengthFactor - factor)) {
394 d->m_labelArmLengthFactor = factor;
426 395 emit changed();
427 396 }
428 397 }
429 398
430 399 #include "moc_qpieslice.cpp"
431 #include "moc_qpiesliceprivate_p.cpp"
432 400
433 401 QTCOMMERCIALCHART_END_NAMESPACE
@@ -28,7 +28,7
28 28 #include <QFont>
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 class QPieSlicePrivate;
31 class PieSliceData;
32 32
33 33 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
34 34 {
@@ -77,13 +77,13 Q_SIGNALS:
77 77 void changed();
78 78
79 79 private:
80 QPieSlicePrivate * const d_ptr;
81 Q_DECLARE_PRIVATE(QPieSlice)
80 friend class PieSliceData;
81 PieSliceData * const d;
82 82 Q_DISABLE_COPY(QPieSlice)
83 83
84 84 public:
85 typedef QPieSlicePrivate * const DataPtr;
86 inline DataPtr &data_ptr() { return d_ptr; }
85 typedef PieSliceData * const DataPtr;
86 inline DataPtr &data_ptr() { return d; }
87 87 };
88 88
89 89 QTCOMMERCIALCHART_END_NAMESPACE
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now