summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-09-02 08:44:28 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-09-02 09:15:58 (GMT)
commit17b2b77713b5e2b1f85e231ca67c7dc378f86fa4 (patch)
tree9037149392f0c86b5ca8351111cca0bc4df913f9 /src/gui/graphicsview
parent473662ce30874155841a992f2f3096a4f1633b46 (diff)
downloadQt-17b2b77713b5e2b1f85e231ca67c7dc378f86fa4.zip
Qt-17b2b77713b5e2b1f85e231ca67c7dc378f86fa4.tar.gz
Qt-17b2b77713b5e2b1f85e231ca67c7dc378f86fa4.tar.bz2
Fix the issue where the simplification did not simplify 2 anchors.
(It had to be minimum three anchors.)
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp85
1 files changed, 49 insertions, 36 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index 8065526..871f009 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -525,23 +525,33 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP
endOfSequence = true;
}
}
- if (endOfSequence && candidates.count() >= 2) {
+ if (endOfSequence && candidates.count() >= 1) {
int i;
AnchorVertex *afterSequence= 0;
- QList<AnchorVertex *> adjacentOfSecondLastVertex = g.adjacentVertices(candidates.last());
- Q_ASSERT(adjacentOfSecondLastVertex.count() == 2);
- if (adjacentOfSecondLastVertex.first() == candidates.at(candidates.count() - 2))
- afterSequence = adjacentOfSecondLastVertex.last();
- else
- afterSequence = adjacentOfSecondLastVertex.first();
-
AnchorVertex *beforeSequence = 0;
- QList<AnchorVertex *> adjacentOfSecondVertex = g.adjacentVertices(candidates.first());
- Q_ASSERT(adjacentOfSecondVertex.count() == 2);
- if (adjacentOfSecondVertex.first() == candidates.at(1))
- beforeSequence = adjacentOfSecondVertex.last();
- else
- beforeSequence = adjacentOfSecondVertex.first();
+ // find the items before and after the valid sequence
+ if (candidates.count() == 1) {
+ QList<AnchorVertex *> beforeAndAfterVertices = g.adjacentVertices(candidates.at(0));
+ Q_ASSERT(beforeAndAfterVertices.count() == 2);
+ // Since we only have one vertex, we can pick
+ // any of the two vertices to become before/after.
+ afterSequence = beforeAndAfterVertices.last();
+ beforeSequence = beforeAndAfterVertices.first();
+ } else {
+ QList<AnchorVertex *> adjacentOfSecondLastVertex = g.adjacentVertices(candidates.last());
+ Q_ASSERT(adjacentOfSecondLastVertex.count() == 2);
+ if (adjacentOfSecondLastVertex.first() == candidates.at(candidates.count() - 2))
+ afterSequence = adjacentOfSecondLastVertex.last();
+ else
+ afterSequence = adjacentOfSecondLastVertex.first();
+
+ QList<AnchorVertex *> adjacentOfSecondVertex = g.adjacentVertices(candidates.first());
+ Q_ASSERT(adjacentOfSecondVertex.count() == 2);
+ if (adjacentOfSecondVertex.first() == candidates.at(1))
+ beforeSequence = adjacentOfSecondVertex.last();
+ else
+ beforeSequence = adjacentOfSecondVertex.first();
+ }
// The complete path of the sequence to simplify is: beforeSequence, <candidates>, afterSequence
// where beforeSequence and afterSequence are the endpoints where the anchor is inserted
// between.
@@ -583,34 +593,37 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP
// start and the end of the sequence. We never want to simplify internal
// center anchors where there is an external anchor connected to the center.
AnchorVertex *intervalVertexFrom = intervalFrom == 0 ? beforeSequence : candidates.at(intervalFrom - 1);
+ int effectiveIntervalFrom = intervalFrom;
if (intervalVertexFrom->m_edge == centerEdge
- && intervalVertexFrom->m_item == candidates.at(intervalFrom)->m_item) {
- ++intervalFrom;
- intervalVertexFrom = candidates.at(intervalFrom - 1);
+ && intervalVertexFrom->m_item == candidates.at(effectiveIntervalFrom)->m_item) {
+ ++effectiveIntervalFrom;
+ intervalVertexFrom = candidates.at(effectiveIntervalFrom - 1);
}
AnchorVertex *intervalVertexTo = intervalTo <= candidates.count() ? candidates.at(intervalTo - 1) : afterSequence;
+ int effectiveIntervalTo = intervalTo;
if (intervalVertexTo->m_edge == centerEdge
- && intervalVertexTo->m_item == candidates.at(intervalTo - 2)->m_item) {
- --intervalTo;
- intervalVertexTo = candidates.at(intervalTo - 1);
- }
-
- QVector<AnchorVertex*> subCandidates;
- if (forward) {
- subCandidates = candidates.mid(intervalFrom, intervalTo - intervalFrom - 1);
- } else {
- // reverse the order of the candidates.
- qSwap(intervalVertexFrom, intervalVertexTo);
- do {
- ++intervalFrom;
- subCandidates.prepend(candidates.at(intervalFrom - 1));
- } while (intervalFrom < intervalTo - 1);
+ && intervalVertexTo->m_item == candidates.at(effectiveIntervalTo - 2)->m_item) {
+ --effectiveIntervalTo;
+ intervalVertexTo = candidates.at(effectiveIntervalTo - 1);
}
- if (simplifySequentialChunk(&g, intervalVertexFrom, subCandidates, intervalVertexTo)) {
- dirty = true;
- break;
+ if (effectiveIntervalTo - effectiveIntervalFrom >= 2) {
+ QVector<AnchorVertex*> subCandidates;
+ if (forward) {
+ subCandidates = candidates.mid(effectiveIntervalFrom, effectiveIntervalTo - effectiveIntervalFrom - 1);
+ } else {
+ // reverse the order of the candidates.
+ qSwap(intervalVertexFrom, intervalVertexTo);
+ do {
+ ++effectiveIntervalFrom;
+ subCandidates.prepend(candidates.at(effectiveIntervalFrom - 1));
+ } while (effectiveIntervalFrom < effectiveIntervalTo - 1);
+ }
+ if (simplifySequentialChunk(&g, intervalVertexFrom, subCandidates, intervalVertexTo)) {
+ dirty = true;
+ break;
+ }
+ // finished simplification of chunk with same direction
}
- // finished simplification of chunk with same direction
}
if (forward == (prev == data->from))
--intervalTo;