Ensure that LayoutItem::setParent resets the parents layout if we are currently its layout and release managed items.

RB:89

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=773471
This commit is contained in:
Aaron J. Seigo 2008-02-11 05:50:47 +00:00
parent a7ccf41c3e
commit 9335a50776
12 changed files with 64 additions and 22 deletions

View File

@ -56,10 +56,7 @@ BorderLayout::BorderLayout(LayoutItem * parent) :
BorderLayout::~BorderLayout()
{
foreach (Plasma::LayoutItem *item, d->itemPositions) {
item->unsetManagingLayout(this);
}
releaseManagedItems();
delete d;
}
@ -117,6 +114,13 @@ void BorderLayout::relayout()
}
}
void BorderLayout::releaseManagedItems()
{
foreach (Plasma::LayoutItem *item, d->itemPositions) {
item->unsetManagingLayout(this);
}
}
QSizeF BorderLayout::sizeHint() const
{
qreal hintHeight = 0.0;

View File

@ -86,6 +86,7 @@ public:
protected:
void relayout();
void releaseManagedItems();
private:
class Private;

View File

@ -297,9 +297,7 @@ BoxLayout::Direction BoxLayout::direction() const
BoxLayout::~BoxLayout()
{
foreach (LayoutItem* item, d->children) {
item->unsetManagingLayout(this);
}
releaseManagedItems();
delete d;
}
@ -532,6 +530,12 @@ void BoxLayout::relayout()
startAnimation();
}
void BoxLayout::releaseManagedItems()
{
foreach (LayoutItem* item, d->children) {
item->unsetManagingLayout(this);
}
}
QSizeF BoxLayout::maximumSize() const
{

View File

@ -89,6 +89,7 @@ class PLASMA_EXPORT BoxLayout : public Layout
protected:
void relayout();
void releaseManagedItems();
private:
class Private;

View File

@ -46,12 +46,10 @@ FlowLayout::FlowLayout(LayoutItem* parent)
, d(new Private)
{
}
FlowLayout::~FlowLayout()
{
foreach (LayoutItem *item, d->items) {
item->unsetManagingLayout(this);
}
releaseManagedItems();
delete d;
}
@ -254,6 +252,13 @@ void FlowLayout::relayout()
startAnimation();
}
void FlowLayout::releaseManagedItems()
{
foreach (LayoutItem *item, d->items) {
item->unsetManagingLayout(this);
}
}
Qt::Orientations FlowLayout::expandingDirections() const
{
return Qt::Vertical | Qt::Horizontal;

View File

@ -53,6 +53,7 @@ public:
protected:
void relayout();
void releaseManagedItems();
private:
class Private;

View File

@ -41,10 +41,7 @@ FreeLayout::FreeLayout(LayoutItem *parent)
FreeLayout::~FreeLayout()
{
foreach (LayoutItem *item, d->children) {
item->unsetManagingLayout(this);
}
releaseManagedItems();
delete d;
}
@ -103,6 +100,13 @@ void FreeLayout::relayout()
}
}
void FreeLayout::releaseManagedItems()
{
foreach (LayoutItem *item, d->children) {
item->unsetManagingLayout(this);
}
}
QRectF FreeLayout::geometry() const
{
if (parent()) {

View File

@ -60,6 +60,7 @@ class PLASMA_EXPORT FreeLayout : public Layout
protected:
void relayout();
void releaseManagedItems();
private:
class Private;

View File

@ -36,13 +36,13 @@ namespace Plasma
class Layout::Private
{
public:
Private(LayoutItem* p)
Private()
: leftMargin(12.0),
rightMargin(12.0),
topMargin(12.0),
bottomMargin(12.0),
spacing(6.0),
parent(p),
parent(0),
animator(0),
relayouting(false)
{
@ -66,13 +66,22 @@ class Layout::Private
Layout::Layout(LayoutItem *parent)
: LayoutItem(),
d(new Private(parent))
d(new Private)
{
setParent(parent);
}
void Layout::setParent(LayoutItem *parent)
{
if (d->parent == parent) {
return;
}
if (d->parent && d->parent->layout() == this) {
d->parent->unsetLayout();
releaseManagedItems();
}
d->parent = parent;
if (parent && parent->layout() != this) {
@ -84,6 +93,7 @@ Layout::~Layout()
{
if (d->parent) {
d->parent->unsetLayout();
d->parent = 0;
}
delete d;

View File

@ -175,6 +175,12 @@ class PLASMA_EXPORT Layout : public LayoutItem
*/
virtual void relayout() = 0;
/**
* When called, the layout must cease management of any
* current LayoutItems it is managing.
*/
virtual void releaseManagedItems() = 0;
/**
* Starts a layout animation. Subclasses may call this
* at the end of their relayout() implementation to

View File

@ -163,10 +163,7 @@ NodeLayout::NodeLayout(LayoutItem * parent)
NodeLayout::~NodeLayout()
{
foreach (LayoutItem * item, d->items.keys()) {
item->unsetManagingLayout(this);
}
releaseManagedItems();
delete d;
}
@ -184,6 +181,13 @@ void NodeLayout::relayout()
}
}
void NodeLayout::releaseManagedItems()
{
foreach (LayoutItem * item, d->items.keys()) {
item->unsetManagingLayout(this);
}
}
QSizeF NodeLayout::sizeHint() const
{
return d->sizeHint;

View File

@ -108,6 +108,7 @@ public:
protected:
void relayout();
void releaseManagedItems();
private:
class Private;