Isis 3 Programmer Reference
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 <QLineEdit>
14 #include <QPushButton>
15 #include <QSpinBox>
16 
17 #include "ScatterPlotWindow.h"
18 #include "IString.h"
19 
20 namespace Isis {
30  ScatterPlotWindow *window, QWidget *parent) : QDialog(parent) {
31  m_window = window;
32 
33  QGridLayout *mainLayout = new QGridLayout;
34 
67  int row = 0;
68  QLabel *headerLabel = new QLabel("<h3>Configure Alarming</h3>");
69  mainLayout->addWidget(headerLabel, row, 0, 1, 3);
70  row++;
71 
72  QLabel *descriptionLabel = new QLabel("Alarming is highlighting the "
73  "corresponding pixels between the scatter plot and the source cubes. "
74  "Alarming happens as you move the mouse around on the plot or cube.");
75  descriptionLabel->setWordWrap(true);
76  mainLayout->addWidget(descriptionLabel, row, 0, 1, 3);
77  row++;
78 
79  QLabel *ontoPlotHeaderLabel =
80  new QLabel("<h4>Alarming From Cube to Plot</h4>");
81  mainLayout->addWidget(ontoPlotHeaderLabel, row, 0, 1, 3);
82  row++;
83 
84  QLabel *ontoPlotEnabledLabel = new QLabel("Enabled");
85  m_alarmOntoPlot = new QCheckBox;
86  connect(m_alarmOntoPlot, SIGNAL(stateChanged(int)),
87  this, SLOT(refreshWidgetStates()));
88  mainLayout->addWidget(ontoPlotEnabledLabel, row, 1);
89  mainLayout->addWidget(m_alarmOntoPlot, row, 2);
90  row++;
91 
92  QLabel *ontoPlotSamplesLabel = new QLabel("Samples");
94  m_alarmOntoPlotSamples->setSingleStep(2);
95  m_alarmOntoPlotSamples->setRange(1, INT_MAX);
96  connect(m_alarmOntoPlotSamples, SIGNAL(valueChanged(int)),
97  this, SLOT(refreshWidgetStates()));
98  mainLayout->addWidget(ontoPlotSamplesLabel, row, 1);
99  mainLayout->addWidget(m_alarmOntoPlotSamples, row, 2);
100  row++;
101 
102  QLabel *ontoPlotLinesLabel = new QLabel("Lines");
104  m_alarmOntoPlotLines->setSingleStep(2);
105  m_alarmOntoPlotLines->setRange(1, INT_MAX);
106  connect(m_alarmOntoPlotLines, SIGNAL(valueChanged(int)),
107  this, SLOT(refreshWidgetStates()));
108  mainLayout->addWidget(ontoPlotLinesLabel, row, 1);
109  mainLayout->addWidget(m_alarmOntoPlotLines, row, 2);
110  row++;
111  row++;
112 
113 
114  QLabel *ontoViewportHeaderLabel =
115  new QLabel("<h4>Alarming From Plot to Cube</h4>");
116  mainLayout->addWidget(ontoViewportHeaderLabel, row, 0, 1, 3);
117  row++;
118 
119  QLabel *ontoViewportEnabledLabel = new QLabel("Enabled");
120  m_alarmOntoViewport = new QCheckBox;
121  connect(m_alarmOntoViewport, SIGNAL(stateChanged(int)),
122  this, SLOT(refreshWidgetStates()));
123  mainLayout->addWidget(ontoViewportEnabledLabel, row, 1);
124  mainLayout->addWidget(m_alarmOntoViewport, row, 2);
125  row++;
126 
127  QLabel *ontoViewportUnitsLabel = new QLabel("Range (units)");
129  m_alarmOntoViewportUnits->addItem("Distance from mouse",
131  m_alarmOntoViewportUnits->addItem("DN range around mouse",
133  connect(m_alarmOntoViewportUnits, SIGNAL(currentIndexChanged(int)),
134  this, SLOT(refreshWidgetStates()));
135  mainLayout->addWidget(ontoViewportUnitsLabel, row, 1);
136  mainLayout->addWidget(m_alarmOntoViewportUnits, row, 2);
137  row++;
138 
139  QLabel *ontoViewportXDnLabel = new QLabel("X Cube DN Box Size");
140  m_alarmOntoViewportXDnSize = new QLineEdit;
141  m_alarmOntoViewportXDnSize->setValidator(
142  new QDoubleValidator(0.0, DBL_MAX, DBL_MAX_10_EXP + DBL_DIG, this));
143  connect(m_alarmOntoViewportXDnSize, SIGNAL(textChanged(QString)),
144  this, SLOT(refreshWidgetStates()));
145  mainLayout->addWidget(ontoViewportXDnLabel, row, 1);
146  mainLayout->addWidget(m_alarmOntoViewportXDnSize, row, 2);
147  row++;
148 
149  QLabel *ontoViewportYDnLabel = new QLabel("Y Cube DN Box Size");
150  m_alarmOntoViewportYDnSize = new QLineEdit;
151  m_alarmOntoViewportYDnSize->setValidator(
152  new QDoubleValidator(0.0, DBL_MAX, DBL_MAX_10_EXP + DBL_DIG, this));
153  connect(m_alarmOntoViewportYDnSize, SIGNAL(textChanged(QString)),
154  this, SLOT(refreshWidgetStates()));
155  mainLayout->addWidget(ontoViewportYDnLabel, row, 1);
156  mainLayout->addWidget(m_alarmOntoViewportYDnSize, row, 2);
157  row++;
158 
159  QLabel *ontoViewportWidthLabel = new QLabel("Width");
161  m_alarmOntoViewportWidth->setSingleStep(2);
162  m_alarmOntoViewportWidth->setRange(1, INT_MAX);
163  connect(m_alarmOntoViewportWidth, SIGNAL(valueChanged(int)),
164  this, SLOT(refreshWidgetStates()));
165  mainLayout->addWidget(ontoViewportWidthLabel, row, 1);
166  mainLayout->addWidget(m_alarmOntoViewportWidth, row, 2);
167  row++;
168 
169  QLabel *ontoViewportHeightLabel = new QLabel("Height");
171  m_alarmOntoViewportHeight->setSingleStep(2);
172  m_alarmOntoViewportHeight->setRange(1, INT_MAX);
173  connect(m_alarmOntoViewportHeight, SIGNAL(valueChanged(int)),
174  this, SLOT(refreshWidgetStates()));
175  mainLayout->addWidget(ontoViewportHeightLabel, row, 1);
176  mainLayout->addWidget(m_alarmOntoViewportHeight, row, 2);
177  row++;
178 
179  QHBoxLayout *applyButtonsLayout = new QHBoxLayout;
180  applyButtonsLayout->addStretch();
181 
182  m_okayButton = new QPushButton("&Ok");
183  m_okayButton->setIcon(QIcon::fromTheme("dialog-ok"));
184  connect(m_okayButton, SIGNAL(clicked()),
185  this, SLOT(applySettingsToScatterPlot()));
186  connect(m_okayButton, SIGNAL(clicked()),
187  this, SLOT(accept()));
188  applyButtonsLayout->addWidget(m_okayButton);
189 
190  m_applyButton = new QPushButton("&Apply");
191  m_applyButton->setIcon(QIcon::fromTheme("dialog-ok-apply"));
192  connect(m_applyButton, SIGNAL(clicked()),
193  this, SLOT(applySettingsToScatterPlot()));
194  applyButtonsLayout->addWidget(m_applyButton);
195 
196  QPushButton *cancelButton = new QPushButton("&Cancel");
197  cancelButton->setIcon(QIcon::fromTheme("dialog-cancel"));
198  connect(cancelButton, SIGNAL(clicked()),
199  this, SLOT(reject()));
200  applyButtonsLayout->addWidget(cancelButton);
201 
202  QWidget *applyButtonsWrapper = new QWidget;
203  applyButtonsWrapper->setLayout(applyButtonsLayout);
204  mainLayout->addWidget(applyButtonsWrapper, row, 0, 1, 3);
205  row++;
206 
207  setLayout(mainLayout);
208 
210  }
211 
212 
213  ScatterPlotAlarmConfigDialog::~ScatterPlotAlarmConfigDialog() {
214  m_window = NULL;
215  }
216 
217 
223  m_window->setAlarmingPlot(m_alarmOntoPlot->isChecked());
224 
225  m_window->setAlarmPlotBoxSize(m_alarmOntoPlotSamples->value(),
226  m_alarmOntoPlotLines->value());
227 
228  m_window->setAlarmingViewport(m_alarmOntoViewport->isChecked());
229 
230  m_window->setAlarmViewportUnits((ScatterPlotWindow::AlarmRangeUnits)
231  m_alarmOntoViewportUnits->itemData(
232  m_alarmOntoViewportUnits->currentIndex()).toInt());
233 
234  m_window->setAlarmViewportScreenBoxSize(
235  m_alarmOntoViewportWidth->value(),
236  m_alarmOntoViewportHeight->value());
237 
238  m_window->setAlarmViewportDnBoxSize(
241 
242  QPair<double, double> alarmViewportDnBoxSize =
243  m_window->alarmViewportDnBoxSize();
245  IString(alarmViewportDnBoxSize.first).ToQt());
247  IString(alarmViewportDnBoxSize.second).ToQt());
248 
249  QPair<int, int> alarmViewportScreenBoxSize =
250  m_window->alarmViewportScreenBoxSize();
251  m_alarmOntoViewportWidth->setValue(alarmViewportScreenBoxSize.first);
252  m_alarmOntoViewportHeight->setValue(alarmViewportScreenBoxSize.second);
253 
255  }
256 
257 
263  setWindowTitle("Configure Alarming - " + m_window->windowTitle());
264 
265  m_alarmOntoPlot->setChecked(m_window->alarmingPlot());
266 
267  QPair<int, int> alarmPlotBoxSize = m_window->alarmPlotBoxSize();
268  m_alarmOntoPlotSamples->setValue(alarmPlotBoxSize.first);
269  m_alarmOntoPlotLines->setValue(alarmPlotBoxSize.second);
270 
271  m_alarmOntoViewport->setChecked(m_window->alarmingViewport());
272 
273  m_alarmOntoViewportUnits->setCurrentIndex(
274  m_alarmOntoViewportUnits->findData(m_window->alarmViewportUnits()));
275 
276  QPair<double, double> alarmViewportDnBoxSize =
277  m_window->alarmViewportDnBoxSize();
279  IString(alarmViewportDnBoxSize.first).ToQt());
281  IString(alarmViewportDnBoxSize.second).ToQt());
282 
283  QPair<int, int> alarmViewportScreenBoxSize =
284  m_window->alarmViewportScreenBoxSize();
285  m_alarmOntoViewportWidth->setValue(alarmViewportScreenBoxSize.first);
286  m_alarmOntoViewportHeight->setValue(alarmViewportScreenBoxSize.second);
287 
289  }
290 
291 
297  bool allValid = true;
298 
299  if (m_alarmOntoPlot->isChecked()) {
300  m_alarmOntoPlotSamples->setEnabled(true);
301  m_alarmOntoPlotLines->setEnabled(true);
302 
303  // Box sizes should be odd
304  allValid = allValid && ((m_alarmOntoPlotSamples->value() % 2) == 1);
305  allValid = allValid && ((m_alarmOntoPlotLines->value() % 2) == 1);
306  }
307  else {
308  m_alarmOntoPlotSamples->setEnabled(false);
309  m_alarmOntoPlotLines->setEnabled(false);
310  }
311 
312 
313  if (m_alarmOntoViewport->isChecked()) {
314  m_alarmOntoViewportUnits->setEnabled(true);
315 
316  if (m_alarmOntoViewportUnits->itemData(
317  m_alarmOntoViewportUnits->currentIndex()).toInt() ==
319  m_alarmOntoViewportXDnSize->setEnabled(true);
320  m_alarmOntoViewportYDnSize->setEnabled(true);
321  m_alarmOntoViewportWidth->setEnabled(false);
322  m_alarmOntoViewportHeight->setEnabled(false);
323 
324  int unused = 0;
325  QString textToTest = m_alarmOntoViewportXDnSize->text();
326  const QValidator *xValidator = m_alarmOntoViewportXDnSize->validator();
327  allValid = allValid && (xValidator->validate(textToTest, unused) ==
328  QValidator::Acceptable);
329 
330  textToTest = m_alarmOntoViewportYDnSize->text();
331  const QValidator *yValidator = m_alarmOntoViewportYDnSize->validator();
332  allValid = allValid && (yValidator->validate(textToTest, unused) ==
333  QValidator::Acceptable);
334  }
335  else {
336  m_alarmOntoViewportXDnSize->setEnabled(false);
337  m_alarmOntoViewportYDnSize->setEnabled(false);
338  m_alarmOntoViewportWidth->setEnabled(true);
339  m_alarmOntoViewportHeight->setEnabled(true);
340 
341  allValid = allValid && ((m_alarmOntoViewportWidth->value() % 2) == 1);
342  allValid = allValid && ((m_alarmOntoViewportHeight->value() % 2) == 1);
343  }
344  }
345  else {
346  m_alarmOntoViewportUnits->setEnabled(false);
347  m_alarmOntoViewportXDnSize->setEnabled(false);
348  m_alarmOntoViewportYDnSize->setEnabled(false);
349  m_alarmOntoViewportWidth->setEnabled(false);
350  m_alarmOntoViewportHeight->setEnabled(false);
351  }
352 
353  m_okayButton->setEnabled(allValid);
354  m_applyButton->setEnabled(allValid);
355  }
356 }
Isis::IString::ToDouble
double ToDouble() const
Returns the floating point value the IString represents.
Definition: IString.cpp:799
Isis::ScatterPlotAlarmConfigDialog::m_window
QPointer< ScatterPlotWindow > m_window
The scatter plot window that we're configuring alarming on.
Definition: ScatterPlotAlarmConfigDialog.h:93
QWidget
Isis::ScatterPlotAlarmConfigDialog::m_alarmOntoViewportWidth
QPointer< QSpinBox > m_alarmOntoViewportWidth
The X-Pixel Screen Box Size for alarming plot->viewport.
Definition: ScatterPlotAlarmConfigDialog.h:76
Isis::ScatterPlotAlarmConfigDialog::m_alarmOntoPlotLines
QPointer< QSpinBox > m_alarmOntoPlotLines
This is the line box size for alarming viewport->plot.
Definition: ScatterPlotAlarmConfigDialog.h:62
Isis::ScatterPlotAlarmConfigDialog::m_alarmOntoPlotSamples
QPointer< QSpinBox > m_alarmOntoPlotSamples
This is the sample box size for alarming viewport->plot.
Definition: ScatterPlotAlarmConfigDialog.h:60
Isis::ScatterPlotAlarmConfigDialog::ScatterPlotAlarmConfigDialog
ScatterPlotAlarmConfigDialog(ScatterPlotWindow *window, QWidget *parent=NULL)
Create an alarming configuration dialog.
Definition: ScatterPlotAlarmConfigDialog.cpp:29
QComboBox
Isis::ScatterPlotAlarmConfigDialog::m_alarmOntoViewport
QPointer< QCheckBox > m_alarmOntoViewport
This is the user option for enabling alarming plot->viewport.
Definition: ScatterPlotAlarmConfigDialog.h:65
Isis::ScatterPlotWindow
Scatter Plot Window.
Definition: ScatterPlotWindow.h:28
Isis::ScatterPlotAlarmConfigDialog::readSettingsFromScatterPlot
void readSettingsFromScatterPlot()
Update the current widgets' states with the current settings in the scatter plot window.
Definition: ScatterPlotAlarmConfigDialog.cpp:262
Isis::ScatterPlotAlarmConfigDialog::m_alarmOntoViewportXDnSize
QPointer< QLineEdit > m_alarmOntoViewportXDnSize
The X-Pixel Cube DN Box Size for alarming plot->viewport.
Definition: ScatterPlotAlarmConfigDialog.h:72
Isis::ScatterPlotWindow::AlarmRangeUnits
AlarmRangeUnits
This enumeration differentiates alarming a strict cube DN box size from a screen region.
Definition: ScatterPlotWindow.h:36
Isis::ScatterPlotAlarmConfigDialog::m_alarmOntoViewportUnits
QPointer< QComboBox > m_alarmOntoViewportUnits
This is whether alarming plot->viewport should be screen pixels or a set box size regardless of zoom ...
Definition: ScatterPlotAlarmConfigDialog.h:70
Isis::ScatterPlotWindow::CubeUnits
@ CubeUnits
Alarming is a DN range around the mouse.
Definition: ScatterPlotWindow.h:38
Isis::ScatterPlotAlarmConfigDialog::applySettingsToScatterPlot
void applySettingsToScatterPlot()
Take the settings that have been configured and apply them to the scatter plot.
Definition: ScatterPlotAlarmConfigDialog.cpp:222
QPair< double, double >
QDialog
Isis::ScatterPlotWindow::ScreenUnits
@ ScreenUnits
Alarming is a visible area around the mouse.
Definition: ScatterPlotWindow.h:40
Isis::IString
Adds specific functionality to C++ strings.
Definition: IString.h:165
Isis::ScatterPlotAlarmConfigDialog::refreshWidgetStates
void refreshWidgetStates()
Update the enabled/disabled states of the various widgets based on the current user inputs' states.
Definition: ScatterPlotAlarmConfigDialog.cpp:296
Isis::ScatterPlotAlarmConfigDialog::m_okayButton
QPointer< QPushButton > m_okayButton
Button for accepting the current settings and closing the window.
Definition: ScatterPlotAlarmConfigDialog.h:84
Isis::ScatterPlotAlarmConfigDialog::m_alarmOntoViewportHeight
QPointer< QSpinBox > m_alarmOntoViewportHeight
The Y-Pixel Screen Box Size for alarming plot->viewport.
Definition: ScatterPlotAlarmConfigDialog.h:78
Isis::ScatterPlotAlarmConfigDialog::m_applyButton
QPointer< QPushButton > m_applyButton
Button for accepting the current settings.
Definition: ScatterPlotAlarmConfigDialog.h:90
Isis::ScatterPlotAlarmConfigDialog::m_alarmOntoViewportYDnSize
QPointer< QLineEdit > m_alarmOntoViewportYDnSize
The Y-Pixel Cube DN Box Size for alarming plot->viewport.
Definition: ScatterPlotAlarmConfigDialog.h:74
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
QSpinBox
Isis::ScatterPlotAlarmConfigDialog::m_alarmOntoPlot
QPointer< QCheckBox > m_alarmOntoPlot
This is the user option for enabling alarming viewport->plot.
Definition: ScatterPlotAlarmConfigDialog.h:58
Isis::IString::ToQt
QString ToQt() const
Retuns the object string as a QString.
Definition: IString.cpp:869