treeitem.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::gui
19 * @author Cedric Seehausen (usdnr at kit dot edu)
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25
26#include "treeitem.h"
27
28#include <QStringList>
29
31using namespace ScenarioManager;
32using namespace Data_Structure;
33
34TreeItem::TreeItem() : enabled(true), m_parentItem(nullptr)
35{
36}
37
39{
40 qDeleteAll(m_childItems);
41}
42
43void
45{
46 item->m_parentItem = this;
47 m_childItems.append(item);
48}
49
52{
53 return m_childItems.value(row);
54}
55
56int
58{
59 return m_childItems.count();
60}
61
62int
64{
65 return m_itemData.count();
66}
67
68QVariant
69TreeItem::data(int column) const
70{
71 return m_itemData.value(column);
72}
73
76{
77 return m_parentItem;
78}
79
80int
82{
83 if (m_parentItem)
84 {
85 return m_parentItem->m_childItems.indexOf(const_cast<TreeItem*>(this));
86 }
87
88 return 0;
89}
90
91void
93{
94 this->enabled = enabled;
95}
96
97bool
99{
100 return enabled;
101}
102
103bool
104TreeItem::setData(int column, const QVariant& value)
105{
106 if (column < 0 || column >= m_itemData.size())
107 {
108 return false;
109 }
110
111 m_itemData[column] = value;
112 return true;
113}
114
115bool
117{
118 if (position < 0 || position > m_childItems.size())
119 {
120 return false;
121 }
122
123 child->m_parentItem = this;
124 m_childItems.insert(position, child);
125
126 return true;
127}
128
129bool
131{
132 if (position < 0 || position > m_childItems.size())
133 {
134 return false;
135 }
136
137 delete m_childItems.takeAt(position);
138
139 return true;
140}
141
142bool
143TreeItem::insertColumn(int position, QVariant data)
144{
145 if (position < 0 || position > m_itemData.size())
146 {
147 return false;
148 }
149
150 m_itemData.insert(position, data);
151
152 foreach (TreeItem* child, m_childItems)
153 {
154 child->insertColumn(position, QVariant());
155 }
156
157 return true;
158}
159
160bool
162{
163 if (position < 0 || position > m_itemData.size())
164 {
165 return false;
166 }
167
168 m_itemData.remove(position);
169
170 foreach (TreeItem* child, m_childItems)
171 {
172 child->removeColumn(position);
173 }
174
175 return true;
176}
int childCount() const
Definition treeitem.cpp:57
bool insertColumn(int position, QVariant data)
Definition treeitem.cpp:143
bool setData(int column, const QVariant &value)
Definition treeitem.cpp:104
void appendChild(TreeItem *child)
Definition treeitem.cpp:44
virtual QVariant data(int column) const
Definition treeitem.cpp:69
void setEnabled(bool enabled)
Definition treeitem.cpp:92
virtual ~TreeItem()
Definition treeitem.cpp:38
int row() const
Definition treeitem.cpp:81
bool removeColumn(int position)
Definition treeitem.cpp:161
bool isEnabled()
Definition treeitem.cpp:98
bool removeChild(int position)
Definition treeitem.cpp:130
bool enabled
Definition treeitem.h:76
bool insertChild(int position, TreeItem *child)
Definition treeitem.cpp:116
TreeItem * parent()
Definition treeitem.cpp:75
int columnCount() const
Definition treeitem.cpp:63
TreeItem * child(int row)
Definition treeitem.cpp:51
QVector< QVariant > m_itemData
Definition treeitem.h:75