diff options
author | Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> | 2009-08-13 23:53:48 (GMT) |
---|---|---|
committer | Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> | 2009-08-13 23:53:48 (GMT) |
commit | fcd2540c1e5190b9edaebc6842263630a5d2da2b (patch) | |
tree | fe21b0ab31d46a2878b84091498b3ee74d01d410 | |
parent | 23441f49a23cbf936b60140c5c8a6d5cb3ca00a7 (diff) | |
download | Qt-fcd2540c1e5190b9edaebc6842263630a5d2da2b.zip Qt-fcd2540c1e5190b9edaebc6842263630a5d2da2b.tar.gz Qt-fcd2540c1e5190b9edaebc6842263630a5d2da2b.tar.bz2 |
QGraphicsAnchorLayout: prepare ground for doing less simplifications
Add variables to track whether the graph is simplified or not, as well
as make the functions that need it simplified/restored call the
corresponding functions. The functions look at the state variables, so
it's safe to just call them.
Also added Q_ASSERT() through the code paths that SHOULD have the full
graph (not simplified), for making easy to track bugs in future
refactorings.
Ironically this commit cause more calls to simplify/restore right now,
but the state will be better when we fix some functions to be
simplification compatible ;-)
Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
Reviewed-by: Artur Duque de Souza <artur.souza@openbossa.org>
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout.cpp | 10 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 59 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.h | 3 |
3 files changed, 57 insertions, 15 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp index 902f0b2..9846988 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp @@ -221,6 +221,12 @@ qreal QGraphicsAnchorLayout::spacing(Qt::Orientation orientation) const void QGraphicsAnchorLayout::setGeometry(const QRectF &geom) { Q_D(QGraphicsAnchorLayout); + + // ### REMOVE IT WHEN calculateVertexPositions and setItemsGeometries are + // simplification compatible! + d->restoreSimplifiedGraph(QGraphicsAnchorLayoutPrivate::Horizontal); + d->restoreSimplifiedGraph(QGraphicsAnchorLayoutPrivate::Vertical); + QGraphicsLayout::setGeometry(geom); d->calculateVertexPositions(QGraphicsAnchorLayoutPrivate::Horizontal); d->calculateVertexPositions(QGraphicsAnchorLayoutPrivate::Vertical); @@ -235,6 +241,10 @@ void QGraphicsAnchorLayout::removeAt(int index) if (!item) return; + // Removing an item affects both horizontal and vertical graphs + d->restoreSimplifiedGraph(QGraphicsAnchorLayoutPrivate::Horizontal); + d->restoreSimplifiedGraph(QGraphicsAnchorLayoutPrivate::Vertical); + d->removeCenterConstraints(item, QGraphicsAnchorLayoutPrivate::Horizontal); d->removeCenterConstraints(item, QGraphicsAnchorLayoutPrivate::Vertical); d->removeAnchors(item); diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 73fc025..75e40c4 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -168,8 +168,10 @@ QString GraphPath::toString() const QGraphicsAnchorLayoutPrivate::QGraphicsAnchorLayoutPrivate() : calculateGraphCacheDirty(1) { - for (int i = 0; i < NOrientations; ++i) + for (int i = 0; i < NOrientations; ++i) { spacing[i] = -1; + graphSimplified[i] = false; + } } QGraphicsAnchorLayout::Edge QGraphicsAnchorLayoutPrivate::oppositeEdge( @@ -288,6 +290,13 @@ static bool simplifySequentialChunk(Graph<AnchorVertex, AnchorData> *graph, void QGraphicsAnchorLayoutPrivate::simplifyGraph(Orientation orientation) { + if (graphSimplified[orientation]) + return; + graphSimplified[orientation] = true; + + qDebug("Simplifying Graph for %s", + orientation == Horizontal ? "Horizontal" : "Vertical"); + AnchorVertex *rootVertex = graph[orientation].rootVertex(); if (!rootVertex) @@ -523,6 +532,13 @@ static void restoreSimplifiedAnchor(Graph<AnchorVertex, AnchorData> &g, void QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(Orientation orientation) { + if (!graphSimplified[orientation]) + return; + graphSimplified[orientation] = false; + + qDebug("Restoring Simplified Graph for %s", + orientation == Horizontal ? "Horizontal" : "Vertical"); + Q_Q(QGraphicsAnchorLayout); Graph<AnchorVertex, AnchorData> &g = graph[orientation]; @@ -593,6 +609,8 @@ void QGraphicsAnchorLayoutPrivate::deleteLayoutEdges() void QGraphicsAnchorLayoutPrivate::createItemEdges(QGraphicsLayoutItem *item) { + Q_ASSERT(!graphSimplified[Horizontal] && !graphSimplified[Vertical]); + items.append(item); // Horizontal @@ -641,6 +659,8 @@ void QGraphicsAnchorLayoutPrivate::createCenterAnchors( return; } + Q_ASSERT(!graphSimplified[orientation]); + // Check if vertex already exists if (internalVertex(item, centerEdge)) return; @@ -700,6 +720,8 @@ void QGraphicsAnchorLayoutPrivate::removeCenterAnchors( return; } + Q_ASSERT(!graphSimplified[orientation]); + // Orientation code QGraphicsAnchorLayout::Edge firstEdge; QGraphicsAnchorLayout::Edge lastEdge; @@ -770,6 +792,8 @@ void QGraphicsAnchorLayoutPrivate::removeCenterAnchors( void QGraphicsAnchorLayoutPrivate::removeCenterConstraints(QGraphicsLayoutItem *item, Orientation orientation) { + Q_ASSERT(!graphSimplified[orientation]); + // Remove the item center constraints associated to this item // ### This is a temporary solution. We should probably use a better // data structure to hold items and/or their associated constraints @@ -829,6 +853,10 @@ void QGraphicsAnchorLayoutPrivate::anchor(QGraphicsLayoutItem *firstItem, return; } + // Guarantee that the graph is no simplified when adding this anchor, + // anchor manipulation always happen in the full graph + restoreSimplifiedGraph(edgeOrientation(firstEdge)); + // In QGraphicsAnchorLayout, items are represented in its internal // graph as four anchors that connect: // - Left -> HCenter @@ -887,6 +915,10 @@ void QGraphicsAnchorLayoutPrivate::addAnchor(QGraphicsLayoutItem *firstItem, QGraphicsAnchorLayout::Edge secondEdge, AnchorData *data) { + // Guarantee that the graph is no simplified when adding this anchor, + // anchor manipulation always happen in the full graph + restoreSimplifiedGraph(edgeOrientation(firstEdge)); + // Is the Vertex (firstItem, firstEdge) already represented in our // internal structure? AnchorVertex *v1 = addInternalVertex(firstItem, firstEdge); @@ -960,6 +992,10 @@ void QGraphicsAnchorLayoutPrivate::removeAnchor(QGraphicsLayoutItem *firstItem, QGraphicsLayoutItem *secondItem, QGraphicsAnchorLayout::Edge secondEdge) { + // Guarantee that the graph is no simplified when adding this anchor, + // anchor manipulation always happen in the full graph + restoreSimplifiedGraph(edgeOrientation(firstEdge)); + // Look for both vertices AnchorVertex *v1 = internalVertex(firstItem, firstEdge); AnchorVertex *v2 = internalVertex(secondItem, secondEdge); @@ -990,6 +1026,8 @@ void QGraphicsAnchorLayoutPrivate::removeVertex(QGraphicsLayoutItem *item, QGrap void QGraphicsAnchorLayoutPrivate::removeAnchors(QGraphicsLayoutItem *item) { + Q_ASSERT(!graphSimplified[Horizontal] && !graphSimplified[Vertical]); + // remove the center anchor first!! removeCenterAnchors(item, QGraphicsAnchorLayout::HCenter, false); removeVertex(item, QGraphicsAnchorLayout::Left); @@ -1090,14 +1128,6 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs() if (!calculateGraphCacheDirty) return; - //simplifyGraph(Horizontal); - //simplifyGraph(Vertical); - //Q_Q(QGraphicsAnchorLayout); - //q->dumpGraph(); - //restoreSimplifiedGraph(Horizontal); // should not be here, but currently crashes if not - //restoreSimplifiedGraph(Vertical); // should not be here, but currently crashes if not - - calculateGraphs(Horizontal); calculateGraphs(Vertical); @@ -1145,6 +1175,10 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs( { Q_Q(QGraphicsAnchorLayout); + // ### REMOVE IT WHEN calculateVertexPositions and setItemsGeometries are + // simplification compatible! + restoreSimplifiedGraph(orientation); + // Reset the nominal sizes of each anchor based on the current item sizes setAnchorSizeHintsFromItems(orientation); @@ -1154,9 +1188,7 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs( // However, as the two setAnchorSizeHints methods above are not // ready to be run on top of a simplified graph, we must simplify // and restore it every time we get here. - static bool simplification = qgetenv("QT_ANCHORLAYOUT_NO_SIMPLIFICATION").isEmpty(); - if (simplification) - simplifyGraph(orientation); + simplifyGraph(orientation); // Traverse all graph edges and store the possible paths to each vertex findPaths(orientation); @@ -1285,9 +1317,6 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs( qDeleteAll(constraints[orientation]); constraints[orientation].clear(); graphPaths[orientation].clear(); // ### - - if (simplification) - restoreSimplifiedGraph(orientation); } /*! diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index af58065..21a4a3f 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -403,5 +403,8 @@ public: Interval interpolationInterval[2]; qreal interpolationProgress[2]; + // ### + bool graphSimplified[2]; + uint calculateGraphCacheDirty : 1; }; |