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>
30 using namespace ScenarioManager;
31 using namespace Data_Structure;
32 
33 
34 TreeItem::TreeItem() : enabled(true), m_parentItem(nullptr)
35 {
36 }
37 
39 {
40  qDeleteAll(m_childItems);
41 }
42 
44 {
45  item->m_parentItem = this;
46  m_childItems.append(item);
47 }
48 
50 {
51  return m_childItems.value(row);
52 }
53 
55 {
56  return m_childItems.count();
57 }
58 
60 {
61  return m_itemData.count();
62 }
63 
64 QVariant TreeItem::data(int column) const
65 {
66  return m_itemData.value(column);
67 }
68 
70 {
71  return m_parentItem;
72 }
73 
74 int TreeItem::row() const
75 {
76  if (m_parentItem)
77  {
78  return m_parentItem->m_childItems.indexOf(const_cast<TreeItem*>(this));
79  }
80 
81  return 0;
82 }
83 
85 {
86  this->enabled = enabled;
87 }
88 
90 {
91  return enabled;
92 }
93 
94 bool TreeItem::setData(int column, const QVariant& value)
95 {
96  if (column < 0 || column >= m_itemData.size())
97  {
98  return false;
99  }
100 
101  m_itemData[column] = value;
102  return true;
103 }
104 
105 bool TreeItem::insertChild(int position, TreeItem* child)
106 {
107  if (position < 0 || position > m_childItems.size())
108  {
109  return false;
110  }
111 
112  child->m_parentItem = this;
113  m_childItems.insert(position, child);
114 
115  return true;
116 }
117 
118 bool TreeItem::removeChild(int position)
119 {
120  if (position < 0 || position > m_childItems.size())
121  {
122  return false;
123  }
124 
125  delete m_childItems.takeAt(position);
126 
127  return true;
128 }
129 
130 bool TreeItem::insertColumn(int position, QVariant data)
131 {
132  if (position < 0 || position > m_itemData.size())
133  {
134  return false;
135  }
136 
137  m_itemData.insert(position, data);
138 
139  foreach (TreeItem* child, m_childItems)
140  {
141  child->insertColumn(position, QVariant());
142  }
143 
144  return true;
145 }
146 
147 bool TreeItem::removeColumn(int position)
148 {
149  if (position < 0 || position > m_itemData.size())
150  {
151  return false;
152  }
153 
154  m_itemData.remove(position);
155 
156  foreach (TreeItem* child, m_childItems)
157  {
158  child->removeColumn(position);
159  }
160 
161  return true;
162 }
TreeItem::columnCount
int columnCount() const
Definition: treeitem.cpp:59
TreeItem::m_itemData
QVector< QVariant > m_itemData
Definition: treeitem.h:74
TreeItem
Definition: treeitem.h:46
TreeItem::removeColumn
bool removeColumn(int position)
Definition: treeitem.cpp:147
treeitem.h
TreeItem::data
virtual QVariant data(int column) const
Definition: treeitem.cpp:64
TreeItem::parent
TreeItem * parent()
Definition: treeitem.cpp:69
TreeItem::insertChild
bool insertChild(int position, TreeItem *child)
Definition: treeitem.cpp:105
TreeItem::TreeItem
TreeItem()
Definition: treeitem.cpp:34
TreeItem::appendChild
void appendChild(TreeItem *child)
Definition: treeitem.cpp:43
TreeItem::enabled
bool enabled
Definition: treeitem.h:75
TreeItem::childCount
int childCount() const
Definition: treeitem.cpp:54
TreeItem::child
TreeItem * child(int row)
Definition: treeitem.cpp:49
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
TreeItem::~TreeItem
virtual ~TreeItem()
Definition: treeitem.cpp:38
TreeItem::isEnabled
bool isEnabled()
Definition: treeitem.cpp:89
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
TreeItem::setEnabled
void setEnabled(bool enabled)
Definition: treeitem.cpp:84
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
ScenarioManager
Definition: Application.cpp:166
TreeItem::setData
bool setData(int column, const QVariant &value)
Definition: treeitem.cpp:94
Logging.h
TreeItem::row
int row() const
Definition: treeitem.cpp:74
TreeItem::removeChild
bool removeChild(int position)
Definition: treeitem.cpp:118
TreeItem::insertColumn
bool insertColumn(int position, QVariant data)
Definition: treeitem.cpp:130