From b889b21eeadf7efcb1526da012eed28148b3e050 2012-02-27 14:31:15 From: Jani Honkonen Date: 2012-02-27 14:31:15 Subject: [PATCH] QPieSlice: angle() -> startAngle(), angleSpan() -> endAngle() --- diff --git a/src/piechart/piepresenter.cpp b/src/piechart/piepresenter.cpp index 8f3f244..bd6cbd1 100644 --- a/src/piechart/piepresenter.cpp +++ b/src/piechart/piepresenter.cpp @@ -123,7 +123,7 @@ void PiePresenter::updateGeometry() foreach (QPieSlice* s, m_series->m_slices) { // calculate the farthest point in the slice from the pie center - qreal centerAngle = s->angle() + (s->angleSpan() / 2); + qreal centerAngle = s->m_startAngle + (s->m_angleSpan / 2); qreal len = pieRadius + s->labelArmLength() + s->explodeDistance(); QPointF dp(qSin(centerAngle*(PI/180)) * len, -qCos(centerAngle*(PI/180)) * len); QPointF p = pieRect.center() + dp; diff --git a/src/piechart/pieslice.cpp b/src/piechart/pieslice.cpp index 213feff..cdb07d3 100644 --- a/src/piechart/pieslice.cpp +++ b/src/piechart/pieslice.cpp @@ -21,7 +21,7 @@ QPointF offset(qreal angle, qreal length) PieSlice::PieSlice(QGraphicsItem* parent) :QGraphicsObject(parent), m_slicelabel(new PieSliceLabel(this)), - m_angle(0), + m_startAngle(0), m_angleSpan(0), m_isExploded(false), m_explodeDistance(0) @@ -80,7 +80,7 @@ void PieSlice::updateGeometry() prepareGeometryChange(); // calculate center angle - qreal centerAngle = m_angle + (m_angleSpan/2); + qreal centerAngle = m_startAngle + (m_angleSpan/2); // adjust rect for exploding QRectF rect = m_pieRect; @@ -94,7 +94,7 @@ void PieSlice::updateGeometry() // TODO: draw the shape so that it might have a hole in the center QPainterPath path; path.moveTo(rect.center()); - path.arcTo(rect, -m_angle + 90, -m_angleSpan); + path.arcTo(rect, -m_startAngle + 90, -m_angleSpan); path.closeSubpath(); m_path = path; @@ -113,8 +113,8 @@ void PieSlice::updateData(const QPieSlice* sliceData) { // TODO: compare what has changes to avoid unneccesary geometry updates - m_angle = sliceData->angle(); - m_angleSpan = sliceData->angleSpan(); + m_startAngle = sliceData->startAngle(); + m_angleSpan = sliceData->m_angleSpan; m_isExploded = sliceData->isExploded(); m_explodeDistance = sliceData->explodeDistance(); // TODO: expose to public API m_pen = sliceData->pen(); diff --git a/src/piechart/pieslice_p.h b/src/piechart/pieslice_p.h index aca1f3f..fd0660e 100644 --- a/src/piechart/pieslice_p.h +++ b/src/piechart/pieslice_p.h @@ -49,7 +49,7 @@ private: QRectF m_pieRect; QPainterPath m_path; - qreal m_angle; + qreal m_startAngle; qreal m_angleSpan; bool m_isExploded; diff --git a/src/piechart/qpieseries.cpp b/src/piechart/qpieseries.cpp index 4069ee8..4e7cdde 100644 --- a/src/piechart/qpieseries.cpp +++ b/src/piechart/qpieseries.cpp @@ -518,8 +518,8 @@ void QPieSeries::updateDerivativeData() changed = true; } - if (s->m_angle != sliceAngle) { - s->m_angle = sliceAngle; + if (s->m_startAngle != sliceAngle) { + s->m_startAngle = sliceAngle; changed = true; } sliceAngle += sliceSpan; diff --git a/src/piechart/qpieslice.cpp b/src/piechart/qpieslice.cpp index b43f2a1..6ebf884 100644 --- a/src/piechart/qpieslice.cpp +++ b/src/piechart/qpieslice.cpp @@ -44,7 +44,7 @@ QPieSlice::QPieSlice(QObject *parent) m_isExploded(false), m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE), m_percentage(0), - m_angle(0), + m_startAngle(0), m_angleSpan(0), m_pen(DEFAULT_PEN_COLOR), m_brush(DEFAULT_BRUSH_COLOR), @@ -67,7 +67,7 @@ QPieSlice::QPieSlice(qreal value, QString label, QObject *parent) m_isExploded(false), m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE), m_percentage(0), - m_angle(0), + m_startAngle(0), m_angleSpan(0), m_pen(DEFAULT_PEN_COLOR), m_brush(DEFAULT_BRUSH_COLOR), @@ -150,21 +150,21 @@ qreal QPieSlice::percentage() const Updated internally after the slice is added to the series. */ -qreal QPieSlice::angle() const +qreal QPieSlice::startAngle() const { - return m_angle; + return m_startAngle; } /*! - Returns the angle span of this slice in the series it belongs to. + Returns the end angle of this slice in the series it belongs to. Full pie is 360 degrees where 0 degrees is at 12 a'clock. Updated internally after the slice is added to the series. */ -qreal QPieSlice::angleSpan() const +qreal QPieSlice::endAngle() const { - return m_angleSpan; + return m_startAngle + m_angleSpan; } /*! diff --git a/src/piechart/qpieslice.h b/src/piechart/qpieslice.h index 3bb6425..009ede5 100644 --- a/src/piechart/qpieslice.h +++ b/src/piechart/qpieslice.h @@ -29,8 +29,8 @@ public: // generated data qreal percentage() const; - qreal angle() const; - qreal angleSpan() const; + qreal startAngle() const; + qreal endAngle() const; // customization QPen pen() const; @@ -70,6 +70,7 @@ private: // TODO: use private class friend class QPieSeries; friend class PiePresenter; + friend class PieSlice; // data qreal m_value; @@ -80,7 +81,7 @@ private: // generated data qreal m_percentage; - qreal m_angle; + qreal m_startAngle; qreal m_angleSpan; // customization