-
Notifications
You must be signed in to change notification settings - Fork 4
/
treenode.cpp
executable file
·131 lines (103 loc) · 2.67 KB
/
treenode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "treenode.h"
TreeNode::TreeNode(const Project *data,int type, TreeNode *parent)
: m_parentItem(parent)
{
ProjectItem * item = new ProjectItem();
for(int i=0;i< ELEMENT_NUMBER;i++)
{
item->append(data->get(i));
}
m_itemData = item;
this->type = type;
}
TreeNode::TreeNode(ProjectItem *data,int type, TreeNode *parent)
:m_itemData(data), m_parentItem(parent)
{
for(int i=m_itemData->count();i<ELEMENT_NUMBER;i++){
m_itemData->append("");
}
this->type = type;
}
TreeNode::~TreeNode()
{
qDeleteAll(m_childItems);
}
int TreeNode::getType()
{
return this->type;
}
void TreeNode::appendChild(TreeNode *item)
{
m_childItems.append(item);
}
void TreeNode::removeChild(int row)
{
if(row<0 || row>=m_childItems.size()) return;
m_childItems.remove(row);
}
bool TreeNode::insertChildren(int position, int count, QList<ProjectItem *> pI)
{
if (position < 0 || position > m_childItems.size())
return false;
for (int row = 0; row < count; ++row) {
TreeNode *item = new TreeNode(pI.at(row),PROJECT_NODE, this);
m_childItems.insert(position, item);
}
return true;
}
bool TreeNode::insertColumns(int position, int columns)
{
if (position < 0 || position > m_itemData->count())
return false;
for (int column = 0; column < columns; ++column)
m_itemData->insert(position, QVariant());
for (TreeNode *child : qAsConst(m_childItems))
child->insertColumns(position, columns);
return true;
}
bool TreeNode::removeChildren(int position, int count)
{
if (position < 0 || position + count > m_childItems.size())
return false;
for (int row = 0; row < count; ++row)
delete m_childItems.takeAt(position);
return true;
}
bool TreeNode::removeColumns(int position, int columns)
{
if (position < 0 || position + columns > m_itemData->count())
return false;
for (int column = 0; column < columns; ++column)
m_itemData->remove(position);
for (TreeNode *child : qAsConst(m_childItems))
child->removeColumns(position, columns);
return true;
}
TreeNode *TreeNode::child(int row)
{
if (row < 0 || row >= m_childItems.size())
return nullptr;
return m_childItems.at(row);
}
int TreeNode::childCount() const
{
return m_childItems.count();
}
int TreeNode::columnCount() const
{
return m_itemData->count();
}
QVariant TreeNode::data(int column) const
{
return m_itemData->get(column);
}
TreeNode *TreeNode::parent()
{
return m_parentItem;
}
int TreeNode::row() const
{
if (m_parentItem)
return m_parentItem->m_childItems.indexOf(const_cast<TreeNode*>(this));
return 0;
}