SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
indicatesheetsdialog.cpp
Go to the documentation of this file.
1// SedSAT3 – Sediment Source Assessment Tool, version 3
2// U.S. Geological Survey. See LICENSE.md and DISCLAIMER.md in the repository root.
3
5#include "ui_indicatesheetsdialog.h"
6#include "qlabel.h"
7#include "qgroupbox.h"
8#include "QRadioButton"
9#include "QDebug"
10#include "mainwindow.h"
11#include "targetsheet.h"
12#include <QMessageBox>
13#include <QVBoxLayout>
14
16 QDialog(parent),
18{
19 ui->setupUi(this);
20 // Which sheet is the target was hard to see from the radio buttons alone
21 // (domain review): it is named here and shown in bold in the list
22 summary_label = new QLabel(this);
23 summary_label->setWordWrap(true);
24 if (auto* layout = qobject_cast<QVBoxLayout*>(this->layout()))
25 layout->insertWidget(0, summary_label);
26 connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
27 connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
28}
29
34
35void IndicateSheetsDialog::Populate_Table(const QStringList &sheets)
36{
37 // The first sheet used to be preselected as the target. Sheet order says
38 // nothing about which sheet is the target, so accepting the dialog
39 // unchanged made the first sheet the target: in a workbook whose sheets
40 // run Forest, Target, Banks, ... that silently made Forest the target,
41 // which dropped it from every source list and gave wrong unmixing
42 // results. Preselect the sheet whose name says it is the target, and
43 // nothing at all when no single sheet does.
44 const int guessed_target = GuessTargetSheet(sheets);
45
46 for (int i=0; i<sheets.count(); i++)
47 {
48 QLabel *label = new QLabel(ui->scrollAreaWidgetContents);
49 label->setText(sheets[i]);
50 group_names<<sheets[i];
51 sheet_labels.append(label);
52 ui->formLayout->setWidget(i, QFormLayout::LabelRole, label);
53
54 QGroupBox *groupBox = new QGroupBox(ui->scrollAreaWidgetContents);
55 groupBox->setObjectName(QString::fromUtf8("groupBox"));
56
57 QHBoxLayout *horizontalLayout = new QHBoxLayout(groupBox);
58 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
59 QRadioButton* radioButton_mixture = new QRadioButton(groupBox);
60 radioButton_mixture->setObjectName(QString::fromUtf8("Target"));
61 radioButton_mixture->setText("Target");
62 horizontalLayout->addWidget(radioButton_mixture);
63 radio_buttons_sinks.append(radioButton_mixture);
64 QRadioButton* radioButton_source = new QRadioButton(groupBox);
65 radioButton_source->setObjectName(QString::fromUtf8("Source"));
66 radioButton_source->setText("Source");
67 horizontalLayout->addWidget(radioButton_source);
68 radio_buttons_sources.append(radioButton_source);
69
70 radioButton_source->setChecked(i!=guessed_target);
71 radioButton_mixture->setChecked(i==guessed_target);
72 connect(radioButton_mixture,SIGNAL(clicked()),this, SLOT(on_radio_button_changed()));
73 connect(radioButton_source,SIGNAL(clicked()),this, SLOT(on_radio_button_changed()));
74 ui->formLayout->setWidget(i, QFormLayout::FieldRole, groupBox);
75
76 }
78}
79
81{
82 QString target;
83 for (int i = 0; i < sheet_labels.count(); i++)
84 {
85 const bool is_target = radio_buttons_sinks[i]->isChecked();
86 sheet_labels[i]->setText(is_target ? group_names[i] + " (target)" : group_names[i]);
87 sheet_labels[i]->setStyleSheet(is_target ? "font-weight: bold; color: #0072B2;" : "");
88 if (is_target)
89 target = group_names[i];
90 }
91 if (summary_label != nullptr)
92 summary_label->setText(target.isEmpty()
93 ? tr("Choose the sheet that holds the target samples: select <b>Target</b> on its row. Every other sheet is a source group.")
94 : tr("Target samples: <b>%1</b>. Every other sheet is a source group.").arg(target.toHtmlEscaped()));
95}
96
98{
99 QDialog::reject();
100}
102{
103 bool target_chosen = false;
104 for (QRadioButton* button : radio_buttons_sinks)
105 target_chosen = target_chosen || button->isChecked();
106 if (!target_chosen)
107 {
108 // Without a target sheet the import used to go ahead with none
109 QMessageBox::warning(this, tr("Target sheet"), tr("Select the sheet that holds the target samples."));
110 return;
111 }
112 for (int i=0; i<radio_buttons_sinks.count(); i++)
113 {
114 if (radio_buttons_sinks[i]->isChecked())
115 { dynamic_cast<MainWindow*>(parent())->SetSinkSheet(i);
116 dynamic_cast<MainWindow*>(parent())->Data()->SetTargetGroup(group_names[i].toStdString());
117 }
118 }
119 QDialog::accept();
120}
121
123{
124 if (dynamic_cast<QRadioButton*>(sender())->text()=="Target" && dynamic_cast<QRadioButton*>(sender())->isChecked())
125 {
126 for (int i=0; i<radio_buttons_sinks.count(); i++)
127 {
128 if (radio_buttons_sinks[i]!=sender())
129 {
130 radio_buttons_sinks[i]->setChecked(false);
131 radio_buttons_sources[i]->setChecked(true);
132 }
133
134 }
135 }
137}
QList< QLabel * > sheet_labels
void UpdateTargetHighlight()
Shows the target sheet's name in bold, and names it above the list.
Ui::IndicateSheetsDialog * ui
QList< QRadioButton * > radio_buttons_sinks
QList< QRadioButton * > radio_buttons_sources
void Populate_Table(const QStringList &sheets)
IndicateSheetsDialog(QWidget *parent=nullptr)
Main application window for SedSAT3 source apportionment analysis.
Definition mainwindow.h:45
int GuessTargetSheet(const QStringList &sheets)
Index of the sheet whose name says it holds the target samples.
Which sheet of a workbook holds the target samples.