Commit 1b609720 authored by Thomas Zander's avatar Thomas 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.

svn path=/branches/koffice/2.0/koffice/; revision=954447
parent acfcbbf2
...@@ -387,13 +387,14 @@ void KoShape::setParent(KoShapeContainer *parent) ...@@ -387,13 +387,14 @@ void KoShape::setParent(KoShapeContainer *parent)
{ {
if (d->parent == parent) if (d->parent == parent)
return; return;
if (parent && dynamic_cast<KoShape*>(parent) != this) { KoShapeContainer *oldParent = d->parent;
if (d->parent) d->parent = 0; // avoids recursive removing
d->parent->removeChild(this); if (oldParent)
oldParent->removeChild(this);
if (parent && parent != this) {
d->parent = parent; d->parent = parent;
parent->addChild(this); parent->addChild(this);
} else }
d->parent = 0;
notifyChanged(); notifyChanged();
d->shapeChanged(ParentChanged); d->shapeChanged(ParentChanged);
} }
......
...@@ -63,5 +63,17 @@ void TestShapeContainer::testSetParent() ...@@ -63,5 +63,17 @@ void TestShapeContainer::testSetParent()
QCOMPARE(shape.parent(), &container2); 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) QTEST_MAIN(TestShapeContainer)
#include "TestShapeContainer.moc" #include "TestShapeContainer.moc"
...@@ -10,7 +10,7 @@ private slots: ...@@ -10,7 +10,7 @@ private slots:
// tests // tests
void testModel(); void testModel();
void testSetParent(); void testSetParent();
void testSetParent2();
}; };
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment