went through and checked methods that take or return pointers or indexes and added safety precautions against bad parameters

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=744630
This commit is contained in:
Aaron J. Seigo 2007-12-03 23:53:56 +00:00
parent bc093cdcf5
commit 946e0127b8
3 changed files with 53 additions and 13 deletions

View File

@ -313,6 +313,10 @@ void BoxLayout::insertItem(int index, LayoutItem *item)
void BoxLayout::addItem(LayoutItem *item)
{
if (!item) {
return;
}
insertItem(-1, item);
}
@ -325,8 +329,9 @@ void BoxLayout::removeItem(LayoutItem *item)
item->unsetManagingLayout(this);
d->children.removeAll(item);
if ( animator() )
animator()->setCurrentState(item,LayoutAnimator::RemovedState);
if (animator()) {
animator()->setCurrentState(item, LayoutAnimator::RemovedState);
}
updateGeometry();
}
@ -338,13 +343,20 @@ int BoxLayout::indexOf(LayoutItem *l) const
LayoutItem *BoxLayout::itemAt(int i) const
{
if (i >= d->children.count()) {
return 0;
}
return d->children[i];
}
LayoutItem *BoxLayout::takeAt(int i)
{
return d->children.takeAt(i);
if (i >= d->children.count()) {
return 0;
}
return d->children.takeAt(i);
updateGeometry();
}

View File

@ -57,7 +57,7 @@ int FlowLayout::count() const
void FlowLayout::addItem(LayoutItem* item)
{
if (d->items.contains(item)) {
if (!item || d->items.contains(item)) {
return;
}
@ -71,6 +71,10 @@ void FlowLayout::addItem(LayoutItem* item)
}
void FlowLayout::removeItem(LayoutItem* item)
{
if (!item) {
return;
}
item->unsetManagingLayout(this);
d->items.removeAll(item);
@ -80,12 +84,21 @@ void FlowLayout::removeItem(LayoutItem* item)
}
int FlowLayout::indexOf(LayoutItem* item) const
{
if (!item) {
return -1;
}
return d->items.indexOf(item);
}
LayoutItem* FlowLayout::itemAt(int i) const
{
if (i >= d->items.count()) {
return 0;
}
return d->items[i];
}
QSizeF FlowLayout::sizeHint() const
{
// TODO A proper algorithm here
@ -98,8 +111,13 @@ QSizeF FlowLayout::sizeHint() const
// testing
return QSizeF(500,500);
}
LayoutItem* FlowLayout::takeAt(int i)
{
if (i >= d->items.count()) {
return 0;
}
return d->items.takeAt(i);
}
@ -123,7 +141,7 @@ void FlowLayout::relayout()
qreal totalWidth = 0;
qreal totalHeight = 0;
foreach( LayoutItem *item , d->items ) {
foreach(LayoutItem *item , d->items) {
totalWidth += item->sizeHint().width();
totalHeight += item->sizeHint().height();
}
@ -146,8 +164,7 @@ void FlowLayout::relayout()
qreal rowHeight = 0;
// lay the items out in left-to-right , top-to-bottom order
foreach( LayoutItem *item , d->items ) {
foreach(LayoutItem *item , d->items) {
const QSizeF& itemSize = item->sizeHint();
int columnSpan = (int)ceil(itemSize.width() / averageWidth);

View File

@ -174,12 +174,12 @@ QSizeF NodeLayout::sizeHint() const
return d->sizeHint;
}
void NodeLayout::addItem (LayoutItem * item)
void NodeLayout::addItem(LayoutItem * item)
{
NodeLayout::addItem (item, NodeCoordinate());
NodeLayout::addItem(item, NodeCoordinate());
}
void NodeLayout::addItem (LayoutItem * item, NodeCoordinate topLeft, NodeCoordinate bottomRight)
void NodeLayout::addItem(LayoutItem * item, NodeCoordinate topLeft, NodeCoordinate bottomRight)
{
if (!item) {
return;
@ -190,7 +190,7 @@ void NodeLayout::addItem (LayoutItem * item, NodeCoordinate topLeft, NodeCoordin
d->calculateSizeHint(item);
}
void NodeLayout::addItem (LayoutItem * item, NodeCoordinate node, qreal xr, qreal yr)
void NodeLayout::addItem(LayoutItem * item, NodeCoordinate node, qreal xr, qreal yr)
{
if (!item) {
return;
@ -202,7 +202,7 @@ void NodeLayout::addItem (LayoutItem * item, NodeCoordinate node, qreal xr, qrea
d->calculateSizeHint(item);
}
void NodeLayout::removeItem (LayoutItem * item)
void NodeLayout::removeItem(LayoutItem * item)
{
if (!item) {
return;
@ -220,17 +220,28 @@ int NodeLayout::count() const
int NodeLayout::indexOf(LayoutItem * item) const
{
if (!item) return -1;
if (!item) {
return -1;
}
return d->items.keys().indexOf(item);
}
LayoutItem * NodeLayout::itemAt(int i) const
{
if (i >= d->items.count()) {
return 0;
}
return d->items.keys()[i];
}
LayoutItem * NodeLayout::takeAt(int i)
{
if (i >= d->items.count()) {
return 0;
}
LayoutItem * item = itemAt(i);
removeItem(item);
return item;