HyperspaceExplorer 0.7.1
|
#include <SlotHelper.h>
Public Slots | |
void | slot () |
Public Member Functions | |
SlotHelper (C4DView *view, const std::string &displayable_name) | |
Construction. | |
virtual | ~SlotHelper () |
Cleanup. | |
Private Attributes | |
C4DView * | view_ |
The C4DView which wants to instantiate Function's. | |
std::string | displayable_name_ |
The name of the Displayable as taken by the FunctionFactory. |
Single-stop slot for menu QActions generating Displayable objects Your mission, should you choose to accept it, is to have a single function to serve as slot for all menu Actions which generate a new Displayable. After all, this could be done with a template.
In fact, it's not quite so easy and we need an indirection. Because moc can't compile class templates, we need another class to stand between the QAction triggered by (e.g.) menu item selection and the creation of a Function object.
This class provides a single slot, which calls the factory method of the FunctionFactory that was passed to the SlotHelper object during construction.
This way, a single slot function can create all Function objects. The drawback is that now many SlotHelper objects exist, one for every type of Function that is present in the menus.