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