-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.cpp
More file actions
141 lines (121 loc) · 4.22 KB
/
settings.cpp
File metadata and controls
141 lines (121 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "settings.h"
#include "ui_settings.h"
#include <QFileDialog>
#include <QSettings>
#include <QFileInfo>
ModelSettings::ModelSettings(QWidget *parent) :
QDialog(parent),
ui(new Ui::settings)
{
ui->setupUi(this);
this->setWindowTitle("Model settings");
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
if (settings.value("model_file","").toString() != "")
{
ui->txt_model_file->setText(settings.value("model_file","").toString());
}
if (settings.value("ghg_file","").toString() != "")
{
ui->txt_ghg->setText(settings.value("ghg_file","").toString());
}
if (settings.value("stock_file","").toString() != "")
{
ui->txt_stock->setText(settings.value("stock_file","").toString());
}
if (settings.value("enery_file","").toString() != "")
{
ui->txt_energy->setText(settings.value("enery_file","").toString());
}
if (settings.value("rscript_file","").toString() != "")
{
ui->txtr->setText(settings.value("rscript_file","").toString());
}
if (settings.value("dbman_file","").toString() != "")
{
ui->txtdbman->setText(settings.value("dbman_file","").toString());
}
}
ModelSettings::~ModelSettings()
{
delete ui;
}
QString ModelSettings::getModelFile()
{
return ui->txt_model_file->text();
}
void ModelSettings::setModelFile(QString modelFile)
{
return ui->txt_model_file->setText(modelFile);
}
void ModelSettings::on_cmb_browse_model_clicked()
{
const QString fileName = QFileDialog::getOpenFileName(this,tr("Select a model file"), ".", "R (*.r)");
if (!fileName.isEmpty())
ui->txt_model_file->setText(fileName);
}
void ModelSettings::on_buttonBox_accepted()
{
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
QFileInfo file;
file.setFile(ui->txt_ghg->text());
if (file.exists())
settings.setValue("ghg_file", ui->txt_ghg->text());
file.setFile(ui->txt_stock->text());
if (file.exists())
settings.setValue("stock_file", ui->txt_stock->text());
file.setFile(ui->txt_energy->text());
if (file.exists())
settings.setValue("enery_file", ui->txt_energy->text());
file.setFile(ui->txt_model_file->text());
if (file.exists())
settings.setValue("model_file", ui->txt_model_file->text());
file.setFile(ui->txtr->text());
if (file.exists())
settings.setValue("rscript_file", ui->txtr->text());
file.setFile(ui->txtdbman->text());
if (file.exists())
settings.setValue("dbman_file", ui->txtdbman->text());
this->close();
}
void ModelSettings::on_buttonBox_rejected()
{
this->close();
}
void ModelSettings::on_cmd_ghg_clicked()
{
const QString fileName = QFileDialog::getOpenFileName(this,tr("Select a GHG settings file"), ".", "JSON (*.json)");
if (!fileName.isEmpty())
ui->txt_ghg->setText(fileName);
}
void ModelSettings::on_cmd_stock_clicked()
{
const QString fileName = QFileDialog::getOpenFileName(this,tr("Select a stock change settings file"), ".", "JSON (*.json)");
if (!fileName.isEmpty())
ui->txt_stock->setText(fileName);
}
void ModelSettings::on_cmd_energy_clicked()
{
const QString fileName = QFileDialog::getOpenFileName(this,tr("Select a energy settings file"), ".", "JSON (*.json)");
if (!fileName.isEmpty())
ui->txt_energy->setText(fileName);
}
void ModelSettings::on_cmdbrowser_clicked()
{
#if defined(__linux__)
QString fileName = QFileDialog::getOpenFileName(this,tr("RScript"), QDir::homePath(), tr("Executable file (Rscript)"));
#else
QString fileName = QFileDialog::getOpenFileName(this,tr("RScript"), QDir::homePath(), tr("Executable file (Rscript.exe)"));
#endif
if (fileName != "")
ui->txtr->setText(fileName);
}
void ModelSettings::on_cmdbrowsedbman_clicked()
{
#if defined(__linux__)
QString fileName = QFileDialog::getOpenFileName(this,tr("DB Browser for SQLite"), QDir::homePath(), tr("Executable file (sqlitebrowser)"));
#else
QString fileName = QFileDialog::getOpenFileName(this,tr("DB Browser for SQLite"), QDir::homePath(), tr("Executable file (*.exe)"));
#endif
if (fileName != "")
ui->txtdbman->setText(fileName);
}