##// END OF EJS Templates
Fix animation artifact with boxplots....
Miikka Heikkinen -
r2564:b874ab753024
parent child
Show More
@@ -1,93 +1,97
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "boxplotanimation_p.h"
21 #include "boxplotanimation_p.h"
22 #include "boxplotchartitem_p.h"
22 #include "boxplotchartitem_p.h"
23 #include "boxwhiskersdata_p.h"
23 #include "boxwhiskersdata_p.h"
24 #include "boxwhiskersanimation_p.h"
24 #include "boxwhiskersanimation_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 BoxPlotAnimation::BoxPlotAnimation(BoxPlotChartItem *item)
28 BoxPlotAnimation::BoxPlotAnimation(BoxPlotChartItem *item)
29 : QObject(item),
29 : QObject(item),
30 m_item(item)
30 m_item(item)
31 {
31 {
32 }
32 }
33
33
34 BoxPlotAnimation::~BoxPlotAnimation()
34 BoxPlotAnimation::~BoxPlotAnimation()
35 {
35 {
36 }
36 }
37
37
38 void BoxPlotAnimation::addBox(BoxWhiskers *box)
38 void BoxPlotAnimation::addBox(BoxWhiskers *box)
39 {
39 {
40 BoxWhiskersAnimation *animation = m_animations.value(box);
40 BoxWhiskersAnimation *animation = m_animations.value(box);
41 if (!animation) {
41 if (!animation) {
42 animation = new BoxWhiskersAnimation(box, this);
42 animation = new BoxWhiskersAnimation(box, this);
43 m_animations.insert(box, animation);
43 m_animations.insert(box, animation);
44 BoxWhiskersData start;
44 BoxWhiskersData start;
45 start.m_lowerExtreme = box->m_data.m_median;
46 start.m_lowerQuartile = box->m_data.m_median;
45 start.m_median = box->m_data.m_median;
47 start.m_median = box->m_data.m_median;
48 start.m_upperQuartile = box->m_data.m_median;
49 start.m_upperExtreme = box->m_data.m_median;
46 animation->setup(start, box->m_data);
50 animation->setup(start, box->m_data);
47 } else {
51 } else {
48 animation->stop();
52 animation->stop();
49 animation->setEndData(box->m_data);
53 animation->setEndData(box->m_data);
50 }
54 }
51 }
55 }
52
56
53 ChartAnimation *BoxPlotAnimation::boxAnimation(BoxWhiskers *box)
57 ChartAnimation *BoxPlotAnimation::boxAnimation(BoxWhiskers *box)
54 {
58 {
55 BoxWhiskersAnimation *animation = m_animations.value(box);
59 BoxWhiskersAnimation *animation = m_animations.value(box);
56 if (animation)
60 if (animation)
57 animation->m_moveMedianLine = false;
61 animation->m_changeAnimation = false;
58
62
59 return animation;
63 return animation;
60 }
64 }
61
65
62 ChartAnimation *BoxPlotAnimation::boxChangeAnimation(BoxWhiskers *box)
66 ChartAnimation *BoxPlotAnimation::boxChangeAnimation(BoxWhiskers *box)
63 {
67 {
64 BoxWhiskersAnimation *animation = m_animations.value(box);
68 BoxWhiskersAnimation *animation = m_animations.value(box);
65 animation->m_moveMedianLine = true;
69 animation->m_changeAnimation = true;
66 animation->setEndData(box->m_data);
70 animation->setEndData(box->m_data);
67
71
68 return animation;
72 return animation;
69 }
73 }
70
74
71 void BoxPlotAnimation::setAnimationStart(BoxWhiskers *box)
75 void BoxPlotAnimation::setAnimationStart(BoxWhiskers *box)
72 {
76 {
73 BoxWhiskersAnimation *animation = m_animations.value(box);
77 BoxWhiskersAnimation *animation = m_animations.value(box);
74 animation->setStartData(box->m_data);
78 animation->setStartData(box->m_data);
75 }
79 }
76
80
77 void BoxPlotAnimation::stopAll()
81 void BoxPlotAnimation::stopAll()
78 {
82 {
79 foreach (BoxWhiskers *box, m_animations.keys()) {
83 foreach (BoxWhiskers *box, m_animations.keys()) {
80 BoxWhiskersAnimation *animation = m_animations.value(box);
84 BoxWhiskersAnimation *animation = m_animations.value(box);
81 animation->stopAndDestroyLater();
85 animation->stopAndDestroyLater();
82 m_animations.remove(box);
86 m_animations.remove(box);
83 }
87 }
84 }
88 }
85
89
86 void BoxPlotAnimation::removeBoxAnimation(BoxWhiskers *box)
90 void BoxPlotAnimation::removeBoxAnimation(BoxWhiskers *box)
87 {
91 {
88 m_animations.remove(box);
92 m_animations.remove(box);
89 }
93 }
90
94
91 #include "moc_boxplotanimation_p.cpp"
95 #include "moc_boxplotanimation_p.cpp"
92
96
93 QTCOMMERCIALCHART_END_NAMESPACE
97 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,110 +1,110
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "boxwhiskersanimation_p.h"
21 #include "boxwhiskersanimation_p.h"
22 #include "boxplotanimation_p.h"
22 #include "boxplotanimation_p.h"
23 #include "boxplotchartitem_p.h"
23 #include "boxplotchartitem_p.h"
24 #include "boxwhiskersdata_p.h"
24 #include "boxwhiskersdata_p.h"
25
25
26 Q_DECLARE_METATYPE(QVector<QRectF>)
26 Q_DECLARE_METATYPE(QVector<QRectF>)
27 Q_DECLARE_METATYPE(QTCOMMERCIALCHART_NAMESPACE::BoxWhiskersData)
27 Q_DECLARE_METATYPE(QTCOMMERCIALCHART_NAMESPACE::BoxWhiskersData)
28 Q_DECLARE_METATYPE(qreal)
28 Q_DECLARE_METATYPE(qreal)
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box, BoxPlotAnimation *boxPlotAnimation)
32 BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box, BoxPlotAnimation *boxPlotAnimation)
33 : ChartAnimation(box),
33 : ChartAnimation(box),
34 m_box(box),
34 m_box(box),
35 m_boxPlotAnimation(boxPlotAnimation)
35 m_boxPlotAnimation(boxPlotAnimation)
36 {
36 {
37 setDuration(ChartAnimationDuration);
37 setDuration(ChartAnimationDuration);
38 setEasingCurve(QEasingCurve::OutQuart);
38 setEasingCurve(QEasingCurve::OutQuart);
39 }
39 }
40
40
41 BoxWhiskersAnimation::~BoxWhiskersAnimation()
41 BoxWhiskersAnimation::~BoxWhiskersAnimation()
42 {
42 {
43 if (m_boxPlotAnimation)
43 if (m_boxPlotAnimation)
44 m_boxPlotAnimation->removeBoxAnimation(m_box);
44 m_boxPlotAnimation->removeBoxAnimation(m_box);
45 }
45 }
46
46
47 QVariant BoxWhiskersAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
47 QVariant BoxWhiskersAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
48 {
48 {
49 BoxWhiskersData startData = qvariant_cast<BoxWhiskersData>(from);
49 BoxWhiskersData startData = qvariant_cast<BoxWhiskersData>(from);
50 BoxWhiskersData endData = qvariant_cast<BoxWhiskersData>(to);
50 BoxWhiskersData endData = qvariant_cast<BoxWhiskersData>(to);
51 BoxWhiskersData result;
51 BoxWhiskersData result;
52
52
53 if (m_moveMedianLine) {
53 if (m_changeAnimation) {
54 result.m_lowerExtreme = startData.m_lowerExtreme + progress * (endData.m_lowerExtreme - startData.m_lowerExtreme);
54 result.m_lowerExtreme = startData.m_lowerExtreme + progress * (endData.m_lowerExtreme - startData.m_lowerExtreme);
55 result.m_lowerQuartile = startData.m_lowerQuartile + progress * (endData.m_lowerQuartile - startData.m_lowerQuartile);
55 result.m_lowerQuartile = startData.m_lowerQuartile + progress * (endData.m_lowerQuartile - startData.m_lowerQuartile);
56 result.m_median = startData.m_median + progress * (endData.m_median - startData.m_median);
56 result.m_median = startData.m_median + progress * (endData.m_median - startData.m_median);
57 result.m_upperQuartile = startData.m_upperQuartile + progress * (endData.m_upperQuartile - startData.m_upperQuartile);
57 result.m_upperQuartile = startData.m_upperQuartile + progress * (endData.m_upperQuartile - startData.m_upperQuartile);
58 result.m_upperExtreme = startData.m_upperExtreme + progress * (endData.m_upperExtreme - startData.m_upperExtreme);
58 result.m_upperExtreme = startData.m_upperExtreme + progress * (endData.m_upperExtreme - startData.m_upperExtreme);
59 } else {
59 } else {
60 result.m_lowerExtreme = endData.m_median + progress * (endData.m_lowerExtreme - endData.m_median);
60 result.m_lowerExtreme = endData.m_median + progress * (endData.m_lowerExtreme - endData.m_median);
61 result.m_lowerQuartile = endData.m_median + progress * (endData.m_lowerQuartile - endData.m_median);
61 result.m_lowerQuartile = endData.m_median + progress * (endData.m_lowerQuartile - endData.m_median);
62 result.m_median = endData.m_median;
62 result.m_median = endData.m_median;
63 result.m_upperQuartile = endData.m_median + progress * (endData.m_upperQuartile - endData.m_median);
63 result.m_upperQuartile = endData.m_median + progress * (endData.m_upperQuartile - endData.m_median);
64 result.m_upperExtreme = endData.m_median + progress * (endData.m_upperExtreme - endData.m_median);
64 result.m_upperExtreme = endData.m_median + progress * (endData.m_upperExtreme - endData.m_median);
65 }
65 }
66 result.m_index = endData.m_index;
66 result.m_index = endData.m_index;
67 result.m_boxItems = endData.m_boxItems;
67 result.m_boxItems = endData.m_boxItems;
68
68
69 result.m_maxX = endData.m_maxX;
69 result.m_maxX = endData.m_maxX;
70 result.m_minX = endData.m_minX;
70 result.m_minX = endData.m_minX;
71 result.m_maxY = endData.m_maxY;
71 result.m_maxY = endData.m_maxY;
72 result.m_minY = endData.m_minY;
72 result.m_minY = endData.m_minY;
73 result.m_seriesIndex = endData.m_seriesIndex;
73 result.m_seriesIndex = endData.m_seriesIndex;
74 result.m_seriesCount = endData.m_seriesCount;
74 result.m_seriesCount = endData.m_seriesCount;
75
75
76 return qVariantFromValue(result);
76 return qVariantFromValue(result);
77 }
77 }
78
78
79 void BoxWhiskersAnimation::updateCurrentValue(const QVariant &value)
79 void BoxWhiskersAnimation::updateCurrentValue(const QVariant &value)
80 {
80 {
81 BoxWhiskersData data = qvariant_cast<BoxWhiskersData>(value);
81 BoxWhiskersData data = qvariant_cast<BoxWhiskersData>(value);
82 m_box->setLayout(data);
82 m_box->setLayout(data);
83 }
83 }
84
84
85 void BoxWhiskersAnimation::setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData)
85 void BoxWhiskersAnimation::setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData)
86 {
86 {
87 setKeyValueAt(0.0, qVariantFromValue(startData));
87 setKeyValueAt(0.0, qVariantFromValue(startData));
88 setKeyValueAt(1.0, qVariantFromValue(endData));
88 setKeyValueAt(1.0, qVariantFromValue(endData));
89 }
89 }
90
90
91 void BoxWhiskersAnimation::setEndData(const BoxWhiskersData &endData)
91 void BoxWhiskersAnimation::setEndData(const BoxWhiskersData &endData)
92 {
92 {
93 if (state() != QAbstractAnimation::Stopped)
93 if (state() != QAbstractAnimation::Stopped)
94 stop();
94 stop();
95
95
96 setEndValue(qVariantFromValue(endData));
96 setEndValue(qVariantFromValue(endData));
97 }
97 }
98
98
99 void BoxWhiskersAnimation::setStartData(const BoxWhiskersData &endData)
99 void BoxWhiskersAnimation::setStartData(const BoxWhiskersData &endData)
100 {
100 {
101 if (state() != QAbstractAnimation::Stopped)
101 if (state() != QAbstractAnimation::Stopped)
102 stop();
102 stop();
103
103
104 setStartValue(qVariantFromValue(endData));
104 setStartValue(qVariantFromValue(endData));
105 }
105 }
106
106
107 #include "moc_boxwhiskersanimation_p.cpp"
107 #include "moc_boxwhiskersanimation_p.cpp"
108
108
109 QTCOMMERCIALCHART_END_NAMESPACE
109 QTCOMMERCIALCHART_END_NAMESPACE
110
110
@@ -1,69 +1,69
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef BOXWHISKERSANIMATION_P_H
30 #ifndef BOXWHISKERSANIMATION_P_H
31 #define BOXWHISKERSANIMATION_P_H
31 #define BOXWHISKERSANIMATION_P_H
32
32
33 #include "chartanimation_p.h"
33 #include "chartanimation_p.h"
34 #include "boxwhiskers_p.h"
34 #include "boxwhiskers_p.h"
35 #include "boxwhiskersdata_p.h"
35 #include "boxwhiskersdata_p.h"
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 class BoxPlotChartItem;
39 class BoxPlotChartItem;
40 class BoxPlotAnimation;
40 class BoxPlotAnimation;
41
41
42 class BoxWhiskersAnimation : public ChartAnimation
42 class BoxWhiskersAnimation : public ChartAnimation
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45
45
46 public:
46 public:
47 BoxWhiskersAnimation(BoxWhiskers *box, BoxPlotAnimation *boxPlotAnimation);
47 BoxWhiskersAnimation(BoxWhiskers *box, BoxPlotAnimation *boxPlotAnimation);
48 ~BoxWhiskersAnimation();
48 ~BoxWhiskersAnimation();
49
49
50 public: // from QVariantAnimation
50 public: // from QVariantAnimation
51 virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const;
51 virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const;
52 virtual void updateCurrentValue(const QVariant &value);
52 virtual void updateCurrentValue(const QVariant &value);
53
53
54 void setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData);
54 void setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData);
55 void setEndData(const BoxWhiskersData &endData);
55 void setEndData(const BoxWhiskersData &endData);
56 void setStartData(const BoxWhiskersData &endData);
56 void setStartData(const BoxWhiskersData &endData);
57
57
58 void moveMedianLine(bool move);
58 void moveMedianLine(bool move);
59
59
60 protected:
60 protected:
61 friend class BoxPlotAnimation;
61 friend class BoxPlotAnimation;
62 BoxWhiskers *m_box;
62 BoxWhiskers *m_box;
63 bool m_moveMedianLine;
63 bool m_changeAnimation;
64 BoxPlotAnimation *m_boxPlotAnimation;
64 BoxPlotAnimation *m_boxPlotAnimation;
65 };
65 };
66
66
67 QTCOMMERCIALCHART_END_NAMESPACE
67 QTCOMMERCIALCHART_END_NAMESPACE
68
68
69 #endif // BOXWHISKERSANIMATION_P_H
69 #endif // BOXWHISKERSANIMATION_P_H
General Comments 0
You need to be logged in to leave comments. Login now