-
Notifications
You must be signed in to change notification settings - Fork 0
/
characteristicsitem.cpp
77 lines (75 loc) · 1.79 KB
/
characteristicsitem.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
#include "characteristicsitem.h"
CharacteristicsItem::CharacteristicsItem()
{
}
CharacteristicsItem::CharacteristicsItem(const QList<QList<QVariant> > & data, QString header, CharacteristicsItem *parent)
{
_data = data;
_header = header;
_parent = parent;
}
CharacteristicsItem::~CharacteristicsItem()
{
qDeleteAll(_childItems);
}
int CharacteristicsItem::childCount() const
{
return _childItems.count();
}
int CharacteristicsItem::columnCount() const
{
return _data.count();
}
QVariant CharacteristicsItem::data(int column, int role) const
{
if (column < _data.size() && role < _data.value(column).size())
{
return _data.value(column).value(role);
}
else
{
return QVariant();
}
}
QString CharacteristicsItem::getHeader()
{
return _header;
}
CharacteristicsItem* CharacteristicsItem::child(int row)
{
return _childItems.value(row);
}
int CharacteristicsItem::row() const
{
if (_parent)
return _parent->_childItems.indexOf(const_cast<CharacteristicsItem*>(this));
return 0;
}
void CharacteristicsItem::appendChild(CharacteristicsItem *child)
{
if (!_childItems.contains(child))
{
_childItems.append(child);
child->setParent(this);
}
}
void CharacteristicsItem::appendChildren(QList<CharacteristicsItem *> children)
{
this->_childItems.append(children);
}
void CharacteristicsItem::setParent(CharacteristicsItem *parent)
{
_parent = parent;
}
void CharacteristicsItem::clearChildren()
{
for (int i=0; i<_childItems.count(); i++)
{
_childItems.value(i)->setParent(0);
}
this->_childItems.clear();
}
void CharacteristicsItem::setData(QVariant data, int column, int role)
{
this->_data[column][role] = data;
}