Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
Extension Point Definition

This example plugin defines an extension point and collects extensions.

ExtensionPointWithoutExtension.png

In this example the extension point concept is used to define an extension point and extend the plugin functionality with it. The GUI consists of a view with two group boxes. In the right box the user can insert text in an input text field. The left box is the area where extensions for this plugin are displayed.

In the plugin.xml file of this application the extension point is defined as follows:

DefinitionXML.png

The according schema (changetext.exsd) defines attributes for extensions of this extension point like a description.

In the view of this plugin the registry is used to find all available extensions. For each found descriptor a push button is created that holds the functionality extension.

QList<ChangeTextDescriptor::Pointer> changeTexts = m_Registry.GetChangeTexts();
foreach (const ChangeTextDescriptor::Pointer &changeText, changeTexts)
{
// Create a push button for each "changetext" descriptor
QPushButton *button = new QPushButton(changeText->GetName(), m_Controls.m_ButtonContainer);
button->setToolTip(changeText->GetDescription());
button->setObjectName(changeText->GetID());
layout->addWidget(button);
connect(button, SIGNAL(clicked()), &m_SignalMapper, SLOT(map()));
m_SignalMapper.setMapping(button, changeText->GetID());
}
layout->addStretch();
connect(&m_SignalMapper, SIGNAL(mapped(QString)), this, SLOT(ChangeText(QString)));

These created push buttons are connected to the ChangeText method that alters the input text (in the way the extension defines) and outputs the changed text in another text field.

void MinimalView::ChangeText(const QString &id)
{
ChangeTextDescriptor::Pointer changeTextDescr = m_Registry.Find(id);
// lazily create an instance of IChangeText (the descriptor will cache it)
IChangeText::Pointer changeText = changeTextDescr->CreateChangeText();
m_Controls.m_OutputText->setText(changeText->ChangeText(m_Controls.m_InputText->text()));
}

The plugin can now be extened by extensions provided by other plugins.

View complete source files:

[Extension Points] [Next: Extension Contribution] [BlueBerry Examples]