15 #include <itkCommand.h> 22 m_AutoSelectNewNodes(autoSelectNewNodes)
30 bool autoSelectNewNodes)
49 dataStorage->AddNodeEvent.RemoveListener(
53 dataStorage->RemoveNodeEvent.RemoveListener(
64 std::iterator_traits<mitk::DataNode*>::difference_type index = -1;
69 index = std::distance(
m_Nodes.begin(), nodeIt);
71 return static_cast<int>(index);
91 if (this->count() == 0)
94 int currentIndex = this->currentIndex();
96 return currentIndex >= 0 ? this->
GetNode(currentIndex) :
nullptr;
101 mitk::DataStorage::SetOfObjects::Pointer setOfObjects = mitk::DataStorage::SetOfObjects::New();
105 setOfObjects->push_back(*it);
108 return setOfObjects.GetPointer();
121 if (currentDataStorage.GetPointer() != dataStorage)
124 if (currentDataStorage.IsNotNull())
126 currentDataStorage->AddNodeEvent.RemoveListener(
130 currentDataStorage->RemoveNodeEvent.RemoveListener(
142 currentDataStorage->AddNodeEvent.AddListener(
146 currentDataStorage->RemoveNodeEvent.AddListener(
183 this->removeItem(index);
203 if (dataNode ==
m_Nodes.at(index))
205 this->setItemText(index, QString::fromStdString(dataNode->
GetName()));
216 this->
SetNode(this->
Find(dataNode), otherDataNode);
231 const itk::ModifiedEvent *modifiedEvent =
dynamic_cast<const itk::ModifiedEvent *
>(&event);
249 if (index >= 0 && index < this->count())
257 int index = this->
Find(node);
260 MITK_INFO <<
"QmitkDataStorageComboBox: item not available";
264 this->setCurrentIndex(index);
274 bool addNewNode =
false;
275 bool insertNewNode =
false;
276 bool changedNode =
false;
282 if (dataNode !=
m_Nodes.at(index))
286 insertNewNode =
true;
303 if (this->
Find(dataNode) != -1)
307 itk::MemberCommand<QmitkDataStorageComboBox>::Pointer propertyListChangedCommand =
308 itk::MemberCommand<QmitkDataStorageComboBox>::New();
313 if (
nullptr != dataNodePropertyList)
316 propertyListChangedCommand));
327 if (
nullptr != baseData)
330 if (
nullptr != baseDataPropertyList)
333 propertyListChangedCommand));
350 m_Nodes.push_back(nonConstDataNode);
351 else if (insertNewNode)
356 this->addItem(QString::fromStdString(nonConstDataNode->
GetName()));
359 this->setCurrentIndex(index);
364 this->setItemText(index, QString::fromStdString(nonConstDataNode->
GetName()));
391 mitk::DataStorage::SetOfObjects::ConstPointer setOfObjects;
395 setOfObjects = dataStorage->GetSubset(
m_Predicate);
397 setOfObjects = dataStorage->GetAll();
400 for (mitk::DataStorage::SetOfObjects::ConstIterator nodeIt = setOfObjects->Begin(); nodeIt != setOfObjects->End();
404 this->
AddNode(nodeIt.Value().GetPointer());
416 if (
nullptr != dataNodePropertyList)
425 if (
nullptr != baseData)
428 if (
nullptr != dataNodePropertyList)
445 for (
const auto& node :
m_Nodes)
447 dataNodePropertyList = node->GetPropertyList();
450 if (
nullptr != baseData)
455 if (propertyList == dataNodePropertyList
456 || propertyList == baseDataPropertyList)
461 auto index =
Find(node);
463 this->setItemText(index, QString::fromStdString(node->GetName()));
std::vector< long > m_BaseDatapropertyListObserverTags
Holds the tags of the base data property observers.
virtual mitk::DataNode::Pointer GetSelectedNode() const
Returns the selected dataNode or 0 if there is none.
mitk::DataStorage::Pointer GetDataStorage() const
Get the DataStorage this ComboBox listens to.
Data management class that handles 'was created by' relations.
itk::SmartPointer< T > Lock() const
Base of all data objects.
virtual mitk::DataNode::Pointer GetNode(int index) const
Returns the dataNode at Index index or 0 if the index is out of bounds.
void Init()
Init-function this class with the given data storage and predicate. This function is called by all ct...
std::vector< mitk::DataNode * > m_Nodes
virtual void InsertNode(int index, const mitk::DataNode *dataNode)
Inserts a new node at the given index. If the index does not exist, the data node is simply appended ...
mitk::WeakPointer< mitk::DataStorage > m_DataStorage
Key-value list holding instances of BaseProperty.
void OnCurrentIndexChanged(int)
Slot for signal when the user selects another item.
~QmitkDataStorageComboBox() override
Standard Dtor. Nothing to do here.
virtual void OnPropertyListChanged(const itk::Object *caller, const itk::EventObject &event)
Called when the name property of the node was modified.
mitk::DataStorage::SetOfObjects::ConstPointer GetNodes() const
Returns all nodes that are stored in this combobox.
void SetSelectedNode(const mitk::DataNode::Pointer &node)
Slot for signal when user wants to set a node as current selected node.
void SetPredicate(const mitk::NodePredicateBase *predicate)
Set the predicate for this ComboBox. (QmitkDataStorageComboBox is now owner of the predicate) ...
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
bool m_AutoSelectNewNodes
If set to "true" new Nodes will be automatically selected.
mitk::DataStorage::Pointer m_DataStorage
bool IsExpired() const noexcept
bool m_BlockEvents
Event function guard. Each function which is called by an event mechanism first checks if this is tru...
virtual bool GetAutoSelectNewItems()
mitk::NodePredicateBase::ConstPointer m_Predicate
Holds the predicate that is responsible for the dataNode selection of this ComboBox. If the predicate is 0, every dataNode will be selected.
void RemoveNodeAndPropertyLists(int index)
virtual void RemoveNode(int index)
const mitk::NodePredicateBase::ConstPointer GetPredicate() const
Return the predicate (may be nullptr) that is responsible for the dataNode selection of this ComboBox...
QmitkDataStorageComboBox(QWidget *parent=nullptr, bool autoSelectNewNodes=false)
Ctor for an empty combobox. Use setDataStorage and setPredicate afterwards.
mitk::PropertyList::Pointer GetPropertyList() const
Get the data's property list.
mitk::PropertyList * GetPropertyList(const mitk::BaseRenderer *renderer=nullptr) const
Get the PropertyList of the renderer. If renderer is nullptr, the BaseRenderer-independent PropertyLi...
void OnSelectionChanged(const mitk::DataNode *)
Throw a signal when the data node selection changed.
std::vector< long > m_DataNodePropertyListObserverTags
Holds the tags of the data node property observers.
virtual int Find(const mitk::DataNode *dataNode) const
Searches for a given node and returns a valid index or -1 if the node was not found.
virtual void AddNode(const mitk::DataNode *dataNode)
virtual void UpdateComboBoxText(const mitk::PropertyList *)
virtual void Reset()
Reset function whenever data storage or predicate changes.
Interface for evaluation conditions used in the DataStorage class GetSubset() method.
bool HasIndex(unsigned int index) const
Checks if the given index is within the range of the m_Nodes vector.
virtual void SetNode(int index, const mitk::DataNode *dataNode)
Class for nodes of the DataTree.
bool GetName(std::string &nodeName, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="name") const
Convenience access method for accessing the name of an object (instance of StringProperty with proper...
void SetDataStorage(mitk::DataStorage *dataStorage)
Set the DataStorage this ComboBox should listen to.
virtual void SetAutoSelectNewItems(bool autoSelectNewItems)