153void QAnimationGroup::insertAnimation(
int index, QAbstractAnimation *animation)
155 Q_D(QAnimationGroup);
157 if (index < 0 || index > d->animations.size()) {
158 qWarning(
"QAnimationGroup::insertAnimation: index is out of bounds");
162 if (QAnimationGroup *oldGroup = animation->group()) {
163 oldGroup->removeAnimation(animation);
165 index = qMin(index, d->animations.size());
168 d->animations.insert(index, animation);
169 QAbstractAnimationPrivate::get(animation)->group =
this;
171 animation->setParent(
this);
172 d->animationInsertedAt(index);
205QAbstractAnimation *QAnimationGroup::takeAnimation(
int index)
207 Q_D(QAnimationGroup);
208 if (index < 0 || index >= d->animations.size()) {
209 qWarning(
"QAnimationGroup::takeAnimation: no animation at index %d", index);
212 QAbstractAnimation *animation = d->animations.at(index);
213 QAbstractAnimationPrivate::get(animation)->group =
nullptr;
216 d->animations.removeAt(index);
217 animation->setParent(
nullptr);
218 d->animationRemoved(index, animation);
237bool QAnimationGroup::event(QEvent *event)
239 Q_D(QAnimationGroup);
240 if (event->type() == QEvent::ChildAdded) {
241 QChildEvent *childEvent =
static_cast<QChildEvent *>(event);
242 if (QAbstractAnimation *a = qobject_cast<QAbstractAnimation *>(childEvent->child())) {
243 if (a->group() !=
this)
246 }
else if (event->type() == QEvent::ChildRemoved) {
247 QChildEvent *childEvent =
static_cast<QChildEvent *>(event);
251 const QList<QAbstractAnimation *>::const_iterator it
252 = std::find(d->animations.cbegin(), d->animations.cend(), childEvent->child());
253 if (it != d->animations.cend())
254 takeAnimation(it - d->animations.cbegin());
256 return QAbstractAnimation::event(event);
259void QAnimationGroupPrivate::clear(
bool onDestruction)
261 const QList<QAbstractAnimation *> animationsCopy = animations;
264 for (qsizetype i = animationsCopy.size() - 1; i >= 0; --i) {
265 QAbstractAnimation *animation = animationsCopy.at(i);
266 animation->setParent(
nullptr);
267 QAbstractAnimationPrivate::get(animation)->group =
nullptr;
273 animationRemoved(i, animation);