| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | #include <private/pieanimation_p.h> |
| 31 | #include <private/piesliceanimation_p.h> |
| 32 | #include <private/piechartitem_p.h> |
| 33 | |
| 34 | QT_CHARTS_BEGIN_NAMESPACE |
| 35 | |
| 36 | PieAnimation::PieAnimation(PieChartItem *item, int duration, QEasingCurve &curve) |
| 37 | : ChartAnimation(item), |
| 38 | m_item(item), |
| 39 | m_animationDuration(duration), |
| 40 | m_animationCurve(curve) |
| 41 | { |
| 42 | Q_UNUSED(m_item); |
| 43 | } |
| 44 | |
| 45 | PieAnimation::~PieAnimation() |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | ChartAnimation *PieAnimation::updateValue(PieSliceItem *sliceItem, const PieSliceData &sliceData) |
| 50 | { |
| 51 | PieSliceAnimation *animation = m_animations.value(akey: sliceItem); |
| 52 | if (!animation) { |
| 53 | animation = new PieSliceAnimation(sliceItem); |
| 54 | animation->setDuration(m_animationDuration); |
| 55 | animation->setEasingCurve(m_animationCurve); |
| 56 | m_animations.insert(akey: sliceItem, avalue: animation); |
| 57 | } else { |
| 58 | animation->stop(); |
| 59 | } |
| 60 | |
| 61 | animation->updateValue(endValue: sliceData); |
| 62 | |
| 63 | return animation; |
| 64 | } |
| 65 | |
| 66 | ChartAnimation *PieAnimation::addSlice(PieSliceItem *sliceItem, const PieSliceData &sliceData, bool startupAnimation) |
| 67 | { |
| 68 | PieSliceAnimation *animation = new PieSliceAnimation(sliceItem); |
| 69 | animation->setDuration(m_animationDuration); |
| 70 | animation->setEasingCurve(m_animationCurve); |
| 71 | m_animations.insert(akey: sliceItem, avalue: animation); |
| 72 | |
| 73 | PieSliceData startValue = sliceData; |
| 74 | startValue.m_radius = 0; |
| 75 | if (startupAnimation) |
| 76 | startValue.m_startAngle = 0; |
| 77 | else |
| 78 | startValue.m_startAngle = sliceData.m_startAngle + (sliceData.m_angleSpan / 2); |
| 79 | startValue.m_angleSpan = 0; |
| 80 | |
| 81 | if (sliceData.m_holeRadius > 0) |
| 82 | startValue.m_radius = sliceData.m_holeRadius; |
| 83 | |
| 84 | animation->setValue(startValue, endValue: sliceData); |
| 85 | |
| 86 | return animation; |
| 87 | } |
| 88 | |
| 89 | ChartAnimation *PieAnimation::removeSlice(PieSliceItem *sliceItem) |
| 90 | { |
| 91 | PieSliceAnimation *animation = m_animations.value(akey: sliceItem); |
| 92 | Q_ASSERT(animation); |
| 93 | animation->stop(); |
| 94 | |
| 95 | PieSliceData endValue = animation->currentSliceValue(); |
| 96 | if (endValue.m_holeRadius > 0) |
| 97 | endValue.m_radius = endValue.m_holeRadius; |
| 98 | else |
| 99 | endValue.m_radius = 0; |
| 100 | endValue.m_startAngle = endValue.m_startAngle + endValue.m_angleSpan; |
| 101 | endValue.m_angleSpan = 0; |
| 102 | endValue.m_isLabelVisible = false; |
| 103 | |
| 104 | animation->updateValue(endValue); |
| 105 | |
| 106 | // PieSliceItem is the parent of PieSliceAnimation so the animation will be deleted as well.. |
| 107 | connect(sender: animation, SIGNAL(finished()), receiver: sliceItem, SLOT(deleteLater())); |
| 108 | m_animations.remove(akey: sliceItem); |
| 109 | |
| 110 | return animation; |
| 111 | } |
| 112 | |
| 113 | void PieAnimation::updateCurrentValue(const QVariant &) |
| 114 | { |
| 115 | // nothing to do... |
| 116 | } |
| 117 | |
| 118 | QT_CHARTS_END_NAMESPACE |
| 119 | |
| 120 | #include "moc_pieanimation_p.cpp" |
| 121 | |