From ffcf6bc16bbcdbd9fe912c154a5bc002cbe59fc9 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 30 Oct 2007 21:00:01 +0000 Subject: [PATCH] let's not hold on to our own parent pointer; just too easy to have it fall out of date. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=731160 --- widgets/widget.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/widgets/widget.cpp b/widgets/widget.cpp index 57ca14383..834c33457 100644 --- a/widgets/widget.cpp +++ b/widgets/widget.cpp @@ -47,7 +47,6 @@ class Widget::Private : minimumSize(0,0), maximumSize(std::numeric_limits::infinity(), std::numeric_limits::infinity()), - parent(0), opacity(1.0), cachePaintMode(Widget::NoCacheMode), wasMovable(false) @@ -58,7 +57,6 @@ class Widget::Private QSizeF minimumSize; QSizeF maximumSize; - Widget *parent; QList childList; qreal opacity; @@ -91,7 +89,7 @@ bool Widget::Private::shouldPaint(QPainter *painter, const QTransform &transform return true; } -Widget::Widget(QGraphicsItem *parent,QObject* parentObject) +Widget::Widget(QGraphicsItem *parent, QObject* parentObject) : QObject(parentObject), QGraphicsItem(parent), d(new Private) @@ -99,11 +97,10 @@ Widget::Widget(QGraphicsItem *parent,QObject* parentObject) setFlag(QGraphicsItem::ItemClipsToShape, true); setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); setCachePaintMode(DeviceCoordinateCacheMode); - d->parent = dynamic_cast(parent); - if (d->parent) { - d->parent->addChild(this); - d->parent->updateGeometry(); + Widget *w = dynamic_cast(parent); + if (w) { + w->addChild(this); } } @@ -283,7 +280,7 @@ void Widget::resize(qreal w, qreal h) Widget *Widget::parent() const { - return d->parent; + return dynamic_cast(parentItem()); } void Widget::addChild(Widget *w) @@ -293,15 +290,17 @@ void Widget::addChild(Widget *w) } d->childList.append(w); - w->d->parent = this; w->setParentItem(this); //kDebug() << "Added Child Widget" << w; if (layout()) { layout()->addItem(w); - updateGeometry(); } + + updateGeometry(); + + //TODO: is this necessary? w->update(); }