@@ -214,6 +214,7 PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice) | |||||
214 | PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data; |
|
214 | PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data; | |
215 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); |
|
215 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); | |
216 | sliceData.m_radius = m_pieRadius; |
|
216 | sliceData.m_radius = m_pieRadius; | |
|
217 | sliceData.m_donut = m_series->donut(); | |||
217 | return sliceData; |
|
218 | return sliceData; | |
218 | } |
|
219 | } | |
219 |
|
220 |
@@ -82,6 +82,7 public: | |||||
82 | m_radius = 0; |
|
82 | m_radius = 0; | |
83 | m_startAngle = 0; |
|
83 | m_startAngle = 0; | |
84 | m_angleSpan = 0; |
|
84 | m_angleSpan = 0; | |
|
85 | m_donut = false; | |||
85 | } |
|
86 | } | |
86 |
|
87 | |||
87 | bool operator!=(const PieSliceData &other) const |
|
88 | bool operator!=(const PieSliceData &other) const | |
@@ -135,6 +136,7 public: | |||||
135 | qreal m_radius; |
|
136 | qreal m_radius; | |
136 | qreal m_startAngle; |
|
137 | qreal m_startAngle; | |
137 | qreal m_angleSpan; |
|
138 | qreal m_angleSpan; | |
|
139 | bool m_donut; | |||
138 | }; |
|
140 | }; | |
139 |
|
141 | |||
140 | QTCOMMERCIALCHART_END_NAMESPACE |
|
142 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -174,11 +174,19 QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAn | |||||
174 | QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2); |
|
174 | QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2); | |
175 |
|
175 | |||
176 | // slice path |
|
176 | // slice path | |
177 | // TODO: draw the shape so that it might have a hole in the center |
|
|||
178 | QPainterPath path; |
|
177 | QPainterPath path; | |
|
178 | if (m_data.m_donut) { | |||
|
179 | qreal donutFraction = 5.0; | |||
|
180 | QRectF insideRect = rect.adjusted(rect.width() / donutFraction, rect.height() / donutFraction, -rect.width() / donutFraction, -rect.height() / donutFraction); | |||
|
181 | path.arcMoveTo(rect, -startAngle + 90); | |||
|
182 | path.arcTo(rect, -startAngle + 90, -angleSpan); | |||
|
183 | path.arcTo(insideRect, -startAngle + 90 - angleSpan, angleSpan); | |||
|
184 | path.closeSubpath(); | |||
|
185 | } else { | |||
179 | path.moveTo(rect.center()); |
|
186 | path.moveTo(rect.center()); | |
180 | path.arcTo(rect, -startAngle + 90, -angleSpan); |
|
187 | path.arcTo(rect, -startAngle + 90, -angleSpan); | |
181 | path.closeSubpath(); |
|
188 | path.closeSubpath(); | |
|
189 | } | |||
182 |
|
190 | |||
183 | // calculate label arm start point |
|
191 | // calculate label arm start point | |
184 | *armStart = center; |
|
192 | *armStart = center; |
@@ -523,6 +523,19 qreal QPieSeries::sum() const | |||||
523 | return d->m_sum; |
|
523 | return d->m_sum; | |
524 | } |
|
524 | } | |
525 |
|
525 | |||
|
526 | void QPieSeries::setDonut(bool donut) | |||
|
527 | { | |||
|
528 | Q_D(QPieSeries); | |||
|
529 | d->m_donutChart = donut; | |||
|
530 | d->updateDerivativeData(); | |||
|
531 | } | |||
|
532 | ||||
|
533 | bool QPieSeries::donut() const | |||
|
534 | { | |||
|
535 | Q_D(const QPieSeries); | |||
|
536 | return d->m_donutChart; | |||
|
537 | } | |||
|
538 | ||||
526 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
539 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
527 | { |
|
540 | { | |
528 | Q_D(QPieSeries); |
|
541 | Q_D(QPieSeries); | |
@@ -660,7 +673,8 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | |||||
660 | m_pieRelativeSize(0.7), |
|
673 | m_pieRelativeSize(0.7), | |
661 | m_pieStartAngle(0), |
|
674 | m_pieStartAngle(0), | |
662 | m_pieEndAngle(360), |
|
675 | m_pieEndAngle(360), | |
663 | m_sum(0) |
|
676 | m_sum(0), | |
|
677 | m_donutChart(false) | |||
664 | { |
|
678 | { | |
665 | } |
|
679 | } | |
666 |
|
680 | |||
@@ -693,6 +707,7 void QPieSeriesPrivate::updateDerivativeData() | |||||
693 | d->setPercentage(s->value() / m_sum); |
|
707 | d->setPercentage(s->value() / m_sum); | |
694 | d->setStartAngle(sliceAngle); |
|
708 | d->setStartAngle(sliceAngle); | |
695 | d->setAngleSpan(pieSpan * s->percentage()); |
|
709 | d->setAngleSpan(pieSpan * s->percentage()); | |
|
710 | d->m_data.m_donut = m_donutChart; | |||
696 | sliceAngle += s->angleSpan(); |
|
711 | sliceAngle += s->angleSpan(); | |
697 | } |
|
712 | } | |
698 |
|
713 |
@@ -61,6 +61,9 public: | |||||
61 |
|
61 | |||
62 | qreal sum() const; |
|
62 | qreal sum() const; | |
63 |
|
63 | |||
|
64 | void setDonut(bool donut = true); | |||
|
65 | bool donut() const; | |||
|
66 | ||||
64 | void setHorizontalPosition(qreal relativePosition); |
|
67 | void setHorizontalPosition(qreal relativePosition); | |
65 | qreal horizontalPosition() const; |
|
68 | qreal horizontalPosition() const; | |
66 |
|
69 |
General Comments 0
You need to be logged in to leave comments.
Login now