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