Download Report - Jan Hosang
Transcript
QGraphicsScene and a view (QGraphicsView), which was implemented for us, to display the graphical objects. 3.4.2 View The implementation for QGraphicsView automatically listens for mouse input from the user. When mouse input is detected, all information about the mouse input received (including screen co-ordinates, button pressed etc.) is encapsulated in a mouseEvent, which is then passed to the appropriate mouse method in the model. The view is automatically updated as items are added to the board via the model. 3.4.3 Scene/Model The QGraphicsScene class behaves as a model and comes with a default implementation for mouse events whereby any mouse event forwarded to it by the view is then forwarded to the topmost item underneath the cursor. This implementation is useful to perform general operations on any object (repositioning for example), but it is not sufficient to facilitate the drawing of objects onto the canvas by the user. Our BoardModel class provides this functionality by overriding the QGraphicsScene’s mouseDown(), mouseMove() and mouseRelease() methods. We can then forward the mouseEvent each of these methods receives to any class of our choice, finally calling the superclass of BoardModel passing the mouseEvent in order to get existing objects on the board to respond. 3.4.4 Graphic Items Qt defines a family of shapes which all inherit the QGraphicsItem class, these provide a default implementation for the basic set of shapes we need and are responsible for drawing themselves to the canvas. The BoardModel is capable of accepting and returning QGraphicItem objects and any subclass. We describe how to extend this basic implementation in Section 3.4.5. 3.4.5 Identifying Graphical Items During a drawing session, many QGraphicsItems are created by multiple users on a canvas. Traditionally a local system would reference these through pointers, however these are simply local memory addresses which become meaningless on a remote system and we require a more robust method of referencing our QGraphicsItems. In general, this applies to all objects which must be both passed over the network which are referenced at a later time. To solve this we use Timestamps, discussed in further detail in Section 4, to uniquely identify each object by creating a logical ordering for each QGraphicsItem which is consistent across all instances. Due to this ordering, we are able to treat a timestamp as a globally unique identifier for any Event and associated QGraphicsItem in the system. 26