Statistics - initial version
[scorecard] / src / tree-item.cpp
1 #include "tree-item.h"
2
3 TreeItem::TreeItem()
4 {
5   this->type = TypeRoot;
6   this->score = 0;
7   parent = 0;
8 }
9
10 TreeItem::TreeItem(const QString &str)
11 {
12   this->type = TypeDate;
13   this->score = 0;
14   this->str = str;
15   parent = 0;
16 }
17
18 TreeItem::TreeItem(Score *s)
19 {
20   this->type = TypeScore;
21   this->score = s;
22   this->str = s->getDate();
23   parent = 0;
24 }
25
26 TreeItem::~TreeItem()
27 {
28   qDeleteAll(children);
29 }
30
31 #if 1
32 int TreeItem::childCount() const
33 {
34     return children.count();
35 }
36
37 int TreeItem::columnCount() const
38 {
39   return 1;
40 }
41
42 void TreeItem::appendChild(TreeItem *item)
43 {
44   item->parent = this;
45   children.append(item);
46 }
47
48 TreeItem *TreeItem::child(int row)
49 {
50   return children.value(row);
51 }
52
53 QVariant TreeItem::data(int column) const
54 {
55   return str;
56 }
57
58 int TreeItem::row() const
59 {
60   if (parent)
61     return parent->children.indexOf(const_cast<TreeItem*>(this));
62   
63   return 0;
64 }
65 #endif