OGS
TreeItem Class Reference

Detailed Description

Objects nodes for the TreeModel.

The TreeItem class provides simple items that contain several pieces of data, and which can provide information about their parent and child items

See also
TreeModel

Definition at line 27 of file TreeItem.h.

#include <TreeItem.h>

Inheritance diagram for TreeItem:
[legend]
Collaboration diagram for TreeItem:
[legend]

Public Member Functions

 TreeItem (QList< QVariant > data, TreeItem *parent)
 
virtual ~TreeItem ()
 
void appendChild (TreeItem *item)
 
TreeItemchild (int row) const
 
virtual int childCount () const
 
virtual int columnCount () const
 
virtual QVariant data (int column) const
 
virtual bool setData (int column, const QVariant &value)
 
int row () const
 
TreeItemparentItem () const
 
bool removeChildren (int position, int count)
 

Private Attributes

QList< TreeItem * > _childItems
 
QList< QVariant > _itemData
 
TreeItem_parentItem
 

Constructor & Destructor Documentation

◆ TreeItem()

TreeItem::TreeItem ( QList< QVariant > data,
TreeItem * parent )

The constructor is only used to record the item's parent and the data associated with each column.

Definition at line 23 of file TreeItem.cpp.

24 : _itemData(std::move(data)), _parentItem(parent)
25{
26}
TreeItem * _parentItem
Definition TreeItem.h:46
virtual QVariant data(int column) const
Definition TreeItem.cpp:94
QList< QVariant > _itemData
Definition TreeItem.h:45

◆ ~TreeItem()

TreeItem::~TreeItem ( )
virtual

A pointer to each of the child items belonging to this item will be stored in the _childItems private member variable. When the class's destructor is called, it must delete each of these to ensure that their memory is reused.

Definition at line 34 of file TreeItem.cpp.

35{
36 qDeleteAll(_childItems);
37}
QList< TreeItem * > _childItems
Definition TreeItem.h:44

References _childItems.

Member Function Documentation

◆ appendChild()

◆ child()

◆ childCount()

◆ columnCount()

int TreeItem::columnCount ( ) const
virtual

Returns the number of columns of data in the item.

Definition at line 86 of file TreeItem.cpp.

87{
88 return _itemData.count();
89}

References _itemData.

Referenced by TreeModel::columnCount().

◆ data()

◆ parentItem()

◆ removeChildren()

bool TreeItem::removeChildren ( int position,
int count )

Removes a number of children of the TreeItem starting from the given position.

Definition at line 124 of file TreeItem.cpp.

125{
126 if (position < 0 || position + count > _childItems.size())
127 {
128 return false;
129 }
130
131 for (int row = 0; row < count; ++row)
132 {
133 delete _childItems.takeAt(position);
134 }
135
136 return true;
137}

References _childItems, and row().

Referenced by ElementTreeModel::clearView(), FemConditionModel::clearView(), ProcessModel::removeCondition(), MeshModel::removeMesh(), ProcessModel::removeProcessVariable(), TreeModel::removeRows(), and MeshModel::updateMesh().

◆ row()

int TreeItem::row ( ) const

Returns the item's location within its parent's list of items.

Definition at line 73 of file TreeItem.cpp.

74{
75 if (_parentItem)
76 {
77 return _parentItem->_childItems.indexOf(const_cast<TreeItem*>(this));
78 }
79
80 return 0;
81}
Objects nodes for the TreeModel.
Definition TreeItem.h:28

References _childItems, and _parentItem.

Referenced by child(), VtkVisPipelineItem::child(), TreeModel::parent(), removeChildren(), ProcessModel::removeProcessVariable(), GeoTreeView::selectionChanged(), MeshView::selectionChanged(), StationTreeView::selectionChanged(), GeoTreeView::setElementAsCondition(), GeoTreeView::setNameForElement(), and StationTreeView::setNameForElement().

◆ setData()

bool TreeItem::setData ( int column,
const QVariant & value )
virtual

Sets the data at a given column.

Reimplemented in VtkVisPipelineItem.

Definition at line 102 of file TreeItem.cpp.

103{
104 if (column < 0 || column >= _itemData.size())
105 {
106 return false;
107 }
108
109 _itemData[column] = value;
110 return true;
111}

References _itemData.

Referenced by GeoTreeModel::addChildren(), TreeModel::setData(), VtkVisPipelineItem::setData(), GeoTreeModel::setNameForItem(), and StationTreeModel::setNameForItem().

Member Data Documentation

◆ _childItems

QList<TreeItem*> TreeItem::_childItems
private

Definition at line 44 of file TreeItem.h.

Referenced by ~TreeItem(), appendChild(), child(), childCount(), removeChildren(), and row().

◆ _itemData

QList<QVariant> TreeItem::_itemData
private

Definition at line 45 of file TreeItem.h.

Referenced by columnCount(), data(), and setData().

◆ _parentItem

TreeItem* TreeItem::_parentItem
private

Definition at line 46 of file TreeItem.h.

Referenced by parentItem(), and row().


The documentation for this class was generated from the following files: