diff --git a/widgets/borderlayout.cpp b/widgets/borderlayout.cpp index b9234f9db..9ed87b55c 100644 --- a/widgets/borderlayout.cpp +++ b/widgets/borderlayout.cpp @@ -167,7 +167,9 @@ void BorderLayout::addItem(Plasma::LayoutItem * item) void BorderLayout::addItem(Plasma::LayoutItem * item, Position position) { + removeItem(item); d->itemPositions[position] = item; + item->setManagingLayout(this); update(); } @@ -178,6 +180,7 @@ void BorderLayout::removeItem(LayoutItem * item) i.next(); if (i.value() == item) { i.remove(); + item->unsetManagingLayout(this); } } update(); diff --git a/widgets/boxlayout.cpp b/widgets/boxlayout.cpp index c1e60ccc2..3a58ac396 100644 --- a/widgets/boxlayout.cpp +++ b/widgets/boxlayout.cpp @@ -297,26 +297,28 @@ int BoxLayout::count() const void BoxLayout::insertItem(int index, LayoutItem *item) { - if (!item) { + if (!item || d->children.contains(item)) { return; } item->setManagingLayout(this); - if ( index == -1 ) + if (index == -1) { index = d->children.size(); + } d->children.insert(index, item); - if ( animator() ) + if (animator()) { animator()->setCurrentState(item,LayoutAnimator::InsertedState); + } update(); } void BoxLayout::addItem(LayoutItem *item) { - insertItem(-1,item); + insertItem(-1, item); } void BoxLayout::removeItem(LayoutItem *item) diff --git a/widgets/flowlayout.cpp b/widgets/flowlayout.cpp index 6bf129379..a9223dc02 100644 --- a/widgets/flowlayout.cpp +++ b/widgets/flowlayout.cpp @@ -54,21 +54,29 @@ int FlowLayout::count() const { return d->items.count(); } + void FlowLayout::addItem(LayoutItem* item) { + if (d->items.contains(item)) { + return; + } + d->items << item; - if ( animator() ) + if (animator()) { animator()->setCurrentState(item,LayoutAnimator::InsertedState); + } item->setManagingLayout(this); } void FlowLayout::removeItem(LayoutItem* item) { + item->unsetManagingLayout(this); d->items.removeAll(item); - if ( animator() ) + if (animator()) { animator()->setCurrentState(item,LayoutAnimator::RemovedState); + } } int FlowLayout::indexOf(LayoutItem* item) const { diff --git a/widgets/freelayout.cpp b/widgets/freelayout.cpp index 50b21702b..d9326d2c6 100644 --- a/widgets/freelayout.cpp +++ b/widgets/freelayout.cpp @@ -51,6 +51,10 @@ Qt::Orientations FreeLayout::expandingDirections() const void FreeLayout::addItem(LayoutItem *item) { + if (d->children.contains(item)) { + return; + } + d->children << item; item->setManagingLayout(this); } @@ -58,6 +62,7 @@ void FreeLayout::addItem(LayoutItem *item) void FreeLayout::removeItem(LayoutItem *item) { d->children.removeAll(item); + item->unsetManagingLayout(this); } int FreeLayout::indexOf(LayoutItem *item) const diff --git a/widgets/nodelayout.cpp b/widgets/nodelayout.cpp index c99d07da9..358f32748 100644 --- a/widgets/nodelayout.cpp +++ b/widgets/nodelayout.cpp @@ -194,22 +194,34 @@ void NodeLayout::addItem (LayoutItem * item) void NodeLayout::addItem (LayoutItem * item, NodeCoordinate topLeft, NodeCoordinate bottomRight) { - if (!item) return; + if (!item) { + return; + } + d->items[item] = QPair(topLeft, bottomRight); + item->setManagingLayout(this); d->calculateSizeHint(item); } void NodeLayout::addItem (LayoutItem * item, NodeCoordinate node, qreal xr, qreal yr) { - if (!item) return; + if (!item) { + return; + } + d->items[item] = QPair(node, NodeCoordinate::simple(xr, yr, NodeCoordinate::InnerRelative, NodeCoordinate::InnerRelative)); + item->setManagingLayout(this); d->calculateSizeHint(item); } void NodeLayout::removeItem (LayoutItem * item) { - if (!item) return; + if (!item) { + return; + } + + item->unsetManagingLayout(this); d->items.remove(item); d->calculateSizeHint(); }