Isis 3 Programmer Reference
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  AbstractTreeItem::AbstractTreeItem(AbstractTreeItem *parent) : m_parentItem(
22  parent) {
23  m_expanded = false;
24  m_selectable = true;
25  m_selected = false;
26  m_visible = true;
27  m_nextVisibleItem = NULL;
28  m_dataWidth = 0;
29  }
30 
31 
32  AbstractTreeItem::~AbstractTreeItem() {
33  m_nextVisibleItem = NULL;
34  m_parentItem = NULL;
35  }
36 
37 
38  AbstractTreeItem *AbstractTreeItem::parent() const {
39  return m_parentItem;
40  }
41 
42 
43  void AbstractTreeItem::setParent(AbstractTreeItem *newParent) {
44  m_parentItem = newParent;
45  }
46 
47 
48  int AbstractTreeItem::row() const {
49  int rowIndex = -1;
50 
51  if (m_parentItem)
52  rowIndex = m_parentItem->indexOf(const_cast< AbstractTreeItem * >(this));
53 
54  return rowIndex;
55  }
56 
57 
58  QString AbstractTreeItem::getFormattedData() const {
59  return catchNull(getData());
60  }
61 
62 
63  QString AbstractTreeItem::getFormattedData(QString columnTitle) const {
64  return catchNull(getData(columnTitle));
65  }
66 
67 
68  AbstractTreeItem *AbstractTreeItem::getNextVisiblePeer() const {
69  return m_nextVisibleItem;
70  }
71 
72 
73  void AbstractTreeItem::setNextVisiblePeer(AbstractTreeItem *next) {
74  m_nextVisibleItem = next;
75  }
76 
77 
78  bool AbstractTreeItem::hasPoint(ControlPoint *point) const {
79  bool found = false;
80 
81  for (int i = 0; !found && i < childCount(); i++)
82  found = childAt(i)->hasPoint(point);
83 
84  return found;
85  }
86 
87 
88  bool AbstractTreeItem::hasMeasure(ControlMeasure *measure) const {
89  bool found = false;
90 
91  for (int i = 0; !found && i < childCount(); i++)
92  found = childAt(i)->hasMeasure(measure);
93 
94  return found;
95  }
96 
97 
98  bool AbstractTreeItem::hasImage(QString imageSerial) const {
99  bool found = false;
100 
101  for (int i = 0; !found && i < childCount(); i++) {
102  found = childAt(i)->hasImage(imageSerial);
103  }
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 }
const double Null
Value for an Isis Null pixel.
Definition: SpecialPixel.h:110
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31