USGS

Isis 3.0 Object Programmers' Reference

Home

ScatterPlotConfigDialog.cpp
1 #include "IsisDebug.h"
2 #include "ScatterPlotConfigDialog.h"
3 
4 #include <qwt_interval.h>
5 
6 #include <QCheckBox>
7 #include <QComboBox>
8 #include <QFileInfo>
9 #include <QGridLayout>
10 #include <QLabel>
11 #include <QPair>
12 #include <QPushButton>
13 #include <QSpinBox>
14 
15 #include "Cube.h"
16 #include "MdiCubeViewport.h"
17 #include "SpecialPixel.h"
18 #include "Workspace.h"
19 
20 namespace Isis {
30  MdiCubeViewport *activeViewport, Workspace *workspace, QWidget *parent) :
31  QDialog(parent) {
32  setWindowTitle("Configure Scatter Plot");
33 
34  m_oldXAxisCube = NULL;
35  m_workspace = workspace;
36 
37  QGridLayout *mainLayout = new QGridLayout;
38 
67  int curRow = 0;
68  QLabel *titleLabel = new QLabel("<h2>Create Scatter Plot</h2>");
69  mainLayout->addWidget(titleLabel, curRow, 0, 1, 3);
70  curRow++;
71 
72  QLabel *headerLabel = new QLabel("Choose where to gather the scatter plot "
73  "data from. The X and Y axes are a single band of a cube and must have "
74  "the same dimensions");
75  headerLabel->setWordWrap(true);
76  mainLayout->addWidget(headerLabel, curRow, 0, 1, 3);
77  curRow++;
78 
79  int spacerRow = curRow;
80  curRow++;
81 
82  QLabel *configXLabel = new QLabel("Choose X Input Data");
83  mainLayout->addWidget(configXLabel, curRow, 0, 1, 3);
84  curRow++;
85 
86  QLabel *xAxisCubeLabel = new QLabel("Cube");
87  mainLayout->addWidget(xAxisCubeLabel, curRow, 1, 1, 1);
88 
90  m_xAxisCubeCombo->setInsertPolicy(QComboBox::InsertAlphabetically);
91  connect(m_xAxisCubeCombo, SIGNAL(currentIndexChanged(int)),
92  this, SLOT(refreshWidgetStates()));
93  mainLayout->addWidget(m_xAxisCubeCombo, curRow, 2, 1, 1);
94  curRow++;
95 
96  QLabel *xAxisCubeBandLabel = new QLabel("Cube Band");
97  mainLayout->addWidget(xAxisCubeBandLabel, curRow, 1, 1, 1);
98 
100  connect(m_xAxisCubeBandSpinBox, SIGNAL(valueChanged(int)),
101  this, SLOT(refreshWidgetStates()));
102  mainLayout->addWidget(m_xAxisCubeBandSpinBox, curRow, 2, 1, 1);
103  curRow++;
104 
105  QLabel *xAxisBinCountLabel = new QLabel("Bin Count (resolution)");
106  mainLayout->addWidget(xAxisBinCountLabel, curRow, 1, 1, 1);
107 
109  m_xAxisBinCountSpinBox->setMinimum(8);
110  m_xAxisBinCountSpinBox->setMaximum(1048576);
111  m_xAxisBinCountSpinBox->setValue(512);
112  connect(m_xAxisBinCountSpinBox, SIGNAL(valueChanged(int)),
113  this, SLOT(refreshWidgetStates()));
114  mainLayout->addWidget(m_xAxisBinCountSpinBox, curRow, 2, 1, 1);
115  curRow++;
116 
117  QLabel *useViewportRangesLabel = new QLabel("Use Viewport Visible Range");
118  mainLayout->addWidget(useViewportRangesLabel, curRow, 1, 1, 1);
119 
120  m_useViewportRangesCheckBox = new QCheckBox;
121  connect(m_useViewportRangesCheckBox, SIGNAL(stateChanged(int)),
122  this, SLOT(refreshWidgetStates()));
123  mainLayout->addWidget(m_useViewportRangesCheckBox, curRow, 2, 1, 1);
124  curRow++;
125 
126  QLabel *configYLabel = new QLabel("Choose Y Input Data");
127  mainLayout->addWidget(configYLabel, curRow, 0, 1, 3);
128  curRow++;
129 
130  QLabel *yAxisCubeLabel = new QLabel("Cube");
131  mainLayout->addWidget(yAxisCubeLabel, curRow, 1, 1, 1);
132 
134  m_yAxisCubeCombo->setInsertPolicy(QComboBox::InsertAlphabetically);
135  connect(m_yAxisCubeCombo, SIGNAL(currentIndexChanged(int)),
136  this, SLOT(refreshWidgetStates()));
137  mainLayout->addWidget(m_yAxisCubeCombo, curRow, 2, 1, 1);
138  curRow++;
139 
140  QLabel *yAxisCubeBandLabel = new QLabel("Cube Band");
141  mainLayout->addWidget(yAxisCubeBandLabel, curRow, 1, 1, 1);
142 
144  connect(m_yAxisCubeBandSpinBox, SIGNAL(valueChanged(int)),
145  this, SLOT(refreshWidgetStates()));
146  mainLayout->addWidget(m_yAxisCubeBandSpinBox, curRow, 2, 1, 1);
147  curRow++;
148 
149  QLabel *yAxisBinCountLabel = new QLabel("Bin Count (resolution)");
150  mainLayout->addWidget(yAxisBinCountLabel, curRow, 1, 1, 1);
151 
153  m_yAxisBinCountSpinBox->setMinimum(8);
154  m_yAxisBinCountSpinBox->setMaximum(1048576);
155  m_yAxisBinCountSpinBox->setValue(512);
156  connect(m_yAxisBinCountSpinBox, SIGNAL(valueChanged(int)),
157  this, SLOT(refreshWidgetStates()));
158  mainLayout->addWidget(m_yAxisBinCountSpinBox, curRow, 2, 1, 1);
159  curRow++;
160 
161  QHBoxLayout *buttonsLayout = new QHBoxLayout;
162  buttonsLayout->addStretch();
163 
164  m_createButton = new QPushButton("Create");
165  m_createButton->setIcon(QIcon::fromTheme("window-new"));
166  connect(m_createButton, SIGNAL(clicked()),
167  this, SLOT(accept()));
168  buttonsLayout->addWidget(m_createButton);
169 
170  QPushButton *cancelButton = new QPushButton("Cancel");
171  cancelButton->setIcon(QIcon::fromTheme("window-close"));
172  connect(cancelButton, SIGNAL(clicked()),
173  this, SLOT(reject()));
174  buttonsLayout->addWidget(cancelButton);
175 
176  QWidget *buttonsWrapper = new QWidget;
177  buttonsWrapper->setLayout(buttonsLayout);
178  mainLayout->addWidget(buttonsWrapper, curRow, 0, 1, 3);
179 
180  mainLayout->setColumnMinimumWidth(0, 20);
181  mainLayout->setRowMinimumHeight(spacerRow, 20);
182  setLayout(mainLayout);
183 
190  setTabOrder(m_createButton, cancelButton);
191 
193 
194  if (activeViewport) {
195  m_xAxisCubeCombo->setCurrentIndex(
196  m_xAxisCubeCombo->findData(qVariantFromValue(activeViewport->cube())));
197  m_yAxisCubeCombo->setCurrentIndex(
198  m_yAxisCubeCombo->findData(qVariantFromValue(activeViewport->cube())));
199  m_yAxisCubeBandSpinBox->setValue(2);
200  }
201  }
202 
203 
211  return QSize(qRound(QDialog::sizeHint().width() * 1.3),
212  QDialog::sizeHint().height());
213  }
214 
215 
223  return m_xAxisCubeCombo->itemData(
224  m_xAxisCubeCombo->currentIndex()).value<Cube *>();
225  }
226 
227 
235  return m_yAxisCubeCombo->itemData(
236  m_yAxisCubeCombo->currentIndex()).value<Cube *>();
237  }
238 
239 
247  return m_xAxisCubeBandSpinBox->value();
248  }
249 
250 
258  return m_yAxisCubeBandSpinBox->value();
259  }
260 
261 
268  return m_xAxisBinCountSpinBox->value();
269  }
270 
271 
278  return m_yAxisBinCountSpinBox->value();
279  }
280 
281 
290  return range(SampleRange);
291  }
292 
293 
302  return range(LineRange);
303  }
304 
305 
312  MdiCubeViewport * container = NULL;
313 
314  foreach (MdiCubeViewport *viewport, *m_workspace->cubeViewportList()) {
315  if (viewport->cube() == xAxisCube())
316  container = viewport;
317  }
318 
319  return container;
320  }
321 
322 
329  MdiCubeViewport * container = NULL;
330 
331  foreach (MdiCubeViewport *viewport, *m_workspace->cubeViewportList()) {
332  if (viewport->cube() == yAxisCube())
333  container = viewport;
334  }
335 
336  return container;
337  }
338 
339 
346  QList<Cube *> listedXCubes;
347  for (int i = 0; i < m_xAxisCubeCombo->count(); i++) {
348  listedXCubes.append(m_xAxisCubeCombo->itemData(i).value<Cube *>());
349  }
350 
351  QList<Cube *> allXCubes;
352  foreach (MdiCubeViewport *viewport, *m_workspace->cubeViewportList()) {
353  allXCubes.append(viewport->cube());
354  }
355 
356  // We're first going to look for deleted cubes and remove them from the list
357  QList<Cube *> extraXCubes = removeFromList(listedXCubes, allXCubes);
358  foreach (Cube *cubeToRemove, extraXCubes) {
359  m_xAxisCubeCombo->removeItem(
360  m_xAxisCubeCombo->findData(qVariantFromValue(cubeToRemove)));
361  }
362 
363  // Now let's add items that are missing from the list
364  QList<Cube *> missingXCubes = removeFromList(allXCubes, listedXCubes);
365  foreach (Cube *cubeToAdd, missingXCubes) {
366  if (m_xAxisCubeCombo->findData(qVariantFromValue(cubeToAdd)) == -1) {
367  QString cubeName = QFileInfo(cubeToAdd->fileName()).baseName();
368  m_xAxisCubeCombo->addItem(cubeName, qVariantFromValue(cubeToAdd));
369  }
370  }
371 
372  m_xAxisCubeBandSpinBox->setMinimum(1);
373 
374  if (xAxisCube()) {
375  m_xAxisCubeBandSpinBox->setEnabled(true);
376  m_xAxisBinCountSpinBox->setEnabled(true);
377  m_useViewportRangesCheckBox->setEnabled(true);
378  m_yAxisCubeCombo->setEnabled(true);
379 
380  m_xAxisCubeBandSpinBox->setMaximum(xAxisCube()->bandCount());
381 
382  QList<Cube *> listedYCubes;
383  for (int i = 0; i < m_yAxisCubeCombo->count(); i++) {
384  listedYCubes.append(m_yAxisCubeCombo->itemData(i).value<Cube *>());
385  }
386 
387  QList<Cube *> allYCubes;
388  foreach (MdiCubeViewport *viewport, *m_workspace->cubeViewportList()) {
389  Cube *cube = viewport->cube();
390 
391  if (cube->sampleCount() == xAxisCube()->sampleCount() &&
392  cube->lineCount() == xAxisCube()->lineCount()) {
393  allYCubes.append(cube);
394  }
395  }
396 
397  // We're first going to look for deleted cubes and remove them from the list
398  QList<Cube *> extraYCubes = removeFromList(listedYCubes, allYCubes);
399  foreach (Cube *cubeToRemove, extraYCubes) {
400  m_yAxisCubeCombo->removeItem(
401  m_yAxisCubeCombo->findData(qVariantFromValue(cubeToRemove)));
402  }
403 
404  // Now let's add items that are missing from the list
405  QList<Cube *> missingYCubes = removeFromList(allYCubes, listedYCubes);
406  foreach (Cube *cubeToAdd, missingYCubes) {
407  if (m_yAxisCubeCombo->findData(qVariantFromValue(cubeToAdd)) == -1) {
408  QString cubeName = QFileInfo(cubeToAdd->fileName()).baseName();
409  m_yAxisCubeCombo->addItem(cubeName, qVariantFromValue(cubeToAdd));
410  }
411  }
412 
413  if (m_useViewportRangesCheckBox->isChecked()) {
414  m_yAxisCubeCombo->setEnabled(false);
415  }
416 
417  if (xAxisCube() != m_oldXAxisCube) {
419  m_yAxisCubeCombo->setCurrentIndex(
420  m_yAxisCubeCombo->findData(qVariantFromValue(xAxisCube())));
421  }
422 
423  m_yAxisCubeBandSpinBox->setMinimum(1);
424 
425  m_yAxisCubeBandSpinBox->setEnabled(yAxisCube() != NULL);
426  m_yAxisBinCountSpinBox->setEnabled(yAxisCube() != NULL);
427 
428  if (yAxisCube()) {
429  m_yAxisCubeBandSpinBox->setMaximum(yAxisCube()->bandCount());
430  }
431  }
432  else {
433  m_xAxisCubeBandSpinBox->setMaximum(1);
434  m_xAxisCubeBandSpinBox->setEnabled(false);
435  m_xAxisBinCountSpinBox->setEnabled(false);
436  m_useViewportRangesCheckBox->setEnabled(false);
437  m_yAxisCubeCombo->setEnabled(false);
438  m_yAxisCubeBandSpinBox->setMaximum(1);
439  m_yAxisCubeBandSpinBox->setEnabled(false);
440  m_yAxisBinCountSpinBox->setEnabled(false);
441  m_createButton->setEnabled(false);
442  }
443 
444  bool allowCreation = true;
445 
446  if (!xAxisCube() || !yAxisCube())
447  allowCreation = false;
448 
449  if (allowCreation) {
450  if (xAxisCube() == yAxisCube() &&
451  m_xAxisCubeBandSpinBox->value() == m_yAxisCubeBandSpinBox->value()) {
452  allowCreation = false;
453  }
454  }
455 
456  if (m_createButton->isEnabled() != allowCreation)
457  m_createButton->setEnabled(allowCreation);
458  }
459 
460 
471  QList<Cube *> itemsToRemove) {
472  foreach (Cube *toRemove, itemsToRemove) {
473  list.removeAll(toRemove);
474  }
475 
476  return list;
477  }
478 
479 
491  QwtInterval ScatterPlotConfigDialog::range(RangeType rangeType) const {
492  QwtInterval sampleRange;
493  QwtInterval lineRange;
494 
495  if (m_useViewportRangesCheckBox->isChecked()) {
496  MdiCubeViewport * container = xAxisCubeViewport();
497  if (!container && xAxisCube()) {
498  ASSERT(0);
499  sampleRange.setInterval(1.0, xAxisCube()->sampleCount());
500  lineRange.setInterval(1.0, xAxisCube()->lineCount());
501  }
502  else if (container && xAxisCube()) {
503  double startSample = Null;
504  double startLine = Null;
505  double endSample = Null;
506  double endLine = Null;
507 
508  container->viewportToCube(0, 0, startSample, startLine);
509  container->viewportToCube(container->viewport()->width() - 1,
510  container->viewport()->height() - 1,
511  endSample, endLine);
512  sampleRange.setInterval(qRound(startSample), qRound(endSample));
513  lineRange.setInterval(qRound(startLine), qRound(endLine));
514  }
515  }
516  else {
517  sampleRange.setInterval(1.0, xAxisCube()->sampleCount());
518  lineRange.setInterval(1.0, xAxisCube()->lineCount());
519  }
520 
521  if (rangeType == SampleRange)
522  return sampleRange;
523  else
524  return lineRange;
525  }
526 }
527