navigationitem.cc 2.12 KB
Newer Older
1
2
3
#include "radixwidgets/navigationitem.hh"
#include "radixbug/bug.hh"

4
#include <QList>
5
6
7

namespace radix
{
8
class NavigationItem::PImpl
9
{
10
11
12
13
 public:
  NavigationItem *parent = nullptr;
  QList<NavigationItem *> children;
  QList<QVariant> data;
14
  bool checked = false;
15
  int type     = 0;
16
  ~PImpl();
17
18
};

19
NavigationItem::PImpl::~PImpl() { qDeleteAll(children); }
20

21
NavigationItem::NavigationItem(QVariant data, NavigationItem *parentItem)
22
    : p(new PImpl())
23
24
25
26
27
28
{
  p->parent = parentItem;
  p->data.append(data);
}

NavigationItem::NavigationItem(QList<QVariant> data, NavigationItem *parentItem)
29
    : p(new PImpl())
30
31
32
33
34
35
{
  p->parent = parentItem;
  p->data   = data;
}

NavigationItem::NavigationItem(NavigationItem *parentItem)
36
    : p(new PImpl())
37
38
39
40
{
  p->parent = parentItem;
}

41
NavigationItem::~NavigationItem() { delete p; }
Huff, Israel's avatar
Huff, Israel committed
42

43
44
45
46
int NavigationItem::type() const { return p->type; }

void NavigationItem::setType(int type) { p->type = type; }

47
48
49
50
51
52
53
void NavigationItem::addChild(NavigationItem *child)
{
  p->children.append(child);
}

int NavigationItem::childCount() const { return p->children.size(); }

54
55
56
57
58
59
60
61
62
63
int NavigationItem::columnCount() const
{
  // recursively find the largest number of columns from children
  int count = p->data.size();
  for (int ci = 0; ci < p->children.size(); ++ci)
  {
    count = std::max(count, p->children[ci]->columnCount());
  }
  return count;
}
64
65
66
67

QVariant NavigationItem::data(int column) const
{
  if (column >= p->data.size()) return QVariant();
68
  return p->data.value(column);
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
}

void NavigationItem::setData(int column, QVariant value)
{
  int size = p->data.size();
  for (int i = size; i <= column; ++i)
  {
    p->data.append(QVariant());
  }
  p->data[column] = value;
}

int NavigationItem::row() const
{
  if (p->parent)
  {
    return p->parent->p->children.indexOf(const_cast<NavigationItem *>(this));
  }
87
  return 0;
88
89
90
91
}

NavigationItem *NavigationItem::parentItem() { return p->parent; }

92
93
94
95
bool NavigationItem::isChecked() const { return p->checked; }

void NavigationItem::setChecked(bool checked) { p->checked = checked; }

96
97
98
99
NavigationItem *NavigationItem::child(int row)
{
  return p->children.value(row);
}
100
101

}  // namespace radix