From 3c690fea84459e11f2c9a7c2eb313d70b78b1fbb Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Mon, 28 May 2007 05:52:05 +0000 Subject: [PATCH] * add API docu to the methods i added * add a resetLayout() so layouts can release LayoutItems on deletion, avoiding dangling pointers and possible crashes svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=668931 --- widgets/layoutitem.cpp | 5 +++++ widgets/layoutitem.h | 20 ++++++++++++++++++++ widgets/vboxlayout.cpp | 3 +++ 3 files changed, 28 insertions(+) diff --git a/widgets/layoutitem.cpp b/widgets/layoutitem.cpp index 05356182a..ddc8518e0 100644 --- a/widgets/layoutitem.cpp +++ b/widgets/layoutitem.cpp @@ -70,6 +70,11 @@ qreal LayoutItem::widthForHeight(qreal h) const return 0.0; } +void LayoutItem::resetLayout() +{ + d->layout = 0; +} + void LayoutItem::setLayout(Layout* layout) { if (d->layout) { diff --git a/widgets/layoutitem.h b/widgets/layoutitem.h index f8db42c06..b30ffb53b 100644 --- a/widgets/layoutitem.h +++ b/widgets/layoutitem.h @@ -54,7 +54,27 @@ class KDE_EXPORT LayoutItem virtual QSizeF sizeHint() const = 0; + /** + * Resets the layout to 0 and doesn't notify the previous layout. + * Should only be used by the current layout when relinquishing the item, + * e.g. during layout destruction. + */ + void resetLayout(); + + /** + * Sets the layout so that the LayoutItem may inform the layout of its + * deletion. Should only be used by the layout it is added to. + * + * If the layout item is currently associated with another layout, it will + * first remove itself from that layout. + * + * @param layout The Layout that this LayoutItem will be managed by. + */ void setLayout(Layout* layout); + + /** + * Returns the layout this item is currently associated with + */ Layout* layout(); private: diff --git a/widgets/vboxlayout.cpp b/widgets/vboxlayout.cpp index bc125273a..00d87de76 100644 --- a/widgets/vboxlayout.cpp +++ b/widgets/vboxlayout.cpp @@ -44,6 +44,9 @@ VBoxLayout::VBoxLayout(LayoutItem *parent) VBoxLayout::~VBoxLayout() { + foreach (LayoutItem *l, d->childList) { + l->resetLayout(); + } } Qt::Orientations VBoxLayout::expandingDirections() const