| 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/candlestick_p.h> |
| 31 | #include <private/candlestickanimation_p.h> |
| 32 | #include <private/candlestickbodywicksanimation_p.h> |
| 33 | #include <private/candlestickchartitem_p.h> |
| 34 | #include <private/candlestickdata_p.h> |
| 35 | |
| 36 | QT_CHARTS_BEGIN_NAMESPACE |
| 37 | |
| 38 | CandlestickAnimation::CandlestickAnimation(CandlestickChartItem *item, int duration, |
| 39 | QEasingCurve &curve) |
| 40 | : QObject(item), |
| 41 | m_item(item), |
| 42 | m_animationDuration(duration), |
| 43 | m_animationCurve(curve) |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | CandlestickAnimation::~CandlestickAnimation() |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | void CandlestickAnimation::addCandlestick(Candlestick *candlestick) |
| 52 | { |
| 53 | CandlestickBodyWicksAnimation *animation = m_animations.value(akey: candlestick, adefaultValue: 0); |
| 54 | if (!animation) { |
| 55 | animation = new CandlestickBodyWicksAnimation(candlestick, this, m_animationDuration, |
| 56 | m_animationCurve); |
| 57 | m_animations.insert(akey: candlestick, avalue: animation); |
| 58 | |
| 59 | qreal median = (candlestick->m_data.m_open + candlestick->m_data.m_close) / 2; |
| 60 | CandlestickData start; |
| 61 | start.m_open = median; |
| 62 | start.m_high = median; |
| 63 | start.m_low = median; |
| 64 | start.m_close = median; |
| 65 | animation->setup(startData: start, endData: candlestick->m_data); |
| 66 | } else { |
| 67 | animation->stop(); |
| 68 | animation->setEndData(candlestick->m_data); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | ChartAnimation *CandlestickAnimation::candlestickAnimation(Candlestick *candlestick) |
| 73 | { |
| 74 | CandlestickBodyWicksAnimation *animation = m_animations.value(akey: candlestick, adefaultValue: 0); |
| 75 | if (animation) |
| 76 | animation->m_changeAnimation = false; |
| 77 | |
| 78 | return animation; |
| 79 | } |
| 80 | |
| 81 | ChartAnimation *CandlestickAnimation::candlestickChangeAnimation(Candlestick *candlestick) |
| 82 | { |
| 83 | CandlestickBodyWicksAnimation *animation = m_animations.value(akey: candlestick, adefaultValue: 0); |
| 84 | if (animation) { |
| 85 | animation->m_changeAnimation = true; |
| 86 | animation->setEndData(candlestick->m_data); |
| 87 | } |
| 88 | |
| 89 | return animation; |
| 90 | } |
| 91 | |
| 92 | void CandlestickAnimation::setAnimationStart(Candlestick *candlestick) |
| 93 | { |
| 94 | CandlestickBodyWicksAnimation *animation = m_animations.value(akey: candlestick, adefaultValue: 0); |
| 95 | if (animation) |
| 96 | animation->setStartData(candlestick->m_data); |
| 97 | } |
| 98 | |
| 99 | void CandlestickAnimation::stopAll() |
| 100 | { |
| 101 | foreach (Candlestick *candlestick, m_animations.keys()) { |
| 102 | CandlestickBodyWicksAnimation *animation = m_animations.value(akey: candlestick, adefaultValue: 0); |
| 103 | if (animation) |
| 104 | animation->stopAndDestroyLater(); |
| 105 | m_animations.remove(akey: candlestick); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | void CandlestickAnimation::removeCandlestickAnimation(Candlestick *candlestick) |
| 110 | { |
| 111 | m_animations.remove(akey: candlestick); |
| 112 | } |
| 113 | |
| 114 | QT_CHARTS_END_NAMESPACE |
| 115 | |
| 116 | #include "moc_candlestickanimation_p.cpp" |
| 117 | |