From kde-commits Wed Apr 15 19:32:57 2009 From: Thomas Zander Date: Wed, 15 Apr 2009 19:32:57 +0000 To: kde-commits Subject: branches/koffice/2.0/koffice/libs/flake Message-Id: <1239823977.173336.4118.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=123982398631535 SVN commit 954447 by zander: Fixes: setting a shape parent to zero didn't always remove it from the parent BUG:189558 RevBy: Thorsten Z Details: The code to avoid recursing deletion was missing one usecase of when the parent was set to zero. Added test and fixed it in a better way. M +6 -5 KoShape.cpp M +12 -0 tests/TestShapeContainer.cpp M +1 -1 tests/TestShapeContainer.h --- branches/koffice/2.0/koffice/libs/flake/KoShape.cpp #954446:954447 @@ -387,13 +387,14 @@ { if (d->parent == parent) return; - if (parent && dynamic_cast(parent) != this) { - if (d->parent) - d->parent->removeChild(this); + KoShapeContainer *oldParent = d->parent; + d->parent = 0; // avoids recursive removing + if (oldParent) + oldParent->removeChild(this); + if (parent && parent != this) { d->parent = parent; parent->addChild(this); - } else - d->parent = 0; + } notifyChanged(); d->shapeChanged(ParentChanged); } --- branches/koffice/2.0/koffice/libs/flake/tests/TestShapeContainer.cpp #954446:954447 @@ -63,5 +63,17 @@ QCOMPARE(shape.parent(), &container2); } +void TestShapeContainer::testSetParent2() +{ + MockContainerModel *model = new MockContainerModel(); + MockContainer container(model); + MockShape *shape = new MockShape(); + shape->setParent(&container); + QCOMPARE(model->iterator().count(), 1); + + shape->setParent(0); + QCOMPARE(model->iterator().count(), 0); +} + QTEST_MAIN(TestShapeContainer) #include "TestShapeContainer.moc" --- branches/koffice/2.0/koffice/libs/flake/tests/TestShapeContainer.h #954446:954447 @@ -10,7 +10,7 @@ // tests void testModel(); void testSetParent(); - + void testSetParent2(); }; #endif