| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses |
| 5 | |
| 6 | #include <private/boxplotanimation_p.h> |
| 7 | #include <private/boxplotchartitem_p.h> |
| 8 | #include <private/boxwhiskersdata_p.h> |
| 9 | #include <private/boxwhiskersanimation_p.h> |
| 10 | |
| 11 | QT_BEGIN_NAMESPACE |
| 12 | |
| 13 | BoxPlotAnimation::BoxPlotAnimation(BoxPlotChartItem *item, int duration, QEasingCurve &curve) |
| 14 | : QObject(item), |
| 15 | m_item(item), |
| 16 | m_animationDuration(duration), |
| 17 | m_animationCurve(curve) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | BoxPlotAnimation::~BoxPlotAnimation() |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | void BoxPlotAnimation::addBox(BoxWhiskers *box) |
| 26 | { |
| 27 | BoxWhiskersAnimation *animation = m_animations.value(key: box); |
| 28 | if (!animation) { |
| 29 | animation = new BoxWhiskersAnimation(box, this, m_animationDuration, m_animationCurve); |
| 30 | m_animations.insert(key: box, value: animation); |
| 31 | BoxWhiskersData start; |
| 32 | start.m_lowerExtreme = box->m_data.m_median; |
| 33 | start.m_lowerQuartile = box->m_data.m_median; |
| 34 | start.m_median = box->m_data.m_median; |
| 35 | start.m_upperQuartile = box->m_data.m_median; |
| 36 | start.m_upperExtreme = box->m_data.m_median; |
| 37 | animation->setup(startData: start, endData: box->m_data); |
| 38 | |
| 39 | } else { |
| 40 | animation->stop(); |
| 41 | animation->setEndData(box->m_data); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | ChartAnimation *BoxPlotAnimation::boxAnimation(BoxWhiskers *box) |
| 46 | { |
| 47 | BoxWhiskersAnimation *animation = m_animations.value(key: box); |
| 48 | if (animation) |
| 49 | animation->m_changeAnimation = false; |
| 50 | |
| 51 | return animation; |
| 52 | } |
| 53 | |
| 54 | ChartAnimation *BoxPlotAnimation::boxChangeAnimation(BoxWhiskers *box) |
| 55 | { |
| 56 | BoxWhiskersAnimation *animation = m_animations.value(key: box); |
| 57 | animation->m_changeAnimation = true; |
| 58 | animation->setEndData(box->m_data); |
| 59 | |
| 60 | return animation; |
| 61 | } |
| 62 | |
| 63 | void BoxPlotAnimation::setAnimationStart(BoxWhiskers *box) |
| 64 | { |
| 65 | BoxWhiskersAnimation *animation = m_animations.value(key: box); |
| 66 | animation->setStartData(box->m_data); |
| 67 | } |
| 68 | |
| 69 | void BoxPlotAnimation::stopAll() |
| 70 | { |
| 71 | foreach (BoxWhiskers *box, m_animations.keys()) { |
| 72 | BoxWhiskersAnimation *animation = m_animations.value(key: box); |
| 73 | animation->stopAndDestroyLater(); |
| 74 | m_animations.remove(key: box); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | void BoxPlotAnimation::removeBoxAnimation(BoxWhiskers *box) |
| 79 | { |
| 80 | m_animations.remove(key: box); |
| 81 | } |
| 82 | |
| 83 | QT_END_NAMESPACE |
| 84 | |
| 85 | #include "moc_boxplotanimation_p.cpp" |
| 86 | |