Isis 3 Programmer Reference
ManualStretchType.cpp
1 #include "ManualStretchType.h"
2 
3 #include <QVBoxLayout>
4 #include <QLayout>
5 #include <QLineEdit>
6 #include <QLabel>
7 #include <QTableWidget>
8 #include <QPushButton>
9 
10 #include "CubeViewport.h"
11 #include "HistogramWidget.h"
12 #include "Statistics.h"
13 #include "Stretch.h"
14 
15 namespace Isis {
25  const Stretch &stretch,
26  const QString &name, const QColor &color)
27  : StretchType(hist, stretch, name, color) {
28  p_errorMessage = NULL;
29 
30  QWidget *buttonContainer = new QWidget();
31  QHBoxLayout *buttonLayout = new QHBoxLayout();
32  p_errorMessage = new QLabel;
33 
34  QPushButton *addButton = new QPushButton("Add Row");
35  connect(addButton, SIGNAL(clicked(bool)),
36  this, SLOT(addButtonPressed(bool)));
37  buttonLayout->addWidget(addButton);
38 
39  QPushButton *deleteButton = new QPushButton("Delete Row");
40  connect(deleteButton, SIGNAL(clicked(bool)),
41  this, SLOT(deleteButtonPressed(bool)));
42  buttonLayout->addWidget(deleteButton);
43 
44  buttonContainer->setLayout(buttonLayout);
45 
46  p_mainLayout->addWidget(buttonContainer, 1, 0);
47  p_mainLayout->addWidget(p_errorMessage, 4, 0);
48 
49  p_table->setSelectionMode(QAbstractItemView::SingleSelection);
50  p_table->setSelectionBehavior(QAbstractItemView::SelectRows);
51  p_table->setEditTriggers(QAbstractItemView::DoubleClicked |
52  QAbstractItemView::SelectedClicked |
53  QAbstractItemView::AnyKeyPressed);
54  connect(p_table, SIGNAL(cellChanged(int, int)),
55  this, SLOT(readTable()));
56  disconnect(this, SIGNAL(stretchChanged()), this, SLOT(updateTable()));
57 
58  setLayout(p_mainLayout);
59  setStretch(stretch);
60  }
61 
62 
67  }
68 
69 
85  if(newStretch.Text() != p_stretch->Text()) {
86  p_stretch->CopyPairs(newStretch);
87  updateTable();
88  emit stretchChanged();
89  }
90  }
91 
92 
99  p_table->insertRow(p_table->rowCount());
100  }
101 
102 
108  QList<QTableWidgetSelectionRange> selectedRanges =
109  p_table->selectedRanges();
110 
111  if (selectedRanges.empty()) {
112  IString msg = "You must select a row to delete";
114  }
115 
116  int row = selectedRanges.first().topRow();
117  p_table->removeRow(row);
118  }
119 
120  void ManualStretchType::readTable() {
121  *p_stretch = convertTableToStretch();
122  emit stretchChanged();
123  }
124 
125 
126  Stretch ManualStretchType::convertTableToStretch() {
127  Stretch stretch(*p_stretch);
128  stretch.ClearPairs();
129 
130  p_errorMessage->setText("");
131  try {
132  if (p_table->columnCount() == 2) {
133  for (int i = 0; i < p_table->rowCount(); i++) {
134  if (p_table->item(i, 0) &&
135  p_table->item(i, 1) &&
136  !p_table->item(i, 0)->data(Qt::DisplayRole).isNull() &&
137  !p_table->item(i, 1)->data(Qt::DisplayRole).isNull()) {
138  stretch.AddPair(
139  p_table->item(i, 0)->data(Qt::DisplayRole).toString().toDouble(),
140  p_table->item(i, 1)->data(Qt::DisplayRole).toString().toDouble());
141  }
142  }
143  }
144  }
145  catch (IException &e) {
146  p_errorMessage->setText(
147  "<font color='red'>" + e.toString() + "</font>");
148  }
149 
150  return stretch;
151  }
152 }
virtual void setStretch(Stretch)
Given an arbitrary stretch, this will re-interpret it, as best as possible, into a manual stretch...
void stretchChanged()
Emitted when a new Stretch object is available.
ManualStretchType(const Histogram &, const Stretch &, const QString &name, const QColor &color)
This constructs a manual stretch type.
Stretch * p_stretch
Current stretch pairs stored here.
Definition: StretchType.h:70
QTableWidget * p_table
Pairs table.
Definition: StretchType.h:68
void CopyPairs(const Stretch &other)
Copies the stretch pairs from another Stretch object, but maintains special pixel values...
Definition: Stretch.cpp:407
Container of a cube histogram.
Definition: Histogram.h:86
Pixel value mapper.
Definition: Stretch.h:72
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
void deleteButtonPressed(bool)
This is called when a user clicks "Delete" and is responsible for removing the pair with the given in...
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:142
QString Text() const
Converts stretch pair to a string.
Definition: Stretch.cpp:283
Isis exception class.
Definition: IException.h:107
Adds specific functionality to C++ strings.
Definition: IString.h:181
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
This is the base class for advanced stretches.
Definition: StretchType.h:38
void updateTable()
This updates the table with the current stretch pairs.
void addButtonPressed(bool)
This is called when a user clicks "Add / Edit" and is responsible for adding the pair into the correc...
QGridLayout * p_mainLayout
Main layout.
Definition: StretchType.h:66