Display the data selection of a ToolManager. More...
#include <QmitkToolWorkingDataSelectionBox.h>
Public Types | |
enum | DisplayMode { ListDataIfAllToolsMatch, ListDataIfAnyToolMatches } |
What kind of items should be displayed. More... | |
Signals | |
void | WorkingNodeSelected (const mitk::DataNode *) |
Public Member Functions | |
QmitkToolWorkingDataSelectionBox (QWidget *parent=0, mitk::DataStorage *storage=0) | |
virtual | ~QmitkToolWorkingDataSelectionBox () |
mitk::DataStorage * | GetDataStorage () |
void | SetDataStorage (mitk::DataStorage &storage) |
void | UpdateDataDisplay () |
Can be called to trigger an update of the list contents. | |
mitk::ToolManager * | GetToolManager () |
Returns the associated mitk::ToolManager. | |
void | SetToolManager (mitk::ToolManager &) |
Tell this object to listen to another ToolManager. | |
mitk::ToolManager::DataVectorType | GetAllNodes (bool onlyDerivedFromOriginal=true) |
A list of all displayed DataNode objects. This method might be convenient for program modules that want to display additional information about these nodes, like a total volume of all segmentations, etc. | |
mitk::ToolManager::DataVectorType | GetSelectedNodes () |
A list of all selected DataNode objects. This method might be convenient for program modules that want to display additional information about these nodes, like a total volume of all segmentations, etc. | |
mitk::DataNode * | GetSelectedNode () |
Like GetSelectedNodes(), but will only return one object. Will only return what QListView gives as selected object (documentation says nothing is returned if list is in Single selection mode). | |
void | OnToolManagerWorkingDataModified () |
Callback function, no need to call it. This is used to observe and react to changes in the mitk::ToolManager object. | |
void | OnToolManagerReferenceDataModified () |
Callback function, no need to call it. This is used to observe and react to changes in the mitk::ToolManager object. | |
Protected Types | |
typedef std::map < QListWidgetItem *, mitk::DataNode * > | ItemNodeMapType |
Protected Slots | |
void | OnWorkingDataSelectionChanged () |
Protected Attributes | |
mitk::ToolManager::Pointer | m_ToolManager |
ItemNodeMapType | m_Node |
bool | m_SelfCall |
mitk::DataNode * | m_LastSelectedReferenceData |
std::string | m_ToolGroupsForFiltering |
bool | m_DisplayOnlyDerivedNodes |
Display the data selection of a ToolManager.
There is a separate page describing the general design of QmitkInteractiveSegmentation: QmitkInteractiveSegmentationTechnicalPage
Shows the working data of a ToolManager in a segmentation setting. By default only the segmentation name is shown.
The working images (segmentations) are listed in a QListView, each row telling the color and name of a single segmentation. One or several segmentations can be selected to be the "active" segmentations.
Definition at line 46 of file QmitkToolWorkingDataSelectionBox.h.
typedef std::map< QListWidgetItem*, mitk::DataNode* > QmitkToolWorkingDataSelectionBox::ItemNodeMapType [protected] |
Definition at line 127 of file QmitkToolWorkingDataSelectionBox.h.
What kind of items should be displayed.
Every mitk::Tool holds a NodePredicateBase object, telling the kind of data that this tool will successfully work with. There are two ways that this list box deals with these predicates.
DEFAULT is: list data if ANY one of the displayed tools' predicate matches. Other option: list data if ALL one of the displayed tools' predicate matches
Definition at line 62 of file QmitkToolWorkingDataSelectionBox.h.
QmitkToolWorkingDataSelectionBox::QmitkToolWorkingDataSelectionBox | ( | QWidget * | parent = 0 , |
mitk::DataStorage * | storage = 0 |
||
) |
Definition at line 21 of file QmitkToolWorkingDataSelectionBox.cpp.
References m_ToolManager, mitk::ToolManager::New(), OnToolManagerReferenceDataModified(), OnToolManagerWorkingDataModified(), and OnWorkingDataSelectionChanged().
:QListWidget(parent), m_SelfCall(false), m_LastSelectedReferenceData(NULL), m_ToolGroupsForFiltering("default"), m_DisplayOnlyDerivedNodes(true) { m_ToolManager = mitk::ToolManager::New( storage ); // this widget should be placeable from designer so it can't take other than the defaul parameters QListWidget::setSelectionMode( QListWidget::MultiSelection ); QListWidget::setDragDropMode(QListWidget::InternalMove); connect( this, SIGNAL(itemSelectionChanged()), this, SLOT(OnWorkingDataSelectionChanged()) ); m_ToolManager->ReferenceDataChanged += mitk::MessageDelegate<QmitkToolWorkingDataSelectionBox>( this, &QmitkToolWorkingDataSelectionBox::OnToolManagerReferenceDataModified ); m_ToolManager->WorkingDataChanged += mitk::MessageDelegate<QmitkToolWorkingDataSelectionBox>( this, &QmitkToolWorkingDataSelectionBox::OnToolManagerWorkingDataModified ); }
QmitkToolWorkingDataSelectionBox::~QmitkToolWorkingDataSelectionBox | ( | ) | [virtual] |
Definition at line 39 of file QmitkToolWorkingDataSelectionBox.cpp.
{ }
mitk::ToolManager::DataVectorType QmitkToolWorkingDataSelectionBox::GetAllNodes | ( | bool | onlyDerivedFromOriginal = true ) |
A list of all displayed DataNode objects. This method might be convenient for program modules that want to display additional information about these nodes, like a total volume of all segmentations, etc.
Build up predicate:
Definition at line 203 of file QmitkToolWorkingDataSelectionBox.cpp.
References mitk::DataStorage::GetAll(), mitk::DataStorage::GetDerivations(), mitk::Tool::GetGroup(), mitk::Tool::GetName(), mitk::DataStorage::GetSubset(), mitk::Tool::GetWorkingDataPreference(), m_ToolGroupsForFiltering, m_ToolManager, and mitk::NodePredicateOr::New().
Referenced by UpdateDataDisplay().
{ mitk::DataStorage* dataStorage = m_ToolManager->GetDataStorage(); if (!dataStorage) { return mitk::ToolManager::DataVectorType(); } std::vector< mitk::NodePredicateBase::ConstPointer > m_Predicates; mitk::NodePredicateBase::ConstPointer completePredicate = NULL; bool rebuildNeeded = true; if (rebuildNeeded) { m_Predicates.clear(); const mitk::ToolManager::ToolVectorTypeConst allTools = m_ToolManager->GetTools(); for ( mitk::ToolManager::ToolVectorTypeConst::const_iterator iter = allTools.begin(); iter != allTools.end(); ++iter ) { const mitk::Tool* tool = *iter; if ( (m_ToolGroupsForFiltering.empty()) || ( m_ToolGroupsForFiltering.find( tool->GetGroup() ) != std::string::npos ) || ( m_ToolGroupsForFiltering.find( tool->GetName() ) != std::string::npos ) ) { if (completePredicate.IsNotNull()) { m_Predicates.push_back( mitk::NodePredicateOr::New( completePredicate, tool->GetWorkingDataPreference()).GetPointer() ); completePredicate = m_Predicates.back(); } else { completePredicate = tool->GetWorkingDataPreference(); } } } } // TODO delete all m_Predicates mitk::DataStorage::SetOfObjects::ConstPointer allObjects; if ( onlyDerivedFromOriginal ) { mitk::DataNode* sourceNode( m_ToolManager->GetReferenceData(0) ); if (sourceNode) { allObjects = dataStorage->GetDerivations( sourceNode, completePredicate, false ); } else { allObjects = mitk::DataStorage::SetOfObjects::New(); } } else { if (completePredicate) { allObjects = dataStorage->GetSubset( completePredicate ); } else { allObjects = dataStorage->GetAll(); } } m_Predicates.clear(); completePredicate = NULL; mitk::ToolManager::DataVectorType resultVector; for ( mitk::DataStorage::SetOfObjects::const_iterator objectIter = allObjects->begin(); objectIter != allObjects->end(); ++objectIter ) { mitk::DataNode* node = (*objectIter).GetPointer(); resultVector.push_back( node ); } return resultVector; }
mitk::DataStorage * QmitkToolWorkingDataSelectionBox::GetDataStorage | ( | ) |
Definition at line 44 of file QmitkToolWorkingDataSelectionBox.cpp.
References m_ToolManager.
{ return m_ToolManager->GetDataStorage(); }
mitk::DataNode * QmitkToolWorkingDataSelectionBox::GetSelectedNode | ( | ) |
Like GetSelectedNodes(), but will only return one object. Will only return what QListView gives as selected object (documentation says nothing is returned if list is in Single selection mode).
Definition at line 188 of file QmitkToolWorkingDataSelectionBox.cpp.
References m_Node.
mitk::ToolManager::DataVectorType QmitkToolWorkingDataSelectionBox::GetSelectedNodes | ( | ) |
A list of all selected DataNode objects. This method might be convenient for program modules that want to display additional information about these nodes, like a total volume of all segmentations, etc.
Definition at line 158 of file QmitkToolWorkingDataSelectionBox.cpp.
References m_Node.
Referenced by OnWorkingDataSelectionChanged().
{ mitk::ToolManager::DataVectorType result; QList<QListWidgetItem *> items; for (int j=0; j<this->count(); j++) { if (this->item(j)->isSelected()) items.append(this->item(j)); } for (int i=0; i<items.size();++i) { QListWidgetItem* item = items.at(i); if (item) { ItemNodeMapType::iterator it = m_Node.find(item); if (it != m_Node.end()) { mitk::DataNode::Pointer node = it->second; if (node) result.push_back(node); } } } return result; }
mitk::ToolManager * QmitkToolWorkingDataSelectionBox::GetToolManager | ( | ) |
Returns the associated mitk::ToolManager.
Definition at line 55 of file QmitkToolWorkingDataSelectionBox.cpp.
References m_ToolManager.
{ return m_ToolManager; }
void QmitkToolWorkingDataSelectionBox::OnToolManagerReferenceDataModified | ( | ) |
Callback function, no need to call it. This is used to observe and react to changes in the mitk::ToolManager object.
Definition at line 106 of file QmitkToolWorkingDataSelectionBox.cpp.
References m_LastSelectedReferenceData, m_ToolManager, and UpdateDataDisplay().
Referenced by QmitkToolWorkingDataSelectionBox(), and SetToolManager().
{ if ( m_ToolManager->GetReferenceData(0) != m_LastSelectedReferenceData ) { m_ToolManager->SetWorkingData(NULL); UpdateDataDisplay(); m_LastSelectedReferenceData = m_ToolManager->GetReferenceData(0); } }
void QmitkToolWorkingDataSelectionBox::OnToolManagerWorkingDataModified | ( | ) |
Callback function, no need to call it. This is used to observe and react to changes in the mitk::ToolManager object.
Definition at line 96 of file QmitkToolWorkingDataSelectionBox.cpp.
References m_SelfCall, m_ToolManager, UpdateDataDisplay(), and WorkingNodeSelected().
Referenced by QmitkToolWorkingDataSelectionBox(), and SetToolManager().
{ if (m_SelfCall) return; const mitk::DataNode* node = m_ToolManager->GetWorkingData(0); emit WorkingNodeSelected(node); UpdateDataDisplay(); }
void QmitkToolWorkingDataSelectionBox::OnWorkingDataSelectionChanged | ( | ) | [protected, slot] |
Definition at line 73 of file QmitkToolWorkingDataSelectionBox.cpp.
References GetSelectedNodes(), m_SelfCall, m_ToolManager, and WorkingNodeSelected().
Referenced by QmitkToolWorkingDataSelectionBox().
{ static mitk::ToolManager::DataVectorType previouslySelectedNodes; mitk::ToolManager::DataVectorType selection = this->GetSelectedNodes(); previouslySelectedNodes = selection; if (selection.size() >0) { const mitk::DataNode* node = selection[0]; emit WorkingNodeSelected(node); } else { emit WorkingNodeSelected(NULL); } m_SelfCall = true; m_ToolManager->SetWorkingData( selection ); // maybe empty m_SelfCall = false; }
void QmitkToolWorkingDataSelectionBox::SetDataStorage | ( | mitk::DataStorage & | storage ) |
Definition at line 49 of file QmitkToolWorkingDataSelectionBox.cpp.
References m_ToolManager.
{ m_ToolManager->SetDataStorage(storage); }
void QmitkToolWorkingDataSelectionBox::SetToolManager | ( | mitk::ToolManager & | newManager ) |
Tell this object to listen to another ToolManager.
Definition at line 60 of file QmitkToolWorkingDataSelectionBox.cpp.
References m_ToolManager, OnToolManagerReferenceDataModified(), OnToolManagerWorkingDataModified(), and UpdateDataDisplay().
{ m_ToolManager->ReferenceDataChanged -= mitk::MessageDelegate<QmitkToolWorkingDataSelectionBox>( this, &QmitkToolWorkingDataSelectionBox::OnToolManagerReferenceDataModified ); m_ToolManager->WorkingDataChanged -= mitk::MessageDelegate<QmitkToolWorkingDataSelectionBox>( this, &QmitkToolWorkingDataSelectionBox::OnToolManagerWorkingDataModified ); m_ToolManager = &newManager; m_ToolManager->ReferenceDataChanged += mitk::MessageDelegate<QmitkToolWorkingDataSelectionBox>( this, &QmitkToolWorkingDataSelectionBox::OnToolManagerReferenceDataModified ); m_ToolManager->WorkingDataChanged += mitk::MessageDelegate<QmitkToolWorkingDataSelectionBox>( this, &QmitkToolWorkingDataSelectionBox::OnToolManagerWorkingDataModified ); UpdateDataDisplay(); }
void QmitkToolWorkingDataSelectionBox::UpdateDataDisplay | ( | ) |
Can be called to trigger an update of the list contents.
Definition at line 117 of file QmitkToolWorkingDataSelectionBox.cpp.
References GetAllNodes(), mitk::DataNode::GetColor(), mitk::DataNode::GetName(), and m_Node.
Referenced by OnToolManagerReferenceDataModified(), OnToolManagerWorkingDataModified(), and SetToolManager().
{ // clear all QListWidget::clear(); m_Node.clear(); // rebuild contents mitk::ToolManager::DataVectorType allObjects = GetAllNodes( false ); for ( mitk::ToolManager::DataVectorType::const_iterator objectIter = allObjects.begin(); objectIter != allObjects.end(); ++objectIter) { mitk::DataNode* node = *objectIter; if (node) // delete this check when datastorage is really used { // get name and color std::string name = node->GetName(); float rgb[3]; rgb[0] = 1.0; rgb[1] = 0.0; rgb[2] = 0.0; node->GetColor(rgb); QRgb qrgb = qRgb( (int)(rgb[0]*255.0), (int)(rgb[1]*255.0), (int)(rgb[2]*255.0) ); QPixmap pixmap(25,18); pixmap.fill(QColor(qrgb)); // create a list item QListWidgetItem* newItem = new QListWidgetItem(); QString qname = QString::fromLocal8Bit(name.c_str()); //set name and color newItem->setText(qname); newItem->setIcon(QIcon(pixmap)); this->addItem(newItem); m_Node.insert( std::make_pair( newItem, node ) ); } } }
void QmitkToolWorkingDataSelectionBox::WorkingNodeSelected | ( | const mitk::DataNode * | ) | [signal] |
Referenced by OnToolManagerWorkingDataModified(), and OnWorkingDataSelectionChanged().
bool QmitkToolWorkingDataSelectionBox::m_DisplayOnlyDerivedNodes [protected] |
Definition at line 139 of file QmitkToolWorkingDataSelectionBox.h.
Definition at line 135 of file QmitkToolWorkingDataSelectionBox.h.
Referenced by OnToolManagerReferenceDataModified().
Definition at line 131 of file QmitkToolWorkingDataSelectionBox.h.
Referenced by GetSelectedNode(), GetSelectedNodes(), and UpdateDataDisplay().
bool QmitkToolWorkingDataSelectionBox::m_SelfCall [protected] |
Definition at line 133 of file QmitkToolWorkingDataSelectionBox.h.
Referenced by OnToolManagerWorkingDataModified(), and OnWorkingDataSelectionChanged().
std::string QmitkToolWorkingDataSelectionBox::m_ToolGroupsForFiltering [protected] |
Definition at line 137 of file QmitkToolWorkingDataSelectionBox.h.
Referenced by GetAllNodes().
Definition at line 129 of file QmitkToolWorkingDataSelectionBox.h.
Referenced by GetAllNodes(), GetDataStorage(), GetToolManager(), OnToolManagerReferenceDataModified(), OnToolManagerWorkingDataModified(), OnWorkingDataSelectionChanged(), QmitkToolWorkingDataSelectionBox(), SetDataStorage(), and SetToolManager().