##// END OF EJS Templates
Fixed: when animation enabled charts crash when setting the range which has no ticks (logvalueaxis, categoryaxis)
Marek Rosa -
r2385:bce67224e7a2
parent child
Show More
@@ -1,138 +1,140
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 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 "axisanimation_p.h"
21 #include "axisanimation_p.h"
22 #include "chartaxis_p.h"
22 #include "chartaxis_p.h"
23
23
24 Q_DECLARE_METATYPE(QVector<qreal>)
24 Q_DECLARE_METATYPE(QVector<qreal>)
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28
28
29 AxisAnimation::AxisAnimation(ChartAxis *axis)
29 AxisAnimation::AxisAnimation(ChartAxis *axis)
30 : ChartAnimation(axis),
30 : ChartAnimation(axis),
31 m_axis(axis),
31 m_axis(axis),
32 m_type(DefaultAnimation)
32 m_type(DefaultAnimation)
33 {
33 {
34 setDuration(ChartAnimationDuration);
34 setDuration(ChartAnimationDuration);
35 setEasingCurve(QEasingCurve::OutQuart);
35 setEasingCurve(QEasingCurve::OutQuart);
36 }
36 }
37
37
38 AxisAnimation::~AxisAnimation()
38 AxisAnimation::~AxisAnimation()
39 {
39 {
40 }
40 }
41
41
42 void AxisAnimation::setAnimationType(Animation type)
42 void AxisAnimation::setAnimationType(Animation type)
43 {
43 {
44 if (state() != QAbstractAnimation::Stopped)
44 if (state() != QAbstractAnimation::Stopped)
45 stop();
45 stop();
46 m_type = type;
46 m_type = type;
47 }
47 }
48
48
49 void AxisAnimation::setAnimationPoint(const QPointF &point)
49 void AxisAnimation::setAnimationPoint(const QPointF &point)
50 {
50 {
51 if (state() != QAbstractAnimation::Stopped)
51 if (state() != QAbstractAnimation::Stopped)
52 stop();
52 stop();
53 m_point = point;
53 m_point = point;
54 }
54 }
55
55
56 void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout)
56 void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout)
57 {
57 {
58 if (state() != QAbstractAnimation::Stopped) stop();
58 if (state() != QAbstractAnimation::Stopped) stop();
59
59
60 if (newLayout.count() == 0)
60 // TODO: cannot return even if layout is empty
61 return;
61 // New layout is not set properly without it (crash)
62 // if (newLayout.count() == 0)
63 // return;
62
64
63 switch (m_type) {
65 switch (m_type) {
64 case ZoomOutAnimation: {
66 case ZoomOutAnimation: {
65 QRectF rect = m_axis->gridGeometry();
67 QRectF rect = m_axis->gridGeometry();
66 oldLayout.resize(newLayout.count());
68 oldLayout.resize(newLayout.count());
67
69
68 for (int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) {
70 for (int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) {
69 oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.bottom();
71 oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.bottom();
70 oldLayout[j] = m_axis->orientation() == Qt::Horizontal ? rect.right() : rect.top();
72 oldLayout[j] = m_axis->orientation() == Qt::Horizontal ? rect.right() : rect.top();
71 }
73 }
72 }
74 }
73 break;
75 break;
74 case ZoomInAnimation: {
76 case ZoomInAnimation: {
75 int index = qMin(oldLayout.count() * (m_axis->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0);
77 int index = qMin(oldLayout.count() * (m_axis->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0);
76 oldLayout.resize(newLayout.count());
78 oldLayout.resize(newLayout.count());
77
79
78 for (int i = 0; i < oldLayout.count(); i++)
80 for (int i = 0; i < oldLayout.count(); i++)
79 oldLayout[i] = oldLayout[index];
81 oldLayout[i] = oldLayout[index];
80 }
82 }
81 break;
83 break;
82 case MoveForwardAnimation: {
84 case MoveForwardAnimation: {
83 oldLayout.resize(newLayout.count());
85 oldLayout.resize(newLayout.count());
84
86
85 for (int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j)
87 for (int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j)
86 oldLayout[i] = oldLayout[j];
88 oldLayout[i] = oldLayout[j];
87 }
89 }
88 break;
90 break;
89 case MoveBackwordAnimation: {
91 case MoveBackwordAnimation: {
90 oldLayout.resize(newLayout.count());
92 oldLayout.resize(newLayout.count());
91
93
92 for (int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j)
94 for (int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j)
93 oldLayout[i] = oldLayout[j];
95 oldLayout[i] = oldLayout[j];
94 }
96 }
95 break;
97 break;
96 default: {
98 default: {
97 oldLayout.resize(newLayout.count());
99 oldLayout.resize(newLayout.count());
98 QRectF rect = m_axis->gridGeometry();
100 QRectF rect = m_axis->gridGeometry();
99 for (int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j)
101 for (int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j)
100 oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.top();
102 oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.top();
101 }
103 }
102 break;
104 break;
103 }
105 }
104
106
105 QVariantAnimation::KeyValues value;
107 QVariantAnimation::KeyValues value;
106 setKeyValues(value); //workaround for wrong interpolation call
108 setKeyValues(value); //workaround for wrong interpolation call
107 setKeyValueAt(0.0, qVariantFromValue(oldLayout));
109 setKeyValueAt(0.0, qVariantFromValue(oldLayout));
108 setKeyValueAt(1.0, qVariantFromValue(newLayout));
110 setKeyValueAt(1.0, qVariantFromValue(newLayout));
109 }
111 }
110
112
111 QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
113 QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
112 {
114 {
113 QVector<qreal> startVector = qvariant_cast<QVector<qreal> >(start);
115 QVector<qreal> startVector = qvariant_cast<QVector<qreal> >(start);
114 QVector<qreal> endVecotr = qvariant_cast<QVector<qreal> >(end);
116 QVector<qreal> endVecotr = qvariant_cast<QVector<qreal> >(end);
115 QVector<qreal> result;
117 QVector<qreal> result;
116
118
117 Q_ASSERT(startVector.count() == endVecotr.count()) ;
119 Q_ASSERT(startVector.count() == endVecotr.count()) ;
118
120
119 for (int i = 0; i < startVector.count(); i++) {
121 for (int i = 0; i < startVector.count(); i++) {
120 qreal value = startVector[i] + ((endVecotr[i] - startVector[i]) * progress); //qBound(0.0, progress, 1.0));
122 qreal value = startVector[i] + ((endVecotr[i] - startVector[i]) * progress); //qBound(0.0, progress, 1.0));
121 result << value;
123 result << value;
122 }
124 }
123 return qVariantFromValue(result);
125 return qVariantFromValue(result);
124 }
126 }
125
127
126
128
127 void AxisAnimation::updateCurrentValue(const QVariant &value)
129 void AxisAnimation::updateCurrentValue(const QVariant &value)
128 {
130 {
129 if (state() != QAbstractAnimation::Stopped) { //workaround
131 if (state() != QAbstractAnimation::Stopped) { //workaround
130 QVector<qreal> vector = qvariant_cast<QVector<qreal> >(value);
132 QVector<qreal> vector = qvariant_cast<QVector<qreal> >(value);
131 Q_ASSERT(vector.count() != 0);
133 // Q_ASSERT(vector.count() != 0);
132 m_axis->setLayout(vector);
134 m_axis->setLayout(vector);
133 m_axis->updateGeometry();
135 m_axis->updateGeometry();
134 }
136 }
135
137
136 }
138 }
137
139
138 QTCOMMERCIALCHART_END_NAMESPACE
140 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now