diff --git a/demos/piechartcustomization/mainwidget.cpp b/demos/piechartcustomization/mainwidget.cpp index ec0bfdc..af69375 100644 --- a/demos/piechartcustomization/mainwidget.cpp +++ b/demos/piechartcustomization/mainwidget.cpp @@ -115,6 +115,14 @@ MainWidget::MainWidget(QWidget* parent) m_endAngle->setValue(m_series->pieEndAngle()); m_endAngle->setSingleStep(1); + m_isDonut = new QCheckBox(); + + m_donutInnerSize = new QDoubleSpinBox(); + m_donutInnerSize->setMinimum(0.0); + m_donutInnerSize->setMaximum(1.0); + m_donutInnerSize->setSingleStep(0.1); + m_donutInnerSize->setValue(m_series->donutInnerSize()); + QPushButton *appendSlice = new QPushButton("Append slice"); QPushButton *insertSlice = new QPushButton("Insert slice"); QPushButton *removeSlice = new QPushButton("Remove selected slice"); @@ -125,6 +133,8 @@ MainWidget::MainWidget(QWidget* parent) seriesSettingsLayout->addRow("Size factor", m_sizeFactor); seriesSettingsLayout->addRow("Start angle", m_startAngle); seriesSettingsLayout->addRow("End angle", m_endAngle); + seriesSettingsLayout->addRow("Is donut", m_isDonut); + seriesSettingsLayout->addRow("Donut inner size", m_donutInnerSize); seriesSettingsLayout->addRow(appendSlice); seriesSettingsLayout->addRow(insertSlice); seriesSettingsLayout->addRow(removeSlice); @@ -136,6 +146,8 @@ MainWidget::MainWidget(QWidget* parent) connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); + connect(m_isDonut, SIGNAL(toggled(bool)), this, SLOT(updateSerieSettings())); + connect(m_donutInnerSize, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); connect(appendSlice, SIGNAL(clicked()), this, SLOT(appendSlice())); connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice())); @@ -239,6 +251,8 @@ void MainWidget::updateSerieSettings() m_series->setPieSize(m_sizeFactor->value()); m_series->setPieStartAngle(m_startAngle->value()); m_series->setPieEndAngle(m_endAngle->value()); + m_series->setDonut(m_isDonut->isChecked()); + m_series->setDonutInnerSize(m_donutInnerSize->value()); } void MainWidget::updateSliceSettings() diff --git a/demos/piechartcustomization/mainwidget.h b/demos/piechartcustomization/mainwidget.h index 1f45e12..4f82b0c 100644 --- a/demos/piechartcustomization/mainwidget.h +++ b/demos/piechartcustomization/mainwidget.h @@ -72,6 +72,8 @@ private: QDoubleSpinBox* m_sizeFactor; QDoubleSpinBox* m_startAngle; QDoubleSpinBox* m_endAngle; + QCheckBox* m_isDonut; + QDoubleSpinBox* m_donutInnerSize; QLineEdit* m_sliceName; QDoubleSpinBox* m_sliceValue; diff --git a/src/animations/pieanimation.cpp b/src/animations/pieanimation.cpp index 15d5e44..0cc5bfe 100644 --- a/src/animations/pieanimation.cpp +++ b/src/animations/pieanimation.cpp @@ -60,8 +60,11 @@ ChartAnimation* PieAnimation::addSlice(PieSliceItem *sliceItem, const PieSliceDa else startValue.m_startAngle = sliceData.m_startAngle + (sliceData.m_angleSpan / 2); startValue.m_angleSpan = 0; - animation->setValue(startValue, sliceData); + if (sliceData.m_donut) + startValue.m_radius = sliceData.m_innerRadius; + + animation->setValue(startValue, sliceData); animation->setDuration(ChartAnimationDuration); animation->setEasingCurve(QEasingCurve::OutQuart); @@ -75,7 +78,10 @@ ChartAnimation* PieAnimation::removeSlice(PieSliceItem *sliceItem) animation->stop(); PieSliceData endValue = animation->currentSliceValue(); - endValue.m_radius = 0; + if (endValue.m_donut) + endValue.m_radius = endValue.m_innerRadius; + else + endValue.m_radius = 0; endValue.m_startAngle = endValue.m_startAngle + endValue.m_angleSpan; endValue.m_angleSpan = 0; endValue.m_isLabelVisible = false; diff --git a/src/animations/piesliceanimation.cpp b/src/animations/piesliceanimation.cpp index 10c770e..9cf0bb9 100644 --- a/src/animations/piesliceanimation.cpp +++ b/src/animations/piesliceanimation.cpp @@ -110,6 +110,7 @@ QVariant PieSliceAnimation::interpolated(const QVariant &start, const QVariant & result.m_angleSpan = linearPos(startValue.m_angleSpan, endValue.m_angleSpan, progress); result.m_slicePen = linearPos(startValue.m_slicePen, endValue.m_slicePen, progress); result.m_sliceBrush = linearPos(startValue.m_sliceBrush, endValue.m_sliceBrush, progress); + result.m_innerRadius = linearPos(startValue.m_innerRadius, endValue.m_innerRadius, progress); return qVariantFromValue(result); }