| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/util/qquickspringanimation.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||
| 5 | - | |||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||
| 7 | - | |||||||||||||||||||||||||
| 8 | - | |||||||||||||||||||||||||
| 9 | - | |||||||||||||||||||||||||
| 10 | class QQuickSpringAnimationPrivate; | - | ||||||||||||||||||||||||
| 11 | class __attribute__((visibility("default"))) QSpringAnimation : public QAbstractAnimationJob | - | ||||||||||||||||||||||||
| 12 | { | - | ||||||||||||||||||||||||
| 13 | QSpringAnimation(const QSpringAnimation &) = delete; QSpringAnimation &operator=(const QSpringAnimation &) = delete; | - | ||||||||||||||||||||||||
| 14 | public: | - | ||||||||||||||||||||||||
| 15 | QSpringAnimation(QQuickSpringAnimationPrivate * = nullptr); | - | ||||||||||||||||||||||||
| 16 | - | |||||||||||||||||||||||||
| 17 | ~QSpringAnimation(); | - | ||||||||||||||||||||||||
| 18 | int duration() const override; | - | ||||||||||||||||||||||||
| 19 | void restart(); | - | ||||||||||||||||||||||||
| 20 | void init(); | - | ||||||||||||||||||||||||
| 21 | - | |||||||||||||||||||||||||
| 22 | qreal currentValue; | - | ||||||||||||||||||||||||
| 23 | qreal to; | - | ||||||||||||||||||||||||
| 24 | qreal velocity; | - | ||||||||||||||||||||||||
| 25 | int startTime; | - | ||||||||||||||||||||||||
| 26 | int dura; | - | ||||||||||||||||||||||||
| 27 | int lastTime; | - | ||||||||||||||||||||||||
| 28 | int stopTime; | - | ||||||||||||||||||||||||
| 29 | enum Mode { | - | ||||||||||||||||||||||||
| 30 | Track, | - | ||||||||||||||||||||||||
| 31 | Velocity, | - | ||||||||||||||||||||||||
| 32 | Spring | - | ||||||||||||||||||||||||
| 33 | }; | - | ||||||||||||||||||||||||
| 34 | Mode mode; | - | ||||||||||||||||||||||||
| 35 | QQmlProperty target; | - | ||||||||||||||||||||||||
| 36 | - | |||||||||||||||||||||||||
| 37 | qreal velocityms; | - | ||||||||||||||||||||||||
| 38 | qreal maxVelocity; | - | ||||||||||||||||||||||||
| 39 | qreal mass; | - | ||||||||||||||||||||||||
| 40 | qreal spring; | - | ||||||||||||||||||||||||
| 41 | qreal damping; | - | ||||||||||||||||||||||||
| 42 | qreal epsilon; | - | ||||||||||||||||||||||||
| 43 | qreal modulus; | - | ||||||||||||||||||||||||
| 44 | - | |||||||||||||||||||||||||
| 45 | bool useMass : 1; | - | ||||||||||||||||||||||||
| 46 | bool haveModulus : 1; | - | ||||||||||||||||||||||||
| 47 | bool skipUpdate : 1; | - | ||||||||||||||||||||||||
| 48 | typedef QHash<QQmlProperty, QSpringAnimation*> ActiveAnimationHash; | - | ||||||||||||||||||||||||
| 49 | typedef ActiveAnimationHash::Iterator ActiveAnimationHashIt; | - | ||||||||||||||||||||||||
| 50 | - | |||||||||||||||||||||||||
| 51 | void clearTemplate() { animationTemplate = nullptr; } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 52 | - | |||||||||||||||||||||||||
| 53 | protected: | - | ||||||||||||||||||||||||
| 54 | void updateCurrentTime(int time) override; | - | ||||||||||||||||||||||||
| 55 | void updateState(QAbstractAnimationJob::State, QAbstractAnimationJob::State) override; | - | ||||||||||||||||||||||||
| 56 | void debugAnimation(QDebug d) const override; | - | ||||||||||||||||||||||||
| 57 | - | |||||||||||||||||||||||||
| 58 | private: | - | ||||||||||||||||||||||||
| 59 | QQuickSpringAnimationPrivate *animationTemplate; | - | ||||||||||||||||||||||||
| 60 | }; | - | ||||||||||||||||||||||||
| 61 | - | |||||||||||||||||||||||||
| 62 | class QQuickSpringAnimationPrivate : public QQuickPropertyAnimationPrivate | - | ||||||||||||||||||||||||
| 63 | { | - | ||||||||||||||||||||||||
| 64 | inline QQuickSpringAnimation* q_func() { return static_cast<QQuickSpringAnimation *>(q_ptr); } inline const QQuickSpringAnimation* q_func() const { return static_cast<const QQuickSpringAnimation *>(q_ptr); } friend class QQuickSpringAnimation; | - | ||||||||||||||||||||||||
| 65 | public: | - | ||||||||||||||||||||||||
| 66 | QQuickSpringAnimationPrivate() | - | ||||||||||||||||||||||||
| 67 | : QQuickPropertyAnimationPrivate() | - | ||||||||||||||||||||||||
| 68 | , velocityms(0) | - | ||||||||||||||||||||||||
| 69 | , maxVelocity(0) | - | ||||||||||||||||||||||||
| 70 | , mass(1.0) | - | ||||||||||||||||||||||||
| 71 | , spring(0.) | - | ||||||||||||||||||||||||
| 72 | , damping(0.) | - | ||||||||||||||||||||||||
| 73 | , epsilon(0.01) | - | ||||||||||||||||||||||||
| 74 | , modulus(0.0) | - | ||||||||||||||||||||||||
| 75 | , useMass(false) | - | ||||||||||||||||||||||||
| 76 | , haveModulus(false) | - | ||||||||||||||||||||||||
| 77 | , mode(QSpringAnimation::Track) | - | ||||||||||||||||||||||||
| 78 | { elapsed.start(); } executed 56 times by 4 tests: end of blockExecuted by:
| 56 | ||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||
| 80 | void updateMode(); | - | ||||||||||||||||||||||||
| 81 | qreal velocityms; | - | ||||||||||||||||||||||||
| 82 | qreal maxVelocity; | - | ||||||||||||||||||||||||
| 83 | qreal mass; | - | ||||||||||||||||||||||||
| 84 | qreal spring; | - | ||||||||||||||||||||||||
| 85 | qreal damping; | - | ||||||||||||||||||||||||
| 86 | qreal epsilon; | - | ||||||||||||||||||||||||
| 87 | qreal modulus; | - | ||||||||||||||||||||||||
| 88 | - | |||||||||||||||||||||||||
| 89 | bool useMass : 1; | - | ||||||||||||||||||||||||
| 90 | bool haveModulus : 1; | - | ||||||||||||||||||||||||
| 91 | QSpringAnimation::Mode mode; | - | ||||||||||||||||||||||||
| 92 | - | |||||||||||||||||||||||||
| 93 | QSpringAnimation::ActiveAnimationHash activeAnimations; | - | ||||||||||||||||||||||||
| 94 | QElapsedTimer elapsed; | - | ||||||||||||||||||||||||
| 95 | }; | - | ||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||
| 97 | QSpringAnimation::QSpringAnimation(QQuickSpringAnimationPrivate *priv) | - | ||||||||||||||||||||||||
| 98 | : QAbstractAnimationJob() | - | ||||||||||||||||||||||||
| 99 | , currentValue(0) | - | ||||||||||||||||||||||||
| 100 | , to(0) | - | ||||||||||||||||||||||||
| 101 | , velocity(0) | - | ||||||||||||||||||||||||
| 102 | , startTime(0) | - | ||||||||||||||||||||||||
| 103 | , dura(0) | - | ||||||||||||||||||||||||
| 104 | , lastTime(0) | - | ||||||||||||||||||||||||
| 105 | , stopTime(-1) | - | ||||||||||||||||||||||||
| 106 | , mode(Track) | - | ||||||||||||||||||||||||
| 107 | , velocityms(0) | - | ||||||||||||||||||||||||
| 108 | , maxVelocity(0) | - | ||||||||||||||||||||||||
| 109 | , mass(1.0) | - | ||||||||||||||||||||||||
| 110 | , spring(0.) | - | ||||||||||||||||||||||||
| 111 | , damping(0.) | - | ||||||||||||||||||||||||
| 112 | , epsilon(0.01) | - | ||||||||||||||||||||||||
| 113 | , modulus(0.0) | - | ||||||||||||||||||||||||
| 114 | , useMass(false) | - | ||||||||||||||||||||||||
| 115 | , haveModulus(false) | - | ||||||||||||||||||||||||
| 116 | , skipUpdate(false) | - | ||||||||||||||||||||||||
| 117 | , animationTemplate(priv) | - | ||||||||||||||||||||||||
| 118 | { | - | ||||||||||||||||||||||||
| 119 | } executed 26 times by 4 tests: end of blockExecuted by:
| 26 | ||||||||||||||||||||||||
| 120 | - | |||||||||||||||||||||||||
| 121 | QSpringAnimation::~QSpringAnimation() | - | ||||||||||||||||||||||||
| 122 | { | - | ||||||||||||||||||||||||
| 123 | if (animationTemplate
| 4-20 | ||||||||||||||||||||||||
| 124 | if (target.object()
| 2-18 | ||||||||||||||||||||||||
| 125 | ActiveAnimationHashIt it = animationTemplate->activeAnimations.find(target); | - | ||||||||||||||||||||||||
| 126 | if (it != animationTemplate->activeAnimations.end()
| 0-2 | ||||||||||||||||||||||||
| 127 | animationTemplate->activeAnimations.erase(it); executed 2 times by 1 test: animationTemplate->activeAnimations.erase(it);Executed by:
| 2 | ||||||||||||||||||||||||
| 128 | } executed 2 times by 1 test: else {end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 129 | - | |||||||||||||||||||||||||
| 130 | for (ActiveAnimationHashIt it = animationTemplate->activeAnimations.begin(); it != animationTemplate->activeAnimations.end()
| 0-18 | ||||||||||||||||||||||||
| 131 | if (it.value() == this
| 0-18 | ||||||||||||||||||||||||
| 132 | animationTemplate->activeAnimations.erase(it); | - | ||||||||||||||||||||||||
| 133 | break; executed 18 times by 2 tests: break;Executed by:
| 18 | ||||||||||||||||||||||||
| 134 | } | - | ||||||||||||||||||||||||
| 135 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 136 | } executed 18 times by 2 tests: end of blockExecuted by:
| 18 | ||||||||||||||||||||||||
| 137 | } | - | ||||||||||||||||||||||||
| 138 | } executed 24 times by 3 tests: end of blockExecuted by:
| 24 | ||||||||||||||||||||||||
| 139 | - | |||||||||||||||||||||||||
| 140 | int QSpringAnimation::duration() const | - | ||||||||||||||||||||||||
| 141 | { | - | ||||||||||||||||||||||||
| 142 | return executed 606 times by 4 tests: -1;return -1;Executed by:
executed 606 times by 4 tests: return -1;Executed by:
| 606 | ||||||||||||||||||||||||
| 143 | } | - | ||||||||||||||||||||||||
| 144 | - | |||||||||||||||||||||||||
| 145 | void QSpringAnimation::restart() | - | ||||||||||||||||||||||||
| 146 | { | - | ||||||||||||||||||||||||
| 147 | if (isRunning()
| 0-2 | ||||||||||||||||||||||||
| 148 | skipUpdate = true; | - | ||||||||||||||||||||||||
| 149 | init(); | - | ||||||||||||||||||||||||
| 150 | } executed 2 times by 1 test: else {end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 151 | skipUpdate = false; | - | ||||||||||||||||||||||||
| 152 | - | |||||||||||||||||||||||||
| 153 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 154 | } | - | ||||||||||||||||||||||||
| 155 | - | |||||||||||||||||||||||||
| 156 | void QSpringAnimation::init() | - | ||||||||||||||||||||||||
| 157 | { | - | ||||||||||||||||||||||||
| 158 | lastTime = startTime = 0; | - | ||||||||||||||||||||||||
| 159 | stopTime = -1; | - | ||||||||||||||||||||||||
| 160 | } executed 28 times by 4 tests: end of blockExecuted by:
| 28 | ||||||||||||||||||||||||
| 161 | - | |||||||||||||||||||||||||
| 162 | void QSpringAnimation::updateCurrentTime(int time) | - | ||||||||||||||||||||||||
| 163 | { | - | ||||||||||||||||||||||||
| 164 | if (skipUpdate
| 2-574 | ||||||||||||||||||||||||
| 165 | skipUpdate = false; | - | ||||||||||||||||||||||||
| 166 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||||||||
| 167 | } | - | ||||||||||||||||||||||||
| 168 | - | |||||||||||||||||||||||||
| 169 | if (mode == Track
| 0-574 | ||||||||||||||||||||||||
| 170 | stop(); | - | ||||||||||||||||||||||||
| 171 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 172 | } | - | ||||||||||||||||||||||||
| 173 | - | |||||||||||||||||||||||||
| 174 | int elapsed = time - lastTime; | - | ||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||
| 176 | if (!elapsed
| 26-548 | ||||||||||||||||||||||||
| 177 | return; executed 26 times by 4 tests: return;Executed by:
| 26 | ||||||||||||||||||||||||
| 178 | - | |||||||||||||||||||||||||
| 179 | int count = elapsed / 16; | - | ||||||||||||||||||||||||
| 180 | - | |||||||||||||||||||||||||
| 181 | if (mode == Spring
| 2-546 | ||||||||||||||||||||||||
| 182 | if (elapsed < 16
| 5-541 | ||||||||||||||||||||||||
| 183 | return; executed 5 times by 1 test: return;Executed by:
| 5 | ||||||||||||||||||||||||
| 184 | lastTime = time - (elapsed - count * 16); | - | ||||||||||||||||||||||||
| 185 | } executed 541 times by 2 tests: else {end of blockExecuted by:
| 541 | ||||||||||||||||||||||||
| 186 | lastTime = time; | - | ||||||||||||||||||||||||
| 187 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 188 | - | |||||||||||||||||||||||||
| 189 | qreal srcVal = to; | - | ||||||||||||||||||||||||
| 190 | - | |||||||||||||||||||||||||
| 191 | bool stopped = false; | - | ||||||||||||||||||||||||
| 192 | - | |||||||||||||||||||||||||
| 193 | if (haveModulus
| 218-325 | ||||||||||||||||||||||||
| 194 | currentValue = fmod(currentValue, modulus); | - | ||||||||||||||||||||||||
| 195 | srcVal = fmod(srcVal, modulus); | - | ||||||||||||||||||||||||
| 196 | } executed 218 times by 1 test: end of blockExecuted by:
| 218 | ||||||||||||||||||||||||
| 197 | if (mode == Spring
| 2-541 | ||||||||||||||||||||||||
| 198 | - | |||||||||||||||||||||||||
| 199 | - | |||||||||||||||||||||||||
| 200 | for (int i = 0; i < count
| 541-546 | ||||||||||||||||||||||||
| 201 | qreal diff = srcVal - currentValue; | - | ||||||||||||||||||||||||
| 202 | if (haveModulus
| 0-328 | ||||||||||||||||||||||||
| 203 | if (diff < 0
| 0 | ||||||||||||||||||||||||
| 204 | diff += modulus; never executed: diff += modulus; | 0 | ||||||||||||||||||||||||
| 205 | else | - | ||||||||||||||||||||||||
| 206 | diff -= modulus; never executed: diff -= modulus; | 0 | ||||||||||||||||||||||||
| 207 | } | - | ||||||||||||||||||||||||
| 208 | if (useMass
| 236-310 | ||||||||||||||||||||||||
| 209 | velocity = velocity + (spring * diff - damping * velocity) / mass; executed 310 times by 2 tests: velocity = velocity + (spring * diff - damping * velocity) / mass;Executed by:
| 310 | ||||||||||||||||||||||||
| 210 | else | - | ||||||||||||||||||||||||
| 211 | velocity = velocity + spring * diff - damping * velocity; executed 236 times by 1 test: velocity = velocity + spring * diff - damping * velocity;Executed by:
| 236 | ||||||||||||||||||||||||
| 212 | if (maxVelocity > 0.
| 218-328 | ||||||||||||||||||||||||
| 213 | - | |||||||||||||||||||||||||
| 214 | if (velocity > maxVelocity
| 82-136 | ||||||||||||||||||||||||
| 215 | velocity = maxVelocity; executed 136 times by 1 test: velocity = maxVelocity;Executed by:
| 136 | ||||||||||||||||||||||||
| 216 | else if (velocity < -maxVelocity
| 0-82 | ||||||||||||||||||||||||
| 217 | velocity = -maxVelocity; never executed: velocity = -maxVelocity; | 0 | ||||||||||||||||||||||||
| 218 | } executed 218 times by 1 test: end of blockExecuted by:
| 218 | ||||||||||||||||||||||||
| 219 | currentValue += velocity * 16.0 / 1000.0; | - | ||||||||||||||||||||||||
| 220 | if (haveModulus
| 218-328 | ||||||||||||||||||||||||
| 221 | currentValue = fmod(currentValue, modulus); | - | ||||||||||||||||||||||||
| 222 | if (currentValue < 0.0
| 0-218 | ||||||||||||||||||||||||
| 223 | currentValue += modulus; never executed: currentValue += modulus; | 0 | ||||||||||||||||||||||||
| 224 | } executed 218 times by 1 test: end of blockExecuted by:
| 218 | ||||||||||||||||||||||||
| 225 | } executed 546 times by 2 tests: end of blockExecuted by:
| 546 | ||||||||||||||||||||||||
| 226 | if (qAbs(velocity) < epsilon
| 0-533 | ||||||||||||||||||||||||
| 227 | velocity = 0.0; | - | ||||||||||||||||||||||||
| 228 | currentValue = srcVal; | - | ||||||||||||||||||||||||
| 229 | stopped = true; | - | ||||||||||||||||||||||||
| 230 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||
| 231 | } executed 541 times by 2 tests: else {end of blockExecuted by:
| 541 | ||||||||||||||||||||||||
| 232 | qreal moveBy = elapsed * velocityms; | - | ||||||||||||||||||||||||
| 233 | qreal diff = srcVal - currentValue; | - | ||||||||||||||||||||||||
| 234 | if (haveModulus
| 0-2 | ||||||||||||||||||||||||
| 235 | if (diff < 0
| 0 | ||||||||||||||||||||||||
| 236 | diff += modulus; never executed: diff += modulus; | 0 | ||||||||||||||||||||||||
| 237 | else | - | ||||||||||||||||||||||||
| 238 | diff -= modulus; never executed: diff -= modulus; | 0 | ||||||||||||||||||||||||
| 239 | } | - | ||||||||||||||||||||||||
| 240 | if (diff > 0
| 0-2 | ||||||||||||||||||||||||
| 241 | currentValue += moveBy; | - | ||||||||||||||||||||||||
| 242 | if (haveModulus
| 0-2 | ||||||||||||||||||||||||
| 243 | currentValue = std::fmod(currentValue, modulus); never executed: currentValue = std::fmod(currentValue, modulus); | 0 | ||||||||||||||||||||||||
| 244 | } executed 2 times by 1 test: else {end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 245 | currentValue -= moveBy; | - | ||||||||||||||||||||||||
| 246 | if (haveModulus
| 0 | ||||||||||||||||||||||||
| 247 | currentValue = std::fmod(currentValue, modulus) + modulus; never executed: currentValue = std::fmod(currentValue, modulus) + modulus; | 0 | ||||||||||||||||||||||||
| 248 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 249 | if (lastTime - startTime >= dura
| 0-2 | ||||||||||||||||||||||||
| 250 | currentValue = to; | - | ||||||||||||||||||||||||
| 251 | stopped = true; | - | ||||||||||||||||||||||||
| 252 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 253 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 254 | - | |||||||||||||||||||||||||
| 255 | qreal old_to = to; | - | ||||||||||||||||||||||||
| 256 | - | |||||||||||||||||||||||||
| 257 | QQmlPropertyPrivate::write(target, currentValue, | - | ||||||||||||||||||||||||
| 258 | QQmlPropertyData::BypassInterceptor | | - | ||||||||||||||||||||||||
| 259 | QQmlPropertyData::DontRemoveBinding); | - | ||||||||||||||||||||||||
| 260 | - | |||||||||||||||||||||||||
| 261 | if (stopped
| 0-533 | ||||||||||||||||||||||||
| 262 | if (animationTemplate
| 2-8 | ||||||||||||||||||||||||
| 263 | stopTime = animationTemplate->elapsed.elapsed(); executed 8 times by 3 tests: stopTime = animationTemplate->elapsed.elapsed();Executed by:
| 8 | ||||||||||||||||||||||||
| 264 | stop(); | - | ||||||||||||||||||||||||
| 265 | } executed 10 times by 3 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||||||||
| 266 | } executed 543 times by 3 tests: end of blockExecuted by:
| 543 | ||||||||||||||||||||||||
| 267 | - | |||||||||||||||||||||||||
| 268 | void QSpringAnimation::updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State ) | - | ||||||||||||||||||||||||
| 269 | { | - | ||||||||||||||||||||||||
| 270 | if (newState == QAbstractAnimationJob::Running
| 10-26 | ||||||||||||||||||||||||
| 271 | init(); executed 26 times by 4 tests: init();Executed by:
| 26 | ||||||||||||||||||||||||
| 272 | } executed 36 times by 4 tests: end of blockExecuted by:
| 36 | ||||||||||||||||||||||||
| 273 | - | |||||||||||||||||||||||||
| 274 | void QSpringAnimation::debugAnimation(QDebug d) const | - | ||||||||||||||||||||||||
| 275 | { | - | ||||||||||||||||||||||||
| 276 | d << "SpringAnimationJob(" << hex << (const void *) this << dec << ")" << "velocity:" << maxVelocity | - | ||||||||||||||||||||||||
| 277 | << "spring:" << spring << "damping:" << damping << "epsilon:" << epsilon << "modulus:" << modulus | - | ||||||||||||||||||||||||
| 278 | << "mass:" << mass << "target:" << target.object() << "property:" << target.name() | - | ||||||||||||||||||||||||
| 279 | << "to:" << to << "current velocity:" << velocity; | - | ||||||||||||||||||||||||
| 280 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 281 | - | |||||||||||||||||||||||||
| 282 | - | |||||||||||||||||||||||||
| 283 | void QQuickSpringAnimationPrivate::updateMode() | - | ||||||||||||||||||||||||
| 284 | { | - | ||||||||||||||||||||||||
| 285 | if (spring == 0.
| 4-54 | ||||||||||||||||||||||||
| 286 | mode = QSpringAnimation::Track; executed 4 times by 1 test: mode = QSpringAnimation::Track;Executed by:
| 4 | ||||||||||||||||||||||||
| 287 | else if (spring > 0.
| 4-54 | ||||||||||||||||||||||||
| 288 | mode = QSpringAnimation::Spring; executed 54 times by 3 tests: mode = QSpringAnimation::Spring;Executed by:
| 54 | ||||||||||||||||||||||||
| 289 | else { | - | ||||||||||||||||||||||||
| 290 | mode = QSpringAnimation::Velocity; | - | ||||||||||||||||||||||||
| 291 | for (QSpringAnimation::ActiveAnimationHashIt it = activeAnimations.begin(), end = activeAnimations.end(); it != end
| 0-4 | ||||||||||||||||||||||||
| 292 | QSpringAnimation *animation = *it; | - | ||||||||||||||||||||||||
| 293 | animation->startTime = animation->lastTime; | - | ||||||||||||||||||||||||
| 294 | qreal dist = qAbs(animation->currentValue - animation->to); | - | ||||||||||||||||||||||||
| 295 | if (haveModulus
| 0 | ||||||||||||||||||||||||
| 296 | dist = modulus - fmod(dist, modulus); never executed: dist = modulus - fmod(dist, modulus); | 0 | ||||||||||||||||||||||||
| 297 | animation->dura = dist / velocityms; | - | ||||||||||||||||||||||||
| 298 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 299 | } executed 4 times by 2 tests: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 300 | } | - | ||||||||||||||||||||||||
| 301 | QQuickSpringAnimation::QQuickSpringAnimation(QObject *parent) | - | ||||||||||||||||||||||||
| 302 | : QQuickNumberAnimation(*(new QQuickSpringAnimationPrivate),parent) | - | ||||||||||||||||||||||||
| 303 | { | - | ||||||||||||||||||||||||
| 304 | } executed 56 times by 4 tests: end of blockExecuted by:
| 56 | ||||||||||||||||||||||||
| 305 | - | |||||||||||||||||||||||||
| 306 | QQuickSpringAnimation::~QQuickSpringAnimation() | - | ||||||||||||||||||||||||
| 307 | { | - | ||||||||||||||||||||||||
| 308 | QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 309 | for (QSpringAnimation::ActiveAnimationHashIt it = d->activeAnimations.begin(), end = d->activeAnimations.end(); it != end
| 2-54 | ||||||||||||||||||||||||
| 310 | it.value()->clearTemplate(); executed 2 times by 1 test: it.value()->clearTemplate();Executed by:
| 2 | ||||||||||||||||||||||||
| 311 | } executed 54 times by 3 tests: end of blockExecuted by:
| 54 | ||||||||||||||||||||||||
| 312 | qreal QQuickSpringAnimation::velocity() const | - | ||||||||||||||||||||||||
| 313 | { | - | ||||||||||||||||||||||||
| 314 | const QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 315 | return executed 6 times by 1 test: d->maxVelocity;return d->maxVelocity;Executed by:
executed 6 times by 1 test: return d->maxVelocity;Executed by:
| 6 | ||||||||||||||||||||||||
| 316 | } | - | ||||||||||||||||||||||||
| 317 | - | |||||||||||||||||||||||||
| 318 | void QQuickSpringAnimation::setVelocity(qreal velocity) | - | ||||||||||||||||||||||||
| 319 | { | - | ||||||||||||||||||||||||
| 320 | QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 321 | d->maxVelocity = velocity; | - | ||||||||||||||||||||||||
| 322 | d->velocityms = velocity / 1000.0; | - | ||||||||||||||||||||||||
| 323 | d->updateMode(); | - | ||||||||||||||||||||||||
| 324 | } executed 8 times by 3 tests: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||
| 325 | qreal QQuickSpringAnimation::spring() const | - | ||||||||||||||||||||||||
| 326 | { | - | ||||||||||||||||||||||||
| 327 | const QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 328 | return executed 6 times by 1 test: d->spring;return d->spring;Executed by:
executed 6 times by 1 test: return d->spring;Executed by:
| 6 | ||||||||||||||||||||||||
| 329 | } | - | ||||||||||||||||||||||||
| 330 | - | |||||||||||||||||||||||||
| 331 | void QQuickSpringAnimation::setSpring(qreal spring) | - | ||||||||||||||||||||||||
| 332 | { | - | ||||||||||||||||||||||||
| 333 | QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 334 | d->spring = spring; | - | ||||||||||||||||||||||||
| 335 | d->updateMode(); | - | ||||||||||||||||||||||||
| 336 | } executed 50 times by 3 tests: end of blockExecuted by:
| 50 | ||||||||||||||||||||||||
| 337 | qreal QQuickSpringAnimation::damping() const | - | ||||||||||||||||||||||||
| 338 | { | - | ||||||||||||||||||||||||
| 339 | const QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 340 | return executed 6 times by 1 test: d->damping;return d->damping;Executed by:
executed 6 times by 1 test: return d->damping;Executed by:
| 6 | ||||||||||||||||||||||||
| 341 | } | - | ||||||||||||||||||||||||
| 342 | - | |||||||||||||||||||||||||
| 343 | void QQuickSpringAnimation::setDamping(qreal damping) | - | ||||||||||||||||||||||||
| 344 | { | - | ||||||||||||||||||||||||
| 345 | QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 346 | if (damping > 1.
| 0-50 | ||||||||||||||||||||||||
| 347 | damping = 1.; never executed: damping = 1.; | 0 | ||||||||||||||||||||||||
| 348 | - | |||||||||||||||||||||||||
| 349 | d->damping = damping; | - | ||||||||||||||||||||||||
| 350 | } executed 50 times by 3 tests: end of blockExecuted by:
| 50 | ||||||||||||||||||||||||
| 351 | qreal QQuickSpringAnimation::epsilon() const | - | ||||||||||||||||||||||||
| 352 | { | - | ||||||||||||||||||||||||
| 353 | const QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 354 | return executed 6 times by 1 test: d->epsilon;return d->epsilon;Executed by:
executed 6 times by 1 test: return d->epsilon;Executed by:
| 6 | ||||||||||||||||||||||||
| 355 | } | - | ||||||||||||||||||||||||
| 356 | - | |||||||||||||||||||||||||
| 357 | void QQuickSpringAnimation::setEpsilon(qreal epsilon) | - | ||||||||||||||||||||||||
| 358 | { | - | ||||||||||||||||||||||||
| 359 | QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 360 | d->epsilon = epsilon; | - | ||||||||||||||||||||||||
| 361 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 362 | qreal QQuickSpringAnimation::modulus() const | - | ||||||||||||||||||||||||
| 363 | { | - | ||||||||||||||||||||||||
| 364 | const QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 365 | return executed 6 times by 1 test: d->modulus;return d->modulus;Executed by:
executed 6 times by 1 test: return d->modulus;Executed by:
| 6 | ||||||||||||||||||||||||
| 366 | } | - | ||||||||||||||||||||||||
| 367 | - | |||||||||||||||||||||||||
| 368 | void QQuickSpringAnimation::setModulus(qreal modulus) | - | ||||||||||||||||||||||||
| 369 | { | - | ||||||||||||||||||||||||
| 370 | QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 371 | if (d->modulus != modulus
| 0-4 | ||||||||||||||||||||||||
| 372 | d->haveModulus = modulus != 0.0; | - | ||||||||||||||||||||||||
| 373 | d->modulus = modulus; | - | ||||||||||||||||||||||||
| 374 | d->updateMode(); | - | ||||||||||||||||||||||||
| 375 | modulusChanged(); | - | ||||||||||||||||||||||||
| 376 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 377 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 378 | qreal QQuickSpringAnimation::mass() const | - | ||||||||||||||||||||||||
| 379 | { | - | ||||||||||||||||||||||||
| 380 | const QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 381 | return executed 6 times by 1 test: d->mass;return d->mass;Executed by:
executed 6 times by 1 test: return d->mass;Executed by:
| 6 | ||||||||||||||||||||||||
| 382 | } | - | ||||||||||||||||||||||||
| 383 | - | |||||||||||||||||||||||||
| 384 | void QQuickSpringAnimation::setMass(qreal mass) | - | ||||||||||||||||||||||||
| 385 | { | - | ||||||||||||||||||||||||
| 386 | QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 387 | if (d->mass != mass
| 0-32 | ||||||||||||||||||||||||
| 388 | d->useMass = mass != 1.0; | - | ||||||||||||||||||||||||
| 389 | d->mass = mass; | - | ||||||||||||||||||||||||
| 390 | massChanged(); | - | ||||||||||||||||||||||||
| 391 | } executed 6 times by 2 tests: end of blockExecuted by:
| 6 | ||||||||||||||||||||||||
| 392 | } executed 38 times by 3 tests: end of blockExecuted by:
| 38 | ||||||||||||||||||||||||
| 393 | - | |||||||||||||||||||||||||
| 394 | QAbstractAnimationJob* QQuickSpringAnimation::transition(QQuickStateActions &actions, | - | ||||||||||||||||||||||||
| 395 | QQmlProperties &modified, | - | ||||||||||||||||||||||||
| 396 | TransitionDirection direction, | - | ||||||||||||||||||||||||
| 397 | QObject *defaultTarget) | - | ||||||||||||||||||||||||
| 398 | { | - | ||||||||||||||||||||||||
| 399 | QQuickSpringAnimationPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 400 | (void)direction;; | - | ||||||||||||||||||||||||
| 401 | - | |||||||||||||||||||||||||
| 402 | QContinuingAnimationGroupJob *wrapperGroup = new QContinuingAnimationGroupJob(); | - | ||||||||||||||||||||||||
| 403 | - | |||||||||||||||||||||||||
| 404 | QQuickStateActions dataActions = QQuickNumberAnimation::createTransitionActions(actions, modified, defaultTarget); | - | ||||||||||||||||||||||||
| 405 | if (!dataActions.isEmpty()
| 0-28 | ||||||||||||||||||||||||
| 406 | QSet<QAbstractAnimationJob*> anims; | - | ||||||||||||||||||||||||
| 407 | for (int i = 0; i < dataActions.size()
| 28 | ||||||||||||||||||||||||
| 408 | QSpringAnimation *animation; | - | ||||||||||||||||||||||||
| 409 | bool needsRestart = false; | - | ||||||||||||||||||||||||
| 410 | const QQmlProperty &property = dataActions.at(i).property; | - | ||||||||||||||||||||||||
| 411 | if (d->activeAnimations.contains(property)
| 2-26 | ||||||||||||||||||||||||
| 412 | animation = d->activeAnimations[property]; | - | ||||||||||||||||||||||||
| 413 | needsRestart = true; | - | ||||||||||||||||||||||||
| 414 | } executed 2 times by 1 test: else {end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 415 | animation = new QSpringAnimation(d); | - | ||||||||||||||||||||||||
| 416 | d->activeAnimations.insert(property, animation); | - | ||||||||||||||||||||||||
| 417 | animation->target = property; | - | ||||||||||||||||||||||||
| 418 | } executed 26 times by 4 tests: end of blockExecuted by:
| 26 | ||||||||||||||||||||||||
| 419 | wrapperGroup->appendAnimation(initInstance(animation)); | - | ||||||||||||||||||||||||
| 420 | - | |||||||||||||||||||||||||
| 421 | animation->to = dataActions.at(i).toValue.toReal(); | - | ||||||||||||||||||||||||
| 422 | animation->startTime = 0; | - | ||||||||||||||||||||||||
| 423 | animation->velocityms = d->velocityms; | - | ||||||||||||||||||||||||
| 424 | animation->mass = d->mass; | - | ||||||||||||||||||||||||
| 425 | animation->spring = d->spring; | - | ||||||||||||||||||||||||
| 426 | animation->damping = d->damping; | - | ||||||||||||||||||||||||
| 427 | animation->epsilon = d->epsilon; | - | ||||||||||||||||||||||||
| 428 | animation->modulus = d->modulus; | - | ||||||||||||||||||||||||
| 429 | animation->useMass = d->useMass; | - | ||||||||||||||||||||||||
| 430 | animation->haveModulus = d->haveModulus; | - | ||||||||||||||||||||||||
| 431 | animation->mode = d->mode; | - | ||||||||||||||||||||||||
| 432 | animation->dura = -1; | - | ||||||||||||||||||||||||
| 433 | animation->maxVelocity = d->maxVelocity; | - | ||||||||||||||||||||||||
| 434 | - | |||||||||||||||||||||||||
| 435 | if (d->fromIsDefined
| 4-24 | ||||||||||||||||||||||||
| 436 | animation->currentValue = dataActions.at(i).fromValue.toReal(); executed 4 times by 1 test: animation->currentValue = dataActions.at(i).fromValue.toReal();Executed by:
| 4 | ||||||||||||||||||||||||
| 437 | else | - | ||||||||||||||||||||||||
| 438 | animation->currentValue = property.read().toReal(); executed 24 times by 4 tests: animation->currentValue = property.read().toReal();Executed by:
| 24 | ||||||||||||||||||||||||
| 439 | if (animation->mode == QSpringAnimation::Velocity
| 4-24 | ||||||||||||||||||||||||
| 440 | qreal dist = qAbs(animation->currentValue - animation->to); | - | ||||||||||||||||||||||||
| 441 | if (d->haveModulus
| 0-4 | ||||||||||||||||||||||||
| 442 | dist = d->modulus - fmod(dist, d->modulus); never executed: dist = d->modulus - fmod(dist, d->modulus); | 0 | ||||||||||||||||||||||||
| 443 | animation->dura = dist / animation->velocityms; | - | ||||||||||||||||||||||||
| 444 | } executed 4 times by 2 tests: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 445 | - | |||||||||||||||||||||||||
| 446 | if (needsRestart
| 2-26 | ||||||||||||||||||||||||
| 447 | animation->restart(); executed 2 times by 1 test: animation->restart();Executed by:
| 2 | ||||||||||||||||||||||||
| 448 | anims.insert(animation); | - | ||||||||||||||||||||||||
| 449 | } executed 28 times by 4 tests: end of blockExecuted by:
| 28 | ||||||||||||||||||||||||
| 450 | const auto copy = d->activeAnimations; | - | ||||||||||||||||||||||||
| 451 | for (QSpringAnimation *anim : copy) { | - | ||||||||||||||||||||||||
| 452 | if (!anims.contains(anim)
| 2-28 | ||||||||||||||||||||||||
| 453 | anim->clearTemplate(); | - | ||||||||||||||||||||||||
| 454 | d->activeAnimations.remove(anim->target); | - | ||||||||||||||||||||||||
| 455 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 456 | } executed 30 times by 4 tests: end of blockExecuted by:
| 30 | ||||||||||||||||||||||||
| 457 | } executed 28 times by 4 tests: end of blockExecuted by:
| 28 | ||||||||||||||||||||||||
| 458 | return executed 28 times by 4 tests: wrapperGroup;return wrapperGroup;Executed by:
executed 28 times by 4 tests: return wrapperGroup;Executed by:
| 28 | ||||||||||||||||||||||||
| 459 | } | - | ||||||||||||||||||||||||
| 460 | - | |||||||||||||||||||||||||
| 461 | - | |||||||||||||||||||||||||
| 462 | - | |||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |