-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdomainparametersdialog.cpp
More file actions
295 lines (233 loc) · 7.1 KB
/
domainparametersdialog.cpp
File metadata and controls
295 lines (233 loc) · 7.1 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#include "domainparametersdialog.h"
#include "QtCore/qobjectdefs.h"
#include "ui_domainparametersdialog.h"
#include "account.h"
DomainParametersDialog::DomainParametersDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::DomainParametersDialog)
{
ui->setupUi(this);
QSettings settings;
QString current_domain = settings.value("current-domain").toString();
int ix = -1;
/*
* Populate the combobox, noting which index corresponds to the
* current-domain value is settings
*/
foreach(Domain *dom, Domain::domains)
{
QString domainName = dom->getName();
ui->cbDomainName->addItem(domainName);
if (domainName == current_domain) {
ix = ui->cbDomainName->count() - 1;
}
}
/*
* There must be at least one domain in the list -- don't allow this
* dialog to be called otherwise
*/
Q_ASSERT (ix != -1);
/*
* Set the combobox to the current domain and prevent it from being
* edited
*/
ui->cbDomainName->setCurrentIndex(ix);
ui->cbDomainName->setEditable(false);
/*
* Get the settings for the current domain and populate the rest of the
* parameters. This must happen whenever the combobox value is changed
*/
readParameters();
// Ignore the compiler warning -- I've done it this way for consistency with
// the SIGNAL macro as defined for QObject::connect...
connect(ui->cbDomainName, SIGNAL(currentIndexChanged(const QString&)),
this, SLOT(readParameters()));
/***
* This is from the documentation for Signals and Slots
*
connect(sender, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(Qbject*)));
connect(sender, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed()));
connect(sender, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));
*
*/
}
DomainParametersDialog::~DomainParametersDialog()
{
delete ui;
}
void DomainParametersDialog::setDomain(QString name)
{
}
void DomainParametersDialog::readParameters()
{
qDebug() << "DomainParametersDialog::getParameters()";
/*
* Get the new domain from the combobox and populate the parameters from
* the settings for that domain. (See also Domain::restoreDomains())
*/
QString name = ui->cbDomainName->currentText();
Domain *dom = Domain::getDomain(name);
qDebug() << "Gettng parameters for domain:" << name;
QSettings settings;
settings.beginGroup("Domains");
settings.beginGroup(name);
/*
* Copy settings into the dialog fields for the currently selected domain
*/
foreach (ParamType p, Domain::parameterKeys.keys())
{
QString key_string = Domain::parameterKeys.value(p);
if (settings.contains(key_string))
{
int val = settings.value(key_string).toInt();
dom->params[p] = val;
/*
* NB params emp_rate and active_pop have been provisionally
* discontinued
*/
switch(p)
{
case ParamType::procurement:
ui->sbGovProcurement->setValue(val);
break;
case ParamType::prop_con:
ui->sbPropConsInc->setValue(val);
break;
case ParamType::inc_tax_rate:
ui->sbIncTax->setValue(val);
break;
case ParamType::inc_thresh:
ui->sbTaxThresh->setValue(val);
break;
case ParamType::sales_tax_rate:
ui->sbSalesTax->setValue(val);
break;
case ParamType::firm_creation_prob:
ui->sbStartupProb->setValue(val);
break;
case ParamType::dedns:
ui->sbDeductions->setValue(val);
break;
case ParamType::unemp_ben_rate:
ui->sbBens->setValue(val);
break;
case ParamType::pop:
ui->sbPopulation->setValue(val);
break;
case ParamType::distrib:
ui->sbPropInvest->setValue(val);
break;
case ParamType::prop_inv:
ui->sbPropInvest->setValue(val);
break;
case ParamType::boe_int:
ui->sbCentralBankInterest->setValue(val);
break;
case ParamType::bus_int:
ui->sbClearingBankInterest->setValue(val);
break;
case ParamType::loan_prob:
ui->sbLoanProb->setValue(val);
break;
case ParamType::recoup:
ui->sbRecoup->setValue(val);
break;
case ParamType::std_wage:
ui->sbStdWage->setValue(val);
break;
case ParamType::gov_size:
ui->sbGovSize->setValue(val);
break;
default:
// TO DO: Missing parameters
// sbBasicInc, sbImportPref, sbPropConsSav are not handled, no
// paramType for standard wage (sbStdWage)
// NB: We should maintain separate retail interest rates for
// saving and borrowing. At the moment we only have one, which
// is implicitly a borrowing rate
Q_ASSERT(false);
}
}
else
{
qWarning() << "Parameter" << key_string
<< "is missing from settings for"
<< dom->getName();
}
}
settings.endGroup();
settings.endGroup();
}
QString DomainParametersDialog::getDomain()
{
return ui->cbDomainName->currentText();
}
int DomainParametersDialog::getProcurement()
{
return ui->sbGovProcurement->value();
}
int DomainParametersDialog::getPropConsumeInc()
{
return ui->sbPropConsInc->value();
}
int DomainParametersDialog::getIncTaxRate()
{
return ui->sbIncTax->value();
}
int DomainParametersDialog::getIncTaxThresh()
{
return ui->sbTaxThresh->value();
}
int DomainParametersDialog::getSalesTaxRate()
{
return ui->sbSalesTax->value();
}
int DomainParametersDialog::getStartupProb()
{
return ui->sbStartupProb->value();
}
int DomainParametersDialog::getDedns()
{
return ui->sbDeductions->value();
}
int DomainParametersDialog::getUnempBen()
{
return ui->sbBens->value();
}
int DomainParametersDialog::getPopulation()
{
return ui->sbPopulation->value();
}
int DomainParametersDialog::getPropInvest()
{
return ui->sbPropInvest->value();
}
int DomainParametersDialog::getDistrib()
{
Q_ASSERT(false);
return 0;
}
int DomainParametersDialog::getCBInterest()
{
return ui->sbCentralBankInterest->value();
}
int DomainParametersDialog::getClearingBankInterest()
{
return ui->sbClearingBankInterest->value();
}
int DomainParametersDialog::getLoanProb()
{
return ui->sbLoanProb->value();
}
int DomainParametersDialog::getRecoupPeriods()
{
return ui->sbRecoup->value();
}
int DomainParametersDialog::getStdWage()
{
return ui->sbStdWage->value();
}
int DomainParametersDialog::getGovSize()
{
return ui->sbGovSize->value();
}