canvas::Layout: clear parent/canvas after calling onRemove.

This commit is contained in:
Thomas Geymayer
2014-07-21 23:56:41 +02:00
parent e036dfc5bf
commit 23413b4781
2 changed files with 8 additions and 3 deletions

View File

@@ -125,8 +125,8 @@ namespace canvas
LayoutItems::iterator it = _layout_items.begin() + index;
LayoutItemRef item = it->layout_item;
item->setParent(LayoutItemWeakRef());
item->onRemove();
item->setParent(LayoutItemWeakRef());
_layout_items.erase(it);
invalidate();
@@ -141,8 +141,8 @@ namespace canvas
it != _layout_items.end();
++it )
{
it->layout_item->setParent(LayoutItemWeakRef());
it->layout_item->onRemove();
it->layout_item->setParent(LayoutItemWeakRef());
}
_layout_items.clear();
invalidate();

View File

@@ -163,7 +163,12 @@ namespace canvas
{
_parent = parent;
LayoutItemRef parent_ref = parent.lock();
setCanvas(parent_ref ? parent_ref->_canvas : CanvasWeakPtr());
if( parent_ref )
// Only change the canvas if there is a new parent. If the item is removed
// keep the old canvas, as it may be used for example during the call to
// onRemove.
setCanvas(parent_ref->_canvas);
setVisibleInternal(!parent_ref || parent_ref->isVisible());
}