From f48d5dd7554edef5ac3fa11ebd86eaa52a8e23b6 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Thu, 23 Jul 2009 19:59:05 -0300 Subject: QGraphicsAnchorLayout: Fix center anchor deletion logic We were missing a call to "removeCenterAnchors" in the "removeAnchors" method. To solve that, and also reduce the number of useless calls to that method, this commit: 1) Calls it only from "removeInternalVertex" 2) Does some preliminary testing before calling it 3) Replace the former test inside "removeCenterAnchors" by a Q_ASSERT It also adds other Q_ASSERTs to protect us from regression bugs. Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraphicsanchorlayout.cpp | 3 --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp index fe335e8..6360e75 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp @@ -200,9 +200,6 @@ void QGraphicsAnchorLayout::removeAnchor(QGraphicsLayoutItem *firstItem, Edge fi } d->removeAnchor(firstItem, firstEdge, secondItem, secondEdge); - d->removeCenterAnchors(firstItem, firstEdge); - d->removeCenterAnchors(secondItem, secondEdge); - invalidate(); } diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 7516c06..afe60a1 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -456,6 +456,9 @@ void QGraphicsAnchorLayoutPrivate::deleteLayoutEdges() { Q_Q(QGraphicsAnchorLayout); + Q_ASSERT(internalVertex(q, QGraphicsAnchorLayout::HCenter) == NULL); + Q_ASSERT(internalVertex(q, QGraphicsAnchorLayout::VCenter) == NULL); + removeAnchor(q, QGraphicsAnchorLayout::Left, q, QGraphicsAnchorLayout::Right); removeAnchor(q, QGraphicsAnchorLayout::Top, q, QGraphicsAnchorLayout::Bottom); } @@ -568,11 +571,6 @@ void QGraphicsAnchorLayoutPrivate::removeCenterAnchors( return; } - // Check if vertex is used by other than the internal anchors - AnchorVertex *center = internalVertex(item, centerEdge); - if (graph[orientation].adjacentVertices(center).count() > 2) - return; - // Orientation code QGraphicsAnchorLayout::Edge firstEdge; QGraphicsAnchorLayout::Edge lastEdge; @@ -586,8 +584,10 @@ void QGraphicsAnchorLayoutPrivate::removeCenterAnchors( } AnchorVertex *first = internalVertex(item, firstEdge); + AnchorVertex *center = internalVertex(item, centerEdge); AnchorVertex *last = internalVertex(item, lastEdge); - Q_ASSERT(first && last); + Q_ASSERT(first && center && last); + Q_ASSERT(graph[orientation].adjacentVertices(center).count() == 2); // Create new anchor AnchorData *oldData = graph[orientation].edgeData(first, center); @@ -792,6 +792,12 @@ void QGraphicsAnchorLayoutPrivate::removeInternalVertex(QGraphicsLayoutItem *ite } else { // Update reference count m_vertexList.insert(pair, v); + + if ((v.second == 2) && + ((edge == QGraphicsAnchorLayout::HCenter) || + (edge == QGraphicsAnchorLayout::VCenter))) { + removeCenterAnchors(item, edge); + } } } -- cgit v0.12