From 924499b21823e64889d310d8e82a24e49a9571e7 2012-04-02 11:28:38 From: Jani Honkonen Date: 2012-04-02 11:28:38 Subject: [PATCH] Polish QPieSlice API by removing the DataPtr stuff --- diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 09333ee..74f5626 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -223,7 +223,7 @@ void ChartTheme::decorate(QPieSeries* series, int index, bool force) QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); QPieSlice *s = series->slices().at(i); - PieSliceData data = *s->data_ptr(); + PieSliceData data = PieSliceData::data(s); if (data.m_slicePen.isThemed() || force) { data.m_slicePen = penColor; @@ -245,9 +245,9 @@ void ChartTheme::decorate(QPieSeries* series, int index, bool force) data.m_labelFont.setThemed(true); } - if (*s->data_ptr() != data) { - *s->data_ptr() = data; - emit s->data_ptr()->emitChangedSignal(s); + if (PieSliceData::data(s) != data) { + PieSliceData::data(s) = data; + emit PieSliceData::data(s).emitChangedSignal(s); } } } diff --git a/src/piechart/piechartitem.cpp b/src/piechart/piechartitem.cpp index 3a6679a..82ce8a1 100644 --- a/src/piechart/piechartitem.cpp +++ b/src/piechart/piechartitem.cpp @@ -147,7 +147,7 @@ void PieChartItem::calculatePieLayout() PieSliceData PieChartItem::sliceData(QPieSlice *slice) { // TODO: This function is kid of useless now. Refactor. - PieSliceData sliceData = *slice->data_ptr(); + PieSliceData sliceData = PieSliceData::data(slice); sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); sliceData.m_radius = m_pieRadius; return sliceData; diff --git a/src/piechart/pieslicedata_p.h b/src/piechart/pieslicedata_p.h index b60ad9a..e596ce1 100644 --- a/src/piechart/pieslicedata_p.h +++ b/src/piechart/pieslicedata_p.h @@ -110,6 +110,12 @@ public: emit s->changed(); } + static PieSliceData &data(QPieSlice *slice) + { + Q_ASSERT(slice); + return *slice->d; + } + qreal m_value; Themed m_slicePen; diff --git a/src/piechart/qpieseries.cpp b/src/piechart/qpieseries.cpp index 29caa99..b0466f4 100644 --- a/src/piechart/qpieseries.cpp +++ b/src/piechart/qpieseries.cpp @@ -69,21 +69,21 @@ void QPieSeriesPrivate::updateDerivativeData() QVector changed; foreach (QPieSlice* s, m_slices) { - PieSliceData data = *s->data_ptr(); + PieSliceData data = PieSliceData::data(s); data.m_percentage = s->value() / m_total; data.m_angleSpan = pieSpan * data.m_percentage; data.m_startAngle = sliceAngle; sliceAngle += data.m_angleSpan; - if (*s->data_ptr() != data) { - *s->data_ptr() = data; + if (PieSliceData::data(s) != data) { + PieSliceData::data(s) = data; changed << s; } } // emit signals foreach (QPieSlice* s, changed) - s->data_ptr()->emitChangedSignal(s); + PieSliceData::data(s).emitChangedSignal(s); } void QPieSeriesPrivate::sliceChanged() diff --git a/src/piechart/qpieslice.h b/src/piechart/qpieslice.h index 5a6e984..a82d13e 100644 --- a/src/piechart/qpieslice.h +++ b/src/piechart/qpieslice.h @@ -80,10 +80,6 @@ private: friend class PieSliceData; PieSliceData * const d; Q_DISABLE_COPY(QPieSlice) - -public: - typedef PieSliceData * const DataPtr; - inline DataPtr &data_ptr() { return d; } }; QTCOMMERCIALCHART_END_NAMESPACE