OGS
TreeItem.cpp
Go to the documentation of this file.
1
15#include "Base/TreeItem.h"
16
17#include <utility>
18
23TreeItem::TreeItem(QList<QVariant> data, TreeItem* parent)
24 : _itemData(std::move(data)), _parentItem(parent)
25{
26}
27
35{
36 qDeleteAll(_childItems);
37}
38
43{
44 _childItems.append(item);
45}
46
53{
54 if (_childItems.count() > row)
55 {
56 return _childItems.value(row);
57 }
58
59 return nullptr;
60}
61
66{
67 return _childItems.count();
68}
69
73int TreeItem::row() const
74{
75 if (_parentItem)
76 {
77 return _parentItem->_childItems.indexOf(const_cast<TreeItem*>(this));
78 }
79
80 return 0;
81}
82
87{
88 return _itemData.count();
89}
90
94QVariant TreeItem::data(int column) const
95{
96 return _itemData.value(column);
97}
98
102bool TreeItem::setData(int column, const QVariant& value)
103{
104 if (column < 0 || column >= _itemData.size())
105 {
106 return false;
107 }
108
109 _itemData[column] = value;
110 return true;
111}
116{
117 return _parentItem;
118}
119
124bool TreeItem::removeChildren(int position, int count)
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}
Definition of the TreeItem class.
Objects nodes for the TreeModel.
Definition TreeItem.h:28
virtual int childCount() const
Definition TreeItem.cpp:65
void appendChild(TreeItem *item)
Definition TreeItem.cpp:42
virtual int columnCount() const
Definition TreeItem.cpp:86
QList< TreeItem * > _childItems
Definition TreeItem.h:44
TreeItem * parentItem() const
Definition TreeItem.cpp:115
TreeItem * child(int row) const
Definition TreeItem.cpp:52
virtual ~TreeItem()
Definition TreeItem.cpp:34
TreeItem * _parentItem
Definition TreeItem.h:46
int row() const
Definition TreeItem.cpp:73
bool removeChildren(int position, int count)
Definition TreeItem.cpp:124
virtual bool setData(int column, const QVariant &value)
Definition TreeItem.cpp:102
TreeItem(QList< QVariant > data, TreeItem *parent)
Definition TreeItem.cpp:23
virtual QVariant data(int column) const
Definition TreeItem.cpp:94
QList< QVariant > _itemData
Definition TreeItem.h:45