| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickspriteengine_p.h |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
| 24 | ** | - | ||||||
| 25 | ** GNU General Public License Usage | - | ||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
| 35 | ** | - | ||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||
| 37 | ** | - | ||||||
| 38 | ****************************************************************************/ | - | ||||||
| 39 | - | |||||||
| 40 | #ifndef QQUICKSPRITEENGINE_P_H | - | ||||||
| 41 | #define QQUICKSPRITEENGINE_P_H | - | ||||||
| 42 | - | |||||||
| 43 | // | - | ||||||
| 44 | // W A R N I N G | - | ||||||
| 45 | // ------------- | - | ||||||
| 46 | // | - | ||||||
| 47 | // This file is not part of the Qt API. It exists purely as an | - | ||||||
| 48 | // implementation detail. This header file may change from version to | - | ||||||
| 49 | // version without notice, or even be removed. | - | ||||||
| 50 | // | - | ||||||
| 51 | // We mean it. | - | ||||||
| 52 | // | - | ||||||
| 53 | - | |||||||
| 54 | #include <private/qtquickglobal_p.h> | - | ||||||
| 55 | - | |||||||
| 56 | QT_REQUIRE_CONFIG(quick_sprite); | - | ||||||
| 57 | - | |||||||
| 58 | #include <QObject> | - | ||||||
| 59 | #include <QVector> | - | ||||||
| 60 | #include <QTimer> | - | ||||||
| 61 | #include <QTime> | - | ||||||
| 62 | #include <QList> | - | ||||||
| 63 | #include <QQmlListProperty> | - | ||||||
| 64 | #include <QImage> | - | ||||||
| 65 | #include <QPair> | - | ||||||
| 66 | #include <QRandomGenerator> | - | ||||||
| 67 | #include <private/qquickpixmapcache_p.h> | - | ||||||
| 68 | #include <private/qtquickglobal_p.h> | - | ||||||
| 69 | - | |||||||
| 70 | QT_BEGIN_NAMESPACE | - | ||||||
| 71 | - | |||||||
| 72 | class QQuickSprite; | - | ||||||
| 73 | class Q_QUICK_PRIVATE_EXPORT QQuickStochasticState : public QObject //Currently for internal use only - Sprite and ParticleGroup | - | ||||||
| 74 | { | - | ||||||
| 75 | Q_OBJECT | - | ||||||
| 76 | Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) | - | ||||||
| 77 | Q_PROPERTY(int durationVariation READ durationVariation WRITE setDurationVariation NOTIFY durationVariationChanged) | - | ||||||
| 78 | //Note that manually advanced sprites need to query this variable and implement own behaviour for it | - | ||||||
| 79 | Q_PROPERTY(bool randomStart READ randomStart WRITE setRandomStart NOTIFY randomStartChanged) | - | ||||||
| 80 | Q_PROPERTY(QVariantMap to READ to WRITE setTo NOTIFY toChanged) | - | ||||||
| 81 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) | - | ||||||
| 82 | - | |||||||
| 83 | public: | - | ||||||
| 84 | QQuickStochasticState(QObject* parent = nullptr) | - | ||||||
| 85 | : QObject(parent) | - | ||||||
| 86 | { | - | ||||||
| 87 | } executed 118 times by 6 tests: end of blockExecuted by:
| 118 | ||||||
| 88 | - | |||||||
| 89 | int duration() const | - | ||||||
| 90 | { | - | ||||||
| 91 | return m_duration; executed 8 times by 2 tests: return m_duration;Executed by:
| 8 | ||||||
| 92 | } | - | ||||||
| 93 | - | |||||||
| 94 | QString name() const | - | ||||||
| 95 | { | - | ||||||
| 96 | return m_name; executed 1522 times by 4 tests: return m_name;Executed by:
| 1522 | ||||||
| 97 | } | - | ||||||
| 98 | - | |||||||
| 99 | QVariantMap to() const | - | ||||||
| 100 | { | - | ||||||
| 101 | return m_to; never executed: return m_to; | 0 | ||||||
| 102 | } | - | ||||||
| 103 | - | |||||||
| 104 | int durationVariation() const | - | ||||||
| 105 | { | - | ||||||
| 106 | return m_durationVariation; never executed: return m_durationVariation; | 0 | ||||||
| 107 | } | - | ||||||
| 108 | - | |||||||
| 109 | - | |||||||
| 110 | virtual int variedDuration() const | - | ||||||
| 111 | { | - | ||||||
| 112 | return qMax(qreal(0.0) , m_duration executed 21120 times by 1 test: return qMax(qreal(0.0) , m_duration + (m_durationVariation * QRandomGenerator::global()->bounded(2.0)) - m_durationVariation);Executed by:
| 21120 | ||||||
| 113 | + (m_durationVariation * QRandomGenerator::global()->bounded(2.0)) executed 21120 times by 1 test: return qMax(qreal(0.0) , m_duration + (m_durationVariation * QRandomGenerator::global()->bounded(2.0)) - m_durationVariation);Executed by:
| 21120 | ||||||
| 114 | - m_durationVariation); executed 21120 times by 1 test: return qMax(qreal(0.0) , m_duration + (m_durationVariation * QRandomGenerator::global()->bounded(2.0)) - m_durationVariation);Executed by:
| 21120 | ||||||
| 115 | } | - | ||||||
| 116 | - | |||||||
| 117 | bool randomStart() const | - | ||||||
| 118 | { | - | ||||||
| 119 | return m_randomStart; executed 5184 times by 5 tests: return m_randomStart;Executed by:
| 5184 | ||||||
| 120 | } | - | ||||||
| 121 | - | |||||||
| 122 | Q_SIGNALS: | - | ||||||
| 123 | void durationChanged(int arg); | - | ||||||
| 124 | - | |||||||
| 125 | void nameChanged(const QString &arg); | - | ||||||
| 126 | - | |||||||
| 127 | void toChanged(const QVariantMap &arg); | - | ||||||
| 128 | - | |||||||
| 129 | void durationVariationChanged(int arg); | - | ||||||
| 130 | - | |||||||
| 131 | void entered();//### Just playing around - don't expect full state API | - | ||||||
| 132 | - | |||||||
| 133 | void randomStartChanged(bool arg); | - | ||||||
| 134 | - | |||||||
| 135 | public Q_SLOTS: | - | ||||||
| 136 | void setDuration(int arg) | - | ||||||
| 137 | { | - | ||||||
| 138 | if (m_duration != arg) {
| 0-14 | ||||||
| 139 | m_duration = arg; | - | ||||||
| 140 | Q_EMIT durationChanged(arg); | - | ||||||
| 141 | } executed 14 times by 2 tests: end of blockExecuted by:
| 14 | ||||||
| 142 | } executed 14 times by 2 tests: end of blockExecuted by:
| 14 | ||||||
| 143 | - | |||||||
| 144 | void setName(const QString &arg) | - | ||||||
| 145 | { | - | ||||||
| 146 | if (m_name != arg) {
| 6-90 | ||||||
| 147 | m_name = arg; | - | ||||||
| 148 | Q_EMIT nameChanged(arg); | - | ||||||
| 149 | } executed 90 times by 5 tests: end of blockExecuted by:
| 90 | ||||||
| 150 | } executed 96 times by 5 tests: end of blockExecuted by:
| 96 | ||||||
| 151 | - | |||||||
| 152 | void setTo(const QVariantMap &arg) | - | ||||||
| 153 | { | - | ||||||
| 154 | if (m_to != arg) {
| 0-32 | ||||||
| 155 | m_to = arg; | - | ||||||
| 156 | Q_EMIT toChanged(arg); | - | ||||||
| 157 | } executed 32 times by 3 tests: end of blockExecuted by:
| 32 | ||||||
| 158 | } executed 32 times by 3 tests: end of blockExecuted by:
| 32 | ||||||
| 159 | - | |||||||
| 160 | void setDurationVariation(int arg) | - | ||||||
| 161 | { | - | ||||||
| 162 | if (m_durationVariation != arg) {
| 0-2 | ||||||
| 163 | m_durationVariation = arg; | - | ||||||
| 164 | Q_EMIT durationVariationChanged(arg); | - | ||||||
| 165 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 166 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 167 | - | |||||||
| 168 | void setRandomStart(bool arg) | - | ||||||
| 169 | { | - | ||||||
| 170 | if (m_randomStart != arg) {
| 0-2 | ||||||
| 171 | m_randomStart = arg; | - | ||||||
| 172 | Q_EMIT randomStartChanged(arg); | - | ||||||
| 173 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 174 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 175 | - | |||||||
| 176 | private: | - | ||||||
| 177 | QString m_name; | - | ||||||
| 178 | QVariantMap m_to; | - | ||||||
| 179 | int m_duration = -1; | - | ||||||
| 180 | int m_durationVariation = 0; | - | ||||||
| 181 | - | |||||||
| 182 | friend class QQuickStochasticEngine; | - | ||||||
| 183 | bool m_randomStart = false; | - | ||||||
| 184 | }; | - | ||||||
| 185 | - | |||||||
| 186 | class Q_QUICK_PRIVATE_EXPORT QQuickStochasticEngine : public QObject | - | ||||||
| 187 | { | - | ||||||
| 188 | Q_OBJECT | - | ||||||
| 189 | //TODO: Optimize single state case? | - | ||||||
| 190 | Q_PROPERTY(QString globalGoal READ globalGoal WRITE setGlobalGoal NOTIFY globalGoalChanged) | - | ||||||
| 191 | Q_PROPERTY(QQmlListProperty<QQuickStochasticState> states READ states) | - | ||||||
| 192 | public: | - | ||||||
| 193 | explicit QQuickStochasticEngine(QObject *parent = nullptr); | - | ||||||
| 194 | QQuickStochasticEngine(const QList<QQuickStochasticState*> &states, QObject *parent = nullptr); | - | ||||||
| 195 | ~QQuickStochasticEngine() override; | - | ||||||
| 196 | - | |||||||
| 197 | QQmlListProperty<QQuickStochasticState> states() | - | ||||||
| 198 | { | - | ||||||
| 199 | return QQmlListProperty<QQuickStochasticState>(this, m_states); never executed: return QQmlListProperty<QQuickStochasticState>(this, m_states); | 0 | ||||||
| 200 | } | - | ||||||
| 201 | - | |||||||
| 202 | QString globalGoal() const | - | ||||||
| 203 | { | - | ||||||
| 204 | return m_globalGoal; never executed: return m_globalGoal; | 0 | ||||||
| 205 | } | - | ||||||
| 206 | - | |||||||
| 207 | int count() const {return m_things.count();} executed 2464 times by 2 tests: return m_things.count();Executed by:
| 2464 | ||||||
| 208 | void setCount(int c); | - | ||||||
| 209 | - | |||||||
| 210 | void setGoal(int state, int sprite=0, bool jump=false); | - | ||||||
| 211 | void start(int index=0, int state=0); | - | ||||||
| 212 | virtual void restart(int index=0); | - | ||||||
| 213 | virtual void advance(int index=0);//Sends state to the next chosen state, unlike goal. | - | ||||||
| 214 | void stop(int index=0); | - | ||||||
| 215 | int curState(int index=0) const {return m_things[index];} executed 41868 times by 3 tests: return m_things[index];Executed by:
| 41868 | ||||||
| 216 | - | |||||||
| 217 | QQuickStochasticState* state(int idx) const {return m_states[idx];} executed 18 times by 2 tests: return m_states[idx];Executed by:
| 18 | ||||||
| 218 | int stateIndex(QQuickStochasticState* s) const {return m_states.indexOf(s);} never executed: return m_states.indexOf(s); | 0 | ||||||
| 219 | int stateIndex(const QString& s) const { | - | ||||||
| 220 | for (int i=0; i<m_states.count(); i++)
| 0-8 | ||||||
| 221 | if (m_states[i]->name() == s)
| 2-6 | ||||||
| 222 | return i; executed 6 times by 1 test: return i;Executed by:
| 6 | ||||||
| 223 | return -1; never executed: return -1; | 0 | ||||||
| 224 | } | - | ||||||
| 225 | - | |||||||
| 226 | int stateCount() {return m_states.count();} executed 4 times by 1 test: return m_states.count();Executed by:
| 4 | ||||||
| 227 | private: | - | ||||||
| 228 | Q_SIGNALS: | - | ||||||
| 229 | - | |||||||
| 230 | void globalGoalChanged(const QString &arg); | - | ||||||
| 231 | void stateChanged(int idx); | - | ||||||
| 232 | - | |||||||
| 233 | public Q_SLOTS: | - | ||||||
| 234 | void setGlobalGoal(const QString &arg) | - | ||||||
| 235 | { | - | ||||||
| 236 | if (m_globalGoal != arg) {
| 0 | ||||||
| 237 | m_globalGoal = arg; | - | ||||||
| 238 | Q_EMIT globalGoalChanged(arg); | - | ||||||
| 239 | } never executed: end of block | 0 | ||||||
| 240 | } never executed: end of block | 0 | ||||||
| 241 | - | |||||||
| 242 | uint updateSprites(uint time); | - | ||||||
| 243 | - | |||||||
| 244 | protected: | - | ||||||
| 245 | friend class QQuickParticleSystem; | - | ||||||
| 246 | void addToUpdateList(uint t, int idx); | - | ||||||
| 247 | int nextState(int curState, int idx=0); | - | ||||||
| 248 | int goalSeek(int curState, int idx, int dist=-1); | - | ||||||
| 249 | QList<QQuickStochasticState*> m_states; | - | ||||||
| 250 | //### Consider struct or class for the four data variables? | - | ||||||
| 251 | QVector<int> m_things;//int is the index in m_states of the current state | - | ||||||
| 252 | QVector<int> m_goals; | - | ||||||
| 253 | QVector<int> m_duration; | - | ||||||
| 254 | QVector<int> m_startTimes; | - | ||||||
| 255 | QVector<QPair<uint, QVector<int> > > m_stateUpdates;//### This could be done faster - priority queue? | - | ||||||
| 256 | - | |||||||
| 257 | QTime m_advanceTime; | - | ||||||
| 258 | uint m_timeOffset; | - | ||||||
| 259 | QString m_globalGoal; | - | ||||||
| 260 | int m_maxFrames; | - | ||||||
| 261 | int m_imageStateCount; | - | ||||||
| 262 | bool m_addAdvance; | - | ||||||
| 263 | }; | - | ||||||
| 264 | - | |||||||
| 265 | class Q_QUICK_PRIVATE_EXPORT QQuickSpriteEngine : public QQuickStochasticEngine | - | ||||||
| 266 | { | - | ||||||
| 267 | Q_OBJECT | - | ||||||
| 268 | Q_PROPERTY(QQmlListProperty<QQuickSprite> sprites READ sprites) | - | ||||||
| 269 | public: | - | ||||||
| 270 | explicit QQuickSpriteEngine(QObject *parent = nullptr); | - | ||||||
| 271 | QQuickSpriteEngine(const QList<QQuickSprite*> &sprites, QObject *parent = nullptr); | - | ||||||
| 272 | ~QQuickSpriteEngine() override; | - | ||||||
| 273 | QQmlListProperty<QQuickSprite> sprites() | - | ||||||
| 274 | { | - | ||||||
| 275 | return QQmlListProperty<QQuickSprite>(this, m_sprites); never executed: return QQmlListProperty<QQuickSprite>(this, m_sprites); | 0 | ||||||
| 276 | } | - | ||||||
| 277 | - | |||||||
| 278 | QQuickSprite* sprite(int sprite = 0) const; | - | ||||||
| 279 | int spriteState(int sprite = 0) const; | - | ||||||
| 280 | int spriteStart(int sprite = 0) const; | - | ||||||
| 281 | int spriteFrames(int sprite = 0) const; | - | ||||||
| 282 | int spriteDuration(int sprite = 0) const; | - | ||||||
| 283 | int spriteX(int sprite = 0) const; | - | ||||||
| 284 | int spriteY(int sprite = 0) const; | - | ||||||
| 285 | int spriteWidth(int sprite = 0) const; | - | ||||||
| 286 | int spriteHeight(int sprite = 0) const; | - | ||||||
| 287 | int spriteCount() const;//Like state count | - | ||||||
| 288 | int maxFrames() const; | - | ||||||
| 289 | - | |||||||
| 290 | void restart(int index=0) override; | - | ||||||
| 291 | void advance(int index=0) override; | - | ||||||
| 292 | - | |||||||
| 293 | //Similar API to QQuickPixmap for async loading convenience | - | ||||||
| 294 | bool isNull() const { return status() == QQuickPixmap::Null; } never executed: return status() == QQuickPixmap::Null; | 0 | ||||||
| 295 | bool isReady() const { return status() == QQuickPixmap::Ready; } never executed: return status() == QQuickPixmap::Ready; | 0 | ||||||
| 296 | bool isLoading() const { return status() == QQuickPixmap::Loading; } executed 28 times by 3 tests: return status() == QQuickPixmap::Loading;Executed by:
| 28 | ||||||
| 297 | bool isError() const { return status() == QQuickPixmap::Error; } never executed: return status() == QQuickPixmap::Error; | 0 | ||||||
| 298 | QQuickPixmap::Status status() const; //Composed status of all Sprites | - | ||||||
| 299 | void startAssemblingImage(); | - | ||||||
| 300 | QImage assembledImage(int maxSize = 2048); | - | ||||||
| 301 | - | |||||||
| 302 | private: | - | ||||||
| 303 | int pseudospriteProgress(int, int, int *rd = nullptr) const; | - | ||||||
| 304 | QList<QQuickSprite*> m_sprites; | - | ||||||
| 305 | bool m_startedImageAssembly; | - | ||||||
| 306 | bool m_loaded; | - | ||||||
| 307 | bool m_errorsPrinted; | - | ||||||
| 308 | }; | - | ||||||
| 309 | - | |||||||
| 310 | //Common use is to have your own list property which is transparently an engine | - | ||||||
| 311 | inline void spriteAppend(QQmlListProperty<QQuickSprite> *p, QQuickSprite* s) | - | ||||||
| 312 | { | - | ||||||
| 313 | reinterpret_cast<QList<QQuickSprite *> *>(p->data)->append(s); | - | ||||||
| 314 | p->object->metaObject()->invokeMethod(p->object, "createEngine"); | - | ||||||
| 315 | } executed 72 times by 4 tests: end of blockExecuted by:
| 72 | ||||||
| 316 | - | |||||||
| 317 | inline QQuickSprite* spriteAt(QQmlListProperty<QQuickSprite> *p, int idx) | - | ||||||
| 318 | { | - | ||||||
| 319 | return reinterpret_cast<QList<QQuickSprite *> *>(p->data)->at(idx); never executed: return reinterpret_cast<QList<QQuickSprite *> *>(p->data)->at(idx); | 0 | ||||||
| 320 | } | - | ||||||
| 321 | - | |||||||
| 322 | inline void spriteClear(QQmlListProperty<QQuickSprite> *p) | - | ||||||
| 323 | { | - | ||||||
| 324 | reinterpret_cast<QList<QQuickSprite *> *>(p->data)->clear(); | - | ||||||
| 325 | p->object->metaObject()->invokeMethod(p->object, "createEngine"); | - | ||||||
| 326 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||
| 327 | - | |||||||
| 328 | inline int spriteCount(QQmlListProperty<QQuickSprite> *p) | - | ||||||
| 329 | { | - | ||||||
| 330 | return reinterpret_cast<QList<QQuickSprite *> *>(p->data)->count(); never executed: return reinterpret_cast<QList<QQuickSprite *> *>(p->data)->count(); | 0 | ||||||
| 331 | } | - | ||||||
| 332 | - | |||||||
| 333 | QT_END_NAMESPACE | - | ||||||
| 334 | - | |||||||
| 335 | #endif // QQUICKSPRITEENGINE_P_H | - | ||||||
| Source code | Switch to Preprocessed file |