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