more safety, allowing anyone delete a layout or call setParent and have the Right Things(tm) happen without anyone's toes getting blown off in the process.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=771851
This commit is contained in:
Aaron J. Seigo 2008-02-07 02:24:19 +00:00
parent 613d5ef850
commit 72b7c6f393
3 changed files with 29 additions and 7 deletions

View File

@ -68,17 +68,24 @@ Layout::Layout(LayoutItem *parent)
: LayoutItem(),
d(new Private(parent))
{
if (parent) {
setParent(parent);
}
void Layout::setParent(LayoutItem *parent)
{
d->parent = parent;
if (parent && parent->layout() != this) {
parent->setLayout(this);
}
}
void Layout::setParent(LayoutItem *parent) {
d->parent = parent;
}
Layout::~Layout()
{
if (d->parent) {
d->parent->unsetLayout();
}
delete d;
}

View File

@ -90,13 +90,18 @@ void LayoutItem::setLayout(Layout* layout)
if (d->layout == layout) {
return;
}
delete d->layout;
d->layout = layout;
if (layout) {
layout->setParent(this);
}
}
d->layout = layout;
void LayoutItem::unsetLayout()
{
d->layout = 0;
}
Layout* LayoutItem::layout() const

View File

@ -117,12 +117,22 @@ class PLASMA_EXPORT LayoutItem
virtual QSizeF sizeHint() const = 0;
/**
* Sets the layout that will manage children items
* Sets the layout that will manage children items. The LayoutItem
* takes ownership of the layout from that point forward, unless
* unsetLayout() is called.
*
* @param layout The Layout that this LayoutItem will be managed by.
*/
void setLayout(Layout* layout);
/**
* Resets the layout that will manage children items to no layout.
* Note that the caller of this method must alert any items managed
* by the layout of this change if necessary. Primarily, this should
* only be used from the dtors of LayoutItem subclasses.
*/
void unsetLayout();
/**
* @return the layout this item is currently associated with.
*/