| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickitemviewtransition.cpp |
| 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 | #include "qquickitemviewtransition_p.h" | - | ||||||||||||||||||
| 41 | #include <QtQuick/qquickitem.h> | - | ||||||||||||||||||
| 42 | #include <QtQuick/private/qquicktransition_p.h> | - | ||||||||||||||||||
| 43 | #include <QtQuick/private/qquicktransitionmanager_p_p.h> | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | static QList<int> qquickitemviewtransition_emptyIndexes = QList<int>(); | - | ||||||||||||||||||
| 48 | static QList<QObject *> qquickitemviewtransition_emptyTargets = QList<QObject *>(); | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | - | |||||||||||||||||||
| 51 | class QQuickItemViewTransitionJob : public QQuickTransitionManager | - | ||||||||||||||||||
| 52 | { | - | ||||||||||||||||||
| 53 | public: | - | ||||||||||||||||||
| 54 | QQuickItemViewTransitionJob(); | - | ||||||||||||||||||
| 55 | ~QQuickItemViewTransitionJob(); | - | ||||||||||||||||||
| 56 | - | |||||||||||||||||||
| 57 | void startTransition(QQuickItemViewTransitionableItem *item, int index, QQuickItemViewTransitioner *transitioner, QQuickItemViewTransitioner::TransitionType type, const QPointF &to, bool isTargetItem); | - | ||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | QQuickItemViewTransitioner *m_transitioner; | - | ||||||||||||||||||
| 60 | QQuickItemViewTransitionableItem *m_item; | - | ||||||||||||||||||
| 61 | QPointF m_toPos; | - | ||||||||||||||||||
| 62 | QQuickItemViewTransitioner::TransitionType m_type; | - | ||||||||||||||||||
| 63 | bool m_isTarget; | - | ||||||||||||||||||
| 64 | bool *m_wasDeleted; | - | ||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | protected: | - | ||||||||||||||||||
| 67 | void finished() override; | - | ||||||||||||||||||
| 68 | }; | - | ||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | QQuickItemViewTransitionJob::QQuickItemViewTransitionJob() | - | ||||||||||||||||||
| 72 | : m_transitioner(nullptr) | - | ||||||||||||||||||
| 73 | , m_item(nullptr) | - | ||||||||||||||||||
| 74 | , m_type(QQuickItemViewTransitioner::NoTransition) | - | ||||||||||||||||||
| 75 | , m_isTarget(false) | - | ||||||||||||||||||
| 76 | , m_wasDeleted(nullptr) | - | ||||||||||||||||||
| 77 | { | - | ||||||||||||||||||
| 78 | } executed 10412 times by 4 tests: end of blockExecuted by:
| 10412 | ||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | QQuickItemViewTransitionJob::~QQuickItemViewTransitionJob() | - | ||||||||||||||||||
| 81 | { | - | ||||||||||||||||||
| 82 | if (m_wasDeleted)
| 86-10326 | ||||||||||||||||||
| 83 | *m_wasDeleted = true; executed 86 times by 2 tests: *m_wasDeleted = true;Executed by:
| 86 | ||||||||||||||||||
| 84 | if (m_transitioner)
| 466-9946 | ||||||||||||||||||
| 85 | m_transitioner->runningJobs.remove(this); executed 466 times by 3 tests: m_transitioner->runningJobs.remove(this);Executed by:
| 466 | ||||||||||||||||||
| 86 | } executed 10412 times by 4 tests: end of blockExecuted by:
| 10412 | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | void QQuickItemViewTransitionJob::startTransition(QQuickItemViewTransitionableItem *item, int index, QQuickItemViewTransitioner *transitioner, QQuickItemViewTransitioner::TransitionType type, const QPointF &to, bool isTargetItem) | - | ||||||||||||||||||
| 89 | { | - | ||||||||||||||||||
| 90 | if (type == QQuickItemViewTransitioner::NoTransition)
| 0-10556 | ||||||||||||||||||
| 91 | return; never executed: return; | 0 | ||||||||||||||||||
| 92 | if (!item) {
| 0-10556 | ||||||||||||||||||
| 93 | qWarning("startTransition(): invalid item"); | - | ||||||||||||||||||
| 94 | return; never executed: return; | 0 | ||||||||||||||||||
| 95 | } | - | ||||||||||||||||||
| 96 | if (!transitioner) {
| 0-10556 | ||||||||||||||||||
| 97 | qWarning("startTransition(): invalid transitioner"); | - | ||||||||||||||||||
| 98 | return; never executed: return; | 0 | ||||||||||||||||||
| 99 | } | - | ||||||||||||||||||
| 100 | - | |||||||||||||||||||
| 101 | QQuickTransition *trans = transitioner->transitionObject(type, isTargetItem); | - | ||||||||||||||||||
| 102 | if (!trans) {
| 0-10556 | ||||||||||||||||||
| 103 | qWarning("QQuickItemView: invalid view transition!"); | - | ||||||||||||||||||
| 104 | return; never executed: return; | 0 | ||||||||||||||||||
| 105 | } | - | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | m_item = item; | - | ||||||||||||||||||
| 108 | m_transitioner = transitioner; | - | ||||||||||||||||||
| 109 | m_toPos = to; | - | ||||||||||||||||||
| 110 | m_type = type; | - | ||||||||||||||||||
| 111 | m_isTarget = isTargetItem; | - | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | QQuickViewTransitionAttached *attached = | - | ||||||||||||||||||
| 114 | static_cast<QQuickViewTransitionAttached*>(qmlAttachedPropertiesObject<QQuickViewTransitionAttached>(trans)); | - | ||||||||||||||||||
| 115 | if (attached) {
| 0-10556 | ||||||||||||||||||
| 116 | attached->m_index = index; | - | ||||||||||||||||||
| 117 | attached->m_item = item->item; | - | ||||||||||||||||||
| 118 | attached->m_destination = to; | - | ||||||||||||||||||
| 119 | attached->m_targetIndexes = m_transitioner->targetIndexes(type); | - | ||||||||||||||||||
| 120 | attached->m_targetItems = m_transitioner->targetItems(type); | - | ||||||||||||||||||
| 121 | emit attached->indexChanged(); | - | ||||||||||||||||||
| 122 | emit attached->itemChanged(); | - | ||||||||||||||||||
| 123 | emit attached->destinationChanged(); | - | ||||||||||||||||||
| 124 | emit attached->targetIndexesChanged(); | - | ||||||||||||||||||
| 125 | emit attached->targetItemsChanged(); | - | ||||||||||||||||||
| 126 | } executed 10556 times by 4 tests: end of blockExecuted by:
| 10556 | ||||||||||||||||||
| 127 | - | |||||||||||||||||||
| 128 | QQuickStateOperation::ActionList actions; | - | ||||||||||||||||||
| 129 | actions << QQuickStateAction(item->item, QLatin1String("x"), QVariant(to.x())); | - | ||||||||||||||||||
| 130 | actions << QQuickStateAction(item->item, QLatin1String("y"), QVariant(to.y())); | - | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | m_transitioner->runningJobs << this; | - | ||||||||||||||||||
| 133 | QQuickTransitionManager::transition(actions, trans, item->item); | - | ||||||||||||||||||
| 134 | } executed 10556 times by 4 tests: end of blockExecuted by:
| 10556 | ||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | void QQuickItemViewTransitionJob::finished() | - | ||||||||||||||||||
| 137 | { | - | ||||||||||||||||||
| 138 | QQuickTransitionManager::finished(); | - | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | if (m_transitioner) {
| 0-8832 | ||||||||||||||||||
| 141 | bool deleted = false; | - | ||||||||||||||||||
| 142 | m_wasDeleted = &deleted; | - | ||||||||||||||||||
| 143 | m_transitioner->finishedTransition(this, m_item); | - | ||||||||||||||||||
| 144 | if (deleted)
| 86-8746 | ||||||||||||||||||
| 145 | return; executed 86 times by 2 tests: return;Executed by:
| 86 | ||||||||||||||||||
| 146 | m_wasDeleted = nullptr; | - | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | m_transitioner = nullptr; | - | ||||||||||||||||||
| 149 | } executed 8746 times by 4 tests: end of blockExecuted by:
| 8746 | ||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | m_item = nullptr; | - | ||||||||||||||||||
| 152 | m_toPos.setX(0); | - | ||||||||||||||||||
| 153 | m_toPos.setY(0); | - | ||||||||||||||||||
| 154 | m_type = QQuickItemViewTransitioner::NoTransition; | - | ||||||||||||||||||
| 155 | m_isTarget = false; | - | ||||||||||||||||||
| 156 | } executed 8746 times by 4 tests: end of blockExecuted by:
| 8746 | ||||||||||||||||||
| 157 | - | |||||||||||||||||||
| 158 | - | |||||||||||||||||||
| 159 | QQuickItemViewTransitioner::QQuickItemViewTransitioner() | - | ||||||||||||||||||
| 160 | : populateTransition(nullptr) | - | ||||||||||||||||||
| 161 | , addTransition(nullptr), addDisplacedTransition(nullptr) | - | ||||||||||||||||||
| 162 | , moveTransition(nullptr), moveDisplacedTransition(nullptr) | - | ||||||||||||||||||
| 163 | , removeTransition(nullptr), removeDisplacedTransition(nullptr) | - | ||||||||||||||||||
| 164 | , displacedTransition(nullptr) | - | ||||||||||||||||||
| 165 | , changeListener(nullptr) | - | ||||||||||||||||||
| 166 | , usePopulateTransition(false) | - | ||||||||||||||||||
| 167 | { | - | ||||||||||||||||||
| 168 | } executed 1474 times by 5 tests: end of blockExecuted by:
| 1474 | ||||||||||||||||||
| 169 | - | |||||||||||||||||||
| 170 | QQuickItemViewTransitioner::~QQuickItemViewTransitioner() | - | ||||||||||||||||||
| 171 | { | - | ||||||||||||||||||
| 172 | typedef QSet<QQuickItemViewTransitionJob *>::iterator JobIt; | - | ||||||||||||||||||
| 173 | - | |||||||||||||||||||
| 174 | for (JobIt it = runningJobs.begin(), end = runningJobs.end(); it != end; ++it)
| 1200-1474 | ||||||||||||||||||
| 175 | (*it)->m_transitioner = nullptr; executed 1200 times by 1 test: (*it)->m_transitioner = nullptr;Executed by:
| 1200 | ||||||||||||||||||
| 176 | } executed 1474 times by 5 tests: end of blockExecuted by:
| 1474 | ||||||||||||||||||
| 177 | - | |||||||||||||||||||
| 178 | bool QQuickItemViewTransitioner::canTransition(QQuickItemViewTransitioner::TransitionType type, bool asTarget) const | - | ||||||||||||||||||
| 179 | { | - | ||||||||||||||||||
| 180 | if (!asTarget
| 8610-19396 | ||||||||||||||||||
| 181 | && type != NoTransition && type != PopulateTransition
| 0-8610 | ||||||||||||||||||
| 182 | && displacedTransition && displacedTransition->enabled()) {
| 96-3700 | ||||||||||||||||||
| 183 | return true; executed 3700 times by 4 tests: return true;Executed by:
| 3700 | ||||||||||||||||||
| 184 | } | - | ||||||||||||||||||
| 185 | - | |||||||||||||||||||
| 186 | switch (type) { | - | ||||||||||||||||||
| 187 | case NoTransition: never executed: case NoTransition: | 0 | ||||||||||||||||||
| 188 | break; never executed: break; | 0 | ||||||||||||||||||
| 189 | case PopulateTransition: executed 14454 times by 5 tests: case PopulateTransition:Executed by:
| 14454 | ||||||||||||||||||
| 190 | return usePopulateTransition executed 14454 times by 5 tests: return usePopulateTransition && populateTransition && populateTransition->enabled();Executed by:
| 14454 | ||||||||||||||||||
| 191 | && populateTransition && populateTransition->enabled(); executed 14454 times by 5 tests: return usePopulateTransition && populateTransition && populateTransition->enabled();Executed by:
| 14454 | ||||||||||||||||||
| 192 | case AddTransition: executed 4942 times by 4 tests: case AddTransition:Executed by:
| 4942 | ||||||||||||||||||
| 193 | if (asTarget)
| 1398-3544 | ||||||||||||||||||
| 194 | return addTransition && addTransition->enabled(); executed 3544 times by 4 tests: return addTransition && addTransition->enabled();Executed by:
| 3544 | ||||||||||||||||||
| 195 | else | - | ||||||||||||||||||
| 196 | return addDisplacedTransition && addDisplacedTransition->enabled(); executed 1398 times by 3 tests: return addDisplacedTransition && addDisplacedTransition->enabled();Executed by:
| 1398 | ||||||||||||||||||
| 197 | case MoveTransition: executed 3014 times by 5 tests: case MoveTransition:Executed by:
| 3014 | ||||||||||||||||||
| 198 | if (asTarget)
| 842-2172 | ||||||||||||||||||
| 199 | return moveTransition && moveTransition->enabled(); executed 842 times by 3 tests: return moveTransition && moveTransition->enabled();Executed by:
| 842 | ||||||||||||||||||
| 200 | else | - | ||||||||||||||||||
| 201 | return moveDisplacedTransition && moveDisplacedTransition->enabled(); executed 2172 times by 4 tests: return moveDisplacedTransition && moveDisplacedTransition->enabled();Executed by:
| 2172 | ||||||||||||||||||
| 202 | case RemoveTransition: executed 1896 times by 4 tests: case RemoveTransition:Executed by:
| 1896 | ||||||||||||||||||
| 203 | if (asTarget)
| 556-1340 | ||||||||||||||||||
| 204 | return removeTransition && removeTransition->enabled(); executed 556 times by 3 tests: return removeTransition && removeTransition->enabled();Executed by:
| 556 | ||||||||||||||||||
| 205 | else | - | ||||||||||||||||||
| 206 | return removeDisplacedTransition && removeDisplacedTransition->enabled(); executed 1340 times by 3 tests: return removeDisplacedTransition && removeDisplacedTransition->enabled();Executed by:
| 1340 | ||||||||||||||||||
| 207 | } | - | ||||||||||||||||||
| 208 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 209 | } | - | ||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | void QQuickItemViewTransitioner::transitionNextReposition(QQuickItemViewTransitionableItem *item, QQuickItemViewTransitioner::TransitionType type, bool isTarget) | - | ||||||||||||||||||
| 212 | { | - | ||||||||||||||||||
| 213 | item->setNextTransition(type, isTarget); | - | ||||||||||||||||||
| 214 | } executed 15080 times by 5 tests: end of blockExecuted by:
| 15080 | ||||||||||||||||||
| 215 | - | |||||||||||||||||||
| 216 | void QQuickItemViewTransitioner::addToTargetLists(QQuickItemViewTransitioner::TransitionType type, QQuickItemViewTransitionableItem *item, int index) | - | ||||||||||||||||||
| 217 | { | - | ||||||||||||||||||
| 218 | switch (type) { | - | ||||||||||||||||||
| 219 | case NoTransition: never executed: case NoTransition: | 0 | ||||||||||||||||||
| 220 | break; never executed: break; | 0 | ||||||||||||||||||
| 221 | case PopulateTransition: executed 1016 times by 4 tests: case PopulateTransition:Executed by:
| 1016 | ||||||||||||||||||
| 222 | case AddTransition: executed 3544 times by 4 tests: case AddTransition:Executed by:
| 3544 | ||||||||||||||||||
| 223 | addTransitionIndexes << index; | - | ||||||||||||||||||
| 224 | addTransitionTargets << item->item; | - | ||||||||||||||||||
| 225 | break; executed 4560 times by 5 tests: break;Executed by:
| 4560 | ||||||||||||||||||
| 226 | case MoveTransition: executed 340 times by 2 tests: case MoveTransition:Executed by:
| 340 | ||||||||||||||||||
| 227 | moveTransitionIndexes << index; | - | ||||||||||||||||||
| 228 | moveTransitionTargets << item->item; | - | ||||||||||||||||||
| 229 | break; executed 340 times by 2 tests: break;Executed by:
| 340 | ||||||||||||||||||
| 230 | case RemoveTransition: executed 120 times by 2 tests: case RemoveTransition:Executed by:
| 120 | ||||||||||||||||||
| 231 | removeTransitionIndexes << index; | - | ||||||||||||||||||
| 232 | removeTransitionTargets << item->item; | - | ||||||||||||||||||
| 233 | break; executed 120 times by 2 tests: break;Executed by:
| 120 | ||||||||||||||||||
| 234 | } | - | ||||||||||||||||||
| 235 | } executed 5020 times by 5 tests: end of blockExecuted by:
| 5020 | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | void QQuickItemViewTransitioner::resetTargetLists() | - | ||||||||||||||||||
| 238 | { | - | ||||||||||||||||||
| 239 | addTransitionIndexes.clear(); | - | ||||||||||||||||||
| 240 | addTransitionTargets.clear(); | - | ||||||||||||||||||
| 241 | - | |||||||||||||||||||
| 242 | removeTransitionIndexes.clear(); | - | ||||||||||||||||||
| 243 | removeTransitionTargets.clear(); | - | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | moveTransitionIndexes.clear(); | - | ||||||||||||||||||
| 246 | moveTransitionTargets.clear(); | - | ||||||||||||||||||
| 247 | } executed 2304 times by 5 tests: end of blockExecuted by:
| 2304 | ||||||||||||||||||
| 248 | - | |||||||||||||||||||
| 249 | QQuickTransition *QQuickItemViewTransitioner::transitionObject(QQuickItemViewTransitioner::TransitionType type, bool asTarget) const | - | ||||||||||||||||||
| 250 | { | - | ||||||||||||||||||
| 251 | if (type == QQuickItemViewTransitioner::NoTransition)
| 0-10556 | ||||||||||||||||||
| 252 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||
| 253 | - | |||||||||||||||||||
| 254 | if (type == PopulateTransition)
| 1016-9540 | ||||||||||||||||||
| 255 | asTarget = true; // no separate displaced transition executed 1016 times by 4 tests: asTarget = true;Executed by:
| 1016 | ||||||||||||||||||
| 256 | - | |||||||||||||||||||
| 257 | QQuickTransition *trans = nullptr; | - | ||||||||||||||||||
| 258 | switch (type) { | - | ||||||||||||||||||
| 259 | case NoTransition: never executed: case NoTransition: | 0 | ||||||||||||||||||
| 260 | break; never executed: break; | 0 | ||||||||||||||||||
| 261 | case PopulateTransition: executed 1016 times by 4 tests: case PopulateTransition:Executed by:
| 1016 | ||||||||||||||||||
| 262 | trans = populateTransition; | - | ||||||||||||||||||
| 263 | break; executed 1016 times by 4 tests: break;Executed by:
| 1016 | ||||||||||||||||||
| 264 | case AddTransition: executed 6182 times by 3 tests: case AddTransition:Executed by:
| 6182 | ||||||||||||||||||
| 265 | trans = asTarget ? addTransition : addDisplacedTransition;
| 2502-3680 | ||||||||||||||||||
| 266 | break; executed 6182 times by 3 tests: break;Executed by:
| 6182 | ||||||||||||||||||
| 267 | case MoveTransition: executed 2438 times by 3 tests: case MoveTransition:Executed by:
| 2438 | ||||||||||||||||||
| 268 | trans = asTarget ? moveTransition : moveDisplacedTransition;
| 328-2110 | ||||||||||||||||||
| 269 | break; executed 2438 times by 3 tests: break;Executed by:
| 2438 | ||||||||||||||||||
| 270 | case RemoveTransition: executed 920 times by 2 tests: case RemoveTransition:Executed by:
| 920 | ||||||||||||||||||
| 271 | trans = asTarget ? removeTransition : removeDisplacedTransition;
| 90-830 | ||||||||||||||||||
| 272 | break; executed 920 times by 2 tests: break;Executed by:
| 920 | ||||||||||||||||||
| 273 | } | - | ||||||||||||||||||
| 274 | - | |||||||||||||||||||
| 275 | if (!asTarget && (!trans || !trans->enabled()))
| 244-6620 | ||||||||||||||||||
| 276 | trans = displacedTransition; executed 3340 times by 3 tests: trans = displacedTransition;Executed by:
| 3340 | ||||||||||||||||||
| 277 | if (trans && trans->enabled())
| 0-10556 | ||||||||||||||||||
| 278 | return trans; executed 10556 times by 4 tests: return trans;Executed by:
| 10556 | ||||||||||||||||||
| 279 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||
| 280 | } | - | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | const QList<int> &QQuickItemViewTransitioner::targetIndexes(QQuickItemViewTransitioner::TransitionType type) const | - | ||||||||||||||||||
| 283 | { | - | ||||||||||||||||||
| 284 | switch (type) { | - | ||||||||||||||||||
| 285 | case NoTransition: never executed: case NoTransition: | 0 | ||||||||||||||||||
| 286 | break; never executed: break; | 0 | ||||||||||||||||||
| 287 | case PopulateTransition: executed 1016 times by 4 tests: case PopulateTransition:Executed by:
| 1016 | ||||||||||||||||||
| 288 | case AddTransition: executed 6182 times by 3 tests: case AddTransition:Executed by:
| 6182 | ||||||||||||||||||
| 289 | return addTransitionIndexes; executed 7198 times by 4 tests: return addTransitionIndexes;Executed by:
| 7198 | ||||||||||||||||||
| 290 | case MoveTransition: executed 2438 times by 3 tests: case MoveTransition:Executed by:
| 2438 | ||||||||||||||||||
| 291 | return moveTransitionIndexes; executed 2438 times by 3 tests: return moveTransitionIndexes;Executed by:
| 2438 | ||||||||||||||||||
| 292 | case RemoveTransition: executed 920 times by 2 tests: case RemoveTransition:Executed by:
| 920 | ||||||||||||||||||
| 293 | return removeTransitionIndexes; executed 920 times by 2 tests: return removeTransitionIndexes;Executed by:
| 920 | ||||||||||||||||||
| 294 | } | - | ||||||||||||||||||
| 295 | - | |||||||||||||||||||
| 296 | return qquickitemviewtransition_emptyIndexes; never executed: return qquickitemviewtransition_emptyIndexes; | 0 | ||||||||||||||||||
| 297 | } | - | ||||||||||||||||||
| 298 | - | |||||||||||||||||||
| 299 | const QList<QObject *> &QQuickItemViewTransitioner::targetItems(QQuickItemViewTransitioner::TransitionType type) const | - | ||||||||||||||||||
| 300 | { | - | ||||||||||||||||||
| 301 | switch (type) { | - | ||||||||||||||||||
| 302 | case NoTransition: never executed: case NoTransition: | 0 | ||||||||||||||||||
| 303 | break; never executed: break; | 0 | ||||||||||||||||||
| 304 | case PopulateTransition: executed 1016 times by 4 tests: case PopulateTransition:Executed by:
| 1016 | ||||||||||||||||||
| 305 | case AddTransition: executed 6182 times by 3 tests: case AddTransition:Executed by:
| 6182 | ||||||||||||||||||
| 306 | return addTransitionTargets; executed 7198 times by 4 tests: return addTransitionTargets;Executed by:
| 7198 | ||||||||||||||||||
| 307 | case MoveTransition: executed 2438 times by 3 tests: case MoveTransition:Executed by:
| 2438 | ||||||||||||||||||
| 308 | return moveTransitionTargets; executed 2438 times by 3 tests: return moveTransitionTargets;Executed by:
| 2438 | ||||||||||||||||||
| 309 | case RemoveTransition: executed 920 times by 2 tests: case RemoveTransition:Executed by:
| 920 | ||||||||||||||||||
| 310 | return removeTransitionTargets; executed 920 times by 2 tests: return removeTransitionTargets;Executed by:
| 920 | ||||||||||||||||||
| 311 | } | - | ||||||||||||||||||
| 312 | - | |||||||||||||||||||
| 313 | return qquickitemviewtransition_emptyTargets; never executed: return qquickitemviewtransition_emptyTargets; | 0 | ||||||||||||||||||
| 314 | } | - | ||||||||||||||||||
| 315 | - | |||||||||||||||||||
| 316 | void QQuickItemViewTransitioner::finishedTransition(QQuickItemViewTransitionJob *job, QQuickItemViewTransitionableItem *item) | - | ||||||||||||||||||
| 317 | { | - | ||||||||||||||||||
| 318 | if (!runningJobs.contains(job))
| 0-8832 | ||||||||||||||||||
| 319 | return; never executed: return; | 0 | ||||||||||||||||||
| 320 | runningJobs.remove(job); | - | ||||||||||||||||||
| 321 | if (item) {
| 0-8832 | ||||||||||||||||||
| 322 | item->finishedTransition(); | - | ||||||||||||||||||
| 323 | if (changeListener)
| 4372-4460 | ||||||||||||||||||
| 324 | changeListener->viewItemTransitionFinished(item); executed 4372 times by 3 tests: changeListener->viewItemTransitionFinished(item);Executed by:
| 4372 | ||||||||||||||||||
| 325 | } executed 8832 times by 4 tests: end of blockExecuted by:
| 8832 | ||||||||||||||||||
| 326 | } executed 8832 times by 4 tests: end of blockExecuted by:
| 8832 | ||||||||||||||||||
| 327 | - | |||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | QQuickItemViewTransitionableItem::QQuickItemViewTransitionableItem(QQuickItem *i) | - | ||||||||||||||||||
| 330 | : item(i) | - | ||||||||||||||||||
| 331 | , transition(nullptr) | - | ||||||||||||||||||
| 332 | , nextTransitionType(QQuickItemViewTransitioner::NoTransition) | - | ||||||||||||||||||
| 333 | , isTransitionTarget(false) | - | ||||||||||||||||||
| 334 | , nextTransitionToSet(false) | - | ||||||||||||||||||
| 335 | , nextTransitionFromSet(false) | - | ||||||||||||||||||
| 336 | , lastMovedToSet(false) | - | ||||||||||||||||||
| 337 | , prepared(false) | - | ||||||||||||||||||
| 338 | { | - | ||||||||||||||||||
| 339 | } executed 10162 times by 5 tests: end of blockExecuted by:
| 10162 | ||||||||||||||||||
| 340 | - | |||||||||||||||||||
| 341 | QQuickItemViewTransitionableItem::~QQuickItemViewTransitionableItem() | - | ||||||||||||||||||
| 342 | { | - | ||||||||||||||||||
| 343 | delete transition; | - | ||||||||||||||||||
| 344 | } executed 10162 times by 5 tests: end of blockExecuted by:
| 10162 | ||||||||||||||||||
| 345 | - | |||||||||||||||||||
| 346 | qreal QQuickItemViewTransitionableItem::itemX() const | - | ||||||||||||||||||
| 347 | { | - | ||||||||||||||||||
| 348 | if (nextTransitionType != QQuickItemViewTransitioner::NoTransition)
| 128-15900 | ||||||||||||||||||
| 349 | return nextTransitionToSet ? nextTransitionTo.x() : item->x(); executed 15900 times by 5 tests: return nextTransitionToSet ? nextTransitionTo.x() : item->x();Executed by:
| 15900 | ||||||||||||||||||
| 350 | else if (transition && transition->isRunning())
| 10-90 | ||||||||||||||||||
| 351 | return transition->m_toPos.x(); executed 80 times by 2 tests: return transition->m_toPos.x();Executed by:
| 80 | ||||||||||||||||||
| 352 | else | - | ||||||||||||||||||
| 353 | return item->x(); executed 48 times by 1 test: return item->x();Executed by:
| 48 | ||||||||||||||||||
| 354 | } | - | ||||||||||||||||||
| 355 | - | |||||||||||||||||||
| 356 | qreal QQuickItemViewTransitionableItem::itemY() const | - | ||||||||||||||||||
| 357 | { | - | ||||||||||||||||||
| 358 | // If item is transitioning to some pos, return that dest pos. | - | ||||||||||||||||||
| 359 | // If item was redirected to some new pos before the current transition finished, | - | ||||||||||||||||||
| 360 | // return that new pos. | - | ||||||||||||||||||
| 361 | if (nextTransitionType != QQuickItemViewTransitioner::NoTransition)
| 2197-28756 | ||||||||||||||||||
| 362 | return nextTransitionToSet ? nextTransitionTo.y() : item->y(); executed 28756 times by 5 tests: return nextTransitionToSet ? nextTransitionTo.y() : item->y();Executed by:
| 28756 | ||||||||||||||||||
| 363 | else if (transition && transition->isRunning())
| 92-1542 | ||||||||||||||||||
| 364 | return transition->m_toPos.y(); executed 1450 times by 2 tests: return transition->m_toPos.y();Executed by:
| 1450 | ||||||||||||||||||
| 365 | else | - | ||||||||||||||||||
| 366 | return item->y(); executed 747 times by 2 tests: return item->y();Executed by:
| 747 | ||||||||||||||||||
| 367 | } | - | ||||||||||||||||||
| 368 | - | |||||||||||||||||||
| 369 | void QQuickItemViewTransitionableItem::moveTo(const QPointF &pos, bool immediate) | - | ||||||||||||||||||
| 370 | { | - | ||||||||||||||||||
| 371 | if (!nextTransitionFromSet && nextTransitionType != QQuickItemViewTransitioner::NoTransition) {
| 26-10166 | ||||||||||||||||||
| 372 | nextTransitionFrom = item->position(); | - | ||||||||||||||||||
| 373 | nextTransitionFromSet = true; | - | ||||||||||||||||||
| 374 | } executed 10140 times by 5 tests: end of blockExecuted by:
| 10140 | ||||||||||||||||||
| 375 | - | |||||||||||||||||||
| 376 | lastMovedTo = pos; | - | ||||||||||||||||||
| 377 | lastMovedToSet = true; | - | ||||||||||||||||||
| 378 | - | |||||||||||||||||||
| 379 | if (immediate || !transitionScheduledOrRunning()) {
| 0-14978 | ||||||||||||||||||
| 380 | if (immediate)
| 0-12 | ||||||||||||||||||
| 381 | stopTransition(); executed 12 times by 1 test: stopTransition();Executed by:
| 12 | ||||||||||||||||||
| 382 | item->setPosition(pos); | - | ||||||||||||||||||
| 383 | } else { executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 384 | nextTransitionTo = pos; | - | ||||||||||||||||||
| 385 | nextTransitionToSet = true; | - | ||||||||||||||||||
| 386 | } executed 14978 times by 5 tests: end of blockExecuted by:
| 14978 | ||||||||||||||||||
| 387 | } | - | ||||||||||||||||||
| 388 | - | |||||||||||||||||||
| 389 | bool QQuickItemViewTransitionableItem::transitionScheduledOrRunning() const | - | ||||||||||||||||||
| 390 | { | - | ||||||||||||||||||
| 391 | return (transition && transition->isRunning()) executed 15988 times by 5 tests: return (transition && transition->isRunning()) || nextTransitionType != QQuickItemViewTransitioner::NoTransition;Executed by:
| 15988 | ||||||||||||||||||
| 392 | || nextTransitionType != QQuickItemViewTransitioner::NoTransition; executed 15988 times by 5 tests: return (transition && transition->isRunning()) || nextTransitionType != QQuickItemViewTransitioner::NoTransition;Executed by:
| 15988 | ||||||||||||||||||
| 393 | } | - | ||||||||||||||||||
| 394 | - | |||||||||||||||||||
| 395 | bool QQuickItemViewTransitionableItem::transitionRunning() const | - | ||||||||||||||||||
| 396 | { | - | ||||||||||||||||||
| 397 | return (transition && transition->isRunning()); executed 9908 times by 4 tests: return (transition && transition->isRunning());Executed by:
| 9908 | ||||||||||||||||||
| 398 | } | - | ||||||||||||||||||
| 399 | - | |||||||||||||||||||
| 400 | bool QQuickItemViewTransitionableItem::isPendingRemoval() const | - | ||||||||||||||||||
| 401 | { | - | ||||||||||||||||||
| 402 | if (nextTransitionType == QQuickItemViewTransitioner::RemoveTransition)
| 12-50 | ||||||||||||||||||
| 403 | return isTransitionTarget; executed 50 times by 2 tests: return isTransitionTarget;Executed by:
| 50 | ||||||||||||||||||
| 404 | if (transition && transition->isRunning() && transition->m_type == QQuickItemViewTransitioner::RemoveTransition)
| 0-10 | ||||||||||||||||||
| 405 | return transition->m_isTarget; never executed: return transition->m_isTarget; | 0 | ||||||||||||||||||
| 406 | return false; executed 12 times by 1 test: return false;Executed by:
| 12 | ||||||||||||||||||
| 407 | } | - | ||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | bool QQuickItemViewTransitionableItem::prepareTransition(QQuickItemViewTransitioner *transitioner, int index, const QRectF &viewBounds) | - | ||||||||||||||||||
| 410 | { | - | ||||||||||||||||||
| 411 | if (nextTransitionType == QQuickItemViewTransitioner::NoTransition)
| 18-14110 | ||||||||||||||||||
| 412 | return false; executed 18 times by 2 tests: return false;Executed by:
| 18 | ||||||||||||||||||
| 413 | - | |||||||||||||||||||
| 414 | if (isTransitionTarget) {
| 5122-8988 | ||||||||||||||||||
| 415 | // If item is not already moving somewhere, set it to not move anywhere. | - | ||||||||||||||||||
| 416 | // This ensures that removed targets don't transition to the default (0,0) and that | - | ||||||||||||||||||
| 417 | // items set for other transition types only transition if they actually move somewhere. | - | ||||||||||||||||||
| 418 | if (!nextTransitionToSet)
| 344-4778 | ||||||||||||||||||
| 419 | moveTo(item->position()); executed 344 times by 4 tests: moveTo(item->position());Executed by:
| 344 | ||||||||||||||||||
| 420 | } else { executed 5122 times by 5 tests: end of blockExecuted by:
| 5122 | ||||||||||||||||||
| 421 | // don't start displaced transitions that don't move anywhere | - | ||||||||||||||||||
| 422 | if (!nextTransitionToSet || (nextTransitionFromSet && nextTransitionFrom == nextTransitionTo)) {
| 0-8260 | ||||||||||||||||||
| 423 | clearCurrentScheduledTransition(); | - | ||||||||||||||||||
| 424 | return false; executed 1538 times by 4 tests: return false;Executed by:
| 1538 | ||||||||||||||||||
| 425 | } | - | ||||||||||||||||||
| 426 | } executed 7450 times by 3 tests: end of blockExecuted by:
| 7450 | ||||||||||||||||||
| 427 | - | |||||||||||||||||||
| 428 | bool doTransition = false; | - | ||||||||||||||||||
| 429 | - | |||||||||||||||||||
| 430 | // For move transitions (both target and displaced) and displaced transitions of other | - | ||||||||||||||||||
| 431 | // types, only run the transition if the item is actually moving to another position. | - | ||||||||||||||||||
| 432 | switch (nextTransitionType) { | - | ||||||||||||||||||
| 433 | case QQuickItemViewTransitioner::NoTransition: never executed: case QQuickItemViewTransitioner::NoTransition: | 0 | ||||||||||||||||||
| 434 | { | - | ||||||||||||||||||
| 435 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 436 | } | - | ||||||||||||||||||
| 437 | case QQuickItemViewTransitioner::PopulateTransition: executed 1044 times by 4 tests: case QQuickItemViewTransitioner::PopulateTransition:Executed by:
| 1044 | ||||||||||||||||||
| 438 | { | - | ||||||||||||||||||
| 439 | doTransition = viewBounds.intersects(QRectF(nextTransitionTo.x(), nextTransitionTo.y(), item->width(), item->height())); | - | ||||||||||||||||||
| 440 | break; executed 1044 times by 4 tests: break;Executed by:
| 1044 | ||||||||||||||||||
| 441 | } | - | ||||||||||||||||||
| 442 | case QQuickItemViewTransitioner::AddTransition: executed 7822 times by 4 tests: case QQuickItemViewTransitioner::AddTransition:Executed by:
| 7822 | ||||||||||||||||||
| 443 | case QQuickItemViewTransitioner::RemoveTransition: executed 1134 times by 2 tests: case QQuickItemViewTransitioner::RemoveTransition:Executed by:
| 1134 | ||||||||||||||||||
| 444 | if (viewBounds.isNull()) {
| 0-8956 | ||||||||||||||||||
| 445 | if (isTransitionTarget)
| 0 | ||||||||||||||||||
| 446 | doTransition = true; never executed: doTransition = true; | 0 | ||||||||||||||||||
| 447 | else | - | ||||||||||||||||||
| 448 | doTransition = transitionWillChangePosition(); never executed: doTransition = transitionWillChangePosition(); | 0 | ||||||||||||||||||
| 449 | } else if (isTransitionTarget) {
| 3726-5230 | ||||||||||||||||||
| 450 | // For Add targets, do transition if item is moving into visible area | - | ||||||||||||||||||
| 451 | // For Remove targets, do transition if item is currently in visible area | - | ||||||||||||||||||
| 452 | doTransition = (nextTransitionType == QQuickItemViewTransitioner::AddTransition)
| 150-3576 | ||||||||||||||||||
| 453 | ? viewBounds.intersects(QRectF(nextTransitionTo.x(), nextTransitionTo.y(), item->width(), item->height())) | - | ||||||||||||||||||
| 454 | : viewBounds.intersects(QRectF(item->x(), item->y(), item->width(), item->height())); | - | ||||||||||||||||||
| 455 | } else { executed 3726 times by 4 tests: end of blockExecuted by:
| 3726 | ||||||||||||||||||
| 456 | // do transition if moving from or into visible area | - | ||||||||||||||||||
| 457 | if (viewBounds.intersects(QRectF(item->x(), item->y(), item->width(), item->height()))
| 301-4929 | ||||||||||||||||||
| 458 | || viewBounds.intersects(QRectF(nextTransitionTo.x(), nextTransitionTo.y(), item->width(), item->height()))) {
| 115-186 | ||||||||||||||||||
| 459 | doTransition = transitionWillChangePosition(); | - | ||||||||||||||||||
| 460 | } executed 5044 times by 3 tests: end of blockExecuted by:
| 5044 | ||||||||||||||||||
| 461 | } executed 5230 times by 3 tests: end of blockExecuted by:
| 5230 | ||||||||||||||||||
| 462 | break; executed 8956 times by 4 tests: break;Executed by:
| 8956 | ||||||||||||||||||
| 463 | case QQuickItemViewTransitioner::MoveTransition: executed 2572 times by 3 tests: case QQuickItemViewTransitioner::MoveTransition:Executed by:
| 2572 | ||||||||||||||||||
| 464 | // do transition if moving from or into visible area | - | ||||||||||||||||||
| 465 | if (transitionWillChangePosition()) {
| 0-2572 | ||||||||||||||||||
| 466 | doTransition = viewBounds.isNull()
| 0-2572 | ||||||||||||||||||
| 467 | || viewBounds.intersects(QRectF(item->x(), item->y(), item->width(), item->height()))
| 354-2218 | ||||||||||||||||||
| 468 | || viewBounds.intersects(QRectF(nextTransitionTo.x(), nextTransitionTo.y(), item->width(), item->height()));
| 78-276 | ||||||||||||||||||
| 469 | } executed 2572 times by 3 tests: end of blockExecuted by:
| 2572 | ||||||||||||||||||
| 470 | break; executed 2572 times by 3 tests: break;Executed by:
| 2572 | ||||||||||||||||||
| 471 | } | - | ||||||||||||||||||
| 472 | - | |||||||||||||||||||
| 473 | if (doTransition) {
| 354-12218 | ||||||||||||||||||
| 474 | // add item to target lists even if canTransition() is false for a target transition, | - | ||||||||||||||||||
| 475 | // since the target lists still need to be filled for displaced transitions | - | ||||||||||||||||||
| 476 | if (isTransitionTarget)
| 5020-7198 | ||||||||||||||||||
| 477 | transitioner->addToTargetLists(nextTransitionType, this, index); executed 5020 times by 5 tests: transitioner->addToTargetLists(nextTransitionType, this, index);Executed by:
| 5020 | ||||||||||||||||||
| 478 | doTransition = transitioner->canTransition(nextTransitionType, isTransitionTarget); | - | ||||||||||||||||||
| 479 | } executed 12218 times by 5 tests: end of blockExecuted by:
| 12218 | ||||||||||||||||||
| 480 | - | |||||||||||||||||||
| 481 | if (!doTransition) {
| 2016-10556 | ||||||||||||||||||
| 482 | // if transition type is not valid, the previous transition still has to be | - | ||||||||||||||||||
| 483 | // canceled so that the item can move immediately to the right position | - | ||||||||||||||||||
| 484 | item->setPosition(nextTransitionTo); | - | ||||||||||||||||||
| 485 | stopTransition(); | - | ||||||||||||||||||
| 486 | } executed 2016 times by 4 tests: end of blockExecuted by:
| 2016 | ||||||||||||||||||
| 487 | - | |||||||||||||||||||
| 488 | prepared = true; | - | ||||||||||||||||||
| 489 | return doTransition; executed 12572 times by 5 tests: return doTransition;Executed by:
| 12572 | ||||||||||||||||||
| 490 | } | - | ||||||||||||||||||
| 491 | - | |||||||||||||||||||
| 492 | void QQuickItemViewTransitionableItem::startTransition(QQuickItemViewTransitioner *transitioner, int index) | - | ||||||||||||||||||
| 493 | { | - | ||||||||||||||||||
| 494 | if (nextTransitionType == QQuickItemViewTransitioner::NoTransition)
| 3414-10556 | ||||||||||||||||||
| 495 | return; executed 3414 times by 4 tests: return;Executed by:
| 3414 | ||||||||||||||||||
| 496 | - | |||||||||||||||||||
| 497 | if (!prepared) {
| 0-10556 | ||||||||||||||||||
| 498 | qWarning("QQuickViewItem::prepareTransition() not called!"); | - | ||||||||||||||||||
| 499 | return; never executed: return; | 0 | ||||||||||||||||||
| 500 | } | - | ||||||||||||||||||
| 501 | - | |||||||||||||||||||
| 502 | if (!transition || transition->m_type != nextTransitionType || transition->m_isTarget != isTransitionTarget) {
| 8-8226 | ||||||||||||||||||
| 503 | delete transition; | - | ||||||||||||||||||
| 504 | transition = new QQuickItemViewTransitionJob; | - | ||||||||||||||||||
| 505 | } executed 10412 times by 4 tests: end of blockExecuted by:
| 10412 | ||||||||||||||||||
| 506 | - | |||||||||||||||||||
| 507 | transition->startTransition(this, index, transitioner, nextTransitionType, nextTransitionTo, isTransitionTarget); | - | ||||||||||||||||||
| 508 | clearCurrentScheduledTransition(); | - | ||||||||||||||||||
| 509 | } executed 10556 times by 4 tests: end of blockExecuted by:
| 10556 | ||||||||||||||||||
| 510 | - | |||||||||||||||||||
| 511 | void QQuickItemViewTransitionableItem::setNextTransition(QQuickItemViewTransitioner::TransitionType type, bool isTargetItem) | - | ||||||||||||||||||
| 512 | { | - | ||||||||||||||||||
| 513 | // Don't reset nextTransitionToSet - once it is set, it cannot be changed | - | ||||||||||||||||||
| 514 | // until the animation finishes since the itemX() and itemY() may be used | - | ||||||||||||||||||
| 515 | // to calculate positions for transitions for other items in the view. | - | ||||||||||||||||||
| 516 | nextTransitionType = type; | - | ||||||||||||||||||
| 517 | isTransitionTarget = isTargetItem; | - | ||||||||||||||||||
| 518 | - | |||||||||||||||||||
| 519 | if (!nextTransitionFromSet && lastMovedToSet) {
| 792-14288 | ||||||||||||||||||
| 520 | nextTransitionFrom = lastMovedTo; | - | ||||||||||||||||||
| 521 | nextTransitionFromSet = true; | - | ||||||||||||||||||
| 522 | } executed 3898 times by 3 tests: end of blockExecuted by:
| 3898 | ||||||||||||||||||
| 523 | } executed 15080 times by 5 tests: end of blockExecuted by:
| 15080 | ||||||||||||||||||
| 524 | - | |||||||||||||||||||
| 525 | bool QQuickItemViewTransitionableItem::transitionWillChangePosition() const | - | ||||||||||||||||||
| 526 | { | - | ||||||||||||||||||
| 527 | if (transitionRunning() && transition->m_toPos != nextTransitionTo)
| 0-7218 | ||||||||||||||||||
| 528 | return true; executed 398 times by 3 tests: return true;Executed by:
| 398 | ||||||||||||||||||
| 529 | if (!nextTransitionFromSet)
| 0-7218 | ||||||||||||||||||
| 530 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 531 | return nextTransitionTo != nextTransitionFrom; executed 7218 times by 3 tests: return nextTransitionTo != nextTransitionFrom;Executed by:
| 7218 | ||||||||||||||||||
| 532 | } | - | ||||||||||||||||||
| 533 | - | |||||||||||||||||||
| 534 | void QQuickItemViewTransitionableItem::resetNextTransitionPos() | - | ||||||||||||||||||
| 535 | { | - | ||||||||||||||||||
| 536 | nextTransitionToSet = false; | - | ||||||||||||||||||
| 537 | nextTransitionTo = QPointF(); | - | ||||||||||||||||||
| 538 | } executed 10860 times by 5 tests: end of blockExecuted by:
| 10860 | ||||||||||||||||||
| 539 | - | |||||||||||||||||||
| 540 | void QQuickItemViewTransitionableItem::finishedTransition() | - | ||||||||||||||||||
| 541 | { | - | ||||||||||||||||||
| 542 | resetNextTransitionPos(); | - | ||||||||||||||||||
| 543 | } executed 8832 times by 4 tests: end of blockExecuted by:
| 8832 | ||||||||||||||||||
| 544 | - | |||||||||||||||||||
| 545 | void QQuickItemViewTransitionableItem::clearCurrentScheduledTransition() | - | ||||||||||||||||||
| 546 | { | - | ||||||||||||||||||
| 547 | // Just clear the current scheduled transition - don't touch the nextTransitionTo | - | ||||||||||||||||||
| 548 | // which may have already been set for a previously scheduled transition | - | ||||||||||||||||||
| 549 | - | |||||||||||||||||||
| 550 | nextTransitionType = QQuickItemViewTransitioner::NoTransition; | - | ||||||||||||||||||
| 551 | isTransitionTarget = false; | - | ||||||||||||||||||
| 552 | prepared = false; | - | ||||||||||||||||||
| 553 | nextTransitionFromSet = false; | - | ||||||||||||||||||
| 554 | } executed 14122 times by 5 tests: end of blockExecuted by:
| 14122 | ||||||||||||||||||
| 555 | - | |||||||||||||||||||
| 556 | void QQuickItemViewTransitionableItem::stopTransition() | - | ||||||||||||||||||
| 557 | { | - | ||||||||||||||||||
| 558 | if (transition)
| 336-1692 | ||||||||||||||||||
| 559 | transition->cancel(); executed 336 times by 2 tests: transition->cancel();Executed by:
| 336 | ||||||||||||||||||
| 560 | clearCurrentScheduledTransition(); | - | ||||||||||||||||||
| 561 | resetNextTransitionPos(); | - | ||||||||||||||||||
| 562 | } executed 2028 times by 4 tests: end of blockExecuted by:
| 2028 | ||||||||||||||||||
| 563 | - | |||||||||||||||||||
| 564 | - | |||||||||||||||||||
| 565 | QQuickViewTransitionAttached::QQuickViewTransitionAttached(QObject *parent) | - | ||||||||||||||||||
| 566 | : QObject(parent), m_item(nullptr), m_index(-1) | - | ||||||||||||||||||
| 567 | { | - | ||||||||||||||||||
| 568 | } executed 1090 times by 4 tests: end of blockExecuted by:
| 1090 | ||||||||||||||||||
| 569 | /*! | - | ||||||||||||||||||
| 570 | \qmltype ViewTransition | - | ||||||||||||||||||
| 571 | \instantiates QQuickViewTransitionAttached | - | ||||||||||||||||||
| 572 | \inqmlmodule QtQuick | - | ||||||||||||||||||
| 573 | \ingroup qtquick-transitions-animations | - | ||||||||||||||||||
| 574 | \brief Specifies items under transition in a view. | - | ||||||||||||||||||
| 575 | - | |||||||||||||||||||
| 576 | With ListView and GridView, it is possible to specify transitions that should be applied whenever | - | ||||||||||||||||||
| 577 | the items in the view change as a result of modifications to the view's model. They both have the | - | ||||||||||||||||||
| 578 | following properties that can be set to the appropriate transitions to be run for various | - | ||||||||||||||||||
| 579 | operations: | - | ||||||||||||||||||
| 580 | - | |||||||||||||||||||
| 581 | \list | - | ||||||||||||||||||
| 582 | \li \c populate - the transition to apply to the items created initially for the view, or when the model changes | - | ||||||||||||||||||
| 583 | \li \c add - the transition to apply to items that are added to the view after it has been created | - | ||||||||||||||||||
| 584 | \li \c remove - the transition to apply to items that are removed from the view | - | ||||||||||||||||||
| 585 | \li \c move - the transition to apply to items that are moved within the view (i.e. as a result | - | ||||||||||||||||||
| 586 | of a move operation in the model) | - | ||||||||||||||||||
| 587 | \li \c displaced - the generic transition to be applied to any items that are displaced by an | - | ||||||||||||||||||
| 588 | add, move or remove operation | - | ||||||||||||||||||
| 589 | \li \c addDisplaced, \c removeDisplaced and \c moveDisplaced - the transitions to be applied when | - | ||||||||||||||||||
| 590 | items are displaced by add, move, or remove operations, respectively (these override the | - | ||||||||||||||||||
| 591 | generic displaced transition if specified) | - | ||||||||||||||||||
| 592 | \endlist | - | ||||||||||||||||||
| 593 | - | |||||||||||||||||||
| 594 | For the \l Row, \l Column, \l Grid and \l Flow positioner types, which operate with collections of child | - | ||||||||||||||||||
| 595 | items rather than data models, the following properties are used instead: | - | ||||||||||||||||||
| 596 | - | |||||||||||||||||||
| 597 | \list | - | ||||||||||||||||||
| 598 | \li \c populate - the transition to apply to items that have been added to the positioner at the | - | ||||||||||||||||||
| 599 | time of its creation | - | ||||||||||||||||||
| 600 | \li \c add - the transition to apply to items that are added to | - | ||||||||||||||||||
| 601 | or reparented to the positioner, or items that have become \l {Item::}{visible} | - | ||||||||||||||||||
| 602 | \li \c move - the transition to apply to items that have moved within the positioner, including | - | ||||||||||||||||||
| 603 | when they are displaced due to the addition or removal of other items, or when items are otherwise | - | ||||||||||||||||||
| 604 | rearranged within the positioner, or when items are repositioned due to the resizing of other | - | ||||||||||||||||||
| 605 | items in the positioner | - | ||||||||||||||||||
| 606 | \endlist | - | ||||||||||||||||||
| 607 | - | |||||||||||||||||||
| 608 | View transitions have access to a ViewTransition attached property that | - | ||||||||||||||||||
| 609 | provides details of the items that are under transition and the operation that triggered the | - | ||||||||||||||||||
| 610 | transition. Since view transitions are run once per item, these details can be used to customize | - | ||||||||||||||||||
| 611 | each transition for each individual item. | - | ||||||||||||||||||
| 612 | - | |||||||||||||||||||
| 613 | The ViewTransition attached property provides the following properties specific to the item to | - | ||||||||||||||||||
| 614 | which the transition is applied: | - | ||||||||||||||||||
| 615 | - | |||||||||||||||||||
| 616 | \list | - | ||||||||||||||||||
| 617 | \li ViewTransition.item - the item that is under transition | - | ||||||||||||||||||
| 618 | \li ViewTransition.index - the index of this item | - | ||||||||||||||||||
| 619 | \li ViewTransition.destination - the (x,y) point to which this item is moving for the relevant view operation | - | ||||||||||||||||||
| 620 | \endlist | - | ||||||||||||||||||
| 621 | - | |||||||||||||||||||
| 622 | In addition, ViewTransition provides properties specific to the items which are the target | - | ||||||||||||||||||
| 623 | of the operation that triggered the transition: | - | ||||||||||||||||||
| 624 | - | |||||||||||||||||||
| 625 | \list | - | ||||||||||||||||||
| 626 | \li ViewTransition.targetIndexes - the indexes of the target items | - | ||||||||||||||||||
| 627 | \li ViewTransition.targetItems - the target items themselves | - | ||||||||||||||||||
| 628 | \endlist | - | ||||||||||||||||||
| 629 | - | |||||||||||||||||||
| 630 | (Note that for the \l Row, \l Column, \l Grid and \l Flow positioner types, the \c move transition only | - | ||||||||||||||||||
| 631 | provides these two additional details when the transition is triggered by the addition of items | - | ||||||||||||||||||
| 632 | to a positioner.) | - | ||||||||||||||||||
| 633 | - | |||||||||||||||||||
| 634 | View transitions can be written without referring to any of the attributes listed | - | ||||||||||||||||||
| 635 | above. These attributes merely provide extra details that are useful for customising view | - | ||||||||||||||||||
| 636 | transitions. | - | ||||||||||||||||||
| 637 | - | |||||||||||||||||||
| 638 | Following is an introduction to view transitions and the ways in which the ViewTransition | - | ||||||||||||||||||
| 639 | attached property can be used to augment view transitions. | - | ||||||||||||||||||
| 640 | - | |||||||||||||||||||
| 641 | - | |||||||||||||||||||
| 642 | \section2 View Transitions: a Simple Example | - | ||||||||||||||||||
| 643 | - | |||||||||||||||||||
| 644 | Here is a basic example of the use of view transitions. The view below specifies transitions for | - | ||||||||||||||||||
| 645 | the \c add and \c displaced properties, which will be run when items are added to the view: | - | ||||||||||||||||||
| 646 | - | |||||||||||||||||||
| 647 | \snippet qml/viewtransitions/viewtransitions-basic.qml 0 | - | ||||||||||||||||||
| 648 | - | |||||||||||||||||||
| 649 | When the space key is pressed, adding an item to the model, the new item will fade in and | - | ||||||||||||||||||
| 650 | increase in scale over 400 milliseconds as it is added to the view. Also, any item that is | - | ||||||||||||||||||
| 651 | displaced by the addition of a new item will animate to its new position in the view over | - | ||||||||||||||||||
| 652 | 400 milliseconds, as specified by the \c displaced transition. | - | ||||||||||||||||||
| 653 | - | |||||||||||||||||||
| 654 | If five items were inserted in succession at index 0, the effect would be this: | - | ||||||||||||||||||
| 655 | - | |||||||||||||||||||
| 656 | \image viewtransitions-basic.gif | - | ||||||||||||||||||
| 657 | - | |||||||||||||||||||
| 658 | Notice that the NumberAnimation objects above do not need to specify a \c target to animate | - | ||||||||||||||||||
| 659 | the appropriate item. Also, the NumberAnimation in the \c addTransition does not need to specify | - | ||||||||||||||||||
| 660 | the \c to value to move the item to its correct position in the view. This is because the view | - | ||||||||||||||||||
| 661 | implicitly sets the \c target and \c to values with the correct item and final item position | - | ||||||||||||||||||
| 662 | values if these properties are not explicitly defined. | - | ||||||||||||||||||
| 663 | - | |||||||||||||||||||
| 664 | At its simplest, a view transition may just animate an item to its new position following a | - | ||||||||||||||||||
| 665 | view operation, just as the \c displaced transition does above, or animate some item properties, | - | ||||||||||||||||||
| 666 | as in the \c add transition above. Additionally, a view transition may make use of the | - | ||||||||||||||||||
| 667 | ViewTransition attached property to customize animation behavior for different items. Following | - | ||||||||||||||||||
| 668 | are some examples of how this can be achieved. | - | ||||||||||||||||||
| 669 | - | |||||||||||||||||||
| 670 | - | |||||||||||||||||||
| 671 | \section2 Using the ViewTransition Attached Property | - | ||||||||||||||||||
| 672 | - | |||||||||||||||||||
| 673 | As stated, the various ViewTransition properties provide details specific to the individual item | - | ||||||||||||||||||
| 674 | being transitioned as well as the operation that triggered the transition. In the animation above, | - | ||||||||||||||||||
| 675 | five items are inserted in succession at index 0. When the fifth and final insertion takes place, | - | ||||||||||||||||||
| 676 | adding "Item 4" to the view, the \c add transition is run once (for the inserted item) and the | - | ||||||||||||||||||
| 677 | \c displaced transition is run four times (once for each of the four existing items in the view). | - | ||||||||||||||||||
| 678 | - | |||||||||||||||||||
| 679 | At this point, if we examined the \c displaced transition that was run for the bottom displaced | - | ||||||||||||||||||
| 680 | item ("Item 0"), the ViewTransition property values provided to this transition would be as follows: | - | ||||||||||||||||||
| 681 | - | |||||||||||||||||||
| 682 | \table | - | ||||||||||||||||||
| 683 | \header | - | ||||||||||||||||||
| 684 | \li Property | - | ||||||||||||||||||
| 685 | \li Value | - | ||||||||||||||||||
| 686 | \li Explanation | - | ||||||||||||||||||
| 687 | \row | - | ||||||||||||||||||
| 688 | \li ViewTransition.item | - | ||||||||||||||||||
| 689 | \li "Item 0" delegate instance | - | ||||||||||||||||||
| 690 | \li The "Item 0" \l Rectangle object itself | - | ||||||||||||||||||
| 691 | \row | - | ||||||||||||||||||
| 692 | \li ViewTransition.index | - | ||||||||||||||||||
| 693 | \li \c int value of 4 | - | ||||||||||||||||||
| 694 | \li The index of "Item 0" within the model following the add operation | - | ||||||||||||||||||
| 695 | \row | - | ||||||||||||||||||
| 696 | \li ViewTransition.destination | - | ||||||||||||||||||
| 697 | \li \l point value of (0, 120) | - | ||||||||||||||||||
| 698 | \li The position that "Item 0" is moving to | - | ||||||||||||||||||
| 699 | \row | - | ||||||||||||||||||
| 700 | \li ViewTransition.targetIndexes | - | ||||||||||||||||||
| 701 | \li \c int array, just contains the integer "0" (zero) | - | ||||||||||||||||||
| 702 | \li The index of "Item 4", the new item added to the view | - | ||||||||||||||||||
| 703 | \row | - | ||||||||||||||||||
| 704 | \li ViewTransition.targetItems | - | ||||||||||||||||||
| 705 | \li object array, just contains the "Item 4" delegate instance | - | ||||||||||||||||||
| 706 | \li The "Item 4" \l Rectangle object - the new item added to the view | - | ||||||||||||||||||
| 707 | \endtable | - | ||||||||||||||||||
| 708 | - | |||||||||||||||||||
| 709 | The ViewTransition.targetIndexes and ViewTransition.targetItems lists provide the items and | - | ||||||||||||||||||
| 710 | indexes of all delegate instances that are the targets of the relevant operation. For an add | - | ||||||||||||||||||
| 711 | operation, these are all the items that are added into the view; for a remove, these are all | - | ||||||||||||||||||
| 712 | the items removed from the view, and so on. (Note these lists will only contain references to | - | ||||||||||||||||||
| 713 | items that have been created within the view or its cached items; targets that are not within | - | ||||||||||||||||||
| 714 | the visible area of the view or within the item cache will not be accessible.) | - | ||||||||||||||||||
| 715 | - | |||||||||||||||||||
| 716 | So, while the ViewTransition.item, ViewTransition.index and ViewTransition.destination values | - | ||||||||||||||||||
| 717 | vary for each individual transition that is run, the ViewTransition.targetIndexes and | - | ||||||||||||||||||
| 718 | ViewTransition.targetItems values are the same for every \c add and \c displaced transition | - | ||||||||||||||||||
| 719 | that is triggered by a particular add operation. | - | ||||||||||||||||||
| 720 | - | |||||||||||||||||||
| 721 | - | |||||||||||||||||||
| 722 | \section3 Delaying Animations Based on Index | - | ||||||||||||||||||
| 723 | - | |||||||||||||||||||
| 724 | Since each view transition is run once for each item affected by the transition, the ViewTransition | - | ||||||||||||||||||
| 725 | properties can be used within a transition to define custom behavior for each item's transition. | - | ||||||||||||||||||
| 726 | For example, the ListView in the previous example could use this information to create a ripple-type | - | ||||||||||||||||||
| 727 | effect on the movement of the displaced items. | - | ||||||||||||||||||
| 728 | - | |||||||||||||||||||
| 729 | This can be achieved by modifying the \c displaced transition so that it delays the animation of | - | ||||||||||||||||||
| 730 | each displaced item based on the difference between its index (provided by ViewTransition.index) | - | ||||||||||||||||||
| 731 | and the first removed index (provided by ViewTransition.targetIndexes): | - | ||||||||||||||||||
| 732 | - | |||||||||||||||||||
| 733 | \snippet qml/viewtransitions/viewtransitions-delayedbyindex.qml 0 | - | ||||||||||||||||||
| 734 | - | |||||||||||||||||||
| 735 | Each displaced item delays its animation by an additional 100 milliseconds, producing a subtle | - | ||||||||||||||||||
| 736 | ripple-type effect when items are displaced by the add, like this: | - | ||||||||||||||||||
| 737 | - | |||||||||||||||||||
| 738 | \image viewtransitions-delayedbyindex.gif | - | ||||||||||||||||||
| 739 | - | |||||||||||||||||||
| 740 | - | |||||||||||||||||||
| 741 | \section3 Animating Items to Intermediate Positions | - | ||||||||||||||||||
| 742 | - | |||||||||||||||||||
| 743 | The ViewTransition.item property gives a reference to the item to which the transition is being | - | ||||||||||||||||||
| 744 | applied. This can be used to access any of the item's attributes, custom \c property values, | - | ||||||||||||||||||
| 745 | and so on. | - | ||||||||||||||||||
| 746 | - | |||||||||||||||||||
| 747 | Below is a modification of the \c displaced transition from the previous example. It adds a | - | ||||||||||||||||||
| 748 | ParallelAnimation with nested NumberAnimation objects that reference ViewTransition.item to access | - | ||||||||||||||||||
| 749 | each item's \c x and \c y values at the start of their transitions. This allows each item to | - | ||||||||||||||||||
| 750 | animate to an intermediate position relative to its starting point for the transition, before | - | ||||||||||||||||||
| 751 | animating to its final position in the view: | - | ||||||||||||||||||
| 752 | - | |||||||||||||||||||
| 753 | \snippet qml/viewtransitions/viewtransitions-intermediatemove.qml 0 | - | ||||||||||||||||||
| 754 | - | |||||||||||||||||||
| 755 | Now, a displaced item will first move to a position of (20, 50) relative to its starting | - | ||||||||||||||||||
| 756 | position, and then to its final, correct position in the view: | - | ||||||||||||||||||
| 757 | - | |||||||||||||||||||
| 758 | \image viewtransitions-intermediatemove.gif | - | ||||||||||||||||||
| 759 | - | |||||||||||||||||||
| 760 | Since the final NumberAnimation does not specify a \c to value, the view implicitly sets this | - | ||||||||||||||||||
| 761 | value to the item's final position in the view, and so this last animation will move this item | - | ||||||||||||||||||
| 762 | to the correct place. If the transition requires the final position of the item for some calculation, | - | ||||||||||||||||||
| 763 | this is accessible through ViewTransition.destination. | - | ||||||||||||||||||
| 764 | - | |||||||||||||||||||
| 765 | Instead of using multiple NumberAnimations, you could use a PathAnimation to animate an item over | - | ||||||||||||||||||
| 766 | a curved path. For example, the \c add transition in the previous example could be augmented with | - | ||||||||||||||||||
| 767 | a PathAnimation as follows: to animate newly added items along a path: | - | ||||||||||||||||||
| 768 | - | |||||||||||||||||||
| 769 | \snippet qml/viewtransitions/viewtransitions-pathanim.qml 0 | - | ||||||||||||||||||
| 770 | - | |||||||||||||||||||
| 771 | This animates newly added items along a path. Notice that each path is specified relative to | - | ||||||||||||||||||
| 772 | each item's final destination point, so that items inserted at different indexes start their | - | ||||||||||||||||||
| 773 | paths from different positions: | - | ||||||||||||||||||
| 774 | - | |||||||||||||||||||
| 775 | \image viewtransitions-pathanim.gif | - | ||||||||||||||||||
| 776 | - | |||||||||||||||||||
| 777 | - | |||||||||||||||||||
| 778 | \section2 Handling Interrupted Animations | - | ||||||||||||||||||
| 779 | - | |||||||||||||||||||
| 780 | A view transition may be interrupted at any time if a different view transition needs to be | - | ||||||||||||||||||
| 781 | applied while the original transition is in progress. For example, say Item A is inserted at index 0 | - | ||||||||||||||||||
| 782 | and undergoes an "add" transition; then, Item B is inserted at index 0 in quick succession before | - | ||||||||||||||||||
| 783 | Item A's transition has finished. Since Item B is inserted before Item A, it will displace Item | - | ||||||||||||||||||
| 784 | A, causing the view to interrupt Item A's "add" transition mid-way and start a "displaced" | - | ||||||||||||||||||
| 785 | transition on Item A instead. | - | ||||||||||||||||||
| 786 | - | |||||||||||||||||||
| 787 | For simple animations that simply animate an item's movement to its final destination, this | - | ||||||||||||||||||
| 788 | interruption is unlikely to require additional consideration. However, if a transition changes other | - | ||||||||||||||||||
| 789 | properties, this interruption may cause unwanted side effects. Consider the first example on this | - | ||||||||||||||||||
| 790 | page, repeated below for convenience: | - | ||||||||||||||||||
| 791 | - | |||||||||||||||||||
| 792 | \snippet qml/viewtransitions/viewtransitions-basic.qml 0 | - | ||||||||||||||||||
| 793 | - | |||||||||||||||||||
| 794 | If multiple items are added in rapid succession, without waiting for a previous transition | - | ||||||||||||||||||
| 795 | to finish, this is the result: | - | ||||||||||||||||||
| 796 | - | |||||||||||||||||||
| 797 | \image viewtransitions-interruptedbad.gif | - | ||||||||||||||||||
| 798 | - | |||||||||||||||||||
| 799 | Each newly added item undergoes an \c add transition, but before the transition can finish, | - | ||||||||||||||||||
| 800 | another item is added, displacing the previously added item. Because of this, the \c add | - | ||||||||||||||||||
| 801 | transition on the previously added item is interrupted and a \c displaced transition is | - | ||||||||||||||||||
| 802 | started on the item instead. Due to the interruption, the \c opacity and \c scale animations | - | ||||||||||||||||||
| 803 | have not completed, thus producing items with opacity and scale that are below 1.0. | - | ||||||||||||||||||
| 804 | - | |||||||||||||||||||
| 805 | To fix this, the \c displaced transition should additionally ensure the item properties are | - | ||||||||||||||||||
| 806 | set to the end values specified in the \c add transition, effectively resetting these values | - | ||||||||||||||||||
| 807 | whenever an item is displaced. In this case, it means setting the item opacity and scale to 1.0: | - | ||||||||||||||||||
| 808 | - | |||||||||||||||||||
| 809 | \snippet qml/viewtransitions/viewtransitions-interruptedgood.qml 0 | - | ||||||||||||||||||
| 810 | - | |||||||||||||||||||
| 811 | Now, when an item's \c add transition is interrupted, its opacity and scale are animated to 1.0 | - | ||||||||||||||||||
| 812 | upon displacement, avoiding the erroneous visual effects from before: | - | ||||||||||||||||||
| 813 | - | |||||||||||||||||||
| 814 | \image viewtransitions-interruptedgood.gif | - | ||||||||||||||||||
| 815 | - | |||||||||||||||||||
| 816 | The same principle applies to any combination of view transitions. An added item may be moved | - | ||||||||||||||||||
| 817 | before its add transition finishes, or a moved item may be removed before its moved transition | - | ||||||||||||||||||
| 818 | finishes, and so on; so, the rule of thumb is that every transition should handle the same set of | - | ||||||||||||||||||
| 819 | properties. | - | ||||||||||||||||||
| 820 | - | |||||||||||||||||||
| 821 | - | |||||||||||||||||||
| 822 | \section2 Restrictions Regarding ScriptAction | - | ||||||||||||||||||
| 823 | - | |||||||||||||||||||
| 824 | When a view transition is initialized, any property bindings that refer to the ViewTransition | - | ||||||||||||||||||
| 825 | attached property are evaluated in preparation for the transition. Due to the nature of the | - | ||||||||||||||||||
| 826 | internal construction of a view transition, the attributes of the ViewTransition attached | - | ||||||||||||||||||
| 827 | property are only valid for the relevant item when the transition is initialized, and may not be | - | ||||||||||||||||||
| 828 | valid when the transition is actually run. | - | ||||||||||||||||||
| 829 | - | |||||||||||||||||||
| 830 | Therefore, a ScriptAction within a view transition should not refer to the ViewTransition | - | ||||||||||||||||||
| 831 | attached property, as it may not refer to the expected values at the time that the ScriptAction | - | ||||||||||||||||||
| 832 | is actually invoked. Consider the following example: | - | ||||||||||||||||||
| 833 | - | |||||||||||||||||||
| 834 | \snippet qml/viewtransitions/viewtransitions-scriptactionbad.qml 0 | - | ||||||||||||||||||
| 835 | - | |||||||||||||||||||
| 836 | When the space key is pressed, three items are moved from index 5 to index 1. For each moved | - | ||||||||||||||||||
| 837 | item, the \c moveTransition sequence presumably animates the item's color to "yellow", then | - | ||||||||||||||||||
| 838 | animates it to its final position, then changes the item color back to "lightsteelblue" using a | - | ||||||||||||||||||
| 839 | ScriptAction. However, when run, the transition does not produce the intended result: | - | ||||||||||||||||||
| 840 | - | |||||||||||||||||||
| 841 | \image viewtransitions-scriptactionbad.gif | - | ||||||||||||||||||
| 842 | - | |||||||||||||||||||
| 843 | Only the last moved item is returned to the "lightsteelblue" color; the others remain yellow. This | - | ||||||||||||||||||
| 844 | is because the ScriptAction is not run until after the transition has already been initialized, by | - | ||||||||||||||||||
| 845 | which time the ViewTransition.item value has changed to refer to a different item; the item that | - | ||||||||||||||||||
| 846 | the script had intended to refer to is not the one held by ViewTransition.item at the time the | - | ||||||||||||||||||
| 847 | ScriptAction is actually invoked. | - | ||||||||||||||||||
| 848 | - | |||||||||||||||||||
| 849 | In this instance, to avoid this issue, the view could set the property using a PropertyAction | - | ||||||||||||||||||
| 850 | instead: | - | ||||||||||||||||||
| 851 | - | |||||||||||||||||||
| 852 | \snippet qml/viewtransitions/viewtransitions-scriptactiongood.qml 0 | - | ||||||||||||||||||
| 853 | - | |||||||||||||||||||
| 854 | When the transition is initialized, the PropertyAction \c target will be set to the respective | - | ||||||||||||||||||
| 855 | ViewTransition.item for the transition and will later run with the correct item target as | - | ||||||||||||||||||
| 856 | expected. | - | ||||||||||||||||||
| 857 | */ | - | ||||||||||||||||||
| 858 | - | |||||||||||||||||||
| 859 | /*! | - | ||||||||||||||||||
| 860 | \qmlattachedproperty int QtQuick::ViewTransition::index | - | ||||||||||||||||||
| 861 | - | |||||||||||||||||||
| 862 | This attached property holds the index of the item that is being | - | ||||||||||||||||||
| 863 | transitioned. | - | ||||||||||||||||||
| 864 | - | |||||||||||||||||||
| 865 | Note that if the item is being moved, this property holds the index that | - | ||||||||||||||||||
| 866 | the item is moving to, not from. | - | ||||||||||||||||||
| 867 | */ | - | ||||||||||||||||||
| 868 | - | |||||||||||||||||||
| 869 | /*! | - | ||||||||||||||||||
| 870 | \qmlattachedproperty item QtQuick::ViewTransition::item | - | ||||||||||||||||||
| 871 | - | |||||||||||||||||||
| 872 | This attached property holds the item that is being transitioned. | - | ||||||||||||||||||
| 873 | - | |||||||||||||||||||
| 874 | \warning This item should not be kept and referred to outside of the transition | - | ||||||||||||||||||
| 875 | as it may become invalid as the view changes. | - | ||||||||||||||||||
| 876 | */ | - | ||||||||||||||||||
| 877 | - | |||||||||||||||||||
| 878 | /*! | - | ||||||||||||||||||
| 879 | \qmlattachedproperty point QtQuick::ViewTransition::destination | - | ||||||||||||||||||
| 880 | - | |||||||||||||||||||
| 881 | This attached property holds the final destination position for the transitioned | - | ||||||||||||||||||
| 882 | item within the view. | - | ||||||||||||||||||
| 883 | - | |||||||||||||||||||
| 884 | This property value is a \l point with \c x and \c y properties. | - | ||||||||||||||||||
| 885 | */ | - | ||||||||||||||||||
| 886 | - | |||||||||||||||||||
| 887 | /*! | - | ||||||||||||||||||
| 888 | \qmlattachedproperty list QtQuick::ViewTransition::targetIndexes | - | ||||||||||||||||||
| 889 | - | |||||||||||||||||||
| 890 | This attached property holds a list of the indexes of the items in view | - | ||||||||||||||||||
| 891 | that are the target of the relevant operation. | - | ||||||||||||||||||
| 892 | - | |||||||||||||||||||
| 893 | The targets are the items that are the subject of the operation. For | - | ||||||||||||||||||
| 894 | an add operation, these are the items being added; for a remove, these | - | ||||||||||||||||||
| 895 | are the items being removed; for a move, these are the items being | - | ||||||||||||||||||
| 896 | moved. | - | ||||||||||||||||||
| 897 | - | |||||||||||||||||||
| 898 | For example, if the transition was triggered by an insert operation | - | ||||||||||||||||||
| 899 | that added two items at index 1 and 2, this targetIndexes list would | - | ||||||||||||||||||
| 900 | have the value [1,2]. | - | ||||||||||||||||||
| 901 | - | |||||||||||||||||||
| 902 | \note The targetIndexes list only contains the indexes of items that are actually | - | ||||||||||||||||||
| 903 | in view, or will be in the view once the relevant operation completes. | - | ||||||||||||||||||
| 904 | - | |||||||||||||||||||
| 905 | \sa QtQuick::ViewTransition::targetItems | - | ||||||||||||||||||
| 906 | */ | - | ||||||||||||||||||
| 907 | - | |||||||||||||||||||
| 908 | /*! | - | ||||||||||||||||||
| 909 | \qmlattachedproperty list QtQuick::ViewTransition::targetItems | - | ||||||||||||||||||
| 910 | - | |||||||||||||||||||
| 911 | This attached property holds the list of items in view that are the | - | ||||||||||||||||||
| 912 | target of the relevant operation. | - | ||||||||||||||||||
| 913 | - | |||||||||||||||||||
| 914 | The targets are the items that are the subject of the operation. For | - | ||||||||||||||||||
| 915 | an add operation, these are the items being added; for a remove, these | - | ||||||||||||||||||
| 916 | are the items being removed; for a move, these are the items being | - | ||||||||||||||||||
| 917 | moved. | - | ||||||||||||||||||
| 918 | - | |||||||||||||||||||
| 919 | For example, if the transition was triggered by an insert operation | - | ||||||||||||||||||
| 920 | that added two items at index 1 and 2, this targetItems list would | - | ||||||||||||||||||
| 921 | contain these two items. | - | ||||||||||||||||||
| 922 | - | |||||||||||||||||||
| 923 | \note The targetItems list only contains items that are actually | - | ||||||||||||||||||
| 924 | in view, or will be in the view once the relevant operation completes. | - | ||||||||||||||||||
| 925 | - | |||||||||||||||||||
| 926 | \warning The objects in this list should not be kept and referred to | - | ||||||||||||||||||
| 927 | outside of the transition as the items may become invalid. The targetItems | - | ||||||||||||||||||
| 928 | are only valid when the Transition is initially created; this also means | - | ||||||||||||||||||
| 929 | they should not be used by ScriptAction objects in the Transition, which are | - | ||||||||||||||||||
| 930 | not evaluated until the transition is run. | - | ||||||||||||||||||
| 931 | - | |||||||||||||||||||
| 932 | \sa QtQuick::ViewTransition::targetIndexes | - | ||||||||||||||||||
| 933 | */ | - | ||||||||||||||||||
| 934 | QQmlListProperty<QObject> QQuickViewTransitionAttached::targetItems() | - | ||||||||||||||||||
| 935 | { | - | ||||||||||||||||||
| 936 | return QQmlListProperty<QObject>(this, m_targetItems); executed 9018 times by 3 tests: return QQmlListProperty<QObject>(this, m_targetItems);Executed by:
| 9018 | ||||||||||||||||||
| 937 | } | - | ||||||||||||||||||
| 938 | - | |||||||||||||||||||
| 939 | QQuickViewTransitionAttached *QQuickViewTransitionAttached::qmlAttachedProperties(QObject *obj) | - | ||||||||||||||||||
| 940 | { | - | ||||||||||||||||||
| 941 | return new QQuickViewTransitionAttached(obj); executed 1090 times by 4 tests: return new QQuickViewTransitionAttached(obj);Executed by:
| 1090 | ||||||||||||||||||
| 942 | } | - | ||||||||||||||||||
| 943 | - | |||||||||||||||||||
| 944 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 945 | - | |||||||||||||||||||
| 946 | #include "moc_qquickitemviewtransition_p.cpp" | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |