PDA

View Full Version : Problem with graph drawing



Rizo Isrof
28th August 2011, 18:20
Hello, Qt Centre!

I am creating a graph/automata drawing tool with Qt and it's QGraphicsView framework. Lately I've been working around a geometrical problem that I just can't solve by myself. I need to draw oriented edges and arcs (edges are strigt lines, while arcs are curved splines). I use QGraphicsLineItem objects and QGraphicsPolygonItem to represent an edge and its arrow; for the arcs I use QGraphicsPathItem objects. What happens is that, since transitions (both, edges and arcs) are always oriented (that is, the arrow is always pointing) to the center of the node's items, I need to solve two problems.

First of all, the arrow position (and the edge's tip point too) should have an offset accordingly to the shape of the node. The arrow should be fixed to the outer point of the node's graphical object. The problem is that nodes may have arbitrary shapes and dimensions so I can't just define a fixed offset. I have to find a way to get an intersection point of the node's shape and the edge's line. It seems that the Qt documentation has no explicit technique to do that. So I'm asking your help...

The second problem rises from the first one. When a arc is added to a node, the end point is the node's center point. So the spline drawing is oriented to that point. If I change the fixing point to the outer point on the node's shape (that I describe in the first question) the rendering of the spline will also be affected (I use the path.quadTo(const QPointF & c, const QPointF & endPoint) method to draw the spline). So my question is: how can I keep the spline's orientation to the node's center point, but draw it only to the fixing point on the node's shape? And thus place the arrow to that fixing point.

Thanks in advance for your attention.

high_flyer
29th August 2011, 09:20
It seems that the Qt documentation has no explicit technique to do that. So I'm asking your help...
I don't see why it even should include such a thing?
Its very specific problem, that has nothing to do with Qt, but with a specific application implementation.


The problem is that nodes may have arbitrary shapes and dimensions so I can't just define a fixed offset. I have to find a way to get an intersection point of the node's shape and the edge's line.
The most obvious way would be to get the shapes bounding rect, and have the intersection at the middle of the upper face.


how can I keep the spline's orientation to the node's center point, but draw it only to the fixing point on the node's shape?
Maybe I don't understand, but you can draw it oriented to the center, and than translate it to the outer point...

akash
29th August 2011, 12:06
may be elasticnode example of Qt can help.
•graphicsview/elasticnodes/