navigationitem.cc 1.85 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
  ~PImpl();
16
17
};

18
NavigationItem::PImpl::~PImpl()
19
{
20
21
  qDeleteAll(children);
  if (parent) delete parent;
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
NavigationItem::NavigationItem(QVariant data, NavigationItem *parentItem)
    : p(new PImpl(), [](PImpl *impl) { delete impl; })
{
  p->parent = parentItem;
  p->data.append(data);
}

NavigationItem::NavigationItem(QList<QVariant> data, NavigationItem *parentItem)
    : p(new PImpl(), [](PImpl *impl) { delete impl; })
{
  p->parent = parentItem;
  p->data   = data;
}

NavigationItem::NavigationItem(NavigationItem *parentItem)
    : p(new PImpl(), [](PImpl *impl) { delete impl; })
{
  p->parent = parentItem;
}

void NavigationItem::addChild(NavigationItem *child)
{
  p->children.append(child);
}

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

int NavigationItem::columnCount() const { return p->data.size(); }

QVariant NavigationItem::data(int column) const
{
  if (column >= p->data.size()) return QVariant();
56
  return p->data.value(column);
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
}

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));
  }
}

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

79
80
81
82
bool NavigationItem::isChecked() const { return p->checked; }

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

83
84
85
86
NavigationItem *NavigationItem::child(int row)
{
  return p->children.value(row);
}
87
88

}  // namespace radix