Isis 3 Programmer Reference
ImageTreeWidgetItem.cpp
1 #include "ImageTreeWidgetItem.h"
2 
3 #include <QDebug>
4 
5 #include "Angle.h"
6 #include "Cube.h"
7 #include "DisplayProperties.h"
9 #include "FileName.h"
10 #include "IException.h"
11 #include "Image.h"
12 #include "ImageList.h"
13 #include "ImageTreeWidget.h"
14 #include "SpecialPixel.h"
15 #include "Table.h"
16 
17 namespace Isis {
18 
27  QTreeWidget *parent) : QTreeWidgetItem(parent, UserType) {
28  m_image = image;
29  m_imageList = imageList;
30  ImageDisplayProperties *displayProps = m_image->displayProperties();
33  connect(displayProps, SIGNAL(supportAdded(int)), this, SLOT(onDisplayPropertiesChanged()));
34  setText(NameColumn, displayProps->displayName());
35 
36  setColumnValue(ResolutionColumn, m_image->resolution());
37  setColumnValue(EmissionAngleColumn, m_image->emissionAngle().degrees());
38  setColumnValue(IncidenceAngleColumn, m_image->incidenceAngle().degrees());
39  setColumnValue(PhaseAngleColumn, m_image->phaseAngle().degrees());
40  setColumnValue(AspectRatioColumn, m_image->aspectRatio());
41  setColumnValue(SampleResolutionColumn, m_image->sampleResolution());
42  setColumnValue(LineResolutionColumn, m_image->lineResolution());
43  setColumnValue(NorthAzimuthColumn, m_image->northAzimuth().degrees());
44 
45  setFlags(Qt::ItemIsEnabled |
46  Qt::ItemIsUserCheckable |
47  Qt::ItemIsSelectable |
48  Qt::ItemIsDragEnabled |
49  Qt::ItemIsDropEnabled);
50 
51  update(false);
52  }
53 
54 
55  ImageTreeWidgetItem::~ImageTreeWidgetItem() {
56  }
57 
58 
59  Image *ImageTreeWidgetItem::image() {
60  return m_image;
61  }
62 
63 
64  QString ImageTreeWidgetItem::imageListName() const {
65  return m_imageList->name();
66  }
67 
68 
69  void ImageTreeWidgetItem::forgetImage() {
70  m_image = NULL;
71  }
72 
73 
74  void ImageTreeWidgetItem::update(bool save) {
75  if (m_image) {
76  ImageDisplayProperties *displayProps = m_image->displayProperties();
77 
78  if (save) {
79  if (displayProps->supports(ImageDisplayProperties::ShowFill))
80  displayProps->setShowFill(checkState(FootprintColumn));
81 
82  if (displayProps->supports(ImageDisplayProperties::ShowOutline))
83  displayProps->setShowOutline(checkState(OutlineColumn));
84 
85  if (displayProps->supports(ImageDisplayProperties::ShowDNs))
86  displayProps->setShowDNs(checkState(ImageColumn));
87 
88  if (displayProps->supports(ImageDisplayProperties::ShowLabel))
89  displayProps->setShowLabel(checkState(LabelColumn));
90 
91  if (parent()) {
92  displayProps->setSelected(isSelected() || parent()->isSelected());
93  }
94  }
95  else {
96 
97  setBackground(NameColumn,
98  QBrush(
99  displayProps->getValue(ImageDisplayProperties::Color).value<QColor>()
100  ));
101 
102  if (displayProps->supports(ImageDisplayProperties::ShowFill))
103  setCheckState(FootprintColumn,
104  toCheck(displayProps->getValue(ImageDisplayProperties::ShowFill)));
105 
106  if (displayProps->supports(ImageDisplayProperties::ShowOutline))
107  setCheckState(OutlineColumn,
108  toCheck(displayProps->getValue(ImageDisplayProperties::ShowOutline)));
109 
110  if (displayProps->supports(ImageDisplayProperties::ShowDNs))
111  setCheckState(ImageColumn,
112  toCheck(displayProps->getValue(ImageDisplayProperties::ShowDNs)));
113 
114  if (displayProps->supports(ImageDisplayProperties::ShowLabel))
115  setCheckState(LabelColumn,
116  toCheck(displayProps->getValue(ImageDisplayProperties::ShowLabel)));
117 
118  bool displaySelected =
119  displayProps->getValue(ImageDisplayProperties::Selected).toBool();
120 
121  if (parent()) {
122  if (displaySelected && !isSelected() && !parent()->isSelected()) {
123  setSelected(true);
124  }
125  else if (!displaySelected && (isSelected() || parent()->isSelected())) {
126  setSelected(false);
127  parent()->setSelected(false);
128  }
129  }
130  }
131  }
132  }
133 
134 
135  Qt::CheckState ImageTreeWidgetItem::toCheck(QVariant var) {
136  if (var.toBool())
137  return Qt::Checked;
138  else
139  return Qt::Unchecked;
140  }
141 
142 
143  QString ImageTreeWidgetItem::treeColumnToString(TreeColumn column) {
144  switch(column) {
145  case NameColumn:
146  return "Name";
147  case FootprintColumn:
148  return "Footprint";
149  case OutlineColumn:
150  return "Outline";
151  case ImageColumn:
152  return "Image";
153  case LabelColumn:
154  return "Label";
155 
156  case ResolutionColumn:
157  return "Resolution";
158  case EmissionAngleColumn:
159  return "Emission Angle";
160  case IncidenceAngleColumn:
161  return "Incidence Angle";
162  case PhaseAngleColumn:
163  return "Phase Angle";
164  case AspectRatioColumn:
165  return "Aspect Ratio";
166  case SampleResolutionColumn:
167  return "Sample Resolution";
168  case LineResolutionColumn:
169  return "Line Resolution";
170  case NorthAzimuthColumn:
171  return "North Azimuth";
172 
173  case BlankColumn:
174  return "";
175  }
176 
177  throw IException(IException::Programmer,
178  "Invalid tree column passed to treeColumnToString", _FILEINFO_);
179  }
180 
181 
182  void ImageTreeWidgetItem::onDisplayPropertiesChanged() {
183  ImageTreeWidget *tree = qobject_cast<ImageTreeWidget *>(treeWidget());
184 
185  if (tree) {
186  tree->enqueueReadDisplayProperties(this);
187  }
188  else {
189  update(false);
190  }
191  }
192 
193 
194  void ImageTreeWidgetItem::setColumnValue(TreeColumn column, double value) {
195  if (!IsSpecial(value)) {
196  setText(column, QString::number(value));
197  }
198  }
199 
200 
201  bool ImageTreeWidgetItem::operator<(const QTreeWidgetItem &other) const {
202  int column = treeWidget()->sortColumn();
203 
204  switch((TreeColumn)column) {
205  case FootprintColumn:
206  case ImageColumn:
207  case LabelColumn:
208  case NameColumn:
209  case OutlineColumn:
210  return text(column) < other.text(column);
211 
212  case EmissionAngleColumn:
213  case IncidenceAngleColumn:
214  case PhaseAngleColumn:
215  case ResolutionColumn:
216  case AspectRatioColumn:
217  case SampleResolutionColumn:
218  case LineResolutionColumn:
219  case NorthAzimuthColumn:
220  return text(column).toDouble() <
221  other.text(column).toDouble();
222 
223  case BlankColumn:
224  return false;
225  }
226 
227  return false;
228  }
229 }
True if the cube should show a fill area if possible (bool)
QString name() const
Get the human-readable name of this image list.
Definition: ImageList.cpp:724
Internalizes a list of images and allows for operations on the entire list.
Definition: ImageList.h:55
ImageTreeWidgetItem(ImageList *imageList, Image *image, QTreeWidget *parent=0)
ImageTreeWidget constructor.
QString displayName() const
Returns the display name.
True if the cube should be outlined (bool)
Angle emissionAngle() const
Get the emission angle of this image, as calculated and attached by camstats.
Definition: Image.cpp:465
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
double degrees() const
Get the angle in units of Degrees.
Definition: Angle.h:249
True if the cube should show DN values if possible (bool)
True if the cube should show its display name (bool)
Angle phaseAngle() const
Get the phase angle of this image, as calculated and attached by camstats.
Definition: Image.cpp:515
This is the GUI communication mechanism for cubes.
double sampleResolution() const
Get the sample resolution of this image, as calculated and attached by camstats.
Definition: Image.cpp:525
double lineResolution() const
Get the line resolution of this image, as calculated and attached by camstats.
Definition: Image.cpp:485
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition: SpecialPixel.h:212
This represents a cube in a project-based GUI interface.
Definition: Image.h:107
ImageDisplayProperties * displayProperties()
Get the display (GUI) properties (information) associated with this image.
Definition: Image.cpp:320
Angle northAzimuth() const
Get the north azimuth of this image, as calculated and attached by camstats.
Definition: Image.cpp:505
void addSupport(int property)
Call this with every property you support, otherwise they will not communicate properly between widge...
double resolution() const
Get the resolution of this image, as calculated and attached by camstats.
Definition: Image.cpp:455
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
The selection state of this cube (bool)
The color of the cube, default randomized (QColor)
double aspectRatio() const
Get the aspect ratio of this image, as calculated and attached by camstats.
Definition: Image.cpp:436
Angle incidenceAngle() const
Get the incidence angle of this image, as calculated and attached by camstats.
Definition: Image.cpp:475
void setShowFill(bool)
Change the visibility of the fill area associated with this cube.