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)
{
if (d->parent == parent)
return;
if (parent && dynamic_cast<KoShape*>(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);
}
......
......@@ -63,5 +63,17 @@ void TestShapeContainer::testSetParent()
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"
......@@ -10,7 +10,7 @@ private slots:
// tests
void testModel();
void testSetParent();
void testSetParent2();
};
#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