From 4419654149be34e646fdff4c4f2897292a129d33 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Tue, 14 Jul 2009 17:58:09 -0300 Subject: QGraphicsAnchorLayout: Testing for existing anchors before adding new ones The layout was not aware of the fact an anchor could already exist when it was added. This commit ensures that only one anchor exists between two vertices to avoid unwanted behavior and memory leaks (AnchorData's and Vertices would leak otherwise). Signed-off-by: Eduardo M. Fleury Reviewed-by: Anselmo Lacerda S. de Melo --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 63179ef..9d145a2 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -642,6 +642,11 @@ void QGraphicsAnchorLayoutPrivate::addAnchor(QGraphicsLayoutItem *firstItem, AnchorVertex *v1 = addInternalVertex(firstItem, firstEdge); AnchorVertex *v2 = addInternalVertex(secondItem, secondEdge); + // Remove previous anchor + // ### Could we update the existing edgeData rather than creating a new one? + if (graph[edgeOrientation(firstEdge)].edgeData(v1, v2)) + removeAnchor(firstItem, firstEdge, secondItem, secondEdge); + // Create a bi-directional edge in the sense it can be transversed both // from v1 or v2. "data" however is shared between the two references // so we still know that the anchor direction is from 1 to 2. -- cgit v0.12