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::~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()

TreeItem * TreeItem::child ( int row) const

Returns the child that corresponds to the specified row number in the item's list of child items Returns nullptr if that child does not exist.

Definition at line 52 of file TreeItem.cpp.

53{
54 if (_childItems.count() > row)
55 {
56 return _childItems.value(row);
57 }
58
59 return nullptr;
60}
int row() const
Definition TreeItem.cpp:73

References TreeItem(), _childItems, and row().

Referenced by GeoTreeModel::addChildren(), GeoTreeModel::addChildren(), VtkVisPipelineItem::child(), StationTreeModel::index(), TreeModel::index(), TreeModelIterator::next(), ProcessModel::removeCondition(), ProcessModel::removeProcessVariable(), GeoTreeView::selectionChanged(), GeoTreeModel::setNameForItem(), and StationTreeModel::setNameForItem().

◆ 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 ProcessModel::removeCondition(), and TreeModel::removeRows().

◆ 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}
TreeItem(QList< QVariant > data, TreeItem *parent)
Definition TreeItem.cpp:23

References TreeItem(), 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(), 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(), and removeChildren().

◆ _itemData

QList<QVariant> TreeItem::_itemData
private

Definition at line 45 of file TreeItem.h.

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

◆ _parentItem

TreeItem* TreeItem::_parentItem
private

Definition at line 46 of file TreeItem.h.

Referenced by TreeItem(), parentItem(), and row().


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