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 
31 using namespace ScenarioManager;
32 using namespace Data_Structure;
33 
34 TreeItem::TreeItem() : enabled(true), m_parentItem(nullptr)
35 {
36 }
37 
39 {
40  qDeleteAll(m_childItems);
41 }
42 
43 void
45 {
46  item->m_parentItem = this;
47  m_childItems.append(item);
48 }
49 
50 TreeItem*
52 {
53  return m_childItems.value(row);
54 }
55 
56 int
58 {
59  return m_childItems.count();
60 }
61 
62 int
64 {
65  return m_itemData.count();
66 }
67 
68 QVariant
69 TreeItem::data(int column) const
70 {
71  return m_itemData.value(column);
72 }
73 
74 TreeItem*
76 {
77  return m_parentItem;
78 }
79 
80 int
82 {
83  if (m_parentItem)
84  {
85  return m_parentItem->m_childItems.indexOf(const_cast<TreeItem*>(this));
86  }
87 
88  return 0;
89 }
90 
91 void
93 {
94  this->enabled = enabled;
95 }
96 
97 bool
99 {
100  return enabled;
101 }
102 
103 bool
104 TreeItem::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 
115 bool
116 TreeItem::insertChild(int position, TreeItem* child)
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 
129 bool
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 
142 bool
143 TreeItem::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 
160 bool
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 }
TreeItem::columnCount
int columnCount() const
Definition: treeitem.cpp:63
TreeItem::m_itemData
QVector< QVariant > m_itemData
Definition: treeitem.h:75
TreeItem
Definition: treeitem.h:47
TreeItem::removeColumn
bool removeColumn(int position)
Definition: treeitem.cpp:161
treeitem.h
TreeItem::data
virtual QVariant data(int column) const
Definition: treeitem.cpp:69
TreeItem::parent
TreeItem * parent()
Definition: treeitem.cpp:75
TreeItem::insertChild
bool insertChild(int position, TreeItem *child)
Definition: treeitem.cpp:116
TreeItem::TreeItem
TreeItem()
Definition: treeitem.cpp:34
TreeItem::appendChild
void appendChild(TreeItem *child)
Definition: treeitem.cpp:44
TreeItem::enabled
bool enabled
Definition: treeitem.h:76
TreeItem::childCount
int childCount() const
Definition: treeitem.cpp:57
TreeItem::child
TreeItem * child(int row)
Definition: treeitem.cpp:51
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
TreeItem::~TreeItem
virtual ~TreeItem()
Definition: treeitem.cpp:38
TreeItem::isEnabled
bool isEnabled()
Definition: treeitem.cpp:98
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
TreeItem::setEnabled
void setEnabled(bool enabled)
Definition: treeitem.cpp:92
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
ScenarioManager
Definition: Application.cpp:180
TreeItem::setData
bool setData(int column, const QVariant &value)
Definition: treeitem.cpp:104
Logging.h
TreeItem::row
int row() const
Definition: treeitem.cpp:81
TreeItem::removeChild
bool removeChild(int position)
Definition: treeitem.cpp:130
TreeItem::insertColumn
bool insertColumn(int position, QVariant data)
Definition: treeitem.cpp:143