summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-07-14 20:58:09 (GMT)
committerEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-07-22 18:04:53 (GMT)
commit4419654149be34e646fdff4c4f2897292a129d33 (patch)
treea96cc8650ceee0901fc7bae651632cdd7732bd3b /src
parentded06db0f1289ab0dbb2bd546cb05cc5ab354be8 (diff)
downloadQt-4419654149be34e646fdff4c4f2897292a129d33.zip
Qt-4419654149be34e646fdff4c4f2897292a129d33.tar.gz
Qt-4419654149be34e646fdff4c4f2897292a129d33.tar.bz2
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 <eduardo.fleury@openbossa.org> Reviewed-by: Anselmo Lacerda S. de Melo <anselmo.melo@openbossa.org>
Diffstat (limited to 'src')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp5
1 files changed, 5 insertions, 0 deletions
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.