New version -- 0.20
[scorecard] / src / tree-item.cpp
1 /*
2  * Copyright (C) 2009 Sakari Poussa
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 2.
7  */
8
9 #include "tree-item.h"
10
11 TreeItem::TreeItem()
12 {
13   this->type = TypeRoot;
14   this->score = 0;
15   parent = 0;
16 }
17
18 TreeItem::TreeItem(const QString &str)
19 {
20   this->type = TypeDate;
21   this->score = 0;
22   this->str = str;
23   parent = 0;
24 }
25
26 TreeItem::TreeItem(Score *s)
27 {
28   this->type = TypeScore;
29   this->score = s;
30   this->str = s->getDate();
31   parent = 0;
32 }
33
34 TreeItem::~TreeItem()
35 {
36   qDeleteAll(children);
37 }
38
39 #if 1
40 int TreeItem::childCount() const
41 {
42     return children.count();
43 }
44
45 int TreeItem::columnCount() const
46 {
47   return 1;
48 }
49
50 void TreeItem::appendChild(TreeItem *item)
51 {
52   item->parent = this;
53   children.append(item);
54 }
55
56 TreeItem *TreeItem::child(int row)
57 {
58   return children.value(row);
59 }
60
61 QVariant TreeItem::data(int column) const
62 {
63   return str;
64 }
65
66 int TreeItem::row() const
67 {
68   if (parent)
69     return parent->children.indexOf(const_cast<TreeItem*>(this));
70   
71   return 0;
72 }
73 #endif