##// END OF EJS Templates
Further animation fixes...
Miikka Heikkinen -
r2492:5a6d23b6b72f
parent child
Show More
@@ -0,0 +1,50
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "scatteranimation_p.h"
22 #include "scatterchartitem_p.h"
23 #include <QDebug>
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
27 ScatterAnimation::ScatterAnimation(ScatterChartItem *item)
28 : XYAnimation(item)
29 {
30 }
31
32 ScatterAnimation::~ScatterAnimation()
33 {
34 }
35
36 void ScatterAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
37 {
38 XYAnimation::updateState(newState, oldState);
39
40 if (oldState == QAbstractAnimation::Running && newState == QAbstractAnimation::Stopped
41 && animationType() == RemovePointAnimation) {
42 // Removing a point from scatter chart will keep extra marker item after animation stops.
43 // Also, if the removed point was not the last one in series, points after the removed one
44 // will report wrong coordinates when clicked. To fix these issues, update geometry after
45 // point removal animation has finished.
46 chartItem()->updateGeometry();
47 }
48 }
49
50 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,50
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef SCATTERANIMATION_P_H
31 #define SCATTERANIMATION_P_H
32 #include "xyanimation_p.h"
33
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
36 class ScatterChartItem;
37
38 class ScatterAnimation : public XYAnimation
39 {
40 public:
41 ScatterAnimation(ScatterChartItem *item);
42 ~ScatterAnimation();
43
44 protected:
45 void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
46 };
47
48 QTCOMMERCIALCHART_END_NAMESPACE
49
50 #endif
@@ -7,7 +7,8 SOURCES += \
7 7 $$PWD/pieanimation.cpp \
8 8 $$PWD/piesliceanimation.cpp \
9 9 $$PWD/splineanimation.cpp \
10 $$PWD/baranimation.cpp
10 $$PWD/baranimation.cpp \
11 $$PWD/scatteranimation.cpp
11 12
12 13 PRIVATE_HEADERS += \
13 14 $$PWD/axisanimation_p.h \
@@ -16,4 +17,5 PRIVATE_HEADERS += \
16 17 $$PWD/pieanimation_p.h \
17 18 $$PWD/piesliceanimation_p.h \
18 19 $$PWD/splineanimation_p.h \
19 $$PWD/baranimation_p.h
20 $$PWD/baranimation_p.h \
21 $$PWD/scatteranimation_p.h
@@ -77,9 +77,9 void SplineAnimation::setup(QVector<QPointF> &oldPoints, QVector<QPointF> &newPo
77 77 m_newSpline.second.insert((index - 1) * 2, newPoints[index - 1]);
78 78 m_newSpline.second.insert((index - 1) * 2 + 1, newPoints[index - 1]);
79 79 } else {
80 m_newSpline.first.insert(index, newPoints[index]);
81 m_newSpline.second.insert(index * 2, newPoints[index]);
82 m_newSpline.second.insert(index * 2 + 1, newPoints[index]);
80 m_newSpline.first.insert(0, newPoints[index]);
81 m_newSpline.second.insert(0, newPoints[index]);
82 m_newSpline.second.insert(1, newPoints[index]);
83 83 }
84 84 m_index = index;
85 85 m_type = RemovePointAnimation;
@@ -92,9 +92,9 void SplineAnimation::setup(QVector<QPointF> &oldPoints, QVector<QPointF> &newPo
92 92 m_oldSpline.second.insert((index - 1) * 2, newPoints[index - 1]);
93 93 m_oldSpline.second.insert((index - 1) * 2 + 1, newPoints[index - 1]);
94 94 } else {
95 m_oldSpline.first.insert(index, newPoints[index]);
96 m_oldSpline.second.insert((index - 1) * 2, newPoints[index]);
97 m_oldSpline.second.insert((index - 1) * 2 + 1, newPoints[index]);
95 m_oldSpline.first.insert(0, newPoints[index]);
96 m_oldSpline.second.insert(0, newPoints[index]);
97 m_oldSpline.second.insert(1, newPoints[index]);
98 98 }
99 99 m_index = index;
100 100 m_type = AddPointAnimation;
@@ -186,9 +186,15 void SplineAnimation::updateState(QAbstractAnimation::State newState, QAbstractA
186 186 if (oldState == QAbstractAnimation::Running && newState == QAbstractAnimation::Stopped) {
187 187 if (m_item->isDirty() && m_type == RemovePointAnimation) {
188 188 if (!m_newSpline.first.isEmpty()) {
189 if (m_index) {
189 190 m_newSpline.first.remove(m_index);
190 191 m_newSpline.second.remove((m_index - 1) * 2);
191 192 m_newSpline.second.remove((m_index - 1) * 2);
193 } else {
194 m_newSpline.first.remove(0);
195 m_newSpline.second.remove(0);
196 m_newSpline.second.remove(0);
197 }
192 198 }
193 199 m_item->setGeometryPoints(m_newSpline.first);
194 200 m_item->setControlGeometryPoints(m_newSpline.second);
@@ -51,6 +51,7 protected:
51 51 QVariant interpolated(const QVariant &start, const QVariant &end, qreal progress) const;
52 52 void updateCurrentValue(const QVariant &value);
53 53 void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
54 XYChart *chartItem() { return m_item; }
54 55 protected:
55 56 Animation m_type;
56 57 bool m_dirty;
@@ -23,6 +23,7
23 23 #include "scatterchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 #include "scatteranimation_p.h"
26 27
27 28 /*!
28 29 \class QScatterSeries
@@ -282,6 +283,19 void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool f
282 283 }
283 284 }
284 285
286 void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
287 {
288 ScatterChartItem *item = static_cast<ScatterChartItem *>(m_item.data());
289 Q_ASSERT(item);
290
291 if (options.testFlag(QChart::SeriesAnimations))
292 item->setAnimation(new ScatterAnimation(item));
293 else
294 item->setAnimation(0);
295
296 QAbstractSeriesPrivate::initializeAnimations(options);
297 }
298
285 299 #include "moc_qscatterseries.cpp"
286 300
287 301 QTCOMMERCIALCHART_END_NAMESPACE
@@ -40,6 +40,7 public:
40 40 QScatterSeriesPrivate(QScatterSeries *q);
41 41 void initializeGraphics(QGraphicsItem* parent);
42 42 void initializeTheme(int index, ChartTheme* theme, bool forced = false);
43 void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options);
43 44
44 45 private:
45 46 QScatterSeries::MarkerShape m_shape;
@@ -133,13 +133,13 void ScatterChartItem::updateGeometry()
133 133 QGraphicsItem *item = items.at(i);
134 134 const QPointF &point = points.at(i);
135 135 const QRectF &rect = item->boundingRect();
136 // During remove/append animation series may have different number of points,
136 // During remove animation series may have different number of points,
137 137 // so ensure we don't go over the index. Animation handling itself ensures that
138 138 // if there is actually no points in the series, then it won't generate a fake point,
139 139 // so we can be assured there is always at least one point in m_series here.
140 140 // Note that marker map values can be technically incorrect during the animation,
141 141 // if it was caused by an insert, but this shouldn't be a problem as the points are
142 // fake anyway.
142 // fake anyway. After remove animation stops, geometry is updated to correct one.
143 143 m_markerMap[item] = m_series->at(qMin(seriesLastIndex, i));
144 144 item->setPos(point.x() - rect.width() / 2, point.y() - rect.height() / 2);
145 145
@@ -73,7 +73,7 QVector<bool> XYChart::offGridStatusVector()
73 73
74 74 QVector<bool> returnVector;
75 75 returnVector.resize(m_points.size());
76 // During remove/append animation series may have different number of points,
76 // During remove animation series may have different number of points,
77 77 // so ensure we don't go over the index. No need to check for zero points, this
78 78 // will not be called in such a situation.
79 79 const int seriesLastIndex = m_series->count() - 1;
General Comments 0
You need to be logged in to leave comments. Login now