Computer Assited Medical Intervention Tool Kit  version 4.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
camitk::ComponentPopupMenu Class Reference

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. More...

#include <ComponentPopupMenu.h>

Inherits QMenu.

Inherited by AtomDCPopup, MultiComponentDCPopup, PMManagerDCPopup, and StructuralComponentDCPopup.

Public Member Functions

 ComponentPopupMenu (Component *, QWidget *)
 default constructor More...
 

Protected Member Functions

QAction * addAction (const QString name, const char *member, bool isCheckable=true)
 Add a new item to the popup menu) More...
 
QAction * addSeparator ()
 insert a menu separator and return the corresponding action More...
 

Protected Attributes

ComponentmyComponent
 the Component concerned by this popup menu More...
 

Detailed Description

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.

Deprecated:
since CamiTK 2.0
Note
this class is deprecated, please use the Action framework.

Example:

// ---------------------------
// -- ExampleComponentPopup.h
// ---------------------------
class ExampleComponentPopup : public camitk::ComponentPopupMenu {
Q _ OBJECT // note: the spaces around the underscore have to be removed
public:
ExampleComponentPopup(camitk::Component *, QWidget*);
public slots:
void test();
};
// -----------------------------
// -- ExampleComponentPopup.cpp
// -----------------------------
#include "ExampleComponentPopup.h"
#include "ExampleComponent.h"
#include <QMessageBox>
using namespace camitk;
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\" .\nNice 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;
}
...

Constructor & Destructor Documentation

◆ ComponentPopupMenu()

camitk::ComponentPopupMenu::ComponentPopupMenu ( Component comp,
QWidget *  parent 
)

default constructor

References myComponent.

Member Function Documentation

◆ addAction()

QAction * camitk::ComponentPopupMenu::addAction ( const QString  name,
const char *  member,
bool  isCheckable = true 
)
protected

Add a new item to the popup menu)

Parameters
namestring that will appears as the name of the menu item
memberis the slot to be connected to this action (slot that should be implemented in your subclass)
isCheckableif the item is checkable
Returns
the corresponding action

Referenced by AtomDCPopup::AtomDCPopup(), MultiComponentDCPopup::MultiComponentDCPopup(), PMManagerDCPopup::PMManagerDCPopup(), and StructuralComponentDCPopup::StructuralComponentDCPopup().

◆ addSeparator()

QAction * camitk::ComponentPopupMenu::addSeparator ( )
protected

insert a menu separator and return the corresponding action

Referenced by PMManagerDCPopup::PMManagerDCPopup().

Member Data Documentation

◆ myComponent

Component* camitk::ComponentPopupMenu::myComponent
protected

The documentation for this class was generated from the following files: