Isis 3 Programmer Reference
AdvancedStretch.cpp
1 #include "AdvancedStretch.h"
2 
3 #include <QStackedWidget>
4 #include <QVBoxLayout>
5 #include <QHBoxLayout>
6 #include <QLabel>
7 #include <QComboBox>
8 #include <QMessageBox>
9 
10 #include "Stretch.h"
11 #include "CubeStretch.h"
12 #include "IString.h"
13 #include "IException.h"
14 #include "StretchType.h"
15 #include "LinearStretchType.h"
16 #include "SawtoothStretchType.h"
17 #include "BinaryStretchType.h"
18 #include "ManualStretchType.h"
19 
20 namespace Isis {
30  const Stretch &curStretch,
31  const QString &name, const QColor &color) {
32  setLayout(new QVBoxLayout());
33 
34  setSizePolicy(QSizePolicy::MinimumExpanding,
35  QSizePolicy::MinimumExpanding);
36  QWidget *typeSelectionArea = new QWidget();
37  typeSelectionArea->setLayout(new QHBoxLayout());
38  typeSelectionArea->layout()->addWidget(new QLabel("Stretch Type"));
39 
41  p_stretchTypeSelection->addItem("Linear", 0);
42  p_stretchTypeSelection->addItem("Sawtooth", 1);
43  p_stretchTypeSelection->addItem("Binary", 2);
44  p_stretchTypeSelection->addItem("Manual", 3);
45 
46  typeSelectionArea->layout()->addWidget(p_stretchTypeSelection);
47  layout()->addWidget(typeSelectionArea);
48 
49  p_stretchTypeStack = new QStackedWidget();
50  LinearStretchType *linear = new LinearStretchType(hist, curStretch,
51  name, color);
52  connect(linear, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged()));
53  connect(linear, SIGNAL(saveToCube()), this, SIGNAL(saveToCube()));
54  connect(linear, SIGNAL(deleteFromCube()), this, SIGNAL(deleteFromCube()));
55  connect(linear, SIGNAL(loadStretch()), this, SIGNAL(loadStretch()));
56  p_stretchTypeStack->addWidget(linear);
57 
58  SawtoothStretchType *sawtooth = new SawtoothStretchType(hist, curStretch,
59  name, color);
60  connect(sawtooth, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged()));
61  connect(sawtooth, SIGNAL(saveToCube()), this, SIGNAL(saveToCube()));
62  connect(sawtooth, SIGNAL(deleteFromCube()), this, SIGNAL(deleteFromCube()));
63  connect(sawtooth, SIGNAL(loadStretch()), this, SIGNAL(loadStretch()));
64  p_stretchTypeStack->addWidget(sawtooth);
65 
66  BinaryStretchType *binary = new BinaryStretchType(hist, curStretch,
67  name, color);
68  connect(binary, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged()));
69  connect(binary, SIGNAL(saveToCube()), this, SIGNAL(saveToCube()));
70  connect(binary, SIGNAL(deleteFromCube()), this, SIGNAL(deleteFromCube()));
71  connect(binary, SIGNAL(loadStretch()), this, SIGNAL(loadStretch()));
72  p_stretchTypeStack->addWidget(binary);
73 
74  ManualStretchType *manual = new ManualStretchType(hist, curStretch,
75  name, color);
76  connect(manual, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged()));
77  connect(manual, SIGNAL(saveToCube()), this, SIGNAL(saveToCube()));
78  connect(manual, SIGNAL(deleteFromCube()), this, SIGNAL(deleteFromCube()));
79  connect(manual, SIGNAL(loadStretch()), this, SIGNAL(loadStretch()));
80  p_stretchTypeStack->addWidget(manual);
81 
82  layout()->addWidget(p_stretchTypeStack);
83  connect(p_stretchTypeSelection, SIGNAL(currentIndexChanged(int)),
84  p_stretchTypeStack, SLOT(setCurrentIndex(int)));
85  connect(p_stretchTypeSelection, SIGNAL(currentIndexChanged(int)),
86  this, SIGNAL(stretchChanged()));
87  }
88 
89 
94  }
95 
96 
103  return ((StretchType *)p_stretchTypeStack->currentWidget())->getStretch();
104  }
105 
106 
116  StretchType *stretchType = (StretchType *)
117  p_stretchTypeStack->currentWidget();
118  stretchType->setStretch(newStretch);
119  }
120 
121 
130  QString stretchTypeName = newStretch.getType();
131  int index = 0;
132  if (stretchTypeName.compare("Linear") == 0 ) {
133  index = 0;
134  }
135  else if (stretchTypeName.compare("Sawtooth") == 0 ) {
136  index = 1;
137  }
138  else if (stretchTypeName.compare("Binary") == 0) {
139  index = 2;
140  }
141  else if (stretchTypeName.compare("Manual") == 0) {
142  index = 3;
143  }
144 
145  // Fail by defaulting to Linear. This is correct for non-Advanced Stretches anyway.
146  p_stretchTypeSelection->setCurrentIndex(index);
147  }
148 
149 
159  for(int stretch = 0; stretch < p_stretchTypeStack->count(); stretch ++) {
160  StretchType *stretchType = (StretchType *)
161  p_stretchTypeStack->widget(stretch);
162  stretchType->setHistogram(newHist);
163  }
164  }
165 };
Isis::AdvancedStretch::p_stretchTypeSelection
QComboBox * p_stretchTypeSelection
ComboBox of StretchTypes.
Definition: AdvancedStretch.h:53
Isis::StretchType::setHistogram
virtual void setHistogram(const Histogram &)
This should be called when the visible area changes.
Definition: StretchType.cpp:109
QWidget
Isis::AdvancedStretch::AdvancedStretch
AdvancedStretch(Histogram &, const Stretch &, const QString &, const QColor &)
This constructs an advanced stretch.
Definition: AdvancedStretch.cpp:29
Isis::AdvancedStretch::p_stretchTypeStack
QStackedWidget * p_stretchTypeStack
StretchType's.
Definition: AdvancedStretch.h:52
Isis::StretchType::setStretch
virtual void setStretch(Stretch)=0
Children must re-implement this to update their stretch pairs and GUI elements appropriately.
Isis::Stretch
Pixel value mapper.
Definition: Stretch.h:58
Isis::SawtoothStretchType
This handles the advanced sawtooth stretch.
Definition: SawtoothStretchType.h:33
Isis::AdvancedStretch::getStretch
CubeStretch getStretch()
This returns the current stretch type's stretch.
Definition: AdvancedStretch.cpp:102
Isis::AdvancedStretch::setHistogram
void setHistogram(const Histogram &newHist)
This is called when the visible area changes, so that the histogram can be updated.
Definition: AdvancedStretch.cpp:158
Isis::AdvancedStretch::stretchChanged
void stretchChanged()
Emitted when a new stretch is available.
Isis::AdvancedStretch::restoreSavedStretch
void restoreSavedStretch(CubeStretch newStretch)
Used to restore a saved Stretch from a cube.
Definition: AdvancedStretch.cpp:129
Isis::StretchType
This is the base class for advanced stretches.
Definition: StretchType.h:39
Isis::CubeStretch
Stores stretch information for a cube.
Definition: CubeStretch.h:27
Isis::ManualStretchType
This handles arbitrary user-input stretches.
Definition: ManualStretchType.h:32
QComboBox
Isis::LinearStretchType
This handles the advanced linear stretch.
Definition: LinearStretchType.h:29
Isis::BinaryStretchType
This handles the advanced binary stretch.
Definition: BinaryStretchType.h:30
Isis::AdvancedStretch::~AdvancedStretch
~AdvancedStretch()
Destructor.
Definition: AdvancedStretch.cpp:93
Isis::Histogram
Container of a cube histogram.
Definition: Histogram.h:74
Isis::AdvancedStretch::setStretch
void setStretch(Stretch newStretch)
This is called when the user creates a stretch outside of the advanced stretch.
Definition: AdvancedStretch.cpp:115
Isis::CubeStretch::getType
QString getType() const
Get the Type of Stretch.
Definition: CubeStretch.cpp:115
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16