Isis 3 Programmer Reference
AbstractParentItem.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include "IsisDebug.h"
10 
11 #include "AbstractParentItem.h"
12 
13 #include <QList>
14 
15 #include "RootItem.h"
16 
17 
18 namespace Isis {
19  AbstractParentItem::AbstractParentItem(AbstractTreeItem *parent) :
20  AbstractTreeItem(parent) {
21  m_children = NULL;
22  m_firstVisibleChild = NULL;
23  m_lastVisibleChild = NULL;
24  m_children = new QList< AbstractTreeItem * >;
25  }
26 
27 
28  AbstractParentItem::~AbstractParentItem() {
29  if (m_children) {
30  for (int i = 0; i < m_children->size(); i++) {
31  delete(*m_children)[i];
32  (*m_children)[i] = NULL;
33  }
34  delete m_children;
35  m_children = NULL;
36  }
37 
38  if (m_firstVisibleChild) {
39  m_firstVisibleChild = NULL;
40  }
41 
42  if (m_lastVisibleChild) {
43  m_lastVisibleChild = NULL;
44  }
45  }
46 
47 
48  AbstractTreeItem *AbstractParentItem::childAt(int row) const {
49  ASSERT(m_children);
50  ASSERT(row >= 0 && row < m_children->size());
51  return m_children->value(row);
52  }
53 
54 
55  QList< AbstractTreeItem * > AbstractParentItem::getChildren() const {
56  ASSERT(m_children);
57  return *m_children;
58  }
59 
60 
61  AbstractTreeItem *AbstractParentItem::getFirstVisibleChild() const {
62  return m_firstVisibleChild;
63  }
64 
65 
66  AbstractTreeItem *AbstractParentItem::getLastVisibleChild() const {
67  return m_lastVisibleChild;
68  }
69 
70 
71  int AbstractParentItem::indexOf(AbstractTreeItem *child) const {
72  ASSERT(child);
73  ASSERT(m_children);
74  return m_children->indexOf(child);
75  }
76 
77 
78  int AbstractParentItem::childCount() const {
79  ASSERT(m_children);
80  return m_children->size();
81  }
82 
83 
84  void AbstractParentItem::addChild(AbstractTreeItem *child) {
85  ASSERT(child);
86  ASSERT(m_children);
87  ASSERT(!dynamic_cast< RootItem * >(child));
88 
89  // if (!m_firstVisibleChild && child->isVisible())
90  // {
91  // m_firstVisibleChild = child;
92  // m_lastVisibleChild = child;
93  // }
94  //
95  // AbstractTreeItem * childWithNewNext = NULL;
96  // if (m_lastVisibleChild && m_firstVisibleChild != child)
97  // {
98  // childWithNewNext = m_lastVisibleChild;
99  // }
100 
101  m_children->append(child);
102  child->setParent(this);
103 
104  // if (childWithNewNext && child->isVisible())
105  // {
106  // childWithNewNext->setNextVisiblePeer(child);
107  // m_lastVisibleChild = child;
108  // }
109  }
110 
111 
112  void AbstractParentItem::setFirstVisibleChild(AbstractTreeItem *child) {
113  m_firstVisibleChild = child;
114  }
115 
116 
117  void AbstractParentItem::setLastVisibleChild(AbstractTreeItem *child) {
118  m_lastVisibleChild = child;
119  }
120 }
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16