don't call values() and optimize the ordering of operations for items not already on the scene

svn path=/trunk/KDE/kdelibs/; revision=1044950
This commit is contained in:
Aaron J. Seigo 2009-11-05 01:12:22 +00:00
parent fd6cd93e9d
commit 84c7463c53

View File

@ -474,19 +474,13 @@ Containment *Corona::addContainmentDelayed(const QString &name, const QVariantLi
void Corona::addOffscreenWidget(QGraphicsWidget *widget)
{
if (d->offscreenWidgets.values().contains(widget)) {
kDebug() << "widget is already an offscreen widget!";
return;
foreach (QGraphicsWidget *w, d->offscreenWidgets) {
if (w == widget) {
kDebug() << "widget is already an offscreen widget!";
return;
}
}
if (!widget->scene()) {
addItem(widget);
}
QGraphicsWidget *pw = widget->parentWidget();
widget->setParentItem(0);
widget->setParent(pw);
//search for an empty spot in the topleft quadrant of the scene. each 'slot' is QWIDGETSIZE_MAX
//x QWIDGETSIZE_MAX, so we're guaranteed to never have to move widgets once they're placed here.
int i = 0;
@ -496,7 +490,15 @@ void Corona::addOffscreenWidget(QGraphicsWidget *widget)
d->offscreenWidgets[i] = widget;
widget->setPos((-i - 1) * QWIDGETSIZE_MAX, -QWIDGETSIZE_MAX);
kDebug() << "adding offscreen widget at slot " << i;
QGraphicsWidget *pw = widget->parentWidget();
widget->setParentItem(0);
widget->setParent(pw);
//kDebug() << "adding offscreen widget at slot " << i;
if (!widget->scene()) {
addItem(widget);
}
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(offscreenWidgetDestroyed(QObject*)));
}