diff options
author | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-08-12 08:35:48 (GMT) |
---|---|---|
committer | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-08-12 09:14:02 (GMT) |
commit | 489685ef0724c852d964504853b86be39bddc7de (patch) | |
tree | e2e200806ebc45a439bae6ea275fd952d95dcc75 /src/gui/graphicsview | |
parent | 3b91bdf93159adcb73c66f64d494a5bdc190c693 (diff) | |
download | Qt-489685ef0724c852d964504853b86be39bddc7de.zip Qt-489685ef0724c852d964504853b86be39bddc7de.tar.gz Qt-489685ef0724c852d964504853b86be39bddc7de.tar.bz2 |
restoring simplified anchors did not work properly recursively.
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 78 |
1 files changed, 51 insertions, 27 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 5469431..9a1cdd0 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -413,6 +413,54 @@ void QGraphicsAnchorLayoutPrivate::simplifyGraph(QGraphicsAnchorLayoutPrivate::O } } +static void restoreSimplifiedAnchor(Graph<AnchorVertex, AnchorData> &g, + AnchorData *edge, + AnchorVertex *before, + AnchorVertex *after) +{ + Q_ASSERT(edge->type != AnchorData::Normal); +#if 0 + static const char *anchortypes[] = {"Normal", + "Sequential", + "Parallel"}; + qDebug("Restoring %s edge.", anchortypes[int(edge->type)]); +#endif + if (edge->type == AnchorData::Sequential) { + SequentialAnchorData* seqEdge = static_cast<SequentialAnchorData*>(edge); + // restore the sequential anchor + AnchorVertex *prev = before; + AnchorVertex *last = after; + if (edge->origin != prev) + qSwap(last, prev); + + for (int i = 0; i < seqEdge->m_edges.count(); ++i) { + AnchorVertex *v1 = (i < seqEdge->m_children.count()) ? seqEdge->m_children.at(i) : last; + AnchorData *data = seqEdge->m_edges.at(i); + if (data->type != AnchorData::Normal) { + restoreSimplifiedAnchor(g, data, prev, v1); + } else { + g.createEdge(prev, v1, data); + } + prev = v1; + } + g.removeEdge(before, after); + } else if (edge->type == AnchorData::Parallel) { + ParallelAnchorData* parallelEdge = static_cast<ParallelAnchorData*>(edge); + AnchorData *parallelEdges[2] = {parallelEdge->firstEdge, + parallelEdge->secondEdge}; + // must remove the old anchor first + g.removeEdge(before, after); + for (int i = 0; i < 2; ++i) { + AnchorData *data = parallelEdges[i]; + if (data->type != AnchorData::Normal) { + restoreSimplifiedAnchor(g, data, before, after); + } else { + g.createEdge(before, after, data); + } + } + } +} + void QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(Orientation orientation) { Q_Q(QGraphicsAnchorLayout); @@ -438,33 +486,9 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(Orientation orientatio if (visited.contains(next)) continue; - QQueue<AnchorData*> queue; - queue.enqueue(g.edgeData(v, next)); - while (!queue.isEmpty()) { - AnchorData *edge = queue.dequeue(); - if (edge->type == AnchorData::Sequential) { - SequentialAnchorData* seqEdge = static_cast<SequentialAnchorData*>(edge); - // restore the sequential anchor - AnchorVertex *prev = v; - AnchorVertex *last = next; - if (edge->origin != prev) - qSwap(last, prev); - - for (int i = 0; i < seqEdge->m_edges.count(); ++i) { - AnchorVertex *v1 = (i < seqEdge->m_children.count()) ? seqEdge->m_children.at(i) : last; - AnchorData *data = seqEdge->m_edges.at(i); - g.createEdge(prev, v1, data); - prev = v1; - } - g.removeEdge(v, next); - } else if (edge->type == AnchorData::Parallel) { - ParallelAnchorData* parallelEdge = static_cast<ParallelAnchorData*>(edge); - queue.enqueue(parallelEdge->firstEdge); - queue.enqueue(parallelEdge->secondEdge); - g.removeEdge(v, next); - } - } - stack.push(next); + AnchorData *edge = g.edgeData(v, next); + if (edge->type != AnchorData::Normal) + restoreSimplifiedAnchor(g, edge, v, next); } visited.insert(v); } |