summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/animation/qanimationgroup.cpp3
-rw-r--r--tests/auto/qanimationgroup/tst_qanimationgroup.cpp34
2 files changed, 36 insertions, 1 deletions
diff --git a/src/corelib/animation/qanimationgroup.cpp b/src/corelib/animation/qanimationgroup.cpp
index f39738b..03573bb 100644
--- a/src/corelib/animation/qanimationgroup.cpp
+++ b/src/corelib/animation/qanimationgroup.cpp
@@ -164,9 +164,10 @@ void QAnimationGroup::insertAnimationAt(int index, QAbstractAnimation *animation
return;
}
- d->animations.insert(index, animation);
if (QAnimationGroup *oldGroup = animation->group())
oldGroup->removeAnimation(animation);
+
+ d->animations.insert(index, animation);
QAbstractAnimationPrivate::get(animation)->group = this;
// this will make sure that ChildAdded event is sent to 'this'
animation->setParent(this);
diff --git a/tests/auto/qanimationgroup/tst_qanimationgroup.cpp b/tests/auto/qanimationgroup/tst_qanimationgroup.cpp
index a7d616a..3cf5631 100644
--- a/tests/auto/qanimationgroup/tst_qanimationgroup.cpp
+++ b/tests/auto/qanimationgroup/tst_qanimationgroup.cpp
@@ -68,6 +68,7 @@ private slots:
void statesAndSignals();
void setParentAutoAdd();
void beginNestedGroup();
+ void addChildTwice();
};
tst_QAnimationGroup::tst_QAnimationGroup()
@@ -343,5 +344,38 @@ void tst_QAnimationGroup::beginNestedGroup()
}
}
+void tst_QAnimationGroup::addChildTwice()
+{
+ QPropertyAnimation *subGroup;
+ QPropertyAnimation *subGroup2;
+ QAnimationGroup *parent = new QSequentialAnimationGroup();
+
+ subGroup = new QPropertyAnimation();
+ subGroup->setParent(parent);
+ parent->addAnimation(subGroup);
+ QCOMPARE(parent->animationCount(), 1);
+
+ parent->clearAnimations();
+
+ QCOMPARE(parent->animationCount(), 0);
+
+ // adding the same item twice to a group will remove the item from its current position
+ // and append it to the end
+ subGroup = new QPropertyAnimation(parent);
+ subGroup2 = new QPropertyAnimation(parent);
+
+ QCOMPARE(parent->animationCount(), 2);
+ QCOMPARE(parent->animationAt(0), subGroup);
+ QCOMPARE(parent->animationAt(1), subGroup2);
+
+ parent->addAnimation(subGroup);
+
+ QCOMPARE(parent->animationCount(), 2);
+ QCOMPARE(parent->animationAt(0), subGroup2);
+ QCOMPARE(parent->animationAt(1), subGroup);
+
+ delete parent;
+}
+
QTEST_MAIN(tst_QAnimationGroup)
#include "tst_qanimationgroup.moc"