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) void Corona::addOffscreenWidget(QGraphicsWidget *widget)
{ {
if (d->offscreenWidgets.values().contains(widget)) { foreach (QGraphicsWidget *w, d->offscreenWidgets) {
kDebug() << "widget is already an offscreen widget!"; if (w == widget) {
return; 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 //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. //x QWIDGETSIZE_MAX, so we're guaranteed to never have to move widgets once they're placed here.
int i = 0; int i = 0;
@ -496,7 +490,15 @@ void Corona::addOffscreenWidget(QGraphicsWidget *widget)
d->offscreenWidgets[i] = widget; d->offscreenWidgets[i] = widget;
widget->setPos((-i - 1) * QWIDGETSIZE_MAX, -QWIDGETSIZE_MAX); 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*))); connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(offscreenWidgetDestroyed(QObject*)));
} }