-
Notifications
You must be signed in to change notification settings - Fork 6
/
treeitem.cpp
91 lines (74 loc) · 1.94 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
//
// TreeItem
//
// Created by Anthony Thibault on 6/5/2019
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "treeitem.h"
#include <QDebug>
#include <QStringList>
TreeItem::TreeItem(const QList<QVariant>& data) {
m_parentItem = nullptr;
m_itemData = data;
}
TreeItem::~TreeItem() {
qDeleteAll(m_childItems);
}
void TreeItem::appendChild(TreeItem *item) {
item->m_parentItem = this;
m_childItems.append(item);
}
int TreeItem::findChild(TreeItem* child) {
for (int i = 0; i < m_childItems.size(); i++) {
if (m_childItems[i] == child) {
return i;
}
}
return -1;
}
void TreeItem::removeChild(int index) {
// TODO: delete TreeItem
m_childItems.removeAt(index);
}
void TreeItem::insertChild(int index, TreeItem* child) {
child->m_parentItem = this;
m_childItems.insert(index, child);
}
TreeItem* TreeItem::child(int row) {
return m_childItems.value(row);
}
int TreeItem::childCount() const {
return m_childItems.count();
}
int TreeItem::columnCount() const {
return m_itemData.count();
}
QVariant TreeItem::data(int column) const {
return m_itemData.value(column);
}
bool TreeItem::setData(int column, const QVariant& value) {
m_itemData[column] = QVariant(value);
return true;
}
TreeItem* TreeItem::parentItem() {
return m_parentItem;
}
int TreeItem::row() const {
if (m_parentItem) {
return m_parentItem->m_childItems.indexOf(const_cast<TreeItem*>(this));
}
return 0;
}
TreeItem* TreeItem::cloneNode() const {
return new TreeItem(m_itemData);
}
TreeItem* TreeItem::cloneNodeAndChildren() const {
TreeItem* newNode = new TreeItem(m_itemData);
for (int i = 0; i < m_childItems.size(); ++i) {
newNode->appendChild(m_childItems[i]->cloneNodeAndChildren());
}
return newNode;
}