1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include <private/candlestick_p.h> |
5 | #include <private/candlestickanimation_p.h> |
6 | #include <private/candlestickbodywicksanimation_p.h> |
7 | #include <private/candlestickchartitem_p.h> |
8 | #include <private/candlestickdata_p.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | CandlestickAnimation::CandlestickAnimation(CandlestickChartItem *item, int duration, |
13 | QEasingCurve &curve) |
14 | : QObject(item), |
15 | m_item(item), |
16 | m_animationDuration(duration), |
17 | m_animationCurve(curve) |
18 | { |
19 | } |
20 | |
21 | CandlestickAnimation::~CandlestickAnimation() |
22 | { |
23 | } |
24 | |
25 | void CandlestickAnimation::addCandlestick(Candlestick *candlestick) |
26 | { |
27 | CandlestickBodyWicksAnimation *animation = m_animations.value(key: candlestick, defaultValue: 0); |
28 | if (!animation) { |
29 | animation = new CandlestickBodyWicksAnimation(candlestick, this, m_animationDuration, |
30 | m_animationCurve); |
31 | m_animations.insert(key: candlestick, value: animation); |
32 | |
33 | qreal median = (candlestick->m_data.m_open + candlestick->m_data.m_close) / 2; |
34 | CandlestickData start; |
35 | start.m_open = median; |
36 | start.m_high = median; |
37 | start.m_low = median; |
38 | start.m_close = median; |
39 | animation->setup(startData: start, endData: candlestick->m_data); |
40 | } else { |
41 | animation->stop(); |
42 | animation->setEndData(candlestick->m_data); |
43 | } |
44 | } |
45 | |
46 | ChartAnimation *CandlestickAnimation::candlestickAnimation(Candlestick *candlestick) |
47 | { |
48 | CandlestickBodyWicksAnimation *animation = m_animations.value(key: candlestick, defaultValue: 0); |
49 | if (animation) |
50 | animation->m_changeAnimation = false; |
51 | |
52 | return animation; |
53 | } |
54 | |
55 | ChartAnimation *CandlestickAnimation::candlestickChangeAnimation(Candlestick *candlestick) |
56 | { |
57 | CandlestickBodyWicksAnimation *animation = m_animations.value(key: candlestick, defaultValue: 0); |
58 | if (animation) { |
59 | animation->m_changeAnimation = true; |
60 | animation->setEndData(candlestick->m_data); |
61 | } |
62 | |
63 | return animation; |
64 | } |
65 | |
66 | void CandlestickAnimation::setAnimationStart(Candlestick *candlestick) |
67 | { |
68 | CandlestickBodyWicksAnimation *animation = m_animations.value(key: candlestick, defaultValue: 0); |
69 | if (animation) |
70 | animation->setStartData(candlestick->m_data); |
71 | } |
72 | |
73 | void CandlestickAnimation::stopAll() |
74 | { |
75 | foreach (Candlestick *candlestick, m_animations.keys()) { |
76 | CandlestickBodyWicksAnimation *animation = m_animations.value(key: candlestick, defaultValue: 0); |
77 | if (animation) |
78 | animation->stopAndDestroyLater(); |
79 | m_animations.remove(key: candlestick); |
80 | } |
81 | } |
82 | |
83 | void CandlestickAnimation::removeCandlestickAnimation(Candlestick *candlestick) |
84 | { |
85 | m_animations.remove(key: candlestick); |
86 | } |
87 | |
88 | QT_END_NAMESPACE |
89 | |
90 | #include "moc_candlestickanimation_p.cpp" |
91 | |