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