summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-04-21 13:38:30 +0200
committerJason McDonald <jason.mcdonald@nokia.com>2009-04-22 09:12:59 +1000
commit727ca7a3b6a63b7b76ffe03c4eea72fe37ba2def (patch)
treea19a5eb94351312a36c4806f61b8a094a474f4f3
parent8035636cfecab04a2ad89709ebfb59f8ccd7fd22 (diff)
downloadqt4-tools-727ca7a3b6a63b7b76ffe03c4eea72fe37ba2def.tar.gz
BT: Fix lock-up & crash in the Elastic Nodes example
Ensure that we don't divide by 0 when two nodes are exactly on top of each other. Reviewed-by: Alexis Reviewed-by: Joao (cherry picked from commit 6a3735a47de8a9851e7795cf023d95d81867260d)
-rw-r--r--examples/graphicsview/elasticnodes/edge.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/examples/graphicsview/elasticnodes/edge.cpp b/examples/graphicsview/elasticnodes/edge.cpp
index b43b1345e1..81ae4da803 100644
--- a/examples/graphicsview/elasticnodes/edge.cpp
+++ b/examples/graphicsview/elasticnodes/edge.cpp
@@ -93,11 +93,16 @@ void Edge::adjust()
QLineF line(mapFromItem(source, 0, 0), mapFromItem(dest, 0, 0));
qreal length = line.length();
- QPointF edgeOffset((line.dx() * 10) / length, (line.dy() * 10) / length);
prepareGeometryChange();
- sourcePoint = line.p1() + edgeOffset;
- destPoint = line.p2() - edgeOffset;
+
+ if (!qFuzzyCompare(length, qreal(0.0))) {
+ QPointF edgeOffset((line.dx() * 10) / length, (line.dy() * 10) / length);
+ sourcePoint = line.p1() + edgeOffset;
+ destPoint = line.p2() - edgeOffset;
+ } else {
+ sourcePoint = destPoint = line.p1();
+ }
}
QRectF Edge::boundingRect() const