| 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/boxwhiskersanimation_p.h> |
| 31 | #include <private/boxplotanimation_p.h> |
| 32 | #include <private/boxplotchartitem_p.h> |
| 33 | #include <private/boxwhiskersdata_p.h> |
| 34 | |
| 35 | Q_DECLARE_METATYPE(QVector<QRectF>) |
| 36 | Q_DECLARE_METATYPE(QT_CHARTS_NAMESPACE::BoxWhiskersData) |
| 37 | Q_DECLARE_METATYPE(qreal) |
| 38 | |
| 39 | QT_CHARTS_BEGIN_NAMESPACE |
| 40 | |
| 41 | BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box, BoxPlotAnimation *boxPlotAnimation, |
| 42 | int duration, QEasingCurve &curve) |
| 43 | : ChartAnimation(box), |
| 44 | m_box(box), |
| 45 | m_changeAnimation(false), |
| 46 | m_boxPlotAnimation(boxPlotAnimation) |
| 47 | { |
| 48 | setDuration(duration); |
| 49 | setEasingCurve(curve); |
| 50 | } |
| 51 | |
| 52 | BoxWhiskersAnimation::~BoxWhiskersAnimation() |
| 53 | { |
| 54 | if (m_boxPlotAnimation) |
| 55 | m_boxPlotAnimation->removeBoxAnimation(box: m_box); |
| 56 | } |
| 57 | |
| 58 | QVariant BoxWhiskersAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
| 59 | { |
| 60 | BoxWhiskersData startData = qvariant_cast<BoxWhiskersData>(v: from); |
| 61 | BoxWhiskersData endData = qvariant_cast<BoxWhiskersData>(v: to); |
| 62 | BoxWhiskersData result; |
| 63 | |
| 64 | if (m_changeAnimation) { |
| 65 | result.m_lowerExtreme = startData.m_lowerExtreme + progress * (endData.m_lowerExtreme - startData.m_lowerExtreme); |
| 66 | result.m_lowerQuartile = startData.m_lowerQuartile + progress * (endData.m_lowerQuartile - startData.m_lowerQuartile); |
| 67 | result.m_median = startData.m_median + progress * (endData.m_median - startData.m_median); |
| 68 | result.m_upperQuartile = startData.m_upperQuartile + progress * (endData.m_upperQuartile - startData.m_upperQuartile); |
| 69 | result.m_upperExtreme = startData.m_upperExtreme + progress * (endData.m_upperExtreme - startData.m_upperExtreme); |
| 70 | } else { |
| 71 | result.m_lowerExtreme = endData.m_median + progress * (endData.m_lowerExtreme - endData.m_median); |
| 72 | result.m_lowerQuartile = endData.m_median + progress * (endData.m_lowerQuartile - endData.m_median); |
| 73 | result.m_median = endData.m_median; |
| 74 | result.m_upperQuartile = endData.m_median + progress * (endData.m_upperQuartile - endData.m_median); |
| 75 | result.m_upperExtreme = endData.m_median + progress * (endData.m_upperExtreme - endData.m_median); |
| 76 | } |
| 77 | result.m_index = endData.m_index; |
| 78 | result.m_boxItems = endData.m_boxItems; |
| 79 | |
| 80 | result.m_maxX = endData.m_maxX; |
| 81 | result.m_minX = endData.m_minX; |
| 82 | result.m_maxY = endData.m_maxY; |
| 83 | result.m_minY = endData.m_minY; |
| 84 | result.m_seriesIndex = endData.m_seriesIndex; |
| 85 | result.m_seriesCount = endData.m_seriesCount; |
| 86 | |
| 87 | return QVariant::fromValue(value: result); |
| 88 | } |
| 89 | |
| 90 | void BoxWhiskersAnimation::updateCurrentValue(const QVariant &value) |
| 91 | { |
| 92 | BoxWhiskersData data = qvariant_cast<BoxWhiskersData>(v: value); |
| 93 | m_box->setLayout(data); |
| 94 | } |
| 95 | |
| 96 | void BoxWhiskersAnimation::setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData) |
| 97 | { |
| 98 | setKeyValueAt(step: 0.0, value: QVariant::fromValue(value: startData)); |
| 99 | setKeyValueAt(step: 1.0, value: QVariant::fromValue(value: endData)); |
| 100 | } |
| 101 | |
| 102 | void BoxWhiskersAnimation::setEndData(const BoxWhiskersData &endData) |
| 103 | { |
| 104 | if (state() != QAbstractAnimation::Stopped) |
| 105 | stop(); |
| 106 | |
| 107 | setEndValue(QVariant::fromValue(value: endData)); |
| 108 | } |
| 109 | |
| 110 | void BoxWhiskersAnimation::setStartData(const BoxWhiskersData &endData) |
| 111 | { |
| 112 | if (state() != QAbstractAnimation::Stopped) |
| 113 | stop(); |
| 114 | |
| 115 | setStartValue(QVariant::fromValue(value: endData)); |
| 116 | } |
| 117 | |
| 118 | QT_CHARTS_END_NAMESPACE |
| 119 | |
| 120 | #include "moc_boxwhiskersanimation_p.cpp" |
| 121 | |