42 #include "TreeItem.hh" 48 TreeItem::TreeItem(
int _id, QString _name,
DataType _type,
TreeItem* _parent) :
59 kTreeMap_[_id] =
this;
63 TreeItem::~TreeItem() {
65 QMap<int,TreeItem*>::iterator iter = kTreeMap_.find(
id() );
66 if( iter != kTreeMap_.end() ) {
67 kTreeMap_.erase(iter);
69 std::cerr <<
"Map accelerator destructor in DataControl: Currently removing object that is not in the map!" << std::endl;
89 return ( dataType_ & _type);
106 if ( parent()->parent() == 0 )
114 return ( parent()->
id() );
119 bool TreeItem::isGroup() {
179 if ( childItems_.size() > 0 ) {
180 return childItems_[0];
186 TreeItem* parentPointer = parentItem_;
190 while ( parentPointer ) {
193 int position = thisPointer->
row() + 1;
194 if ( parentPointer->
childCount() > position ) {
199 thisPointer = parentPointer;
218 while ( current->
parent() != 0 ) {
220 current = current->
parent();
243 parentItem_ = _parent;
250 kTreeMap_[item->
id()] = item;
251 childItems_.append(item);
252 item->
row_ = childItems_.size() - 1;
259 return childItems_.value(row);
266 return childItems_.count();
274 if ( id_ == _objectId )
278 QMap<int,TreeItem*>::const_iterator iter = kTreeMap_.find(_objectId);
281 if( iter == kTreeMap_.end() ) {
291 if ( current ==
this ) {
296 if ( current->
parent() != 0) {
297 current = current->
parent();
310 int idx = (_item != 0) ? _item->
row_ : -1;
312 if ( (idx < 0) || (idx >= childItems_.size()) || (childItems_[idx] != _item) ) {
313 std::cerr <<
"TreeItem: Illegal remove request" << std::endl;
317 childItems_.removeAt(idx);
319 for ( ; idx < childItems_.size(); ++idx ) {
320 --(childItems_[idx]->row_);
328 QList< TreeItem* > items;
330 for (
int i = 0 ; i < childItems_.size(); ++i ) {
331 items = items + childItems_[i]->getLeafs();
335 if ( childCount() == 0 )
336 items.push_back(
this);
346 for (
int i = 0 ; i < childItems_.size(); ++i) {
349 childItems_[i]->deleteSubtree();
352 delete childItems_[i];
DataType dataType()
dataType
int row() const
get the row of this item from the parent
void deleteSubtree()
delete the whole subtree below this item ( The item itself is not touched )
TreeItem * child(int row)
return a child
TreeItem * childExists(int _objectId)
Check if the element exists in the subtree of this element.
void setParent(TreeItem *_parent)
Set the parent pointer.
const DataType DATA_GROUP(1)
Items used for Grouping.
TreeItem * parent()
Get the parent item ( 0 if root item )
int row_
Index of this node in parent's childen.
QList< TreeItem *> getLeafs()
get all leafes of the tree below this object ( These will be all visible objects ) ...
void appendChild(TreeItem *child)
add a child to this node
QList< TreeItem * > childItems_
Children of this node.
TreeItem * parentItem_
Parent item or 0 if root node.
static QMap< int, TreeItem * > kTreeMap_
Acceleration map.
void removeChild(TreeItem *_item)
Remove a child from this object.
int childCount() const
get the number of children
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.