Isis 3 Programmer Reference
ScatterPlotConfigDialog.cpp
1#include "ScatterPlotConfigDialog.h"
2
3#include <qwt_interval.h>
4
5#include <QCheckBox>
6#include <QComboBox>
7#include <QFileInfo>
8#include <QGridLayout>
9#include <QLabel>
10#include <QPair>
11#include <QPushButton>
12#include <QSpinBox>
13
14#include "Cube.h"
15#include "MdiCubeViewport.h"
16#include "SpecialPixel.h"
17#include "Workspace.h"
18
19namespace Isis {
29 MdiCubeViewport *activeViewport, Workspace *workspace, QWidget *parent) :
30 QDialog(parent) {
31 setWindowTitle("Configure Scatter Plot");
32
33 m_oldXAxisCube = NULL;
34 m_workspace = workspace;
35
36 QGridLayout *mainLayout = new QGridLayout;
37
66 int curRow = 0;
67 QLabel *titleLabel = new QLabel("<h2>Create Scatter Plot</h2>");
68 mainLayout->addWidget(titleLabel, curRow, 0, 1, 3);
69 curRow++;
70
71 QLabel *headerLabel = new QLabel("Choose where to gather the scatter plot "
72 "data from. The X and Y axes are a single band of a cube and must have "
73 "the same dimensions");
74 headerLabel->setWordWrap(true);
75 mainLayout->addWidget(headerLabel, curRow, 0, 1, 3);
76 curRow++;
77
78 int spacerRow = curRow;
79 curRow++;
80
81 QLabel *configXLabel = new QLabel("Choose X Input Data");
82 mainLayout->addWidget(configXLabel, curRow, 0, 1, 3);
83 curRow++;
84
85 QLabel *xAxisCubeLabel = new QLabel("Cube");
86 mainLayout->addWidget(xAxisCubeLabel, curRow, 1, 1, 1);
87
89 m_xAxisCubeCombo->setInsertPolicy(QComboBox::InsertAlphabetically);
90 connect(m_xAxisCubeCombo, SIGNAL(currentIndexChanged(int)),
91 this, SLOT(refreshWidgetStates()));
92 mainLayout->addWidget(m_xAxisCubeCombo, curRow, 2, 1, 1);
93 curRow++;
94
95 QLabel *xAxisCubeBandLabel = new QLabel("Cube Band");
96 mainLayout->addWidget(xAxisCubeBandLabel, curRow, 1, 1, 1);
97
99 connect(m_xAxisCubeBandSpinBox, SIGNAL(valueChanged(int)),
100 this, SLOT(refreshWidgetStates()));
101 mainLayout->addWidget(m_xAxisCubeBandSpinBox, curRow, 2, 1, 1);
102 curRow++;
103
104 QLabel *xAxisBinCountLabel = new QLabel("Bin Count (resolution)");
105 mainLayout->addWidget(xAxisBinCountLabel, curRow, 1, 1, 1);
106
108 m_xAxisBinCountSpinBox->setMinimum(8);
109 m_xAxisBinCountSpinBox->setMaximum(1048576);
110 m_xAxisBinCountSpinBox->setValue(512);
111 connect(m_xAxisBinCountSpinBox, SIGNAL(valueChanged(int)),
112 this, SLOT(refreshWidgetStates()));
113 mainLayout->addWidget(m_xAxisBinCountSpinBox, curRow, 2, 1, 1);
114 curRow++;
115
116 QLabel *useViewportRangesLabel = new QLabel("Use Viewport Visible Range");
117 mainLayout->addWidget(useViewportRangesLabel, curRow, 1, 1, 1);
118
119 m_useViewportRangesCheckBox = new QCheckBox;
120 connect(m_useViewportRangesCheckBox, SIGNAL(stateChanged(int)),
121 this, SLOT(refreshWidgetStates()));
122 mainLayout->addWidget(m_useViewportRangesCheckBox, curRow, 2, 1, 1);
123 curRow++;
124
125 QLabel *configYLabel = new QLabel("Choose Y Input Data");
126 mainLayout->addWidget(configYLabel, curRow, 0, 1, 3);
127 curRow++;
128
129 QLabel *yAxisCubeLabel = new QLabel("Cube");
130 mainLayout->addWidget(yAxisCubeLabel, curRow, 1, 1, 1);
131
133 m_yAxisCubeCombo->setInsertPolicy(QComboBox::InsertAlphabetically);
134 connect(m_yAxisCubeCombo, SIGNAL(currentIndexChanged(int)),
135 this, SLOT(refreshWidgetStates()));
136 mainLayout->addWidget(m_yAxisCubeCombo, curRow, 2, 1, 1);
137 curRow++;
138
139 QLabel *yAxisCubeBandLabel = new QLabel("Cube Band");
140 mainLayout->addWidget(yAxisCubeBandLabel, curRow, 1, 1, 1);
141
143 connect(m_yAxisCubeBandSpinBox, SIGNAL(valueChanged(int)),
144 this, SLOT(refreshWidgetStates()));
145 mainLayout->addWidget(m_yAxisCubeBandSpinBox, curRow, 2, 1, 1);
146 curRow++;
147
148 QLabel *yAxisBinCountLabel = new QLabel("Bin Count (resolution)");
149 mainLayout->addWidget(yAxisBinCountLabel, curRow, 1, 1, 1);
150
152 m_yAxisBinCountSpinBox->setMinimum(8);
153 m_yAxisBinCountSpinBox->setMaximum(1048576);
154 m_yAxisBinCountSpinBox->setValue(512);
155 connect(m_yAxisBinCountSpinBox, SIGNAL(valueChanged(int)),
156 this, SLOT(refreshWidgetStates()));
157 mainLayout->addWidget(m_yAxisBinCountSpinBox, curRow, 2, 1, 1);
158 curRow++;
159
160 QHBoxLayout *buttonsLayout = new QHBoxLayout;
161 buttonsLayout->addStretch();
162
163 m_createButton = new QPushButton("Create");
164 m_createButton->setIcon(QIcon::fromTheme("window-new"));
165 connect(m_createButton, SIGNAL(clicked()),
166 this, SLOT(accept()));
167 buttonsLayout->addWidget(m_createButton);
168
169 QPushButton *cancelButton = new QPushButton("Cancel");
170 cancelButton->setIcon(QIcon::fromTheme("window-close"));
171 connect(cancelButton, SIGNAL(clicked()),
172 this, SLOT(reject()));
173 buttonsLayout->addWidget(cancelButton);
174
175 QWidget *buttonsWrapper = new QWidget;
176 buttonsWrapper->setLayout(buttonsLayout);
177 mainLayout->addWidget(buttonsWrapper, curRow, 0, 1, 3);
178
179 mainLayout->setColumnMinimumWidth(0, 20);
180 mainLayout->setRowMinimumHeight(spacerRow, 20);
181 setLayout(mainLayout);
182
189 setTabOrder(m_createButton, cancelButton);
190
192
193 if (activeViewport) {
194 m_xAxisCubeCombo->setCurrentIndex(
195 m_xAxisCubeCombo->findData(qVariantFromValue(activeViewport->cube())));
196 m_yAxisCubeCombo->setCurrentIndex(
197 m_yAxisCubeCombo->findData(qVariantFromValue(activeViewport->cube())));
198 m_yAxisCubeBandSpinBox->setValue(2);
199 }
200 }
201
202
210 return QSize(qRound(QDialog::sizeHint().width() * 1.3),
211 QDialog::sizeHint().height());
212 }
213
214
222 return m_xAxisCubeCombo->itemData(
223 m_xAxisCubeCombo->currentIndex()).value<Cube *>();
224 }
225
226
234 return m_yAxisCubeCombo->itemData(
235 m_yAxisCubeCombo->currentIndex()).value<Cube *>();
236 }
237
238
246 return m_xAxisCubeBandSpinBox->value();
247 }
248
249
257 return m_yAxisCubeBandSpinBox->value();
258 }
259
260
267 return m_xAxisBinCountSpinBox->value();
268 }
269
270
277 return m_yAxisBinCountSpinBox->value();
278 }
279
280
289 return range(SampleRange);
290 }
291
292
301 return range(LineRange);
302 }
303
304
311 MdiCubeViewport * container = NULL;
312
313 foreach (MdiCubeViewport *viewport, *m_workspace->cubeViewportList()) {
314 if (viewport->cube() == xAxisCube())
315 container = viewport;
316 }
317
318 return container;
319 }
320
321
328 MdiCubeViewport * container = NULL;
329
330 foreach (MdiCubeViewport *viewport, *m_workspace->cubeViewportList()) {
331 if (viewport->cube() == yAxisCube())
332 container = viewport;
333 }
334
335 return container;
336 }
337
338
345 QList<Cube *> listedXCubes;
346 for (int i = 0; i < m_xAxisCubeCombo->count(); i++) {
347 listedXCubes.append(m_xAxisCubeCombo->itemData(i).value<Cube *>());
348 }
349
350 QList<Cube *> allXCubes;
351 foreach (MdiCubeViewport *viewport, *m_workspace->cubeViewportList()) {
352 allXCubes.append(viewport->cube());
353 }
354
355 // We're first going to look for deleted cubes and remove them from the list
356 QList<Cube *> extraXCubes = removeFromList(listedXCubes, allXCubes);
357 foreach (Cube *cubeToRemove, extraXCubes) {
358 m_xAxisCubeCombo->removeItem(
359 m_xAxisCubeCombo->findData(qVariantFromValue(cubeToRemove)));
360 }
361
362 // Now let's add items that are missing from the list
363 QList<Cube *> missingXCubes = removeFromList(allXCubes, listedXCubes);
364 foreach (Cube *cubeToAdd, missingXCubes) {
365 if (m_xAxisCubeCombo->findData(qVariantFromValue(cubeToAdd)) == -1) {
366 QString cubeName = QFileInfo(cubeToAdd->fileName()).baseName();
367 m_xAxisCubeCombo->addItem(cubeName, qVariantFromValue(cubeToAdd));
368 }
369 }
370
371 m_xAxisCubeBandSpinBox->setMinimum(1);
372
373 if (xAxisCube()) {
374 m_xAxisCubeBandSpinBox->setEnabled(true);
375 m_xAxisBinCountSpinBox->setEnabled(true);
376 m_useViewportRangesCheckBox->setEnabled(true);
377 m_yAxisCubeCombo->setEnabled(true);
378
379 m_xAxisCubeBandSpinBox->setMaximum(xAxisCube()->bandCount());
380
381 QList<Cube *> listedYCubes;
382 for (int i = 0; i < m_yAxisCubeCombo->count(); i++) {
383 listedYCubes.append(m_yAxisCubeCombo->itemData(i).value<Cube *>());
384 }
385
386 QList<Cube *> allYCubes;
387 foreach (MdiCubeViewport *viewport, *m_workspace->cubeViewportList()) {
388 Cube *cube = viewport->cube();
389
390 if (cube->sampleCount() == xAxisCube()->sampleCount() &&
391 cube->lineCount() == xAxisCube()->lineCount()) {
392 allYCubes.append(cube);
393 }
394 }
395
396 // We're first going to look for deleted cubes and remove them from the list
397 QList<Cube *> extraYCubes = removeFromList(listedYCubes, allYCubes);
398 foreach (Cube *cubeToRemove, extraYCubes) {
399 m_yAxisCubeCombo->removeItem(
400 m_yAxisCubeCombo->findData(qVariantFromValue(cubeToRemove)));
401 }
402
403 // Now let's add items that are missing from the list
404 QList<Cube *> missingYCubes = removeFromList(allYCubes, listedYCubes);
405 foreach (Cube *cubeToAdd, missingYCubes) {
406 if (m_yAxisCubeCombo->findData(qVariantFromValue(cubeToAdd)) == -1) {
407 QString cubeName = QFileInfo(cubeToAdd->fileName()).baseName();
408 m_yAxisCubeCombo->addItem(cubeName, qVariantFromValue(cubeToAdd));
409 }
410 }
411
412 if (m_useViewportRangesCheckBox->isChecked()) {
413 m_yAxisCubeCombo->setEnabled(false);
414 }
415
416 if (xAxisCube() != m_oldXAxisCube) {
418 m_yAxisCubeCombo->setCurrentIndex(
419 m_yAxisCubeCombo->findData(qVariantFromValue(xAxisCube())));
420 }
421
422 m_yAxisCubeBandSpinBox->setMinimum(1);
423
424 m_yAxisCubeBandSpinBox->setEnabled(yAxisCube() != NULL);
425 m_yAxisBinCountSpinBox->setEnabled(yAxisCube() != NULL);
426
427 if (yAxisCube()) {
428 m_yAxisCubeBandSpinBox->setMaximum(yAxisCube()->bandCount());
429 }
430 }
431 else {
432 m_xAxisCubeBandSpinBox->setMaximum(1);
433 m_xAxisCubeBandSpinBox->setEnabled(false);
434 m_xAxisBinCountSpinBox->setEnabled(false);
435 m_useViewportRangesCheckBox->setEnabled(false);
436 m_yAxisCubeCombo->setEnabled(false);
437 m_yAxisCubeBandSpinBox->setMaximum(1);
438 m_yAxisCubeBandSpinBox->setEnabled(false);
439 m_yAxisBinCountSpinBox->setEnabled(false);
440 m_createButton->setEnabled(false);
441 }
442
443 bool allowCreation = true;
444
445 if (!xAxisCube() || !yAxisCube())
446 allowCreation = false;
447
448 if (allowCreation) {
449 if (xAxisCube() == yAxisCube() &&
450 m_xAxisCubeBandSpinBox->value() == m_yAxisCubeBandSpinBox->value()) {
451 allowCreation = false;
452 }
453 }
454
455 if (m_createButton->isEnabled() != allowCreation)
456 m_createButton->setEnabled(allowCreation);
457 }
458
459
469 QList<Cube *> ScatterPlotConfigDialog::removeFromList(QList<Cube *> list,
470 QList<Cube *> itemsToRemove) {
471 foreach (Cube *toRemove, itemsToRemove) {
472 list.removeAll(toRemove);
473 }
474
475 return list;
476 }
477
478
490 QwtInterval ScatterPlotConfigDialog::range(RangeType rangeType) const {
491 QwtInterval sampleRange;
492 QwtInterval lineRange;
493
494 if (m_useViewportRangesCheckBox->isChecked()) {
495 MdiCubeViewport * container = xAxisCubeViewport();
496 if (!container && xAxisCube()) {
497 sampleRange.setInterval(1.0, xAxisCube()->sampleCount());
498 lineRange.setInterval(1.0, xAxisCube()->lineCount());
499 }
500 else if (container && xAxisCube()) {
501 double startSample = Null;
502 double startLine = Null;
503 double endSample = Null;
504 double endLine = Null;
505
506 container->viewportToCube(0, 0, startSample, startLine);
507 container->viewportToCube(container->viewport()->width() - 1,
508 container->viewport()->height() - 1,
509 endSample, endLine);
510 sampleRange.setInterval(qRound(startSample), qRound(endSample));
511 lineRange.setInterval(qRound(startLine), qRound(endLine));
512 }
513 }
514 else {
515 sampleRange.setInterval(1.0, xAxisCube()->sampleCount());
516 lineRange.setInterval(1.0, xAxisCube()->lineCount());
517 }
518
519 if (rangeType == SampleRange)
520 return sampleRange;
521 else
522 return lineRange;
523 }
524}
525
IO Handler for Isis Cubes.
Definition Cube.h:168
int lineCount() const
Definition Cube.cpp:1740
int sampleCount() const
Definition Cube.cpp:1813
Cube * cube() const
Cube display widget for certain Isis MDI applications.
int xAxisCubeBand() const
The current user selection for the band in the x-axis cube to get data from.
QwtInterval sampleRange() const
This is the sample range from which the scatter plot should be created.
QPointer< QSpinBox > m_yAxisCubeBandSpinBox
A user-selection for the y axis cube's band to plot.
Cube * yAxisCube() const
The current user selection for a cube for the x-axis data for a scatter plot.
QwtInterval lineRange() const
This is the line range from which the scatter plot should be created.
QPointer< QSpinBox > m_yAxisBinCountSpinBox
A user-selection for the y axis cube's resolution.
void refreshWidgetStates()
Update the enabled/disabled states of the various widgets based on the current user inputs' states.
virtual QSize sizeHint() const
This is overridden to give a better default size than what Qt calculates by default.
Cube * m_oldXAxisCube
This is used to detect when a user changes the x-axis cube.
int yAxisCubeBand() const
The current user selection for the band in the y-axis cube to get data from.
QPointer< QSpinBox > m_xAxisCubeBandSpinBox
A user-selection for the x axis cube's band to plot.
Cube * xAxisCube() const
The current user selection for a cube for the x-axis data for a scatter plot.
int yAxisBinCount() const
The current user selection for the resolution of the scatter plot's y data.
QPointer< QComboBox > m_yAxisCubeCombo
A user-selection for the y axis cube.
MdiCubeViewport * yAxisCubeViewport() const
This returns a viewport which contains the y-axis cube.
QPointer< QCheckBox > m_useViewportRangesCheckBox
A user-selection for using only the visible range of the viewport.
RangeType
This is used internally to differentiate range accessors.
@ SampleRange
This is used to get the sample range in a generic way.
@ LineRange
This is used to get the line range in a generic way.
Workspace * m_workspace
This is the workspace containing all of the viewports.
QPointer< QComboBox > m_xAxisCubeCombo
A user-selection for the x axis cube.
QPointer< QPushButton > m_createButton
This button triggers an accepted() signal.
QList< Cube * > removeFromList(QList< Cube * > list, QList< Cube * > itemsToRemove)
This is a helper method.
QwtInterval range(RangeType) const
This returns the sample/line ranges indicated by the user for the scatter plot to be created on.
MdiCubeViewport * xAxisCubeViewport() const
This returns a viewport which contains the x-axis cube.
ScatterPlotConfigDialog(MdiCubeViewport *activeViewport, Workspace *workspace, QWidget *parent=NULL)
This method creates all the dialog boxes required for the scatter plot window.
QPointer< QSpinBox > m_xAxisBinCountSpinBox
A user-selection for the x axis cube's resolution.
int xAxisBinCount() const
The current user selection for the resolution of the scatter plot's x data.
QVector< MdiCubeViewport * > * cubeViewportList()
This method returns a Vector of MdiCubeViewports.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
const double Null
Value for an Isis Null pixel.