summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-04-21 14:59:55 (GMT)
committerJoão Abecasis <joao@abecasis.name>2009-04-22 10:09:30 (GMT)
commit5cba8ea7d6b793ba0012dfc387e6859ace7c664a (patch)
treecdb5475e8d74f1aab7ba964609fa990e3b6233e6 /examples
parenta9d0e4f830687b33c3a93cce2a3b8d77cc3546cc (diff)
downloadQt-5cba8ea7d6b793ba0012dfc387e6859ace7c664a.zip
Qt-5cba8ea7d6b793ba0012dfc387e6859ace7c664a.tar.gz
Qt-5cba8ea7d6b793ba0012dfc387e6859ace7c664a.tar.bz2
Fix more NaNs in Elastic Nodes example
Don't try to draw zero-length lines. Don't draw lines if nodes are superimposed. Reviewed-by: Andreas
Diffstat (limited to 'examples')
-rw-r--r--examples/graphicsview/elasticnodes/edge.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/examples/graphicsview/elasticnodes/edge.cpp b/examples/graphicsview/elasticnodes/edge.cpp
index e32a35a..eb02143 100644
--- a/examples/graphicsview/elasticnodes/edge.cpp
+++ b/examples/graphicsview/elasticnodes/edge.cpp
@@ -96,7 +96,7 @@ void Edge::adjust()
prepareGeometryChange();
- if (!qFuzzyCompare(length, qreal(0.0))) {
+ if (length > qreal(20.)) {
QPointF edgeOffset((line.dx() * 10) / length, (line.dy() * 10) / length);
sourcePoint = line.p1() + edgeOffset;
destPoint = line.p2() - edgeOffset;
@@ -124,12 +124,15 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
if (!source || !dest)
return;
- // Draw the line itself
QLineF line(sourcePoint, destPoint);
+ if (qFuzzyCompare(line.length(), qreal(0.)))
+ return;
+
+ // Draw the line itself
painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter->drawLine(line);
- // Draw the arrows if there's enough room
+ // Draw the arrows
double angle = ::acos(line.dx() / line.length());
if (line.dy() >= 0)
angle = TwoPi - angle;