Isis 3 Programmer Reference
MatrixOptionsDialog.cpp
1#include "MatrixOptionsDialog.h"
2
3#include <QDebug>
4#include <QVariant>
5#include <QAction>
6#include <QApplication>
7#include <QButtonGroup>
8#include <QColorDialog>
9#include <QComboBox>
10#include <QGridLayout>
11#include <QHBoxLayout>
12#include <QHeaderView>
13#include <QLabel>
14#include <QLineEdit>
15#include <QPushButton>
16#include <QRadioButton>
17#include <QSizePolicy>
18#include <QSlider>
19#include <QSpacerItem>
20#include <QComboBox>
21#include <QTabWidget>
22#include <QVBoxLayout>
23#include <QWidget>
24
25#include "IString.h"
26#include "MatrixOptions.h"
27
28namespace Isis {
29
67 QWidget *parent) : QDialog(parent) {
68
69// connect( this, SIGNAL( optionsUpdated() ),
70// parent, SLOT( redrawItems() ) );
71
72 connect(parent, SIGNAL( elementClicked(QString) ),
73 this, SLOT( updateCorrelationData(QString) ) );
74
75 m_options = options;
76
77 setWindowTitle("Matrix Options");
78 resize(200, 200);
79// setWindowFlags(Qt::WindowStaysOnTopHint);
80
81 QTabWidget *optionsTabs = new QTabWidget();
82 optionsTabs->setGeometry( QRect(9, 9, 100, 100) );
83
84 /********************************************
85 * Color Options
86 * *****************************************/
87
88 QWidget *colorOptionsPage = new QWidget();
89
90 QGridLayout *mainLayout = new QGridLayout();
91 colorOptionsPage->setLayout(mainLayout);
92 QHBoxLayout *colorPageLayout = new QHBoxLayout(); // = new QHBoxLayout();
93
94 /********************************************
95 * Color Tolerance Settings
96 * *****************************************/
97 QVBoxLayout *colorToleranceLayout = new QVBoxLayout();
98
99 m_colorToleranceRadioButton = new QRadioButton();
100 m_colorToleranceRadioButton->setText("Pick Tolerance");
101 colorToleranceLayout->addWidget(m_colorToleranceRadioButton);
102 connect( m_colorToleranceRadioButton, SIGNAL( clicked() ),
103 this, SLOT( refreshWidgetStates() ) );
104
105 QHBoxLayout *colorToleranceOptionsLayout = new QHBoxLayout();
106
107 m_colorToleranceSlider = new QSlider();
108 m_colorToleranceSlider->setOrientation(Qt::Vertical);
109 m_colorToleranceSlider->setRange(0, 1000);
110 colorToleranceOptionsLayout->addWidget(m_colorToleranceSlider);
111 connect( m_colorToleranceSlider, SIGNAL( valueChanged(int) ),
112 this, SLOT( updateToleranceLineEdit(int) ) );
113
114 QVBoxLayout *colorToleranceEditsLayout = new QVBoxLayout();
115 QHBoxLayout *colorBadCorrLayout = new QHBoxLayout();
116
117 QLabel *colorBadCorrLabel = new QLabel();
118 colorBadCorrLabel->setText("Bad Correlation");
119
120 colorBadCorrLayout->addWidget(colorBadCorrLabel);
121
122 m_badCorrelationColorButton = new QPushButton();
123 colorBadCorrLayout->addWidget(m_badCorrelationColorButton);
124 connect( m_badCorrelationColorButton, SIGNAL( clicked() ),
125 this, SLOT( askUserForBadColor() ) );
126
127
128 colorToleranceEditsLayout->addLayout(colorBadCorrLayout);
129
130 QHBoxLayout *colorEnterTolLayout = new QHBoxLayout();
131
132 QLabel *colorTolLabel = new QLabel();
133 colorTolLabel->setText("Tolerance");
134 colorEnterTolLayout->addWidget(colorTolLabel);
135
136 m_colorToleranceLineEdit = new QLineEdit();
137 m_colorToleranceLineEdit->setValidator( new QDoubleValidator(-1, 1, 10, this) );
138 colorEnterTolLayout->addWidget(m_colorToleranceLineEdit);
139 connect( m_colorToleranceLineEdit, SIGNAL( textChanged(const QString &) ),
140 this, SLOT( updateToleranceSlider(const QString &) ) );
141
142 colorToleranceEditsLayout->addLayout(colorEnterTolLayout);
143
144 QHBoxLayout *colorGoodCorrLayout = new QHBoxLayout();
145 QLabel *colorGoodCorrLabel = new QLabel();
146 colorGoodCorrLabel->setText("Good Correlation");
147
148 colorGoodCorrLayout->addWidget(colorGoodCorrLabel);
149
150 m_goodCorrelationColorButton = new QPushButton();
151 colorGoodCorrLayout->addWidget(m_goodCorrelationColorButton);
152 connect( m_goodCorrelationColorButton, SIGNAL( clicked() ),
153 this, SLOT( askUserForGoodColor() ) );
154
155 colorToleranceEditsLayout->addLayout(colorGoodCorrLayout);
156
157 colorToleranceOptionsLayout->addLayout(colorToleranceEditsLayout);
158
159 colorToleranceLayout->addLayout(colorToleranceOptionsLayout);
160
161 colorPageLayout->addLayout(colorToleranceLayout);
162
163 /********************************************
164 * Color gradient area
165 * *****************************************/
166 QVBoxLayout *colorGradientLayout = new QVBoxLayout();
167
168 m_gradientRadioButton = new QRadioButton();
169 m_gradientRadioButton->setText("Use Gradient");
170 colorGradientLayout->addWidget(m_gradientRadioButton);
171 connect( m_gradientRadioButton, SIGNAL( clicked() ),
172 this, SLOT( refreshWidgetStates() ) );
173
174 QSpacerItem *colorGradSpacer = new QSpacerItem(20,
175 40,
176 QSizePolicy::Minimum,
177 QSizePolicy::Expanding);
178 colorGradientLayout->addItem(colorGradSpacer);
179
180 colorPageLayout->addLayout(colorGradientLayout);
181
182 mainLayout->addLayout(colorPageLayout, 0, 1, 1, 1);
183
184 optionsTabs->addTab(colorOptionsPage, QString() );
185 optionsTabs->setTabText(optionsTabs->indexOf(colorOptionsPage), "Color Options");
186
187 /********************************************
188 * Focus Options
189 * *****************************************/
190
191 QWidget *focusOptionsPage = new QWidget();
192 QHBoxLayout *focusPageLayout = new QHBoxLayout();
193 focusPageLayout->setContentsMargins(0, 0, 0, 0);
194 QVBoxLayout *focusOptionsLayout = new QVBoxLayout();
195
196 m_bestCorrelationRadioButton = new QRadioButton();
197 m_bestCorrelationRadioButton->setText("Best Correlation");
198 focusOptionsLayout->addWidget(m_bestCorrelationRadioButton);
199 connect( m_bestCorrelationRadioButton, SIGNAL( clicked() ),
200 this, SLOT( refreshWidgetStates() ) );
201
202 m_worstCorrelationRadioButton = new QRadioButton();
203 m_worstCorrelationRadioButton->setText("Worst Correlation");
204 focusOptionsLayout->addWidget(m_worstCorrelationRadioButton);
205 connect( m_worstCorrelationRadioButton, SIGNAL( clicked() ),
206 this, SLOT( refreshWidgetStates() ) );
207
208 /********************************************
209 * Focus, specific parameters settings
210 * *****************************************/
211
212 QVBoxLayout *focusSpecParamLayout = new QVBoxLayout();
213
214 m_specificCorrelationRadioButton = new QRadioButton();
215 m_specificCorrelationRadioButton->setText("Specific Parameters");
216 focusSpecParamLayout->addWidget(m_specificCorrelationRadioButton);
217 connect( m_specificCorrelationRadioButton, SIGNAL( clicked() ),
218 this, SLOT( refreshWidgetStates() ) );
219
220 QLabel *focusSpecParam1Label = new QLabel();
221 focusSpecParam1Label->setText("Image 1:");
222 focusSpecParamLayout->addWidget(focusSpecParam1Label);
223
224 QHBoxLayout *focusSpecParam1Layout = new QHBoxLayout();
225
226 m_image1ComboBox = new QComboBox();
227 focusSpecParam1Layout->addWidget(m_image1ComboBox);
228 connect( m_image1ComboBox, SIGNAL( currentIndexChanged(const QString &) ),
229 this, SLOT( updateSpecParam1ComboBox(const QString &) ) );
230
231
232 m_parameter1ComboBox = new QComboBox();
233// m_parameter1ComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
234 focusSpecParam1Layout->addWidget(m_parameter1ComboBox);
235
236 focusSpecParamLayout->addLayout(focusSpecParam1Layout);
237
238 QLabel *focusSpecParam2Label = new QLabel();
239 focusSpecParam2Label->setText("Image 2:");
240 focusSpecParamLayout->addWidget(focusSpecParam2Label);
241
242 QHBoxLayout *focusSpecParam2Layout = new QHBoxLayout();
243
244 m_image2ComboBox = new QComboBox();
245 focusSpecParam2Layout->addWidget(m_image2ComboBox);
246 connect( m_image2ComboBox, SIGNAL( currentIndexChanged(const QString &) ),
247 this, SLOT( updateSpecParam2ComboBox(const QString &) ) );
248
249 m_parameter2ComboBox = new QComboBox();
250 focusSpecParam2Layout->addWidget(m_parameter2ComboBox);
251
252 focusSpecParamLayout->addLayout(focusSpecParam2Layout);
253
254 focusOptionsLayout->addLayout(focusSpecParamLayout);
255
256 focusPageLayout->addLayout(focusOptionsLayout);
257
258 /********************************************
259 * Focus, tolerance stuff
260 * *****************************************/
261 QVBoxLayout *focusTolLayout = new QVBoxLayout();
262
263 m_focusToleranceRadioButton = new QRadioButton();
264 m_focusToleranceRadioButton->setText("Tolerance");
265 focusTolLayout->addWidget(m_focusToleranceRadioButton);
266 connect( m_focusToleranceRadioButton, SIGNAL( clicked() ),
267 this, SLOT( refreshWidgetStates() ) );
268
269 QHBoxLayout *focusTolEditLayout = new QHBoxLayout();
270
271 QLabel *focusTolLabel = new QLabel();
272 focusTolLabel->setText("Tolerance:");
273 focusTolEditLayout->addWidget(focusTolLabel);
274
275 m_focusToleranceLineEdit = new QLineEdit();
276 m_focusToleranceLineEdit->setValidator( new QDoubleValidator(-1, 1, 10, this) );
277 focusTolEditLayout->addWidget(m_focusToleranceLineEdit);
278// connect( m_focusToleranceLineEdit, SIGNAL( textChanged(const QString &) ),
279// this, SLOT( refreshWidgetStates() ) );
280
281 focusTolLayout->addLayout(focusTolEditLayout);
282
283 QHBoxLayout *focusElementsLayout = new QHBoxLayout();
284 QVBoxLayout *focusGoodElementsLayout = new QVBoxLayout();
285
286 QLabel *focusGoodElementsLabel = new QLabel();
287 focusGoodElementsLabel->setFocusPolicy(Qt::NoFocus);
288 focusGoodElementsLabel->setText("Good");
289 focusGoodElementsLayout->addWidget(focusGoodElementsLabel);
290
291 m_goodElementsComboBox = new QComboBox();
292 focusGoodElementsLayout->addWidget(m_goodElementsComboBox);
293
294 focusElementsLayout->addLayout(focusGoodElementsLayout);
295
296 QVBoxLayout *focusBadElementsLayout = new QVBoxLayout();
297
298 QLabel *focusBadElementsLabel = new QLabel();
299 focusBadElementsLabel->setText("Bad");
300 focusBadElementsLayout->addWidget(focusBadElementsLabel);
301
302 m_badElementsComboBox = new QComboBox();
303 focusBadElementsLayout->addWidget(m_badElementsComboBox);
304
305 focusElementsLayout->addLayout(focusBadElementsLayout);
306
307 focusTolLayout->addLayout(focusElementsLayout);
308
309 focusPageLayout->addLayout(focusTolLayout);
310
311 focusOptionsPage->setLayout(focusPageLayout);
312 optionsTabs->addTab( focusOptionsPage, QString() );
313 optionsTabs->setTabText(optionsTabs->indexOf(focusOptionsPage), "Focus Options");
314
315 /********************************************
316 * Current Correlation Stuff
317 * *****************************************/
318 QVBoxLayout *m_currentElementData = new QVBoxLayout();
319 m_currentElementData->setContentsMargins(0, 0, 0, 0);
320
321// QHBoxLayout *currentCorrLayout = new QHBoxLayout();
322
323 QLabel *currentCorrLabel = new QLabel();
324 currentCorrLabel->setText("Current Correlation Info:");
325 m_currentElementData->addWidget(currentCorrLabel);
326// currentCorrLayout->addWidget(currentCorrLabel);
327
328 m_currentValueLabel = new QLabel();
329 m_currentValueLabel->setText("-");
330 m_currentElementData->addWidget(m_currentValueLabel);
331// currentCorrLayout->addWidget(m_currentValueLabel);
332
333// m_currentElementData->addLayout(currentCorrLayout);
334
335// QHBoxLayout *currentCorrImg1Layout = new QHBoxLayout();
336
337// m_image1NameLabel = new QLabel();
338// m_image1NameLabel->setText("Image 1: Sub4-AS15-M-0585_msk");
339// currentCorrImg1Layout->addWidget(m_image1NameLabel);
340
341// m_parameter1NameLabel = new QLabel();
342// m_parameter1NameLabel->setText(" Parameter 1: X");
343// currentCorrImg1Layout->addWidget(m_parameter1NameLabel);
344
345// m_currentElementData->addLayout(currentCorrImg1Layout);
346
347// QHBoxLayout *currentCorrImg2Layout = new QHBoxLayout();
348
349// m_image2NameLabel = new QLabel();
350// m_image2NameLabel->setText("Image 2: Sub4-AS15-M-0586_msk");
351// currentCorrImg2Layout->addWidget(m_image2NameLabel);
352
353// m_parameter2NameLabel = new QLabel;
354// m_parameter2NameLabel->setText(" Parameter 2: TWI");
355// currentCorrImg2Layout->addWidget(m_parameter2NameLabel);
356
357// m_currentElementData->addLayout(currentCorrImg2Layout);
358
359 optionsTabs->setCurrentIndex(0);
360
361 QPushButton *applyButton = new QPushButton("&Apply");
362 applyButton->setIcon( QIcon::fromTheme("dialog-ok-apply") );
363 connect( applyButton, SIGNAL( clicked() ),
364 this, SLOT( applyOptions() ) );
365
366
367 QVBoxLayout *topLayout = new QVBoxLayout();
368 topLayout->addWidget(optionsTabs);
369 topLayout->addWidget(applyButton);
370 topLayout->addLayout(m_currentElementData); // currentCorrDataLayout - not a layout...
371 setLayout(topLayout);
372
373 QMetaObject::connectSlotsByName(this);
374
375 readOptions();
376 }
377
378
379
385
386
387
388/***************************
389 * Slots
390 * *************************/
391
392
393
399 // Color Options
400 QPalette colorPalette( m_goodCorrelationColorButton->palette() );
401 m_options->setGoodCorrelationColor( colorPalette.color(QPalette::Button) );
402
403 colorPalette = m_badCorrelationColorButton->palette();
404 m_options->setBadCorrelationColor( colorPalette.color(QPalette::Button) );
405
406 m_options->setColorScheme( m_colorToleranceRadioButton->isChecked() );
407
408 m_options->setColorTolerance( m_colorToleranceLineEdit->text().toDouble() );
409
410 // Focus Options
411// m_options->setFocusValue( m_colorToleranceLineEdit->text().toDouble() );
412//
413// QList<double> goodElements, badElements;
414//
415// // m_options->setGoodElements(*m_goodElementsComboBox);
416// // m_options->setBadElements(*m_badElementsComboBox);
417//
418// if ( m_bestCorrelationRadioButton->isChecked() ) {
419// m_options->setFocusOption(MatrixOptions::Best);
420// }
421// else if ( m_worstCorrelationRadioButton->isChecked() ) {
422// m_options->setFocusOption(MatrixOptions::Worst);
423// }
424// else if ( m_focusToleranceRadioButton->isChecked() ) {
425// m_options->setFocusOption(MatrixOptions::Tolerance);
426// }
427// else {
428// m_options->setFocusOption(MatrixOptions::Specific);
429// }
430
431 emit optionsUpdated();
432 }
433
434
435
446
447 // Color Options
449 m_colorToleranceRadioButton->setChecked( m_options->colorScheme() );
451
452 if ( m_options->colorScheme() ) {
453 QPalette colorPalette;
454 colorPalette.setColor( QPalette::Button, m_options->goodCorrelationColor() );
455 m_goodCorrelationColorButton->setPalette(colorPalette);
456
457 colorPalette.setColor( QPalette::Button, m_options->badCorrelationColor() );
458 m_badCorrelationColorButton->setPalette(colorPalette);
459
460 m_colorToleranceLineEdit->setText( QString::number( m_options->colorTolerance() ) );
461 m_colorToleranceSlider->blockSignals(true);
462 m_colorToleranceSlider->setValue( qRound( 1000 * m_colorToleranceLineEdit->text().toDouble() ) );
463 m_colorToleranceSlider->blockSignals(false);
464 }
465
466 // Focus Options
467 m_bestCorrelationRadioButton->setChecked(m_options->focusOption() == MatrixOptions::Best);
468 m_worstCorrelationRadioButton->setChecked(m_options->focusOption() == MatrixOptions::Worst);
469 m_focusToleranceRadioButton->setChecked(m_options->focusOption() == MatrixOptions::Tolerance);
470 m_specificCorrelationRadioButton->setChecked(m_options->focusOption() == MatrixOptions::Specific);
471
472 // tolerance focus
473 if (m_options->focusOption() == MatrixOptions::Tolerance) {
474 m_focusToleranceLineEdit->setText( QString::number( m_options->focusValue() ) );
475 //QList<double> goodElements();
476 //QList<double> badElements();
477 }
478 setFocusToleranceStatus(m_options->focusOption() == MatrixOptions::Tolerance);
479
480 // specific focus
481 QMapIterator<QString, QStringList> img( m_options->matrixImgsAndParams() );
482 img.next();
483 for (int param = 0; param < img.value().size(); param++) {
484 m_parameter1ComboBox->addItem(img.value()[param]);
485 m_parameter2ComboBox->addItem(img.value()[param]);
486 }
487 while ( img.hasNext() ) {
488 m_image1ComboBox->addItem( img.key() );
489 m_image2ComboBox->addItem( img.key() );
490 img.next();
491 }
492 setSpecificParametersStatus(m_options->focusOption() == MatrixOptions::Specific);
493
495 }
496
497
498
504 m_currentValueLabel->setText(currentData);
505 //toString( m_options->currentCorrelation() ) );
506
507// m_image1NameLabel->setText( m_options->currentImage1() );
508// m_parameter1NameLabel->setText( m_options->currentParameter1() );
509
510// m_image2NameLabel->setText( m_options->currentImage2() );
511// m_parameter2NameLabel->setText( m_options->currentParameter2() );
512 }
513
514
515
523
534 m_colorToleranceLineEdit->setEnabled(enable);
535 m_goodCorrelationColorButton->setEnabled(enable);
536 m_badCorrelationColorButton->setEnabled(enable);
537 m_colorToleranceSlider->setEnabled(enable);
538 }
539
540
541
549 m_focusToleranceLineEdit->setEnabled(enable);
550 m_goodElementsComboBox->setEnabled(enable);
551 m_badElementsComboBox->setEnabled(enable);
552 }
553
554
555
563 m_image1ComboBox->setEnabled(enable);
564 m_parameter1ComboBox->setEnabled(enable);
565 m_image2ComboBox->setEnabled(enable);
566 m_parameter2ComboBox->setEnabled(enable);
567 }
568
569
570
575 // color
576 setColorToleranceStatus( m_colorToleranceRadioButton->isChecked() );
577
578 // focus
581 }
582
583
584
591
592
593
600
601
602
609 void MatrixOptionsDialog::askUserForColor(QPushButton *button) {
610 QPalette colorPalette( button->palette() );
611
612 QColor newColor = QColorDialog::getColor(colorPalette.color(QPalette::Button), this);
613
614 if( newColor.isValid() ) {
615 colorPalette.setColor(QPalette::Button, newColor);
616 button->setPalette(colorPalette);
617 }
618 }
619
620
621
627 m_colorToleranceSlider->setValue( qRound( 1000 * value.toDouble() ) );
628 }
629
630
631
637 m_colorToleranceLineEdit->setText( QString::number(value / 1000.0) );
638 }
639
640
641
648 updateSpecificParameterComboBox(key, m_parameter1ComboBox);
649 }
650
651
652
659 updateSpecificParameterComboBox(key, m_parameter2ComboBox);
660 }
661
662
663
669 QComboBox *comboBox) {
670 comboBox->clear();
671 comboBox->addItems( m_options->matrixImgsAndParams().value(key) );
672// comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
673 }
674};
void updateCorrelationData(QString currentData)
Update the current correlation information.
void updateSpecificParameterComboBox(const QString &key, QComboBox *comboBox)
When the user switches the image combobox this slot will update the parameter combobox to be filled w...
QPointer< QPushButton > m_goodCorrelationColorButton
Color to use for matrix elements that are below the given threshold.
void askUserForGoodColor()
slot called when user clicks on good correlation color button
void setFocusToleranceStatus(bool enable)
If the focus tolerance radio button is selected, the tolerance widgets will be enabled.
void applyOptions()
Send changes back to scene widget (MatrixOptions) so it can redraw the elements in the right color.
QPointer< QRadioButton > m_bestCorrelationRadioButton
Focus the matrix on the best correlation................. What if there is more than one?
void updateToleranceLineEdit(int value)
slot called when user changes the slider position.
void updateSpecParam2ComboBox(const QString &key)
when the img2 combo box is changed this slot will update the parameter combo box.
MatrixOptionsDialog(MatrixOptions *options, QWidget *parent)
Main constructor.
void readOptions()
Get the current options from the matrix scene widget.
void setSpecificParametersStatus(bool enable)
If the specific parameters radio button is selected, the image and parameter spinboxes will be enable...
void refreshWidgetStates()
This method will enable and disable widgets depending on which radio button is selected.
void askUserForColor(QPushButton *button)
Prompt the user for a new color.
void askUserForBadColor()
slot called when user clicks on bad correlation color button
void updateToleranceSlider(const QString &value)
slot called when user modifies the color tolerance line edit text.
void setColorToleranceStatus(bool enable)
If the tolerance radiobutton is selected, this method will be called with true passed as the paramete...
QPointer< QRadioButton > m_specificCorrelationRadioButton
Focus the matrix on the correlation corresponding to the specified images and parameters.
QPointer< QRadioButton > m_gradientRadioButton
Select a tolerance for the color values.
QPointer< QPushButton > m_badCorrelationColorButton
Color to use when for matrix elements that are above the given threshold.
void updateSpecParam1ComboBox(const QString &key)
when the img1 combo box is changed this slot will update the parameter combo box.
MatrixOptions * m_options
This will be used to populate all the widgets.
QPointer< QRadioButton > m_focusToleranceRadioButton
Focus the matrix on a selected correlation value.
~MatrixOptionsDialog()
Default Destructor.
void populateParameterComboBox(int index)
Update parameter combo boxes at real time, when the img combo boxes are changed.
QPointer< QRadioButton > m_worstCorrelationRadioButton
Focus the matrix on the worst correlation................. What if there is more than one?
This class holds the matrix color and focus information.
QColor badCorrelationColor()
The color selected for the correlation values that are above the given threshold.
FocusOption focusOption()
void setGoodCorrelationColor(QColor color)
void setColorScheme(bool tolerance)
QColor goodCorrelationColor()
The color selected for the correlation values that are below the given threshold.
double colorTolerance()
Threshold for what is considered a bad correlation.
void setBadCorrelationColor(QColor color)
bool colorScheme()
Use the green-red gradient if false.
void setColorTolerance(double tolerance)
QMap< QString, QStringList > matrixImgsAndParams()
This slot will be called when a matrix element is clicked on.
double focusValue()
The value of the spot on the matrix that we need to focus on.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16