Tuesday, October 14, 2008

The Plug-in Framework

A Plug-in in Tinkercell has much control over how the program runs. However, there is a suggested framework that it should follow in order to behave as a “good plug-in”.

Before designing your plug-in ...

  1. Feel comfortable with Qt’s signal/slot framework
  2. Look at all the signals and slots in the MainWindow class
  3. Look at all the functions in the GraphicsScene class
  4. Write down a list of features that you would like to add to TinkerCell

Things to know

  1. All TinkerCell classes belong in the Tinkercell namespace
  2. TinkerCell loads new plug-ins by looking for the function
loadTCTool(Tinkercell::MainWindow * main)

so be sure it is defined. See example (next blog)


  1. All Plug-ins inherit from the Tool class.
  2. Almost all the new features are added through the signal/slot framework.
  3. Avoid defining new graphics item classes unless necessary; for most cases, the signal/slot framework is easier.
  4. All non-trivial actions should have a QUndoCommand associated with it. When performing that action, you should add this undo command to the current scene’s history stack instead of directly performing that action. Note: since GraphicsScene provides most of the basic commands, many new commands can be constructed by using the CompositeCommand.
  5. Use GraphicsScene’s functions when possible. These functions automatically add undo commands to the history stack and send signals informing other plug-ins about the changes.
  6. If you do not use GraphicsScene’s functions, be sure to signal to the MainWindow whenever you make changes to items or their data. Do this in the setMainWindow method.
  7. Define new signals whenever you suspect that another tool might use it.

No comments: