USGS

Isis 3.0 Object Programmers' Reference

Home

AbstractTreeItem.cpp
1 #include "IsisDebug.h"
2 
3 #include "AbstractTreeItem.h"
4 
5 #include <iostream>
6 
7 #include <QDateTime>
8 #include <QFontMetrics>
9 #include <QLocale>
10 #include <QVariant>
11 
12 #include "IException.h"
13 #include "IString.h"
14 #include "SpecialPixel.h"
15 
16 #include "AbstractTableModel.h"
17 #include "TableColumn.h"
18 
19 
20 namespace Isis {
21  namespace CnetViz {
22  AbstractTreeItem::AbstractTreeItem(AbstractTreeItem *parent) : m_parentItem(
23  parent) {
24  m_expanded = false;
25  m_selectable = true;
26  m_selected = false;
27  m_visible = true;
28  m_nextVisibleItem = NULL;
29  m_dataWidth = 0;
30  }
31 
32 
33  AbstractTreeItem::~AbstractTreeItem() {
34  m_nextVisibleItem = NULL;
35  m_parentItem = NULL;
36  }
37 
38 
39  AbstractTreeItem *AbstractTreeItem::parent() const {
40  return m_parentItem;
41  }
42 
43 
44  void AbstractTreeItem::setParent(AbstractTreeItem *newParent) {
45  m_parentItem = newParent;
46  }
47 
48 
49  int AbstractTreeItem::row() const {
50  int rowIndex = -1;
51 
52  if (m_parentItem)
53  rowIndex = m_parentItem->indexOf(const_cast< AbstractTreeItem * >(this));
54 
55  return rowIndex;
56  }
57 
58 
59  QString AbstractTreeItem::getFormattedData() const {
60  return catchNull(getData());
61  }
62 
63 
64  QString AbstractTreeItem::getFormattedData(QString columnTitle) const {
65  return catchNull(getData(columnTitle));
66  }
67 
68 
69  AbstractTreeItem *AbstractTreeItem::getNextVisiblePeer() const {
70  return m_nextVisibleItem;
71  }
72 
73 
74  void AbstractTreeItem::setNextVisiblePeer(AbstractTreeItem *next) {
75  m_nextVisibleItem = next;
76  }
77 
78 
79  bool AbstractTreeItem::hasPoint(ControlPoint *point) const {
80  bool found = false;
81 
82  for (int i = 0; !found && i < childCount(); i++)
83  found = childAt(i)->hasPoint(point);
84 
85  return found;
86  }
87 
88 
89  bool AbstractTreeItem::hasMeasure(ControlMeasure *measure) const {
90  bool found = false;
91 
92  for (int i = 0; !found && i < childCount(); i++)
93  found = childAt(i)->hasMeasure(measure);
94 
95  return found;
96  }
97 
98 
99  bool AbstractTreeItem::hasNode(ControlCubeGraphNode *cube) const {
100  bool found = false;
101 
102  for (int i = 0; !found && i < childCount(); i++)
103  found = childAt(i)->hasNode(cube);
104 
105  return found;
106  }
107 
108 
109  void AbstractTreeItem::setExpanded(bool newState) {
110  m_expanded = newState;
111  }
112 
113  bool AbstractTreeItem::isExpanded() const {
114  return m_expanded;
115  }
116 
117 
118  void AbstractTreeItem::setSelected(bool newState) {
119  m_selected = newState;
120  }
121 
122 
123  void AbstractTreeItem::setSelectable(bool newSelectable) {
124  m_selectable = newSelectable;
125  }
126 
127 
128  bool AbstractTreeItem::isSelected() const {
129  return m_selected;
130  }
131 
132 
133  bool AbstractTreeItem::isSelectable() const {
134  return m_selectable;
135  }
136 
137 
138  void AbstractTreeItem::setVisible(bool newState) {
139  m_visible = newState;
140  }
141 
142 
143  bool AbstractTreeItem::isVisible() const {
144  return m_visible;
145  }
146 
147 
148  int AbstractTreeItem::getDataWidth() const {
149  if (m_dataWidth == 0) {
150  IString msg = "Children of AbstractTreeItem must call setDataWidth "
151  "with a non-zero width";
152  throw IException(IException::Programmer, msg, _FILEINFO_);
153  }
154 
155  return m_dataWidth;
156  }
157 
158 
159  int AbstractTreeItem::getDepth() const {
160  int depth = 0;
161 
162  AbstractTreeItem *item = parent();
163 
164  while (item) {
165  depth++;
166  item = item->parent();
167  }
168 
169  return depth;
170  }
171 
172 
173  void AbstractTreeItem::setLastVisibleFilteredItem(AbstractTreeItem *item) {
174  IString msg = "This tree item does not keep track of visible filtered "
175  "items";
176  throw IException(IException::Programmer, msg, _FILEINFO_);
177  }
178 
179 
180  const AbstractTreeItem *
181  AbstractTreeItem::getLastVisibleFilteredItem() const {
182  return NULL;
183  }
184 
185 
186  void AbstractTreeItem::calcDataWidth(int avgCharWidth) {
187  if (avgCharWidth <= 0) {
188  IString msg = "calcDataWidth() expects a positive non-zero value.";
189  throw IException(IException::Programmer, msg, _FILEINFO_);
190  }
191 
192  m_dataWidth = (avgCharWidth + 1) * getFormattedData().size();
193  }
194 
195 
196  QString AbstractTreeItem::catchNull(QVariant data) {
197  QString result;
198 
199  if (data.type() == QVariant::Double) {
200  double dblData = data.toDouble();
201  result = "NULL";
202 
203  if (dblData != Null) {
204  QLocale locale;
205  result = locale.toString(dblData, 'f');
206  }
207  }
208  else {
209  result = data.toString();
210  }
211 
212  return result;
213  }
214 
215 
216  double AbstractTreeItem::catchNull(QString str) {
217  double d = Null;
218  if (str.toLower() != "null") {
219  QLocale locale;
220  d = locale.toDouble(str);
221  }
222 
223  return d;
224  }
225  }
226 }