##// END OF EJS Templates
Getting rid of friend classes in pie API
Jani Honkonen -
r676:2e47e5550be5
parent child
Show More
@@ -128,7 +128,7 void PieChartItem::calculatePieLayout()
128
128
129 PieSliceData PieChartItem::sliceData(QPieSlice *slice)
129 PieSliceData PieChartItem::sliceData(QPieSlice *slice)
130 {
130 {
131 PieSliceData sliceData = slice->d_ptr->m_data;
131 PieSliceData sliceData = slice->data_ptr()->m_data;
132 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
132 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
133 sliceData.m_radius = m_pieRadius;
133 sliceData.m_radius = m_pieRadius;
134 sliceData.m_angleSpan = slice->endAngle() - slice->startAngle();
134 sliceData.m_angleSpan = slice->endAngle() - slice->startAngle();
@@ -48,19 +48,19 void QPieSeriesPrivate::updateDerivativeData()
48 bool isChanged = false;
48 bool isChanged = false;
49
49
50 qreal percentage = s->value() / m_total;
50 qreal percentage = s->value() / m_total;
51 if (s->d_ptr->m_data.m_percentage != percentage) {
51 if (s->data_ptr()->m_data.m_percentage != percentage) {
52 s->d_ptr->m_data.m_percentage = percentage;
52 s->data_ptr()->m_data.m_percentage = percentage;
53 isChanged = true;
53 isChanged = true;
54 }
54 }
55
55
56 qreal sliceSpan = pieSpan * percentage;
56 qreal sliceSpan = pieSpan * percentage;
57 if (s->d_ptr->m_data.m_angleSpan != sliceSpan) {
57 if (s->data_ptr()->m_data.m_angleSpan != sliceSpan) {
58 s->d_ptr->m_data.m_angleSpan = sliceSpan;
58 s->data_ptr()->m_data.m_angleSpan = sliceSpan;
59 isChanged = true;
59 isChanged = true;
60 }
60 }
61
61
62 if (s->d_ptr->m_data.m_startAngle != sliceAngle) {
62 if (s->data_ptr()->m_data.m_startAngle != sliceAngle) {
63 s->d_ptr->m_data.m_startAngle = sliceAngle;
63 s->data_ptr()->m_data.m_startAngle = sliceAngle;
64 isChanged = true;
64 isChanged = true;
65 }
65 }
66 sliceAngle += sliceSpan;
66 sliceAngle += sliceSpan;
@@ -71,7 +71,7 void QPieSeriesPrivate::updateDerivativeData()
71
71
72 // emit signals
72 // emit signals
73 foreach (QPieSlice* s, changed)
73 foreach (QPieSlice* s, changed)
74 emit s->changed();
74 emit s->data_ptr()->changed();
75 }
75 }
76
76
77 void QPieSeriesPrivate::sliceChanged()
77 void QPieSeriesPrivate::sliceChanged()
@@ -66,10 +66,13 Q_SIGNALS:
66 void pieSizeChanged();
66 void pieSizeChanged();
67
67
68 private:
68 private:
69 friend class QPieSlice;
70 QPieSeriesPrivate * const d_ptr;
69 QPieSeriesPrivate * const d_ptr;
71 Q_DECLARE_PRIVATE(QPieSeries)
70 Q_DECLARE_PRIVATE(QPieSeries)
72 Q_DISABLE_COPY(QPieSeries)
71 Q_DISABLE_COPY(QPieSeries)
72
73 public:
74 typedef QPieSeriesPrivate * const DataPtr;
75 inline DataPtr &data_ptr() { return d_ptr; }
73 };
76 };
74
77
75 QTCOMMERCIALCHART_END_NAMESPACE
78 QTCOMMERCIALCHART_END_NAMESPACE
@@ -262,7 +262,7 void QPieSlice::setValue(qreal value)
262
262
263 QPieSeries *series = qobject_cast<QPieSeries*>(parent());
263 QPieSeries *series = qobject_cast<QPieSeries*>(parent());
264 if (series)
264 if (series)
265 series->d_ptr->updateDerivativeData(); // will emit changed()
265 series->data_ptr()->updateDerivativeData(); // will emit changed()
266 else
266 else
267 emit changed();
267 emit changed();
268 }
268 }
@@ -404,5 +404,6 void QPieSlice::setLabelArmLengthFactor(qreal factor)
404 }
404 }
405
405
406 #include "moc_qpieslice.cpp"
406 #include "moc_qpieslice.cpp"
407 #include "moc_qpiesliceprivate_p.cpp"
407
408
408 QTCOMMERCIALCHART_END_NAMESPACE
409 QTCOMMERCIALCHART_END_NAMESPACE
@@ -9,8 +9,6
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 class QPieSlicePrivate;
11 class QPieSlicePrivate;
12 class QPieSeriesPrivate;
13 class PieChartItem;
14
12
15 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
13 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
16 {
14 {
@@ -59,11 +57,13 Q_SIGNALS:
59 void changed();
57 void changed();
60
58
61 private:
59 private:
62 friend class QPieSeriesPrivate; // TODO: get rid of this
63 friend class PieChartItem; // TODO: get rid of this
64 QPieSlicePrivate * const d_ptr;
60 QPieSlicePrivate * const d_ptr;
65 Q_DECLARE_PRIVATE(QPieSlice)
61 Q_DECLARE_PRIVATE(QPieSlice)
66 Q_DISABLE_COPY(QPieSlice)
62 Q_DISABLE_COPY(QPieSlice)
63
64 public:
65 typedef QPieSlicePrivate * const DataPtr;
66 inline DataPtr &data_ptr() { return d_ptr; }
67 };
67 };
68
68
69 QTCOMMERCIALCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
@@ -6,16 +6,27
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 class QPieSlicePrivate
9 class QPieSlicePrivate : public QObject
10 {
10 {
11 Q_OBJECT
11 Q_DECLARE_PUBLIC(QPieSlice)
12 Q_DECLARE_PUBLIC(QPieSlice)
12
13
13 public:
14 public:
14 QPieSlicePrivate(QPieSlice *parent):q_ptr(parent) {}
15 QPieSlicePrivate(QPieSlice *parent)
16 :QObject(parent),
17 q_ptr(parent)
18 {
19 connect(this, SIGNAL(changed()), q_ptr, SIGNAL(changed()));
20 }
21
15 ~QPieSlicePrivate() {}
22 ~QPieSlicePrivate() {}
16
23
17 QPieSlice * const q_ptr;
24 Q_SIGNALS:
25 void changed();
18
26
27 public:
28 friend class QPieSeriesPrivate;
29 QPieSlice * const q_ptr;
19 PieSliceData m_data;
30 PieSliceData m_data;
20 };
31 };
21
32
General Comments 0
You need to be logged in to leave comments. Login now