diff options
author | Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> | 2009-08-13 21:04:50 (GMT) |
---|---|---|
committer | Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> | 2009-08-13 21:04:50 (GMT) |
commit | 8014408e95b920b98214040a340f68750f38a53b (patch) | |
tree | 613ea4118439b490380c41a8105dc3dd456d5185 /src/gui/graphicsview | |
parent | fd8c247f5fcf56c2dfe65c6dc88e6cc39ae1ea44 (diff) | |
download | Qt-8014408e95b920b98214040a340f68750f38a53b.zip Qt-8014408e95b920b98214040a340f68750f38a53b.tar.gz Qt-8014408e95b920b98214040a340f68750f38a53b.tar.bz2 |
QGraphicsAnchorLayout: implement "deep" simplification
Re-start the simplification procedure every time there's a change it
the adjacent count of a vertex -- which happens when a new parallel
anchor is created.
The original algorithm stopped some simplifications too early,
demanding the simplex unnecessarily.
Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
Reviewed-by: Artur Duque de Souza <artur.souza@openbossa.org>
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 39 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.h | 2 |
2 files changed, 35 insertions, 6 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 09fe1b9..73fc025 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -218,7 +218,7 @@ inline static qreal checkAdd(qreal a, qreal b) * anchors between \a before and \a after, and can be restored back to the anchors it is a * placeholder for. */ -static void simplifySequentialChunk(Graph<AnchorVertex, AnchorData> *graph, +static bool simplifySequentialChunk(Graph<AnchorVertex, AnchorData> *graph, AnchorVertex *before, const QVector<AnchorVertex*> &vertices, AnchorVertex *after) @@ -281,6 +281,23 @@ static void simplifySequentialChunk(Graph<AnchorVertex, AnchorData> *graph, newAnchor->sizeAtMaximum = pref; } graph->createEdge(before, after, newAnchor); + + // True if we created a parallel anchor + return newAnchor != sequence; +} + +void QGraphicsAnchorLayoutPrivate::simplifyGraph(Orientation orientation) +{ + AnchorVertex *rootVertex = graph[orientation].rootVertex(); + + if (!rootVertex) + return; + + bool dirty; + int count = 0; + do { + dirty = simplifyGraphIteration(orientation); + } while (dirty); } /*! @@ -312,15 +329,13 @@ static void simplifySequentialChunk(Graph<AnchorVertex, AnchorData> *graph, * sequence. This is ok, but that sequence should not be affected by stretch factors. * */ -void QGraphicsAnchorLayoutPrivate::simplifyGraph(QGraphicsAnchorLayoutPrivate::Orientation orientation) +bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutPrivate::Orientation orientation) { Q_Q(QGraphicsAnchorLayout); Graph<AnchorVertex, AnchorData> &g = graph[orientation]; AnchorVertex *v = g.rootVertex(); - if (!v) - return; - QSet<AnchorVertex*> visited; + QSet<AnchorVertex *> visited; QStack<AnchorVertex *> stack; stack.push(v); QVector<AnchorVertex*> candidates; @@ -328,6 +343,8 @@ void QGraphicsAnchorLayoutPrivate::simplifyGraph(QGraphicsAnchorLayoutPrivate::O const QGraphicsAnchorLayout::Edge centerEdge = pickEdge(QGraphicsAnchorLayout::HCenter, orientation); const QGraphicsAnchorLayout::Edge layoutEdge = oppositeEdge(v->m_edge); + bool dirty = false; + // walk depth-first. while (!stack.isEmpty()) { v = stack.pop(); @@ -422,7 +439,10 @@ void QGraphicsAnchorLayoutPrivate::simplifyGraph(QGraphicsAnchorLayoutPrivate::O subCandidates.prepend(candidates.at(intervalFrom - 1)); } while (intervalFrom < intervalTo - 1); } - simplifySequentialChunk(&g, intervalVertexFrom, subCandidates, intervalVertexTo); + if (simplifySequentialChunk(&g, intervalVertexFrom, subCandidates, intervalVertexTo)) { + dirty = true; + break; + } // finished simplification of chunk with same direction } if (forward == (prev == data->origin)) @@ -433,7 +453,11 @@ void QGraphicsAnchorLayoutPrivate::simplifyGraph(QGraphicsAnchorLayoutPrivate::O } prev = v1; } + + if (dirty) + break; } + if (endOfSequence) candidates.clear(); @@ -445,8 +469,11 @@ void QGraphicsAnchorLayoutPrivate::simplifyGraph(QGraphicsAnchorLayoutPrivate::O continue; stack.push(next); } + visited.insert(v); } + + return dirty; } static void restoreSimplifiedAnchor(Graph<AnchorVertex, AnchorData> &g, diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index fa79f6b..af58065 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -343,7 +343,9 @@ public: // Activation methods void simplifyGraph(Orientation orientation); + bool simplifyGraphIteration(Orientation orientation); void restoreSimplifiedGraph(Orientation orientation); + void calculateGraphs(); void calculateGraphs(Orientation orientation); void setAnchorSizeHintsFromItems(Orientation orientation); |