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:
parent
613d5ef850
commit
72b7c6f393
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user