162void QAnimationGroup::insertAnimation(
int index, QAbstractAnimation *animation)
164 Q_D(QAnimationGroup);
166 if (index < 0 || index > d->animations.size()) {
167 qWarning(
"QAnimationGroup::insertAnimation: index is out of bounds");
171 if (QAnimationGroup *oldGroup = animation->group()) {
172 oldGroup->removeAnimation(animation);
174 index = qMin(index, d->animations.size());
177 d->animations.insert(index, animation);
178 QAbstractAnimationPrivate::get(animation)->group =
this;
180 animation->setParent(
this);
181 d->animationInsertedAt(index);
214QAbstractAnimation *QAnimationGroup::takeAnimation(
int index)
216 Q_D(QAnimationGroup);
217 if (index < 0 || index >= d->animations.size()) {
218 qWarning(
"QAnimationGroup::takeAnimation: no animation at index %d", index);
221 QAbstractAnimation *animation = d->animations.at(index);
222 QAbstractAnimationPrivate::get(animation)->group =
nullptr;
225 d->animations.removeAt(index);
226 animation->setParent(
nullptr);
227 d->animationRemoved(index, animation);
246bool QAnimationGroup::event(QEvent *event)
248 Q_D(QAnimationGroup);
249 if (event->type() == QEvent::ChildAdded) {
250 QChildEvent *childEvent =
static_cast<QChildEvent *>(event);
251 if (QAbstractAnimation *a = qobject_cast<QAbstractAnimation *>(childEvent->child())) {
252 if (a->group() !=
this)
255 }
else if (event->type() == QEvent::ChildRemoved) {
256 QChildEvent *childEvent =
static_cast<QChildEvent *>(event);
260 const QList<QAbstractAnimation *>::const_iterator it
261 = std::find(d->animations.cbegin(), d->animations.cend(), childEvent->child());
262 if (it != d->animations.cend())
263 takeAnimation(it - d->animations.cbegin());
265 return QAbstractAnimation::event(event);
268void QAnimationGroupPrivate::clear(
bool onDestruction)
270 const QList<QAbstractAnimation *> animationsCopy = animations;
273 for (qsizetype i = animationsCopy.size() - 1; i >= 0; --i) {
274 QAbstractAnimation *animation = animationsCopy.at(i);
275 animation->setParent(
nullptr);
276 QAbstractAnimationPrivate::get(animation)->group =
nullptr;
282 animationRemoved(i, animation);