##// END OF EJS Templates
Bugfix missing parent intialization in axis animations
Michal Klocek -
r303:281730f0b1cb
parent child
Show More
@@ -1,70 +1,71
1 1 #include "axisanimationitem_p.h"
2 2 #include <QPropertyAnimation>
3 3
4 4 Q_DECLARE_METATYPE(QVector<qreal>)
5 5
6 6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 7
8 8 const static int duration = 500;
9 9
10 10 AxisAnimationItem::AxisAnimationItem(AxisType type,QGraphicsItem* parent) :
11 11 AxisItem(type,parent)
12 12 {
13 13 }
14 14
15 15 AxisAnimationItem::~AxisAnimationItem()
16 16 {
17 17 }
18 18
19 19 void AxisAnimationItem::updateItems(QVector<qreal>& vector1)
20 20 {
21 21 QVector<qreal> vector0 = vector1;
22 22 calculateLayout(vector1);
23 23 if(vector1.count()==0) return;
24 24 vector0.resize(vector1.size());
25 25
26 AxisAnimator *animation = new AxisAnimator(this);
26 AxisAnimator *animation = new AxisAnimator(this,this);
27 27 animation->setDuration(duration);
28 28 animation->setEasingCurve(QEasingCurve::InOutBack);
29 29 animation->setKeyValueAt(0.0, qVariantFromValue(vector0));
30 30 animation->setKeyValueAt(1.0, qVariantFromValue(vector1));
31 31 animation->start(QAbstractAnimation::DeleteWhenStopped);
32 32 }
33 33
34 34 void AxisAnimationItem::setLabelsAngle(int angle)
35 35 {
36 36 AxisItem::setLabelsAngle(angle);
37 37 }
38 38
39 AxisAnimator::AxisAnimator(AxisItem *axis): m_axis(axis)
39 AxisAnimator::AxisAnimator(AxisItem *axis,QObject *parent): QVariantAnimation(parent),
40 m_axis(axis)
40 41 {
41 42 }
42 43
43 44 AxisAnimator::~AxisAnimator()
44 45 {
45 46 }
46 47
47 48 QVariant AxisAnimator::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const
48 49 {
49 50 QVector<qreal> startVector = qVariantValue<QVector<qreal> >(start);
50 51 QVector<qreal> endVecotr = qVariantValue<QVector<qreal> >(end);
51 52 QVector<qreal> result;
52 53 Q_ASSERT(startVector.count() == endVecotr.count());
53 54
54 55 for(int i =0 ;i< startVector.count();i++){
55 56 qreal value = startVector[i] + ((endVecotr[i]- startVector[i]) * progress);//qBound(0.0, progress, 1.0));
56 57 result << value;
57 58 }
58 59 return qVariantFromValue(result);
59 60 }
60 61
61 62
62 63 void AxisAnimator::updateCurrentValue (const QVariant & value )
63 64 {
64 65 QVector<qreal> vector = qVariantValue<QVector<qreal> >(value);
65 66 m_axis->applyLayout(vector);
66 67 }
67 68
68 69 #include "moc_axisanimationitem_p.cpp"
69 70
70 71 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,44 +1,44
1 1 #ifndef AXISANIMATIONITEM_H_
2 2 #define AXISANIMATIONITEM_H_
3 3
4 4 #include "domain_p.h"
5 5 #include "axisitem_p.h"
6 6 #include <QGraphicsItem>
7 7 #include <QVariantAnimation>
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 class QChartAxis;
12 12
13 13 class AxisAnimationItem : public AxisItem
14 14 {
15 15 Q_OBJECT
16 16
17 17 public:
18 18 AxisAnimationItem(AxisType type = X_AXIS,QGraphicsItem* parent = 0);
19 19 ~AxisAnimationItem();
20 20
21 21 void setLabelsAngle(int angle);
22 22
23 23 protected:
24 24 void updateItems(QVector<qreal>& vector);
25 25
26 26 };
27 27
28 28 class AxisAnimator: public QVariantAnimation
29 29 {
30 30 public:
31 AxisAnimator(AxisItem *axis);
31 AxisAnimator(AxisItem *axis,QObject *parent = 0);
32 32 virtual ~AxisAnimator();
33 33 protected:
34 34 virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress ) const;
35 35 virtual void updateCurrentValue (const QVariant & value );
36 36 private:
37 37 AxisItem* m_axis;
38 38 };
39 39
40 40 QTCOMMERCIALCHART_END_NAMESPACE
41 41
42 42
43 43
44 44 #endif /* AXISITEM_H_ */
General Comments 0
You need to be logged in to leave comments. Login now