| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickspritesequence.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | - | |||||||
| 5 | QQuickSpriteSequence::QQuickSpriteSequence(QQuickItem *parent) : | - | ||||||
| 6 | QQuickItem(*(new QQuickSpriteSequencePrivate), parent) | - | ||||||
| 7 | { | - | ||||||
| 8 | setFlag(ItemHasContents); | - | ||||||
| 9 | connect(this, qFlagLocation("2""runningChanged(bool)" "\0" __FILE__ ":" "120"), | - | ||||||
| 10 | this, qFlagLocation("1""update()" "\0" __FILE__ ":" "121")); | - | ||||||
| 11 | } executed 14 times by 2 tests: end of blockExecuted by:
| 14 | ||||||
| 12 | - | |||||||
| 13 | void QQuickSpriteSequence::jumpTo(const QString &sprite) | - | ||||||
| 14 | { | - | ||||||
| 15 | QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 16 | if (!d->m_spriteEngine
| 0-2 | ||||||
| 17 | return; never executed: return; | 0 | ||||||
| 18 | d->m_spriteEngine->setGoal(d->m_spriteEngine->stateIndex(sprite), 0, true); | - | ||||||
| 19 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 20 | - | |||||||
| 21 | void QQuickSpriteSequence::setGoalSprite(const QString &sprite) | - | ||||||
| 22 | { | - | ||||||
| 23 | QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 24 | if (d->m_goalState != sprite
| 0-4 | ||||||
| 25 | d->m_goalState = sprite; | - | ||||||
| 26 | goalSpriteChanged(sprite); | - | ||||||
| 27 | if (d->m_spriteEngine
| 2 | ||||||
| 28 | d->m_spriteEngine->setGoal(d->m_spriteEngine->stateIndex(sprite)); executed 2 times by 1 test: d->m_spriteEngine->setGoal(d->m_spriteEngine->stateIndex(sprite));Executed by:
| 2 | ||||||
| 29 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 30 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 31 | - | |||||||
| 32 | void QQuickSpriteSequence::setRunning(bool arg) | - | ||||||
| 33 | { | - | ||||||
| 34 | QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 35 | if (d->m_running != arg
| 0-2 | ||||||
| 36 | d->m_running = arg; | - | ||||||
| 37 | runningChanged(arg); | - | ||||||
| 38 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 39 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 40 | - | |||||||
| 41 | void QQuickSpriteSequence::setInterpolate(bool arg) | - | ||||||
| 42 | { | - | ||||||
| 43 | QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 44 | if (d->m_interpolate != arg
| 0-2 | ||||||
| 45 | d->m_interpolate = arg; | - | ||||||
| 46 | interpolateChanged(arg); | - | ||||||
| 47 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 48 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 49 | - | |||||||
| 50 | QQmlListProperty<QQuickSprite> QQuickSpriteSequence::sprites() | - | ||||||
| 51 | { | - | ||||||
| 52 | QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 53 | return executed 16 times by 2 tests: QQmlListProperty<QQuickSprite>(this, &d->m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);return QQmlListProperty<QQuickSprite>(this, &d->m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);Executed by:
executed 16 times by 2 tests: return QQmlListProperty<QQuickSprite>(this, &d->m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);Executed by:
| 16 | ||||||
| 54 | } | - | ||||||
| 55 | - | |||||||
| 56 | bool QQuickSpriteSequence::running() const | - | ||||||
| 57 | { | - | ||||||
| 58 | const QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 59 | return executed 4 times by 1 test: d->m_running;return d->m_running;Executed by:
executed 4 times by 1 test: return d->m_running;Executed by:
| 4 | ||||||
| 60 | } | - | ||||||
| 61 | - | |||||||
| 62 | bool QQuickSpriteSequence::interpolate() const | - | ||||||
| 63 | { | - | ||||||
| 64 | const QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 65 | return executed 4 times by 1 test: d->m_interpolate;return d->m_interpolate;Executed by:
executed 4 times by 1 test: return d->m_interpolate;Executed by:
| 4 | ||||||
| 66 | } | - | ||||||
| 67 | - | |||||||
| 68 | QString QQuickSpriteSequence::goalSprite() const | - | ||||||
| 69 | { | - | ||||||
| 70 | const QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 71 | return never executed: d->m_goalState;return d->m_goalState;never executed: return d->m_goalState; | 0 | ||||||
| 72 | } | - | ||||||
| 73 | - | |||||||
| 74 | QString QQuickSpriteSequence::currentSprite() const | - | ||||||
| 75 | { | - | ||||||
| 76 | const QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 77 | return executed 9 times by 1 test: d->m_curState;return d->m_curState;Executed by:
executed 9 times by 1 test: return d->m_curState;Executed by:
| 9 | ||||||
| 78 | } | - | ||||||
| 79 | - | |||||||
| 80 | void QQuickSpriteSequence::createEngine() | - | ||||||
| 81 | { | - | ||||||
| 82 | QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 83 | - | |||||||
| 84 | if (d->m_spriteEngine
| 4-16 | ||||||
| 85 | delete d->m_spriteEngine; executed 4 times by 1 test: delete d->m_spriteEngine;Executed by:
| 4 | ||||||
| 86 | if (d->m_sprites.count()
| 2-18 | ||||||
| 87 | d->m_spriteEngine = new QQuickSpriteEngine(d->m_sprites, this); | - | ||||||
| 88 | if (!d->m_goalState.isEmpty()
| 2-16 | ||||||
| 89 | d->m_spriteEngine->setGoal(d->m_spriteEngine->stateIndex(d->m_goalState)); executed 2 times by 1 test: d->m_spriteEngine->setGoal(d->m_spriteEngine->stateIndex(d->m_goalState));Executed by:
| 2 | ||||||
| 90 | } executed 18 times by 2 tests: else {end of blockExecuted by:
| 18 | ||||||
| 91 | d->m_spriteEngine = nullptr; | - | ||||||
| 92 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 93 | reset(); | - | ||||||
| 94 | } executed 20 times by 2 tests: end of blockExecuted by:
| 20 | ||||||
| 95 | - | |||||||
| 96 | QSGSpriteNode *QQuickSpriteSequence::initNode() | - | ||||||
| 97 | { | - | ||||||
| 98 | QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 99 | - | |||||||
| 100 | if (!d->m_spriteEngine
| 0-26 | ||||||
| 101 | qmlWarning(this) << "No sprite engine..."; | - | ||||||
| 102 | return never executed: nullptr;return nullptr;never executed: return nullptr; | 0 | ||||||
| 103 | } else if (d->m_spriteEngine->status() == QQuickPixmap::Null
| 12-14 | ||||||
| 104 | d->m_spriteEngine->startAssemblingImage(); | - | ||||||
| 105 | update(); | - | ||||||
| 106 | return executed 14 times by 2 tests: nullptr;return nullptr;Executed by:
executed 14 times by 2 tests: return nullptr;Executed by:
| 14 | ||||||
| 107 | } else if (d->m_spriteEngine->status() == QQuickPixmap::Loading
| 0-12 | ||||||
| 108 | update(); | - | ||||||
| 109 | return never executed: nullptr;return nullptr;never executed: return nullptr; | 0 | ||||||
| 110 | } | - | ||||||
| 111 | - | |||||||
| 112 | QImage image = d->m_spriteEngine->assembledImage(d->sceneGraphRenderContext()->maxTextureSize()); | - | ||||||
| 113 | if (image.isNull()
| 0-12 | ||||||
| 114 | return never executed: nullptr;return nullptr;never executed: return nullptr; | 0 | ||||||
| 115 | - | |||||||
| 116 | QSGSpriteNode *node = d->sceneGraphContext()->createSpriteNode(); | - | ||||||
| 117 | - | |||||||
| 118 | d->m_sheetSize = QSize(image.size() / image.devicePixelRatioF()); | - | ||||||
| 119 | node->setTexture(window()->createTextureFromImage(image)); | - | ||||||
| 120 | d->m_spriteEngine->start(0); | - | ||||||
| 121 | node->setTime(0.0f); | - | ||||||
| 122 | node->setSourceA(QPoint(d->m_spriteEngine->spriteX(), d->m_spriteEngine->spriteY())); | - | ||||||
| 123 | node->setSourceB(QPoint(d->m_spriteEngine->spriteX(), d->m_spriteEngine->spriteY())); | - | ||||||
| 124 | node->setSpriteSize(QSize(d->m_spriteEngine->spriteWidth(), d->m_spriteEngine->spriteHeight())); | - | ||||||
| 125 | node->setSheetSize(d->m_sheetSize); | - | ||||||
| 126 | node->setSize(QSizeF(width(), height())); | - | ||||||
| 127 | - | |||||||
| 128 | d->m_curState = d->m_spriteEngine->state(d->m_spriteEngine->curState())->name(); | - | ||||||
| 129 | currentSpriteChanged(d->m_curState); | - | ||||||
| 130 | d->m_timestamp.start(); | - | ||||||
| 131 | return executed 12 times by 1 test: node;return node;Executed by:
executed 12 times by 1 test: return node;Executed by:
| 12 | ||||||
| 132 | } | - | ||||||
| 133 | - | |||||||
| 134 | void QQuickSpriteSequence::reset() | - | ||||||
| 135 | { | - | ||||||
| 136 | QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 137 | d->m_pleaseReset = true; | - | ||||||
| 138 | } executed 20 times by 2 tests: end of blockExecuted by:
| 20 | ||||||
| 139 | - | |||||||
| 140 | QSGNode *QQuickSpriteSequence::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) | - | ||||||
| 141 | { | - | ||||||
| 142 | QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 143 | - | |||||||
| 144 | if (d->m_pleaseReset
| 14-1072 | ||||||
| 145 | delete oldNode; | - | ||||||
| 146 | - | |||||||
| 147 | oldNode = nullptr; | - | ||||||
| 148 | d->m_pleaseReset = false; | - | ||||||
| 149 | } executed 14 times by 2 tests: end of blockExecuted by:
| 14 | ||||||
| 150 | - | |||||||
| 151 | QSGSpriteNode *node = static_cast<QSGSpriteNode *>(oldNode); | - | ||||||
| 152 | if (!node
| 26-1060 | ||||||
| 153 | node = initNode(); executed 26 times by 2 tests: node = initNode();Executed by:
| 26 | ||||||
| 154 | - | |||||||
| 155 | if (node
| 14-1072 | ||||||
| 156 | prepareNextFrame(node); executed 1072 times by 1 test: prepareNextFrame(node);Executed by:
| 1072 | ||||||
| 157 | - | |||||||
| 158 | if (d->m_running
| 0-1086 | ||||||
| 159 | update(); | - | ||||||
| 160 | } executed 1086 times by 2 tests: end of blockExecuted by:
| 1086 | ||||||
| 161 | - | |||||||
| 162 | return executed 1086 times by 2 tests: node;return node;Executed by:
executed 1086 times by 2 tests: return node;Executed by:
| 1086 | ||||||
| 163 | } | - | ||||||
| 164 | - | |||||||
| 165 | void QQuickSpriteSequence::prepareNextFrame(QSGSpriteNode *node) | - | ||||||
| 166 | { | - | ||||||
| 167 | QQuickSpriteSequencePrivate * const d = d_func(); | - | ||||||
| 168 | - | |||||||
| 169 | uint timeInt = d->m_timestamp.elapsed(); | - | ||||||
| 170 | qreal time = timeInt / 1000.; | - | ||||||
| 171 | - | |||||||
| 172 | - | |||||||
| 173 | d->m_spriteEngine->updateSprites(timeInt); | - | ||||||
| 174 | if (d->m_curStateIdx != d->m_spriteEngine->curState()
| 2-1070 | ||||||
| 175 | d->m_curStateIdx = d->m_spriteEngine->curState(); | - | ||||||
| 176 | d->m_curState = d->m_spriteEngine->state(d->m_spriteEngine->curState())->name(); | - | ||||||
| 177 | currentSpriteChanged(d->m_curState); | - | ||||||
| 178 | d->m_curFrame= -1; | - | ||||||
| 179 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 180 | - | |||||||
| 181 | - | |||||||
| 182 | qreal animT = d->m_spriteEngine->spriteStart()/1000.0; | - | ||||||
| 183 | qreal frameCount = d->m_spriteEngine->spriteFrames(); | - | ||||||
| 184 | qreal frameDuration = d->m_spriteEngine->spriteDuration()/frameCount; | - | ||||||
| 185 | double frameAt; | - | ||||||
| 186 | qreal progress; | - | ||||||
| 187 | if (frameDuration > 0
| 14-1058 | ||||||
| 188 | qreal frame = (time - animT)/(frameDuration / 1000.0); | - | ||||||
| 189 | frame = qBound(qreal(0.0), frame, frameCount - qreal(1.0)); | - | ||||||
| 190 | progress = std::modf(frame,&frameAt); | - | ||||||
| 191 | } executed 1058 times by 1 test: else {end of blockExecuted by:
| 1058 | ||||||
| 192 | d->m_curFrame++; | - | ||||||
| 193 | if (d->m_curFrame >= frameCount
| 2-12 | ||||||
| 194 | d->m_curFrame = 0; | - | ||||||
| 195 | d->m_spriteEngine->advance(); | - | ||||||
| 196 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 197 | frameAt = d->m_curFrame; | - | ||||||
| 198 | progress = 0; | - | ||||||
| 199 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||
| 200 | if (d->m_spriteEngine->sprite()->reverse()
| 0-1072 | ||||||
| 201 | frameAt = (d->m_spriteEngine->spriteFrames() - 1) - frameAt; never executed: frameAt = (d->m_spriteEngine->spriteFrames() - 1) - frameAt; | 0 | ||||||
| 202 | int y = d->m_spriteEngine->spriteY(); | - | ||||||
| 203 | int w = d->m_spriteEngine->spriteWidth(); | - | ||||||
| 204 | int h = d->m_spriteEngine->spriteHeight(); | - | ||||||
| 205 | int x1 = d->m_spriteEngine->spriteX(); | - | ||||||
| 206 | x1 += frameAt * w; | - | ||||||
| 207 | int x2 = x1; | - | ||||||
| 208 | if (frameAt < (frameCount-1)
| 101-971 | ||||||
| 209 | x2 += w; executed 971 times by 1 test: x2 += w;Executed by:
| 971 | ||||||
| 210 | - | |||||||
| 211 | node->setSourceA(QPoint(x1, y)); | - | ||||||
| 212 | node->setSourceB(QPoint(x2, y)); | - | ||||||
| 213 | node->setSpriteSize(QSize(w, h)); | - | ||||||
| 214 | node->setTime(d->m_interpolate ? progress : 0.0); | - | ||||||
| 215 | node->setSize(QSizeF(width(), height())); | - | ||||||
| 216 | node->setFiltering(smooth() ? QSGTexture::Linear : QSGTexture::Nearest); | - | ||||||
| 217 | node->update(); | - | ||||||
| 218 | } executed 1072 times by 1 test: end of blockExecuted by:
| 1072 | ||||||
| 219 | - | |||||||
| 220 | - | |||||||
| 221 | - | |||||||
| Switch to Source code | Preprocessed file |