| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <private/pieanimation_p.h> |
| 5 | #include <private/piesliceanimation_p.h> |
| 6 | #include <private/piechartitem_p.h> |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | PieAnimation::PieAnimation(PieChartItem *item, int duration, QEasingCurve &curve) |
| 11 | : ChartAnimation(item), |
| 12 | m_item(item), |
| 13 | m_animationDuration(duration), |
| 14 | m_animationCurve(curve) |
| 15 | { |
| 16 | Q_UNUSED(m_item); |
| 17 | } |
| 18 | |
| 19 | PieAnimation::~PieAnimation() |
| 20 | { |
| 21 | } |
| 22 | |
| 23 | ChartAnimation *PieAnimation::updateValue(PieSliceItem *sliceItem, const PieSliceData &sliceData) |
| 24 | { |
| 25 | PieSliceAnimation *animation = m_animations.value(key: sliceItem); |
| 26 | if (!animation) { |
| 27 | animation = new PieSliceAnimation(sliceItem); |
| 28 | animation->setDuration(m_animationDuration); |
| 29 | animation->setEasingCurve(m_animationCurve); |
| 30 | m_animations.insert(key: sliceItem, value: animation); |
| 31 | } else { |
| 32 | animation->stop(); |
| 33 | } |
| 34 | |
| 35 | animation->updateValue(endValue: sliceData); |
| 36 | |
| 37 | return animation; |
| 38 | } |
| 39 | |
| 40 | ChartAnimation *PieAnimation::addSlice(PieSliceItem *sliceItem, const PieSliceData &sliceData, bool startupAnimation) |
| 41 | { |
| 42 | PieSliceAnimation *animation = new PieSliceAnimation(sliceItem); |
| 43 | animation->setDuration(m_animationDuration); |
| 44 | animation->setEasingCurve(m_animationCurve); |
| 45 | m_animations.insert(key: sliceItem, value: animation); |
| 46 | |
| 47 | PieSliceData startValue = sliceData; |
| 48 | startValue.m_radius = 0; |
| 49 | if (startupAnimation) |
| 50 | startValue.m_startAngle = 0; |
| 51 | else |
| 52 | startValue.m_startAngle = sliceData.m_startAngle + (sliceData.m_angleSpan / 2); |
| 53 | startValue.m_angleSpan = 0; |
| 54 | |
| 55 | if (sliceData.m_holeRadius > 0) |
| 56 | startValue.m_radius = sliceData.m_holeRadius; |
| 57 | |
| 58 | animation->setValue(startValue, endValue: sliceData); |
| 59 | |
| 60 | return animation; |
| 61 | } |
| 62 | |
| 63 | ChartAnimation *PieAnimation::removeSlice(PieSliceItem *sliceItem) |
| 64 | { |
| 65 | PieSliceAnimation *animation = m_animations.value(key: sliceItem); |
| 66 | Q_ASSERT(animation); |
| 67 | animation->stop(); |
| 68 | |
| 69 | PieSliceData endValue = animation->currentSliceValue(); |
| 70 | if (endValue.m_holeRadius > 0) |
| 71 | endValue.m_radius = endValue.m_holeRadius; |
| 72 | else |
| 73 | endValue.m_radius = 0; |
| 74 | endValue.m_startAngle = endValue.m_startAngle + endValue.m_angleSpan; |
| 75 | endValue.m_angleSpan = 0; |
| 76 | endValue.m_isLabelVisible = false; |
| 77 | |
| 78 | animation->updateValue(endValue); |
| 79 | |
| 80 | // PieSliceItem is the parent of PieSliceAnimation so the animation will be deleted as well.. |
| 81 | connect(sender: animation, SIGNAL(finished()), receiver: sliceItem, SLOT(deleteLater())); |
| 82 | m_animations.remove(key: sliceItem); |
| 83 | |
| 84 | return animation; |
| 85 | } |
| 86 | |
| 87 | void PieAnimation::updateCurrentValue(const QVariant &) |
| 88 | { |
| 89 | // nothing to do... |
| 90 | } |
| 91 | |
| 92 | QT_END_NAMESPACE |
| 93 | |
| 94 | #include "moc_pieanimation_p.cpp" |
| 95 | |