code defensively so that items can't be double added to layouts. i love the class design here that makes me duplicate code all over =(((

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=738877
This commit is contained in:
Aaron J. Seigo 2007-11-19 22:04:30 +00:00
parent 364b0dca90
commit 9b25961432
5 changed files with 39 additions and 9 deletions

View File

@ -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();

View File

@ -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)

View File

@ -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
{

View File

@ -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

View File

@ -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<NodeCoordinate, NodeCoordinate>(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<NodeCoordinate, NodeCoordinate>(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();
}