50 #include "TreeItem.hh" 56 TreeItem::TreeItem(
int _id, QString _name,
DataType _type,
TreeItem* _parent) :
67 kTreeMap_[_id] =
this;
71 TreeItem::~TreeItem() {
73 QMap<int,TreeItem*>::iterator iter = kTreeMap_.find(
id() );
74 if( iter != kTreeMap_.end() ) {
75 kTreeMap_.erase(iter);
77 std::cerr <<
"Map accelerator destructor in DataControl: Currently removing object that is not in the map!" << std::endl;
97 return ( dataType_ & _type);
114 if ( parent()->parent() == 0 )
122 return ( parent()->
id() );
127 bool TreeItem::isGroup() {
187 if ( childItems_.size() > 0 ) {
188 return childItems_[0];
194 TreeItem* parentPointer = parentItem_;
198 while ( parentPointer ) {
201 int position = thisPointer->
row() + 1;
202 if ( parentPointer->
childCount() > position ) {
207 thisPointer = parentPointer;
226 while ( current->
parent() != 0 ) {
228 current = current->
parent();
251 parentItem_ = _parent;
258 kTreeMap_[item->
id()] = item;
259 childItems_.append(item);
260 item->
row_ = childItems_.size() - 1;
267 return childItems_.value(row);
274 return childItems_.count();
282 if ( id_ == _objectId )
286 QMap<int,TreeItem*>::const_iterator iter = kTreeMap_.find(_objectId);
289 if( iter == kTreeMap_.end() ) {
299 if ( current ==
this ) {
304 if ( current->
parent() != 0) {
305 current = current->
parent();
318 int idx = (_item != 0) ? _item->
row_ : -1;
320 if ( (idx < 0) || (idx >= childItems_.size()) || (childItems_[idx] != _item) ) {
321 std::cerr <<
"TreeItem: Illegal remove request" << std::endl;
325 childItems_.removeAt(idx);
327 for ( ; idx < childItems_.size(); ++idx ) {
328 --(childItems_[idx]->row_);
336 QList< TreeItem* > items;
338 for (
int i = 0 ; i < childItems_.size(); ++i ) {
339 items = items + childItems_[i]->getLeafs();
343 if ( childCount() == 0 )
344 items.push_back(
this);
354 for (
int i = 0 ; i < childItems_.size(); ++i) {
357 childItems_[i]->deleteSubtree();
360 delete childItems_[i];
static QMap< int, TreeItem * > kTreeMap_
Acceleration map.
void deleteSubtree()
delete the whole subtree below this item ( The item itself is not touched )
TreeItem * parent()
Get the parent item ( 0 if root item )
int row_
Index of this node in parent's childen.
TreeItem * childExists(int _objectId)
Check if the element exists in the subtree of this element.
QList< TreeItem * > childItems_
Children of this node.
void setParent(TreeItem *_parent)
Set the parent pointer.
void appendChild(TreeItem *child)
add a child to this node
int row() const
get the row of this item from the parent
TreeItem * child(int row)
return a child
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
TreeItem * parentItem_
Parent item or 0 if root node.
void removeChild(TreeItem *_item)
Remove a child from this object.
const DataType DATA_GROUP(1)
Items used for Grouping.
int childCount() const
get the number of children
QList< TreeItem * > getLeafs()
get all leafes of the tree below this object ( These will be all visible objects ) ...
DataType dataType()
dataType