forked from LongSoft/UEFITool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
treeitem.cpp
225 lines (185 loc) · 4.25 KB
/
treeitem.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* treeitem.cpp
Copyright (c) 2015, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include <QObject>
#include "treeitem.h"
#include "types.h"
TreeItem::TreeItem(const UINT8 type, const UINT8 subtype, const UINT8 compression,
const QString & name, const QString & text, const QString & info,
const QByteArray & header, const QByteArray & body,
TreeItem *parent) :
itemAction(Actions::NoAction),
itemType(type),
itemSubtype(subtype),
itemCompression(compression),
itemDictionarySize(0),
itemName(name),
itemText(text),
itemInfo(info),
itemHeader(header),
itemBody(body),
parentItem(parent)
{
}
TreeItem::~TreeItem()
{
qDeleteAll(childItems);
}
void TreeItem::appendChild(TreeItem *item)
{
childItems.append(item);
}
void TreeItem::prependChild(TreeItem *item)
{
childItems.prepend(item);
}
UINT8 TreeItem::insertChildBefore(TreeItem *item, TreeItem *newItem)
{
int index = childItems.indexOf(item);
if (index == -1)
return ERR_ITEM_NOT_FOUND;
childItems.insert(index, newItem);
return ERR_SUCCESS;
}
UINT8 TreeItem::insertChildAfter(TreeItem *item, TreeItem *newItem)
{
int index = childItems.indexOf(item);
if (index == -1)
return ERR_ITEM_NOT_FOUND;
childItems.insert(index + 1, newItem);
return ERR_SUCCESS;
}
TreeItem *TreeItem::child(int row)
{
return childItems.value(row, NULL);
}
int TreeItem::childCount() const
{
return childItems.count();
}
int TreeItem::columnCount() const
{
return 5;
}
QVariant TreeItem::data(int column) const
{
switch (column)
{
case 0: // Name
return itemName;
case 1: // Action
return actionTypeToQString(itemAction);
case 2: // Type
return itemTypeToQString(itemType);
case 3: // Subtype
return itemSubtypeToQString(itemType, itemSubtype);
case 4: // Text
return itemText;
default:
return QVariant();
}
}
TreeItem *TreeItem::parent()
{
return parentItem;
}
QString TreeItem::name() const
{
return itemName;
}
void TreeItem::setName(const QString &name)
{
itemName = name;
}
QString TreeItem::text() const
{
return itemText;
}
void TreeItem::setText(const QString &text)
{
itemText = text;
}
QString TreeItem::info() const
{
return itemInfo;
}
void TreeItem::addInfo(const QString &info)
{
itemInfo += info;
}
void TreeItem::setInfo(const QString &info)
{
itemInfo = info;
}
int TreeItem::row() const
{
if (parentItem)
return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
return 0;
}
UINT8 TreeItem::type() const
{
return itemType;
}
void TreeItem::setType(const UINT8 type)
{
itemType = type;
}
UINT8 TreeItem::subtype() const
{
return itemSubtype;
}
void TreeItem::setSubtype(const UINT8 subtype)
{
itemSubtype = subtype;
}
UINT8 TreeItem::compression() const
{
return itemCompression;
}
QByteArray TreeItem::header() const
{
return itemHeader;
}
QByteArray TreeItem::body() const
{
return itemBody;
}
bool TreeItem::hasEmptyHeader() const
{
return itemHeader.isEmpty();
}
bool TreeItem::hasEmptyBody() const
{
return itemBody.isEmpty();
}
UINT8 TreeItem::action() const
{
return itemAction;
}
UINT32 TreeItem::dictionarySize() const
{
return itemDictionarySize;
}
void TreeItem::setDictionarySize(const UINT32 dictionarySize)
{
itemDictionarySize = dictionarySize;
}
void TreeItem::setAction(const UINT8 action)
{
itemAction = action;
// On insert action, set insert action for children
if (action == Actions::Insert)
for (int i = 0; i < childCount(); i++)
child(i)->setAction(Actions::Insert);
// Set rebuild action for parent, if it has no action now
if (parentItem && parentItem->type() != Types::Root
&& parentItem->action() == Actions::NoAction)
parentItem->setAction(Actions::Rebuild);
}