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