PDA

View Full Version : Graphics View - Scene & Item hierarchy



mooreaa
29th June 2008, 23:49
Hello,

I have a question regarding organization and design. I've mentioned this in another post, but I am trying to do a basic system like Microsoft's Visio.

I have objects and wires that connect the objects.

I have a few hotspots that causes the system to know when to create a wire. The hotspot system works right now by overriding QGraphicsScene's mousePressEvent, then checking to see what type of object was clicked.

This is more or less how the Diagram Scene example works.

This seems to work, but this doesn't seem to be like the best design. I would think it would be better to override the specific graphics item derived object's mousePressEvent, and then tell the system to start drawing the line.

The problem is in order to draw the line I need to repaint more than just the bounding rect for the given hotspot. So when I place the line code in the hotspot object, the line drawing is all messed up (chopped up/missing, not visible etc).

Right now I am using a poor method (RTTI's typeid) in my QGraphicsScene derived class to determine what type of object was clicked. I'd like to avoid having to put all this kind of code in QGraphicsScnee and move it to the specific object.

Basically have have a "Node" GraphicsItem object and a "Wire" GraphicsItem object, both of these are independent, but the graphicsitem does have a list of wires that are anchored to it, so as an example, if i move a node, I want to use the itemChanged event to update the line rather than the mousemove override in QGraphicsScene. When I did this, my wire line didn't get properly redrawn.

How can I do this and get the redraw to work correctly?