![]() |
Computer Assited Medical Intervention Tool Kit
|
#include <ComponentPopupMenu.h>
Public Member Functions | |
ComponentPopupMenu (Component *, QWidget *) | |
default constructor |
Protected Member Functions | |
QAction * | addAction (const QString name, const char *member, bool isCheckable=true) |
Add a new item to the popup menu) | |
QAction * | addSeparator () |
insert a menu separator and return the corresponding action |
Protected Attributes | |
Component * | myComponent |
the Component concerned by this popup menu |
Generic class for Component popup menu. To create your own Component popup, create a class that inherits from this one. Your class could have as many slot that you want. Create popup menu item and connect your slot using the addAction method. <b>Example:</b> @code// ------------------------— // – ExampleComponentPopup.h // ------------------------— #include <ComponentPopupMenu.h> using namespace camitk;
class ExampleComponentPopup : public ComponentPopupMenu { Q _ OBJECT // note: the spaces around the underscore have to be removed
public: ExampleComponentPopup(Component *, QWidget*);
public slots: void test(); };
// --------------------------— // – ExampleComponentPopup.cpp // --------------------------—
#include "ExampleComponentPopup.h" #include "ExampleComponent.h" #include <QMessageBox>
ExampleComponentPopup::ExampleComponentPopup(Component *comp, QWidget *parent) : ComponentPopupMenu(comp,parent) { addAction("action test", SLOT(test()), true); }
void ExampleComponentPopup::test() { // if you want to do something specific to the ExampleComponent class, then you can // safely use dynamic cast as this: // ExampleComponent comp = dynamic_cast<ExampleComponent>(myComponent); // comp->specificMethodOfExampleComponent(...)
QString testMessage;
// myComponent is known here, so we could ask for its name // getName() is a generic Component method, not specific to ExampleComponent, no need to use dynamic_cast here testMessage = QString("This is a test on \"%1" . isn't it?").arg(QString(myComponent->getName()));
QMessageBox::information( 0, "Test", testMessage);
}
// -------------------— // – ExampleComponent.h // -------------------— ... public: /// Overriden method so that we actually can instanciate a popup menu using ExampleComponentPopup virtual QMenu * getPopupMenu(QWidget* parent); ... private: /// the popup menu QMenu * myPopupMenu; ...
// ---------------------— // – ExampleComponent.cpp // ---------------------— #include "ExampleComponentPopup.h" ... // Do NOT forget to add this line in the constructor myPopupMenu = NULL; ... // Do NOT forget to add these lines in the destructor delete myPopupMenu; myPopupMenu = NULL; ... QMenu * ExampleComponent::getPopupMenu(QWidget* parent) { // lazy instanciation pattern if (!myPopupMenu) { myPopupMenu = new ExampleComponentPopup(this,parent); }
return myPopupMenu; }
...
camitk::ComponentPopupMenu::ComponentPopupMenu | ( | Component * | comp, |
QWidget * | parent | ||
) |
default constructor
References myComponent.
|
protected |
Add a new item to the popup menu)
name | string that will appears as the name of the menu item |
member | is the slot to be connected to this action (slot that should be implemented in your subclass) |
isCheckable | if the item is checkable |
Referenced by AtomDCPopup::AtomDCPopup(), MMLComponentPopup::MMLComponentPopup(), MultiComponentDCPopup::MultiComponentDCPopup(), PMManagerDCPopup::PMManagerDCPopup(), StructuralComponentDCPopup::StructuralComponentDCPopup(), and VtkMeshComponentPopup::VtkMeshComponentPopup().
|
protected |
insert a menu separator and return the corresponding action
Referenced by PMManagerDCPopup::PMManagerDCPopup(), and VtkMeshComponentPopup::VtkMeshComponentPopup().
|
protected |
the Component concerned by this popup menu
Referenced by AtomDCPopup::addLoad(), MultiComponentDCPopup::addNewMultiComponent(), MultiComponentDCPopup::addNewStructuralComponent(), ComponentPopupMenu(), MMLComponentPopup::MMLComponentPopup(), MMLComponentPopup::monitoringTabs(), PMManagerDCPopup::openLoads(), PMManagerDCPopup::openReferencePML(), PMManagerDCPopup::PMManagerDCPopup(), PMManagerDCPopup::saveAsLoads(), and StructuralComponentDCPopup::saveToCsv().