Medical Imaging Interaction Toolkit  2023.04.00
Medical Imaging Interaction Toolkit
MITK DataNode Selections

An example application plug-in with a minimal selection service based on mitk::DataNode objects.

This example is an alternative for the Qt selection service described in the previous example. The selection service is based on MITK data nodes. Again the selection service is used to connect the selection of QListWidgetItems of the SelectionView with the radio buttons from the ListenerView and the funtionality is the same.

This time the SelectionView does not inherit from berry::QtViewPart but from QmitkAbstractView. QmitkAbstractView provides a virtual method called GetDataNodeSelectionModel() with which the selection model of the QListWidget can be returned. No selection provider needs to be registered explicitly with the workbench.

In the SelectionViewMitk.h the method from QmitkAbstractView ist declared:

QItemSelectionModel *GetDataNodeSelectionModel() const override;

First we need to create two data nodes and set some creative names in the SelectionViewMitk.cpp:

// create two data nodes and change there default name
dataNode1->SetName("DataNode 1");
dataNode2->SetName("DataNode 2");

These data nodes are used to create two QListWidgetItems that are added to the QListWidget:

// create two QListWidgetItems and name them after the create data nodes
QListWidgetItem *listItemDataNode1 = new QListWidgetItem(QString::fromStdString(dataNode1->GetName()));
QListWidgetItem *listItemDataNode2 = new QListWidgetItem(QString::fromStdString(dataNode2->GetName()));
// set the data of created QListWidgetItems two the informations of the data nodes
listItemDataNode1->setData(QmitkDataNodeRole, QVariant::fromValue(dataNode1));
listItemDataNode2->setData(QmitkDataNodeRole, QVariant::fromValue(dataNode2));
// add the items to the QListWidget of the view

Now if one of the data nodes is selected in the QListWidget or the selection changes this is registered by the ListenerView. In the ListenerViewMitk.h we reimplement the method from QmitkAbstractView that implements the selection listener functionality:

void OnSelectionChanged(berry::IWorkbenchPart::Pointer part,
const QList<mitk::DataNode::Pointer> &nodes) override;

The simple implementation of this method looks as follows:

void ListenerViewMitk::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*part*/,
const QList<mitk::DataNode::Pointer> &nodes)
// any nodes there?
if (!nodes.empty())
// get the selected node (in the BlueBerry example there is always only one node)
mitk::DataNode::Pointer dataNode = nodes.front();
// pass the name of the selected node to method

View complete source files:

[Selection Service] [Previous: Qt Model/View selections] [BlueBerry Examples]

berry::SmartPointer< Self >
itk::SmartPointer< Self >
@ QmitkDataNodeRole
Definition: QmitkEnums.h:19
static Pointer New()