USGS

Isis 3.0 Object Programmers' Reference

Home

ScatterPlotAlarmConfigDialog.cpp
1 #include "ScatterPlotAlarmConfigDialog.h"
2 
3 #include <float.h>
4 
5 #include <iostream>
6 
7 #include <QCheckBox>
8 #include <QColorDialog>
9 #include <QComboBox>
10 #include <QDoubleSpinBox>
11 #include <QGridLayout>
12 #include <QLabel>
13 #include <QPushButton>
14 #include <QSpinBox>
15 
16 #include "ScatterPlotWindow.h"
17 #include "IString.h"
18 
19 namespace Isis {
29  ScatterPlotWindow *window, QWidget *parent) : QDialog(parent) {
30  m_window = window;
31 
32  QGridLayout *mainLayout = new QGridLayout;
33 
66  int row = 0;
67  QLabel *headerLabel = new QLabel("<h3>Configure Alarming</h3>");
68  mainLayout->addWidget(headerLabel, row, 0, 1, 3);
69  row++;
70 
71  QLabel *descriptionLabel = new QLabel("Alarming is highlighting the "
72  "corresponding pixels between the scatter plot and the source cubes. "
73  "Alarming happens as you move the mouse around on the plot or cube.");
74  descriptionLabel->setWordWrap(true);
75  mainLayout->addWidget(descriptionLabel, row, 0, 1, 3);
76  row++;
77 
78  QLabel *ontoPlotHeaderLabel =
79  new QLabel("<h4>Alarming From Cube to Plot</h4>");
80  mainLayout->addWidget(ontoPlotHeaderLabel, row, 0, 1, 3);
81  row++;
82 
83  QLabel *ontoPlotEnabledLabel = new QLabel("Enabled");
84  m_alarmOntoPlot = new QCheckBox;
85  connect(m_alarmOntoPlot, SIGNAL(stateChanged(int)),
86  this, SLOT(refreshWidgetStates()));
87  mainLayout->addWidget(ontoPlotEnabledLabel, row, 1);
88  mainLayout->addWidget(m_alarmOntoPlot, row, 2);
89  row++;
90 
91  QLabel *ontoPlotSamplesLabel = new QLabel("Samples");
93  m_alarmOntoPlotSamples->setSingleStep(2);
94  m_alarmOntoPlotSamples->setRange(1, INT_MAX);
95  connect(m_alarmOntoPlotSamples, SIGNAL(valueChanged(int)),
96  this, SLOT(refreshWidgetStates()));
97  mainLayout->addWidget(ontoPlotSamplesLabel, row, 1);
98  mainLayout->addWidget(m_alarmOntoPlotSamples, row, 2);
99  row++;
100 
101  QLabel *ontoPlotLinesLabel = new QLabel("Lines");
103  m_alarmOntoPlotLines->setSingleStep(2);
104  m_alarmOntoPlotLines->setRange(1, INT_MAX);
105  connect(m_alarmOntoPlotLines, SIGNAL(valueChanged(int)),
106  this, SLOT(refreshWidgetStates()));
107  mainLayout->addWidget(ontoPlotLinesLabel, row, 1);
108  mainLayout->addWidget(m_alarmOntoPlotLines, row, 2);
109  row++;
110  row++;
111 
112 
113  QLabel *ontoViewportHeaderLabel =
114  new QLabel("<h4>Alarming From Plot to Cube</h4>");
115  mainLayout->addWidget(ontoViewportHeaderLabel, row, 0, 1, 3);
116  row++;
117 
118  QLabel *ontoViewportEnabledLabel = new QLabel("Enabled");
119  m_alarmOntoViewport = new QCheckBox;
120  connect(m_alarmOntoViewport, SIGNAL(stateChanged(int)),
121  this, SLOT(refreshWidgetStates()));
122  mainLayout->addWidget(ontoViewportEnabledLabel, row, 1);
123  mainLayout->addWidget(m_alarmOntoViewport, row, 2);
124  row++;
125 
126  QLabel *ontoViewportUnitsLabel = new QLabel("Range (units)");
128  m_alarmOntoViewportUnits->addItem("Distance from mouse",
130  m_alarmOntoViewportUnits->addItem("DN range around mouse",
132  connect(m_alarmOntoViewportUnits, SIGNAL(currentIndexChanged(int)),
133  this, SLOT(refreshWidgetStates()));
134  mainLayout->addWidget(ontoViewportUnitsLabel, row, 1);
135  mainLayout->addWidget(m_alarmOntoViewportUnits, row, 2);
136  row++;
137 
138  QLabel *ontoViewportXDnLabel = new QLabel("X Cube DN Box Size");
139  m_alarmOntoViewportXDnSize = new QLineEdit;
140  m_alarmOntoViewportXDnSize->setValidator(
141  new QDoubleValidator(0.0, DBL_MAX, DBL_MAX_10_EXP + DBL_DIG, this));
142  connect(m_alarmOntoViewportXDnSize, SIGNAL(textChanged(QString)),
143  this, SLOT(refreshWidgetStates()));
144  mainLayout->addWidget(ontoViewportXDnLabel, row, 1);
145  mainLayout->addWidget(m_alarmOntoViewportXDnSize, row, 2);
146  row++;
147 
148  QLabel *ontoViewportYDnLabel = new QLabel("Y Cube DN Box Size");
149  m_alarmOntoViewportYDnSize = new QLineEdit;
150  m_alarmOntoViewportYDnSize->setValidator(
151  new QDoubleValidator(0.0, DBL_MAX, DBL_MAX_10_EXP + DBL_DIG, this));
152  connect(m_alarmOntoViewportYDnSize, SIGNAL(textChanged(QString)),
153  this, SLOT(refreshWidgetStates()));
154  mainLayout->addWidget(ontoViewportYDnLabel, row, 1);
155  mainLayout->addWidget(m_alarmOntoViewportYDnSize, row, 2);
156  row++;
157 
158  QLabel *ontoViewportWidthLabel = new QLabel("Width");
160  m_alarmOntoViewportWidth->setSingleStep(2);
161  m_alarmOntoViewportWidth->setRange(1, INT_MAX);
162  connect(m_alarmOntoViewportWidth, SIGNAL(valueChanged(int)),
163  this, SLOT(refreshWidgetStates()));
164  mainLayout->addWidget(ontoViewportWidthLabel, row, 1);
165  mainLayout->addWidget(m_alarmOntoViewportWidth, row, 2);
166  row++;
167 
168  QLabel *ontoViewportHeightLabel = new QLabel("Height");
170  m_alarmOntoViewportHeight->setSingleStep(2);
171  m_alarmOntoViewportHeight->setRange(1, INT_MAX);
172  connect(m_alarmOntoViewportHeight, SIGNAL(valueChanged(int)),
173  this, SLOT(refreshWidgetStates()));
174  mainLayout->addWidget(ontoViewportHeightLabel, row, 1);
175  mainLayout->addWidget(m_alarmOntoViewportHeight, row, 2);
176  row++;
177 
178  QHBoxLayout *applyButtonsLayout = new QHBoxLayout;
179  applyButtonsLayout->addStretch();
180 
181  m_okayButton = new QPushButton("&Ok");
182  m_okayButton->setIcon(QIcon::fromTheme("dialog-ok"));
183  connect(m_okayButton, SIGNAL(clicked()),
184  this, SLOT(applySettingsToScatterPlot()));
185  connect(m_okayButton, SIGNAL(clicked()),
186  this, SLOT(accept()));
187  applyButtonsLayout->addWidget(m_okayButton);
188 
189  m_applyButton = new QPushButton("&Apply");
190  m_applyButton->setIcon(QIcon::fromTheme("dialog-ok-apply"));
191  connect(m_applyButton, SIGNAL(clicked()),
192  this, SLOT(applySettingsToScatterPlot()));
193  applyButtonsLayout->addWidget(m_applyButton);
194 
195  QPushButton *cancelButton = new QPushButton("&Cancel");
196  cancelButton->setIcon(QIcon::fromTheme("dialog-cancel"));
197  connect(cancelButton, SIGNAL(clicked()),
198  this, SLOT(reject()));
199  applyButtonsLayout->addWidget(cancelButton);
200 
201  QWidget *applyButtonsWrapper = new QWidget;
202  applyButtonsWrapper->setLayout(applyButtonsLayout);
203  mainLayout->addWidget(applyButtonsWrapper, row, 0, 1, 3);
204  row++;
205 
206  setLayout(mainLayout);
207 
209  }
210 
211 
212  ScatterPlotAlarmConfigDialog::~ScatterPlotAlarmConfigDialog() {
213  m_window = NULL;
214  }
215 
216 
222  m_window->setAlarmingPlot(m_alarmOntoPlot->isChecked());
223 
224  m_window->setAlarmPlotBoxSize(m_alarmOntoPlotSamples->value(),
225  m_alarmOntoPlotLines->value());
226 
227  m_window->setAlarmingViewport(m_alarmOntoViewport->isChecked());
228 
229  m_window->setAlarmViewportUnits((ScatterPlotWindow::AlarmRangeUnits)
230  m_alarmOntoViewportUnits->itemData(
231  m_alarmOntoViewportUnits->currentIndex()).toInt());
232 
233  m_window->setAlarmViewportScreenBoxSize(
234  m_alarmOntoViewportWidth->value(),
235  m_alarmOntoViewportHeight->value());
236 
237  m_window->setAlarmViewportDnBoxSize(
238  IString(m_alarmOntoViewportXDnSize->text()).ToDouble(),
239  IString(m_alarmOntoViewportYDnSize->text()).ToDouble());
240 
241  QPair<double, double> alarmViewportDnBoxSize =
242  m_window->alarmViewportDnBoxSize();
244  IString(alarmViewportDnBoxSize.first).ToQt());
246  IString(alarmViewportDnBoxSize.second).ToQt());
247 
248  QPair<int, int> alarmViewportScreenBoxSize =
249  m_window->alarmViewportScreenBoxSize();
250  m_alarmOntoViewportWidth->setValue(alarmViewportScreenBoxSize.first);
251  m_alarmOntoViewportHeight->setValue(alarmViewportScreenBoxSize.second);
252 
254  }
255 
256 
262  setWindowTitle("Configure Alarming - " + m_window->windowTitle());
263 
264  m_alarmOntoPlot->setChecked(m_window->alarmingPlot());
265 
266  QPair<int, int> alarmPlotBoxSize = m_window->alarmPlotBoxSize();
267  m_alarmOntoPlotSamples->setValue(alarmPlotBoxSize.first);
268  m_alarmOntoPlotLines->setValue(alarmPlotBoxSize.second);
269 
270  m_alarmOntoViewport->setChecked(m_window->alarmingViewport());
271 
272  m_alarmOntoViewportUnits->setCurrentIndex(
273  m_alarmOntoViewportUnits->findData(m_window->alarmViewportUnits()));
274 
275  QPair<double, double> alarmViewportDnBoxSize =
276  m_window->alarmViewportDnBoxSize();
278  IString(alarmViewportDnBoxSize.first).ToQt());
280  IString(alarmViewportDnBoxSize.second).ToQt());
281 
282  QPair<int, int> alarmViewportScreenBoxSize =
283  m_window->alarmViewportScreenBoxSize();
284  m_alarmOntoViewportWidth->setValue(alarmViewportScreenBoxSize.first);
285  m_alarmOntoViewportHeight->setValue(alarmViewportScreenBoxSize.second);
286 
288  }
289 
290 
296  bool allValid = true;
297 
298  if (m_alarmOntoPlot->isChecked()) {
299  m_alarmOntoPlotSamples->setEnabled(true);
300  m_alarmOntoPlotLines->setEnabled(true);
301 
302  // Box sizes should be odd
303  allValid = allValid && ((m_alarmOntoPlotSamples->value() % 2) == 1);
304  allValid = allValid && ((m_alarmOntoPlotLines->value() % 2) == 1);
305  }
306  else {
307  m_alarmOntoPlotSamples->setEnabled(false);
308  m_alarmOntoPlotLines->setEnabled(false);
309  }
310 
311 
312  if (m_alarmOntoViewport->isChecked()) {
313  m_alarmOntoViewportUnits->setEnabled(true);
314 
315  if (m_alarmOntoViewportUnits->itemData(
316  m_alarmOntoViewportUnits->currentIndex()).toInt() ==
318  m_alarmOntoViewportXDnSize->setEnabled(true);
319  m_alarmOntoViewportYDnSize->setEnabled(true);
320  m_alarmOntoViewportWidth->setEnabled(false);
321  m_alarmOntoViewportHeight->setEnabled(false);
322 
323  int unused = 0;
324  QString textToTest = m_alarmOntoViewportXDnSize->text();
325  const QValidator *xValidator = m_alarmOntoViewportXDnSize->validator();
326  allValid = allValid && (xValidator->validate(textToTest, unused) ==
327  QValidator::Acceptable);
328 
329  textToTest = m_alarmOntoViewportYDnSize->text();
330  const QValidator *yValidator = m_alarmOntoViewportYDnSize->validator();
331  allValid = allValid && (yValidator->validate(textToTest, unused) ==
332  QValidator::Acceptable);
333  }
334  else {
335  m_alarmOntoViewportXDnSize->setEnabled(false);
336  m_alarmOntoViewportYDnSize->setEnabled(false);
337  m_alarmOntoViewportWidth->setEnabled(true);
338  m_alarmOntoViewportHeight->setEnabled(true);
339 
340  allValid = allValid && ((m_alarmOntoViewportWidth->value() % 2) == 1);
341  allValid = allValid && ((m_alarmOntoViewportHeight->value() % 2) == 1);
342  }
343  }
344  else {
345  m_alarmOntoViewportUnits->setEnabled(false);
346  m_alarmOntoViewportXDnSize->setEnabled(false);
347  m_alarmOntoViewportYDnSize->setEnabled(false);
348  m_alarmOntoViewportWidth->setEnabled(false);
349  m_alarmOntoViewportHeight->setEnabled(false);
350  }
351 
352  m_okayButton->setEnabled(allValid);
353  m_applyButton->setEnabled(allValid);
354  }
355 }