@@ -37,7 +37,7 SplineAnimation::~SplineAnimation() | |||
|
37 | 37 | { |
|
38 | 38 | } |
|
39 | 39 | |
|
40 |
void SplineAnimation::set |
|
|
40 | void SplineAnimation::setup(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newControlPoints, int index) | |
|
41 | 41 | { |
|
42 | 42 | int x = oldPoints.count(); |
|
43 | 43 | int y = newPoints.count(); |
@@ -34,7 +34,7 class SplineAnimation : public XYAnimation | |||
|
34 | 34 | public: |
|
35 | 35 | SplineAnimation(SplineChartItem *item); |
|
36 | 36 | ~SplineAnimation(); |
|
37 |
void set |
|
|
37 | void setup(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldContorlPoints, QVector<QPointF> &newControlPoints, int index = -1); | |
|
38 | 38 | |
|
39 | 39 | protected: |
|
40 | 40 | QVariant interpolated(const QVariant &start, const QVariant &end, qreal progress) const; |
@@ -39,50 +39,53 XYAnimation::~XYAnimation() | |||
|
39 | 39 | { |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | void XYAnimation::setAnimationType(Animation type) | |
|
42 | void XYAnimation::setup(const QVector<QPointF> &oldPoints, const QVector<QPointF> &newPoints, int index) | |
|
43 | 43 | { |
|
44 | if (state() != QAbstractAnimation::Stopped) stop(); | |
|
45 | m_type=type; | |
|
46 | } | |
|
47 | ||
|
48 | void XYAnimation::setValues(const QVector<QPointF> &oldPoints, const QVector<QPointF> &newPoints, int index) | |
|
49 | { | |
|
50 | if (state() != QAbstractAnimation::Stopped) stop(); | |
|
44 | m_type = NewAnimation; | |
|
51 | 45 | |
|
52 | if (m_item->isDirty()) { | |
|
53 | m_oldPoints = oldPoints; | |
|
54 | m_newPoints = newPoints; | |
|
46 | if (state() != QAbstractAnimation::Stopped){ | |
|
47 | stop(); | |
|
55 | 48 |
|
|
56 | 49 | } |
|
57 | else { | |
|
58 |
|
|
|
59 | m_newPoints = newPoints; | |
|
50 | ||
|
51 | if(!m_dirty){ | |
|
52 | m_dirty = true; | |
|
60 | 53 |
|
|
61 | m_dirty=false; | |
|
62 | } | |
|
63 | 54 | } |
|
64 | 55 | |
|
56 | m_newPoints = newPoints; | |
|
57 | ||
|
65 | 58 |
|
|
66 | 59 |
|
|
67 | 60 | |
|
68 | if (abs(x - y) == 1) { | |
|
69 | if (y < x){ | |
|
70 | if(!newPoints.isEmpty()) m_newPoints.insert(index,newPoints[index]); | |
|
71 | m_index=index;if(newPoints.isEmpty()) | |
|
72 | m_dirty=true; | |
|
61 | if(x - y == 1 && index >= 0 && !newPoints.isEmpty()){ | |
|
62 | //remove point | |
|
63 | m_newPoints.insert(index, index >= 1 ? m_newPoints[index-1] : newPoints[index]); | |
|
64 | m_index=index; | |
|
65 | m_type = RemovePointAnimation; | |
|
73 | 66 | } |
|
74 | if (y > x){ | |
|
75 | m_oldPoints.insert(index, x > 0 ? m_oldPoints[index-1] : newPoints[index]);//add | |
|
67 | ||
|
68 | if(x - y == -1 && index >= 0){ | |
|
69 | //add point | |
|
70 | m_oldPoints.insert(index, x > 0 && index > 1 ? m_oldPoints[index-1] : newPoints[index]); | |
|
71 | m_index=index; | |
|
72 | m_type = AddPointAnimation; | |
|
76 | 73 | } |
|
77 | }else{ | |
|
78 | m_newPoints=newPoints; | |
|
79 | m_dirty=false; | |
|
80 | m_oldPoints.resize(m_newPoints.size()); | |
|
74 | ||
|
75 | x = m_oldPoints.count(); | |
|
76 | y = m_newPoints.count(); | |
|
77 | ||
|
78 | if(x != y) | |
|
79 | { | |
|
80 | m_type = NewAnimation; | |
|
81 | } | |
|
82 | else if(m_type == NewAnimation) | |
|
83 | { | |
|
84 | m_type = ReplacePointAnimation; | |
|
81 | 85 | } |
|
82 | 86 | |
|
83 | 87 | setKeyValueAt(0.0, qVariantFromValue(m_oldPoints)); |
|
84 | 88 | setKeyValueAt(1.0, qVariantFromValue(m_newPoints)); |
|
85 | ||
|
86 | 89 | } |
|
87 | 90 | |
|
88 | 91 | QVariant XYAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const |
@@ -97,8 +100,9 QVariant XYAnimation::interpolated(const QVariant &start, const QVariant &end, q | |||
|
97 | 100 | case AddPointAnimation: |
|
98 | 101 | case RemovePointAnimation: |
|
99 | 102 | { |
|
100 | if (startVector.count() != endVector.count()) | |
|
103 | if (startVector.count() != endVector.count()){ | |
|
101 | 104 | break; |
|
105 | } | |
|
102 | 106 | |
|
103 | 107 | for(int i = 0; i < startVector.count(); i++) { |
|
104 | 108 | qreal x = startVector[i].x() + ((endVector[i].x() - startVector[i].x()) * progress); |
@@ -124,10 +128,13 QVariant XYAnimation::interpolated(const QVariant &start, const QVariant &end, q | |||
|
124 | 128 | void XYAnimation::updateCurrentValue (const QVariant &value) |
|
125 | 129 | { |
|
126 | 130 | if(state()!=QAbstractAnimation::Stopped){ //workaround |
|
131 | ||
|
127 | 132 | QVector<QPointF> vector = qVariantValue<QVector<QPointF> >(value); |
|
128 | 133 | m_item->setGeometryPoints(vector); |
|
129 | 134 | m_item->updateGeometry(); |
|
130 | 135 | m_item->setDirty(true); |
|
136 | m_dirty=false; | |
|
137 | ||
|
131 | 138 | } |
|
132 | 139 | } |
|
133 | 140 |
@@ -34,8 +34,7 public: | |||
|
34 | 34 | enum Animation { AddPointAnimation, RemovePointAnimation, ReplacePointAnimation, NewAnimation }; |
|
35 | 35 | XYAnimation(XYChart *item); |
|
36 | 36 | ~XYAnimation(); |
|
37 |
void set |
|
|
38 | void setAnimationType(Animation type); | |
|
37 | void setup(const QVector<QPointF> &oldPoints, const QVector<QPointF> &newPoints,int index = -1); | |
|
39 | 38 | Animation animationType() const { return m_type; }; |
|
40 | 39 | |
|
41 | 40 | protected: |
@@ -86,7 +86,9 void SplineChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> | |||
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | if (m_animation) { |
|
89 |
m_animation->set |
|
|
89 | m_animation->setup(oldPoints,newPoints,m_controlPoints,controlPoints,index); | |
|
90 | setGeometryPoints(newPoints); | |
|
91 | setDirty(false); | |
|
90 | 92 | presenter()->startAnimation(m_animation); |
|
91 | 93 | } |
|
92 | 94 | else { |
@@ -107,7 +109,9 void SplineChartItem::updateGeometry() | |||
|
107 | 109 | const QVector<QPointF> &controlPoints = controlGeometryPoints(); |
|
108 | 110 | |
|
109 | 111 | if ((points.size()<2) || (controlPoints.size()<2)) { |
|
112 | prepareGeometryChange(); | |
|
110 | 113 | m_path = QPainterPath(); |
|
114 | m_rect = QRect(); | |
|
111 | 115 | return; |
|
112 | 116 | } |
|
113 | 117 |
@@ -117,8 +117,9 QPointF XYChart::calculateDomainPoint(const QPointF &point) const | |||
|
117 | 117 | |
|
118 | 118 | void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index) |
|
119 | 119 | { |
|
120 | ||
|
120 | 121 | if (m_animation) { |
|
121 |
m_animation->set |
|
|
122 | m_animation->setup(oldPoints, newPoints, index); | |
|
122 | 123 | setGeometryPoints(newPoints); |
|
123 | 124 | setDirty(false); |
|
124 | 125 | presenter()->startAnimation(m_animation); |
@@ -138,10 +139,6 void XYChart::handlePointAdded(int index) | |||
|
138 | 139 | |
|
139 | 140 | QVector<QPointF> points; |
|
140 | 141 | |
|
141 | if(m_animation) { | |
|
142 | m_animation->setAnimationType(XYAnimation::AddPointAnimation); | |
|
143 | } | |
|
144 | ||
|
145 | 142 | if(m_dirty) { |
|
146 | 143 | points = calculateGeometryPoints(); |
|
147 | 144 | } else { |
@@ -160,10 +157,6 void XYChart::handlePointRemoved(int index) | |||
|
160 | 157 | |
|
161 | 158 | QVector<QPointF> points; |
|
162 | 159 | |
|
163 | if(m_animation) { | |
|
164 | m_animation->setAnimationType(XYAnimation::RemovePointAnimation); | |
|
165 | } | |
|
166 | ||
|
167 | 160 | if(m_dirty) { |
|
168 | 161 | points = calculateGeometryPoints(); |
|
169 | 162 | } else { |
@@ -181,10 +174,6 void XYChart::handlePointReplaced(int index) | |||
|
181 | 174 | |
|
182 | 175 | QVector<QPointF> points; |
|
183 | 176 | |
|
184 | if(m_animation) { | |
|
185 | m_animation->setAnimationType(XYAnimation::ReplacePointAnimation); | |
|
186 | } | |
|
187 | ||
|
188 | 177 | if(m_dirty) { |
|
189 | 178 | points = calculateGeometryPoints(); |
|
190 | 179 | } else { |
@@ -206,10 +195,6 void XYChart::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY | |||
|
206 | 195 | |
|
207 | 196 | QVector<QPointF> points = calculateGeometryPoints(); |
|
208 | 197 | |
|
209 | if(m_animation) { | |
|
210 | m_animation->setAnimationType(XYAnimation::ReplacePointAnimation); | |
|
211 | } | |
|
212 | ||
|
213 | 198 | updateChart(m_points,points); |
|
214 | 199 | } |
|
215 | 200 | |
@@ -224,10 +209,6 void XYChart::handleGeometryChanged(const QRectF &rect) | |||
|
224 | 209 | |
|
225 | 210 | QVector<QPointF> points = calculateGeometryPoints(); |
|
226 | 211 | |
|
227 | if(m_animation) { | |
|
228 | m_animation->setAnimationType(XYAnimation::NewAnimation); | |
|
229 | } | |
|
230 | ||
|
231 | 212 | updateChart(m_points,points); |
|
232 | 213 | } |
|
233 | 214 |
@@ -65,7 +65,7 Q_SIGNALS: | |||
|
65 | 65 | void clicked(const QPointF& point); |
|
66 | 66 | |
|
67 | 67 | protected: |
|
68 |
virtual void updateChart(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = |
|
|
68 | virtual void updateChart(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = -1); | |
|
69 | 69 | QPointF calculateGeometryPoint(const QPointF &point) const; |
|
70 | 70 | QPointF calculateGeometryPoint(int index) const; |
|
71 | 71 | QPointF calculateDomainPoint(const QPointF &point) const; |
General Comments 0
You need to be logged in to leave comments.
Login now