154void QAnimationGroup::insertAnimation(
int index, QAbstractAnimation *animation)
156 Q_D(QAnimationGroup);
158 if (index < 0 || index > d->animations.size()) {
159 qWarning(
"QAnimationGroup::insertAnimation: index is out of bounds");
163 if (QAnimationGroup *oldGroup = animation->group()) {
164 oldGroup->removeAnimation(animation);
166 index = qMin(index, d->animations.size());
169 d->animations.insert(index, animation);
170 QAbstractAnimationPrivate::get(animation)->group =
this;
172 animation->setParent(
this);
173 d->animationInsertedAt(index);
206QAbstractAnimation *QAnimationGroup::takeAnimation(
int index)
208 Q_D(QAnimationGroup);
209 if (index < 0 || index >= d->animations.size()) {
210 qWarning(
"QAnimationGroup::takeAnimation: no animation at index %d", index);
213 QAbstractAnimation *animation = d->animations.at(index);
214 QAbstractAnimationPrivate::get(animation)->group =
nullptr;
217 d->animations.removeAt(index);
218 animation->setParent(
nullptr);
219 d->animationRemoved(index, animation);
238bool QAnimationGroup::event(QEvent *event)
240 Q_D(QAnimationGroup);
241 if (event->type() == QEvent::ChildAdded) {
242 QChildEvent *childEvent =
static_cast<QChildEvent *>(event);
243 if (QAbstractAnimation *a = qobject_cast<QAbstractAnimation *>(childEvent->child())) {
244 if (a->group() !=
this)
247 }
else if (event->type() == QEvent::ChildRemoved) {
248 QChildEvent *childEvent =
static_cast<QChildEvent *>(event);
252 const QList<QAbstractAnimation *>::const_iterator it
253 = std::find(d->animations.cbegin(), d->animations.cend(), childEvent->child());
254 if (it != d->animations.cend())
255 takeAnimation(it - d->animations.cbegin());
257 return QAbstractAnimation::event(event);
260void QAnimationGroupPrivate::clear(
bool onDestruction)
262 const QList<QAbstractAnimation *> animationsCopy = animations;
265 for (qsizetype i = animationsCopy.size() - 1; i >= 0; --i) {
266 QAbstractAnimation *animation = animationsCopy.at(i);
267 animation->setParent(
nullptr);
268 QAbstractAnimationPrivate::get(animation)->group =
nullptr;
274 animationRemoved(i, animation);