Monday, October 13, 2008

The GraphicsScene Class

Summary of the GraphicsScene class:

This class inherits from Qt's QGraphicsScene class, so please read the Qt documentation on QGraphicsScene and QGraphicsView first.

  • Provides two important lists for tools to exploit: selected() and moving(), which gives a reference to the list of currently selected and currently moving items. The separation between what is selected and what is moving is important when items that are not directly selected, e.g. text items, need to move along. Further, tools can add or remove from both lists, giving tools control over selection and movement. Something to note is that items being moved are grouped into a QGraphicsGroupItem in order to make movement smoother. So, parent of an item will change as they are moved.
  • Other plugins can use the "actionsEnabled" Boolean value to turn on or off the default behaviors of the GraphicsScene. These default behaviors include selecting items, deleting items, etc.
  • Provides a large number of signals such as "itemsInserted", "dataChanged", "itemsAboutToBeRemoved", etc. It is usually not a good idea to connect directly to these signals, because each scene will have its own signals. Each of these signals are also available in the MainWindow class, and the MainWindow relays the signal from each scene. So connecting to MainWindow's signals is generally best unless specifically listening to a particular scene.
  • Has a history stack with stores a list of undo commands (see UndoCommands.h). User scene->historyStack->push( new command ) to execute a new command and place it in the history stack.
  • Provides a large number of convenience functions, eg. moveItems(...), changeData(...), remove(..), insert(...), and so on. Each of these functions do the following: generate an undo command (see UndoCommands.h), put the undo command in the scene's history stack, and send the appropriate signal, such as "itemsInserted" or "itemsAboutToBeRemoved", etc.

No comments: