SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
genericform.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
4#include "genericform.h"
5#include "ui_genericform.h"
6#include "QLabel"
7#include "mainwindow.h"
8#include <QTextBrowser>
9#include <QStandardPaths>
10
11GenericForm::GenericForm(QJsonObject *formdata, QWidget *parent, MainWindow *_mainwindow) :
12 QWidget(parent),
13 ui(new Ui::GenericForm)
14{
15 mainWindow = _mainwindow;
16 ui->setupUi(this);
17
18 for (int i=0; i<formdata->keys().size(); i++)
19 {
20 if (formdata->value(formdata->keys()[i]).isObject())
21 {
22 QJsonObject object = formdata->value(formdata->keys()[i]).toObject();
23 formdata->value(formdata->keys()[i]).toObject();
24 parameter_property parameter_prop;
25 parameter_prop.Name = formdata->keys()[i];
26 parameter_prop.DefaultValue = object.value("default").toString();
27 if (object.contains("type"))
28 {
29 if (object["type"].toString()!="Description")
30 {
31 QLabel *label = new QLabel(parameter_prop.Name, this);
32 QString typeval = object.value("type").toString();
33 if (object.value("type").toString()=="spinBox")
34 {
35 parameter_prop.Type = delegate_type::SpinBox;
36 QSpinBox *spinbox = new QSpinBox(this);
37
38 if (object.contains("minimum"))
39 spinbox->setMinimum(object.value("minimum").toString().toInt());
40 if (object.contains("maximum"))
41 spinbox->setMaximum(object.value("maximum").toString().toInt());
42 spinbox->setValue(object.value("default").toString().toInt());
43 ui->formLayout->addRow(label,spinbox);
44 parameter_prop.InputWidget = spinbox;
45 }
46 if (object.value("type").toString()=="lineEdit")
47 {
48 parameter_prop.Type = delegate_type::LineEdit;
49 QLineEdit *lineedit = new QLineEdit(this);
50 lineedit->setText(object.value("default").toString());
51 ui->formLayout->addRow(label,lineedit);
52 parameter_prop.InputWidget = lineedit;
53 }
54 if (object.value("type").toString()=="comboBox")
55 {
56 parameter_prop.Type = delegate_type::ComboBox;
57 QComboBox *combobox = new QComboBox(this);
58 combobox->setCurrentText(object.value("default").toString());
59 ui->formLayout->addRow(label,combobox);
60 parameter_prop.InputWidget = combobox;
61 {
62 if (object.value("source").toString().contains("Blank"))
63 {
64 combobox->addItem("");
65 }
66 if (object.value("source").toString().contains("TargetSamplesList"))
67 {
68 vector<string> names = mainwindow()->Data()->GetSampleNames(mainwindow()->Data()->GetTargetGroup());
69 for (unsigned int i=0; i<names.size(); i++)
70 combobox->addItem(QString::fromStdString(names[i]));
71 }
72 if (object.value("source").toString().contains("ElementsList"))
73 {
74 vector<string> names = mainwindow()->Data()->GetElementNames();
75 for (unsigned int i=0; i<names.size(); i++)
76 combobox->addItem(QString::fromStdString(names[i]),QString::fromStdString(names[i]));
77
78 }
79 if (object.value("source").toString().contains("SourceList"))
80 {
81 vector<string> names = mainwindow()->Data()->SourceGroupNames();
82 for (unsigned int i=0; i<names.size(); i++)
83 combobox->addItem(QString::fromStdString(names[i]),QString::fromStdString(names[i]));
84
85 }
86 if (object.value("source").toString().contains("Items:"))
87 {
88 QStringList items = object.value("source").toString().split(":")[1].split(",");
89 combobox->addItems(items);
90 }
91 if (object.value("source").toString().contains("OM"))
92 {
93 QString element = QString::fromStdString(mainwindow()->Data()->FirstOMConstituent());
94 if (element!="")
95 combobox->setCurrentIndex(combobox->findText(element));
96 }
97 if (object.value("source").toString().contains("Size"))
98 {
99 QString element = QString::fromStdString(mainwindow()->Data()->FirstSizeConstituent());
100 if (element!="")
101 combobox->setCurrentIndex(combobox->findText(element));
102 }
103 }
104 }
105 if (object.value("type").toString()=="fileBrowser_Save")
106 {
107 parameter_prop.Type = delegate_type::FileBrowser;
108 FileBrowserPushButton *filebrowserpushbutton = new FileBrowserPushButton(this);
109 filebrowserpushbutton->dialog_use = save_open::save;
110 filebrowserpushbutton->setText(object.value("default").toString());
111 ui->formLayout->addRow(label,filebrowserpushbutton);
112 parameter_prop.InputWidget = filebrowserpushbutton;
113
114 }
115 if (object.value("type").toString()=="fileBrowser_Open")
116 {
117 parameter_prop.Type = delegate_type::FileBrowser;
118 FileBrowserPushButton *filebrowserpushbutton = new FileBrowserPushButton(this);
119 filebrowserpushbutton->dialog_use = save_open::open;
120 filebrowserpushbutton->setText(object.value("default").toString());
121 ui->formLayout->addRow(label,filebrowserpushbutton);
122 parameter_prop.InputWidget = filebrowserpushbutton;
123
124 }
125 if (object.value("type").toString()=="checkBox")
126 {
127 parameter_prop.Type = delegate_type::CheckBox;
128 QCheckBox *checkbox = new QCheckBox(this);
129 if (object.value("default").toString().toLower()=="true")
130 checkbox->setCheckState(Qt::CheckState::Checked);
131 else
132 checkbox->setCheckState(Qt::CheckState::Unchecked);
133 ui->formLayout->addRow(label,checkbox);
134 parameter_prop.InputWidget = checkbox;
135 }
136 Parameter_Properties.append(parameter_prop);
137 }
138 }
139 }
140 }
141
142 for (int i=0; i<formdata->keys().size(); i++)
143 {
144 if (formdata->value(formdata->keys()[i]).isObject())
145 {
146 QJsonObject object = formdata->value(formdata->keys()[i]).toObject();
147 formdata->value(formdata->keys()[i]).toObject();
148 parameter_property parameter_prop;
149 parameter_prop.Name = formdata->keys()[i];
150 parameter_prop.DefaultValue = object.value("default").toString();
151 if (object.contains("type"))
152 {
153
154 QLabel *label = nullptr;
155 if (object["type"].toString()=="Description")
156 label = new QLabel(parameter_prop.Name, this);
157 QString typeval = object.value("type").toString();
158 if (object.value("type").toString()=="Description")
159 {
160 parameter_prop.Type = delegate_type::Description;
161 QTextBrowser *textBrowswer = new QTextBrowser(this);
162 textBrowswer->insertHtml(object.value("default").toString());
163 ui->formLayout->addRow(label,textBrowswer);
164 parameter_prop.InputWidget = textBrowswer;
165 }
166 }
167 }
168 }
169
170 buttonOk = new QPushButton("Ok",this);
171 QIcon iconOk = QIcon(qApp->applicationDirPath()+"/../../resources/Icons/Proceed.png");
172 buttonOk->setIcon(iconOk);
173 ui->horizontalLayout->addWidget(buttonOk);
174 connect(buttonOk,SIGNAL(clicked()),this,SLOT(onProceed()));
175 buttonCancel = new QPushButton("Cancel",this);
176 QIcon iconCancel = QIcon(qApp->applicationDirPath()+"/../../resources/Icons/Cancel.png");
177 buttonCancel->setIcon(iconCancel);
178 ui->horizontalLayout->addWidget(buttonCancel);
179 connect(buttonCancel,SIGNAL(clicked()),this,SLOT(onCancel()));
180
181}
182
184{
185 Parameter_Properties.clear();
186 delete ui;
187}
188
190{
191 map<string,string> arguments;
192 for (int i=0; i<Parameter_Properties.count(); i++)
193 {
194 arguments[Parameter_Properties[i].Name.toStdString()] = Parameter_Properties[i].value().toStdString();
195 }
196 mainwindow()->Execute(command.toStdString(),arguments);
197
198}
200{
201 this->close();
202}
203
208
209bool GenericForm::SetCommand(const QString &cmd)
210{
211 command = cmd;
212 return true;
213}
MainWindow * mainwindow()
QString command
Definition genericform.h:74
Ui::GenericForm * ui
Definition genericform.h:72
GenericForm(QJsonObject *formdata, QWidget *parent, MainWindow *mainwindow)
bool SetCommand(const QString &cmd)
QPushButton * buttonCancel
Definition genericform.h:71
QPushButton * buttonOk
Definition genericform.h:70
MainWindow * mainWindow
Definition genericform.h:75
QVector< parameter_property > Parameter_Properties
Definition genericform.h:65
Main application window for SedSAT3 source apportionment analysis.
Definition mainwindow.h:45
SourceSinkData * Data()
Returns pointer to the main data collection.
Definition mainwindow.h:77
bool Execute(const std::string &command, const std::map< std::string, std::string > &arguments)
Executes a specified analysis command.
vector< string > GetElementNames() const
Get all element names in the dataset.
vector< string > SourceGroupNames() const
Retrieves the names of all source groups (excluding target).
vector< string > GetSampleNames(const string &group_name) const
Get all sample names within a specific group.
QWidget * InputWidget
Definition genericform.h:24
QString Name
Parameter name, as in forms_structures.json.
Definition genericform.h:22
delegate_type Type
Definition genericform.h:23