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