Public Member Functions | Protected Attributes

QmitkDataStorageTreeModel::TreeItem Class Reference

#include <QmitkDataStorageTreeModel.h>

Collaboration diagram for QmitkDataStorageTreeModel::TreeItem:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TreeItem (mitk::DataNode *_DataNode, TreeItem *_Parent=0)
virtual ~TreeItem ()
int IndexOfChild (const TreeItem *item) const
TreeItemGetChild (int index) const
TreeItemFind (const mitk::DataNode *_DataNode) const
int GetChildCount () const
int GetIndex () const
TreeItemGetParent () const
mitk::DataNode::Pointer GetDataNode () const
std::vector< TreeItem * > GetChildren () const
void AddChild (TreeItem *item)
void RemoveChild (TreeItem *item)
void InsertChild (TreeItem *item, int index=-1)
void SetParent (TreeItem *_Parent)
 Sets the parent on the treeitem.
void Delete ()

Protected Attributes

TreeItemm_Parent
std::vector< TreeItem * > m_Children
mitk::DataNode::Pointer m_DataNode

Detailed Description

Helper class to represent a tree structure of DataNodes

Definition at line 127 of file QmitkDataStorageTreeModel.h.


Constructor & Destructor Documentation

QmitkDataStorageTreeModel::TreeItem::TreeItem ( mitk::DataNode _DataNode,
TreeItem _Parent = 0 
)

Constructs a new TreeItem with the given DataNode (must not be 0)

Definition at line 526 of file QmitkDataStorageTreeModel.cpp.

References AddChild(), and m_Parent.

: m_Parent(_Parent)
, m_DataNode(_DataNode)
{
  if(m_Parent)
    m_Parent->AddChild(this);
}
QmitkDataStorageTreeModel::TreeItem::~TreeItem (  ) [virtual]

Removes itself as child from its parent-> Does not delete its children

See also:
Delete()

Definition at line 534 of file QmitkDataStorageTreeModel.cpp.

{
  if(m_Parent)
    m_Parent->RemoveChild(this);
}

Member Function Documentation

void QmitkDataStorageTreeModel::TreeItem::AddChild ( TreeItem item )

add another item as a child of this (only if not already in that list)

Definition at line 579 of file QmitkDataStorageTreeModel.cpp.

Referenced by QmitkDataStorageTreeModel::RemoveNode(), SetParent(), and TreeItem().

{
  this->InsertChild(item);
}
void QmitkDataStorageTreeModel::TreeItem::Delete (  )

Deletes the whole tree branch

Definition at line 540 of file QmitkDataStorageTreeModel.cpp.

Referenced by QmitkDataStorageTreeModel::SetDataStorage(), and QmitkDataStorageTreeModel::~QmitkDataStorageTreeModel().

{
  while(m_Children.size() > 0)
    delete m_Children.back();

  delete this;
}
QmitkDataStorageTreeModel::TreeItem * QmitkDataStorageTreeModel::TreeItem::Find ( const mitk::DataNode _DataNode ) const

Find the TreeItem containing a special tree node (recursive tree function)

Definition at line 548 of file QmitkDataStorageTreeModel.cpp.

References Find().

Referenced by QmitkDataStorageTreeModel::AddNode(), Find(), QmitkDataStorageTreeModel::GetIndex(), QmitkDataStorageTreeModel::RemoveNode(), and QmitkDataStorageTreeModel::SetNodeModified().

{
  QmitkDataStorageTreeModel::TreeItem* item = 0;
  if(_DataNode)
  {
    if(m_DataNode == _DataNode)
      item = const_cast<TreeItem*>(this);
    else
    {
      for(std::vector<TreeItem*>::const_iterator it = m_Children.begin(); it != m_Children.end(); ++it)
      {
        if(item)
          break;
        item = (*it)->Find(_DataNode);
      }
    }
  }
  return item;
}
QmitkDataStorageTreeModel::TreeItem * QmitkDataStorageTreeModel::TreeItem::GetChild ( int  index ) const

The child at pos index or 0 if it not exists

Definition at line 574 of file QmitkDataStorageTreeModel.cpp.

References int().

Referenced by QmitkDataStorageTreeModel::index(), QmitkDataStorageTreeModel::TreeToNodeSet(), and QmitkDataStorageTreeModel::TreeToVector().

{
  return (m_Children.size() > 0 && index >= 0 && index < (int)m_Children.size())? m_Children.at(index): 0;
}
int QmitkDataStorageTreeModel::TreeItem::GetChildCount (  ) const
std::vector< QmitkDataStorageTreeModel::TreeItem * > QmitkDataStorageTreeModel::TreeItem::GetChildren (  ) const

Get all children as vector

Definition at line 637 of file QmitkDataStorageTreeModel.cpp.

Referenced by QmitkDataStorageTreeModel::RemoveNode().

{
  return m_Children;
}
mitk::DataNode::Pointer QmitkDataStorageTreeModel::TreeItem::GetDataNode (  ) const
int QmitkDataStorageTreeModel::TreeItem::GetIndex (  ) const
QmitkDataStorageTreeModel::TreeItem * QmitkDataStorageTreeModel::TreeItem::GetParent (  ) const
int QmitkDataStorageTreeModel::TreeItem::IndexOfChild ( const TreeItem item ) const

Find the index of an item

Definition at line 568 of file QmitkDataStorageTreeModel.cpp.

References QuadProgPP::distance().

Referenced by QmitkDataStorageTreeModel::dropMimeData().

{
  std::vector<TreeItem*>::const_iterator it = std::find(m_Children.begin(), m_Children.end(), item);
  return it != m_Children.end() ? std::distance(m_Children.begin(), it): -1;
}
void QmitkDataStorageTreeModel::TreeItem::InsertChild ( TreeItem item,
int  index = -1 
)

inserts a child at the given position. if pos is not in range the element is added at the end

Definition at line 617 of file QmitkDataStorageTreeModel.cpp.

References GetParent(), int(), and SetParent().

Referenced by QmitkDataStorageTreeModel::AddNode(), and QmitkDataStorageTreeModel::dropMimeData().

{
  std::vector<TreeItem*>::iterator it = std::find(m_Children.begin(), m_Children.end(), item);
  if(it == m_Children.end())
  {
    if(m_Children.size() > 0 && index >= 0 && index < (int)m_Children.size())
    {
      it = m_Children.begin();
      std::advance(it, index);
      m_Children.insert(it, item);
    }
    else
      m_Children.push_back(item);

    // add parent if necessary
    if(item->GetParent() != this)
      item->SetParent(this);
  }
}
void QmitkDataStorageTreeModel::TreeItem::RemoveChild ( TreeItem item )

remove another item as child from this

Definition at line 584 of file QmitkDataStorageTreeModel.cpp.

References SetParent().

Referenced by QmitkDataStorageTreeModel::dropMimeData().

{
  std::vector<TreeItem*>::iterator it = std::find(m_Children.begin(), m_Children.end(), item);
  if(it != m_Children.end())
  {
    m_Children.erase(it);
    item->SetParent(0);
  }
}
void QmitkDataStorageTreeModel::TreeItem::SetParent ( TreeItem _Parent )

Sets the parent on the treeitem.

Definition at line 642 of file QmitkDataStorageTreeModel.cpp.

References AddChild().

Referenced by InsertChild(), and RemoveChild().

{
  m_Parent = _Parent;
  if(m_Parent)
    m_Parent->AddChild(this);
}

Member Data Documentation

Definition at line 193 of file QmitkDataStorageTreeModel.h.

Definition at line 194 of file QmitkDataStorageTreeModel.h.

Definition at line 192 of file QmitkDataStorageTreeModel.h.

Referenced by TreeItem().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines