-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparameterwizard.cpp
More file actions
669 lines (524 loc) · 24.3 KB
/
parameterwizard.cpp
File metadata and controls
669 lines (524 loc) · 24.3 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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
#include "parameterwizard.h"
#include <QFormLayout>
#include <QLabel>
#include <QTextEdit>
#include <QLineEdit>
#include <QComboBox>
#include <QtDebug>
#include <QtGlobal>
#include <QListWidgetItem>
#include <QPixmap>
ParameterWizard::ParameterWizard(QWidget *parent) : QWizard(parent)
{
setWindowTitle("Behaviour Definition");
setPixmap(QWizard::BackgroundPixmap, QPixmap(":/background3.png"));
setButtonText(QWizard::CustomButton1, tr("&Add conditionals"));
setOption(QWizard::HaveCustomButton1, true);
setOption(QWizard::NoCancelButton, false);
setOption(QWizard::CancelButtonOnLeft, true);
//setOption(QWizard::HaveFinishButtonOnEarlyPages, true);
importDomain.clear();
setMinimumHeight(660);
rels << "is less than"
<< "is equal to"
<< "is more than"
<< "is not less than"
<< "is not equal to"
<< "is not more than";
connect(this, &QWizard::customButtonClicked, this, &ParameterWizard::createNewPage);
}
void ParameterWizard::setProperties(QMap<QString, Property> map)
{
// NOTE: This includes the preudo-series 'Zero reference line' and
// 'Hundred reference line'. These serve no useful purpose here and
// should be removed. Care needed if translating to make sure the
// same translation is used here as in MainWindow. Any other redundant
// series (names) should also be removed here.
propertyMap = map;
propertyNames.append(map.keys());
propertyNames.removeOne(tr("Zero reference line"));
propertyNames.removeOne(tr("100 reference line"));
}
void ParameterWizard::importFrom(QString domainName)
{
importDomain = domainName;
}
void ParameterWizard::setCurrentDomain(QString domainName)
{
qDebug() << "ParameterWizard::setCurrentBehaviour(): model_name =" << domainName;
// TODO: Build pages from settings for current_model. At the moment we just
// have a default page unless the user adds more pages. For updating the
// parameters we will need to create however many pages are needed.
// First, remove all existing pages
QList<int> page_ids = pageIds();
foreach(int pid, page_ids)
{
qDebug() << "ParameterWizard::modelChanged(): removing page" << pid;
removePage(pid);
}
// Then add a default page for the new model
currentBehaviour = domainName;
qDebug() << "ParameterWizard::modelChanged(): adding default page";
setPage(default_page, new DefaultPage(this));
qDebug() << "ParameterWizard::modelChanged(): restarting";
// and then extra pages if needed
QSettings settings;
int num_pages = settings.value(domainName + "/pages", 1).toInt();
qDebug() << "ParameterWizard::setCurrentModel(): existing pages =" << num_pages;
for (int i = 0; i < num_pages - 1; i++) {
ExtraPage *page = createNewPage();
page->readSettings(currentBehaviour);
}
}
void ParameterWizard::done(int result)
{
qDebug() << "ParameterWizard::done() called: result =" << result << ", page id =" << currentId();
if (result == QDialog::Accepted) {
currentPage()->validatePage();
QSettings settings;
settings.setValue(currentBehaviour + "/pages", this->pageIds().count());
}
QDialog::done(result);
}
int ParameterWizard::nextId() const
{
// This is a 'read-once' value
return nextPageNumber == -1 ? QWizard::nextId() : nextPageNumber;
}
void ParameterWizard::currentIdChanged(int id)
{
qDebug() << "ParameterWizard::currentIdChanged(): id =" << id << ", isFinalPage() returns" << currentPage()->isFinalPage();
setOption(QWizard::HaveCustomButton1, currentPage()->isFinalPage());
}
ExtraPage *ParameterWizard::createNewPage()
{
ExtraPage *page = new ExtraPage(this);
int pageNum = addPage(page);
qDebug() << "ParameterWizard::createNewPage(): new page id =" << pageNum;
page->setPageNumber(pageNum);
page->setFinalPage(true);
nextPageNumber = pageNum;
next();
nextPageNumber = -1;
return page;
}
QSpinBox *ParameterWizard::getSpinBox(int min, int max)
{
QSpinBox *sb = new QSpinBox;
sb->setMinimum(min);
sb->setMaximum(max);
return sb;
}
DefaultPage::DefaultPage(ParameterWizard *w)
{
wiz = w;
int width = 48; // change as required
leCurrencyName = new QLineEdit();
leCurrencyName->setFixedWidth(width);
leCurrencyAbbrev = new QLineEdit();
leCurrencyAbbrev->setFixedWidth(width);
le_dir_exp_rate = new QLineEdit();
le_dir_exp_rate->setFixedWidth(width);
le_thresh = new QLineEdit();
le_thresh->setFixedWidth(width);
sb_emp_rate = wiz->getSpinBox(0, 100);
sb_prop_con = wiz->getSpinBox(0, 100);
sb_dedns = wiz->getSpinBox(0, 100);
sb_inc_tax = wiz->getSpinBox(0, 100);
sb_sales_tax = wiz->getSpinBox(0, 100);
sb_bcr = wiz->getSpinBox(0, 100);
sb_recoup = wiz->getSpinBox(1, 100);
sb_distrib = wiz->getSpinBox(0, 100);
sb_prop_inv = wiz->getSpinBox(0, 100);
sb_ubr = wiz->getSpinBox(0, 100);
sb_boe_loan_int = wiz->getSpinBox(0,99);
sb_bus_loan_int = wiz->getSpinBox(0,99);
xb_locked = new QCheckBox(" Locked");
cb_loan_prob = new QComboBox;
cb_loan_prob->addItem(tr("Never"));
cb_loan_prob->addItem(tr("Rarely"));
cb_loan_prob->addItem(tr("Sometimes"));
cb_loan_prob->addItem(tr("Usually"));
cb_loan_prob->addItem(tr("Always"));
QFormLayout *layout = new QFormLayout;
layout->addRow(new QLabel(tr("Currency name")));
layout->addRow(new QLabel(tr("Currency abbreviation")));
layout->addRow(new QLabel(tr("<b>Government</b>")));
layout->addRow(new QLabel(tr("Currency name")));
layout->addRow(new QLabel(tr("Currency abbreviation")));
layout->addRow(new QLabel(tr("Periodic procurement expenditure")), le_dir_exp_rate);
layout->addRow(new QLabel(tr("Unemployment benefit (%)")), sb_ubr);
layout->addRow(new QLabel(tr("<b>Workers</b>")));
layout->addRow(new QLabel(tr("Propensity to consume (%)")), sb_prop_con);
layout->addRow(new QLabel(tr("Income tax (%)")), sb_inc_tax);
layout->addRow(new QLabel(tr("Income threshold")), le_thresh);
layout->addRow(new QLabel(tr("<b>Businesses</b>")));
layout->addRow(new QLabel(tr("Pre-tax deductions (%)")), sb_dedns);
layout->addRow(new QLabel(tr("Sales tax (%)")), sb_sales_tax);
layout->addRow(new QLabel(tr("Profit distribution rate (%)")), sb_distrib);
layout->addRow(new QLabel(tr("Investment rate (%)")), sb_prop_inv);
layout->addRow(new QLabel(tr("Borrow if needed to pay wages")), cb_loan_prob);
layout->addRow(new QLabel(tr("Business creation rate (%)")), sb_bcr);
layout->addRow(new QLabel(tr("Time (periods) to recoup capex")), sb_recoup);
layout->addRow(new QLabel(tr("<b>Banks</b>")));
layout->addRow(new QLabel(tr("Central Bank lending rate (%)")), sb_boe_loan_int);
layout->addRow(new QLabel(tr("Retail Banks lending rate (%)")), sb_bus_loan_int);
layout->addRow(new QLabel(tr("<b> </b>")));
layout->addRow(new QLabel(tr("<b>Prevent changes</b>")));
layout->addRow(xb_locked);
layout->setVerticalSpacing(4);
setLayout(layout);
}
void DefaultPage::readSettings(QString model)
{
// Read the default parameters from settings. We use 'sensible' default
// defaults so they will have a workable model to start with
QSettings settings;
le_dir_exp_rate->setText(settings.value(model + "/default/govt-procurement", 0).toString());
le_thresh->setText(settings.value(model + "/default/income-threshold", 50).toString());
sb_emp_rate->setValue(settings.value(model + "/default/employment-rate", 95).toInt());
sb_prop_con->setValue(settings.value(model + "/default/propensity-to-consume", 80).toInt());
sb_dedns->setValue(settings.value(model + "/default/pre-tax-dedns-rate", 0).toInt());
sb_inc_tax->setValue(settings.value(model + "/default/income-tax-rate", 10).toInt());
sb_sales_tax->setValue(settings.value(model + "/default/sales-tax-rate", 0).toInt());
sb_bcr->setValue(settings.value(model + "/default/firm-creation-prob", 0).toInt());
sb_recoup->setValue(settings.value(model + "/default/capex-recoup-periods", 10).toInt());
sb_distrib->setValue(settings.value(model + "/default/reserve-rate", 50).toInt());
sb_prop_inv->setValue(settings.value(model + "/default/prop-invest", 2).toInt());
sb_ubr->setValue(settings.value(model + "/default/unempl-benefit-rate", 60).toInt());
sb_boe_loan_int->setValue(settings.value(model + "/default/boe-interest", 1).toInt());
sb_bus_loan_int->setValue(settings.value(model + "/default/bus-interest", 3).toInt());
cb_loan_prob->setCurrentIndex(settings.value(model + "/default/loan-prob", 0).toInt());
xb_locked->setChecked(settings.value(model + "/locked", false).toBool());
connect(xb_locked, &QCheckBox::toggled, this, &DefaultPage::toggleLock);
toggleLock();
}
void DefaultPage::toggleLock()
{
qDebug() << "DefaultPage::toggleLock(): called";
bool unlocked = !xb_locked->isChecked();
le_dir_exp_rate->setEnabled(unlocked);
le_thresh->setEnabled(unlocked);
sb_emp_rate->setEnabled(unlocked);
sb_prop_con->setEnabled(unlocked);
sb_dedns->setEnabled(unlocked);
sb_inc_tax->setEnabled(unlocked);
sb_sales_tax->setEnabled(unlocked);
sb_bcr->setEnabled(unlocked);
sb_recoup->setEnabled(unlocked);
sb_distrib->setEnabled(unlocked);
sb_prop_inv->setEnabled(unlocked);
sb_ubr->setEnabled(unlocked);
sb_boe_loan_int->setEnabled(unlocked);
sb_bus_loan_int->setEnabled(unlocked);
cb_loan_prob->setEnabled(unlocked);
}
// This function should not be called unless wiz->current_model has been set.
void DefaultPage::initializePage()
{
QString model = wiz->currentBehaviour;
qDebug() << "DefaultPage::initialize(): currentBehaviourl =" << model;
setTitle(tr("Default Profile For ") + model);
readSettings(wiz->importDomain.isEmpty() ? model : wiz->importDomain);
}
bool DefaultPage::validatePage()
{
qDebug() << "DefaultPage::validatePage()";
QString model = wiz->currentBehaviour;
// TODO: We don't currently do any actual validation here.
// We just save the default settings assuming they're OK.
QSettings settings;
settings.setValue(model + "/default/govt-procurement", le_dir_exp_rate->text().toInt());
settings.setValue(model + "/default/employment-rate", sb_emp_rate->value());
settings.setValue(model + "/default/propensity-to-consume", sb_prop_con->value());
settings.setValue(model + "/default/income-threshold", le_thresh->text().toInt());
settings.setValue(model + "/default/pre-tax-dedns-rate", sb_dedns->value());
settings.setValue(model + "/default/income-tax-rate", sb_inc_tax->value());
settings.setValue(model + "/default/sales-tax-rate", sb_sales_tax->value());
settings.setValue(model + "/default/firm-creation-prob", sb_bcr->value());
settings.setValue(model + "/default/capex-recoup-periods", sb_recoup->value());
settings.setValue(model + "/default/reserve-rate", sb_distrib->value());
settings.setValue(model + "/default/prop-invest", sb_prop_inv->value());
settings.setValue(model + "/default/unempl-benefit-rate", sb_ubr->value());
settings.setValue(model + "/default/boe-interest", sb_boe_loan_int->value());
settings.setValue(model + "/default/bus-interest", sb_bus_loan_int->value());
settings.setValue(model + "/default/loan-prob", cb_loan_prob->currentIndex());
settings.setValue(model + "/locked", xb_locked->isChecked());
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// \brief ExtraPage::ExtraPage
/// \param w
///
ExtraPage::ExtraPage(ParameterWizard *w)
{
wiz = w;
qDebug() << "ExtraPage::ExtraPage(): called";
cb_property = new QComboBox;
cb_property->addItems(wiz->propertyNames);
cb_rel = new QComboBox;
cb_rel->addItems(wiz->rels);
le_value = new QLineEdit;
QLabel *hdg_1 = new QLabel;
hdg_1->setText("<b>Condition:</b>");
QVBoxLayout *top_layout = new QVBoxLayout;
top_layout->addWidget(hdg_1);
top_layout->addWidget(cb_property);
top_layout->addWidget(cb_rel);
top_layout->addWidget(le_value);
top_layout->setSpacing(3);
cbx_dir_exp_rate = createCheckBox();
cbx_thresh = createCheckBox();
cbx_prop_con = createCheckBox();
cbx_dedns = createCheckBox();
cbx_inc_tax = createCheckBox();
cbx_sales_tax = createCheckBox();
cbx_bcr = createCheckBox();
cbx_recoup = createCheckBox();
cbx_distrib = createCheckBox();
cbx_prop_inv = createCheckBox();
cbx_ubr = createCheckBox();
cbx_boe_loan_int = createCheckBox();
cbx_bus_loan_int = createCheckBox();
cbx_loan_prob = createCheckBox();
le_dir_exp_rate = new QLineEdit();
le_dir_exp_rate->setFixedWidth(48);
le_thresh = new QLineEdit();
le_thresh->setFixedWidth(48);
sb_prop_con = wiz->getSpinBox(0, 100);
sb_dedns = wiz->getSpinBox(0, 100);
sb_inc_tax = wiz->getSpinBox(0, 100);
sb_sales_tax = wiz->getSpinBox(0, 100);
sb_bcr = wiz->getSpinBox(0, 100);
sb_recoup = wiz->getSpinBox(0, 100);
sb_distrib = wiz->getSpinBox(0, 100);
sb_prop_inv = wiz->getSpinBox(0, 100);
sb_ubr = wiz->getSpinBox(0, 100);
sb_boe_loan_int = wiz->getSpinBox(0,99);
sb_bus_loan_int = wiz->getSpinBox(0,99);
cb_loan_prob = new QComboBox;
cb_loan_prob->addItem(tr("Never"));
cb_loan_prob->addItem(tr("Rarely"));
cb_loan_prob->addItem(tr("Sometimes"));
cb_loan_prob->addItem(tr("Usually"));
cb_loan_prob->addItem(tr("Always"));
QGridLayout *bottom_layout = new QGridLayout;
bottom_layout->addWidget(new QLabel(tr("<b>Government</b>")), 0, 0, 1, 3);
bottom_layout->addWidget(cbx_dir_exp_rate, 1, 0);
bottom_layout->addWidget(new QLabel(tr("Periodic procurement expenditure")), 1, 1);
bottom_layout->addWidget(le_dir_exp_rate, 1, 2);
bottom_layout->addWidget(cbx_ubr, 2, 0);
bottom_layout->addWidget(new QLabel(tr("Unemployment benefit (%)")), 2, 1);
bottom_layout->addWidget(sb_ubr, 2, 2);
bottom_layout->addWidget(new QLabel(tr("<b>Workers</b>")), 3, 0, 1, 3);
bottom_layout->addWidget(cbx_prop_con, 4, 0);
bottom_layout->addWidget(new QLabel(tr("Propensity to consume (%)")), 4, 1);
bottom_layout->addWidget(sb_prop_con, 4, 2);
bottom_layout->addWidget(cbx_inc_tax, 5, 0);
bottom_layout->addWidget(new QLabel(tr("Income tax (%)")), 5, 1);
bottom_layout->addWidget(sb_inc_tax, 5, 2);
bottom_layout->addWidget(cbx_thresh, 6, 0);
bottom_layout->addWidget(new QLabel(tr("Income threshold")), 6, 1);
bottom_layout->addWidget(le_thresh, 6, 2);
bottom_layout->addWidget(new QLabel(tr("<b>Businesses</b>")), 7, 0, 1, 3);
bottom_layout->addWidget(cbx_dedns, 8, 0);
bottom_layout->addWidget(new QLabel(tr("Pre-tax deductions (%)")), 8, 1);
bottom_layout->addWidget(sb_dedns, 8, 2);
bottom_layout->addWidget(cbx_sales_tax, 9, 0);
bottom_layout->addWidget(new QLabel(tr("Sales tax (%)")), 9, 1);
bottom_layout->addWidget(sb_sales_tax, 9, 2);
bottom_layout->addWidget(cbx_distrib, 10, 0);
bottom_layout->addWidget(new QLabel(tr("Profit distribution rate (%)")), 10, 1);
bottom_layout->addWidget(sb_distrib, 10, 2);
bottom_layout->addWidget(cbx_prop_inv, 11, 0);
bottom_layout->addWidget(new QLabel(tr("Investment rate (%)")), 11, 1);
bottom_layout->addWidget(sb_prop_inv, 11, 2);
bottom_layout->addWidget(cbx_loan_prob, 12, 0);
bottom_layout->addWidget(new QLabel(tr("Borrow if needed to pay wages")), 12, 1);
bottom_layout->addWidget(cb_loan_prob, 12, 2);
bottom_layout->addWidget(cbx_bcr, 13, 0);
bottom_layout->addWidget(new QLabel(tr("Business creation rate (%)")), 13, 1);
bottom_layout->addWidget(sb_bcr, 13, 2);
bottom_layout->addWidget(cbx_recoup, 14, 0);
bottom_layout->addWidget(new QLabel(tr("Time (periods) to recoup capex")), 14, 1);
bottom_layout->addWidget(sb_recoup, 14, 2);
bottom_layout->addWidget(new QLabel(tr("<b>Banks</b>")), 15, 0, 1, 3);
bottom_layout->addWidget(cbx_boe_loan_int, 16, 0);
bottom_layout->addWidget(new QLabel(tr("Central Bank lending rate (%)")), 16, 1);
bottom_layout->addWidget(sb_boe_loan_int, 16,2);
bottom_layout->addWidget(cbx_bus_loan_int, 17, 0);
bottom_layout->addWidget(new QLabel(tr("Retail lending rate (%)")), 17, 1);
bottom_layout->addWidget(sb_bus_loan_int, 17, 2);
bottom_layout->setVerticalSpacing(3);
QGridLayout *main_layout = new QGridLayout;
main_layout->addLayout(top_layout, 0, 0, 2, 2);
main_layout->addLayout(bottom_layout, 2, 0, 12, 2);
setLayout(main_layout);
}
QCheckBox *ExtraPage::createCheckBox()
{
QCheckBox *cbx = new QCheckBox;
connect(cbx, &QCheckBox::stateChanged, this, &ExtraPage::showAssocCtrl);
return cbx;
}
void ExtraPage::showAssocCtrl(int)
{
// Placeholder function in case we want to (e.g.) disable controls whose
// associated checkbox in unchecked...
}
void ExtraPage::setPageNumber(int page_num)
{
qDebug() << "ExtraPage::setPageNumber(): page_num =" << page_num;
pnum = page_num;
setTitle(tr("Conditional Parameters - Page ") + QString::number(page_num));
readSettings(wiz->importDomain.isEmpty() ? wiz->currentBehaviour : wiz->importDomain);
}
// Attempts to read setting from the settings for the current page. if it
// cannot be found, read the default setting instead
QString ExtraPage::readCondSetting(QString behaviourName, QString key)
{
QSettings settings;
QString base1 = behaviourName + "/condition-" + QString::number(pnum) + "/" + key + "/value";
QString base2 = behaviourName + "/default/" + key;
QString res = settings.value(base1, settings.value(base2 + key)).toString();
return res;
}
QString ExtraPage::getPropertyName(int prop)
{
// Convert the int to a property
Property p = static_cast<Property>(prop);
// and look it up in the property map
QMapIterator<QString,Property> it(wiz->propertyMap);
while (it.hasNext())
{
it.next();
if (it.value() == p) {
return it.key();
}
}
Q_ASSERT(false);
return QString(""); // prevent compiler warning
}
bool ExtraPage::isChecked(QString behaviourName, QString attrib)
{
QSettings settings;
return settings.value(behaviourName + "/condition-" + QString::number(pnum) + "/" + attrib + "/isset", false).toBool();
}
void ExtraPage::readSettings(QString behaviourName)
{
qDebug() << "ExtraPage::readSettings(): from model =" << behaviourName;
QSettings settings;
QString base = behaviourName + "/condition-" + QString::number(pnum) + "/";
cb_property->setCurrentText(getPropertyName(settings.value(base + "property", 0).toInt()));
cb_rel->setCurrentIndex(settings.value(base + "rel", 3).toInt());
le_value->setText(settings.value(base + "value", 0).toString());
QString attrib;
attrib = "govt-procurement";
cbx_dir_exp_rate->setChecked(isChecked(behaviourName, attrib));
le_dir_exp_rate->setText(readCondSetting(behaviourName, attrib));
attrib = "income-threshold";
cbx_thresh->setChecked(isChecked(behaviourName, attrib));
le_thresh->setText(readCondSetting(behaviourName, attrib));
attrib = "propensity-to-consume";
cbx_prop_con->setChecked(isChecked(behaviourName, attrib));
sb_prop_con->setValue(readCondSetting(behaviourName, attrib).toInt());
attrib = "pre-tax-dedns-rate";
cbx_dedns->setChecked(isChecked(behaviourName, attrib));
sb_dedns->setValue(readCondSetting(behaviourName, attrib).toInt());
attrib = "income-tax-rate";
cbx_inc_tax->setChecked(isChecked(behaviourName, attrib));
sb_inc_tax->setValue(readCondSetting(behaviourName, attrib).toInt());
attrib = "sales-tax-rate";
cbx_sales_tax->setChecked(isChecked(behaviourName, attrib));
sb_sales_tax->setValue(readCondSetting(behaviourName, attrib).toInt());
attrib = "firm-creation-prob";
cbx_bcr->setChecked(isChecked(behaviourName, attrib));
sb_bcr->setValue(readCondSetting(behaviourName, attrib).toInt());
attrib = "capex-recoup-periods";
cbx_recoup->setChecked(isChecked(behaviourName, attrib));
sb_recoup->setValue(readCondSetting(behaviourName, attrib).toInt());
attrib = "reserve-rate";
cbx_distrib->setChecked(isChecked(behaviourName, attrib));
sb_distrib->setValue(readCondSetting(behaviourName, attrib).toInt());
attrib = "prop-invest";
cbx_prop_inv->setChecked(isChecked(behaviourName, attrib));
sb_prop_inv->setValue(readCondSetting(behaviourName, attrib).toInt());
attrib = "unempl-benefit-rate";
cbx_ubr->setChecked(isChecked(behaviourName, attrib));
sb_ubr->setValue(readCondSetting(behaviourName, attrib).toInt());
attrib = "boe-interest";
cbx_boe_loan_int->setChecked(isChecked(behaviourName, attrib));
sb_boe_loan_int->setValue(readCondSetting(behaviourName, attrib).toInt());
attrib = "bus-interest";
cbx_bus_loan_int->setChecked(isChecked(behaviourName, attrib));
sb_bus_loan_int->setValue(readCondSetting(behaviourName, attrib).toInt());
attrib = "loan-prob";
cbx_loan_prob->setChecked(isChecked(behaviourName, attrib));
cb_loan_prob->setCurrentIndex(readCondSetting(behaviourName, attrib).toInt());
}
bool ExtraPage::validatePage()
{
qDebug() << "ExtraPage::validatePage()";
QString behaviourName = wiz->currentBehaviour;
QString key = behaviourName + "/condition-" + QString::number(pnum) + "/";
// TODO: We don't currently do any actual validation here.
// We just save the settings assuming they're OK.
QSettings settings;
bool ok;
// We need to store an actual property (Property enum) here, but we have
// to convert it to an int first
QString selected_text = cb_property->currentText();
Property prop = wiz->propertyMap.value(selected_text);
settings.setValue(key + "property", static_cast<int>(prop));
settings.setValue(key + "rel", cb_rel->currentIndex());
// TODO: force input value to be numeric and remove the OK check
int val = le_value->text().toInt(&ok);
if (!ok) {
val = 0;
}
settings.setValue(key + "value", val);
QString attrib;
attrib = "govt-procurement/";
settings.setValue(key + attrib + "isset", cbx_dir_exp_rate->isChecked());
settings.setValue(key + attrib + "value", le_dir_exp_rate->text().toInt());
attrib = "income-threshold/";
settings.setValue(key + attrib + "isset", cbx_thresh->isChecked());
settings.setValue(key + attrib + "value", le_thresh->text().toInt());
attrib = "propensity-to-consume/";
settings.setValue(key + attrib + "isset", cbx_prop_con->isChecked());
settings.setValue(key + attrib + "value", sb_prop_con->value());
attrib = "pre-tax-dedns-rate/";
settings.setValue(key + attrib + "isset", cbx_dedns->isChecked());
settings.setValue(key + attrib + "value", sb_dedns->value());
attrib = "income-tax-rate/";
settings.setValue(key + attrib + "isset", cbx_inc_tax->isChecked());
settings.setValue(key + attrib + "value", sb_inc_tax->value());
attrib = "sales-tax-rate/";
settings.setValue(key + attrib + "isset", cbx_sales_tax->isChecked());
settings.setValue(key + attrib + "value", sb_sales_tax->value());
attrib = "firm-creation-prob/";
settings.setValue(key + attrib + "isset", cbx_bcr->isChecked());
settings.setValue(key + attrib + "value", sb_bcr->value());
attrib = "capex-recoup-periods/";
settings.setValue(key + attrib + "isset", cbx_recoup->isChecked());
settings.setValue(key + attrib + "value", sb_recoup->value());
attrib = "reserve-rate/";
settings.setValue(key + attrib + "isset", cbx_distrib->isChecked());
settings.setValue(key + attrib + "value", sb_distrib->value());
attrib = "prop-invest/";
settings.setValue(key + attrib + "isset", cbx_prop_inv->isChecked());
settings.setValue(key + attrib + "value", sb_prop_inv->value());
attrib = "unempl-benefit-rate/";
settings.setValue(key + attrib + "isset", cbx_ubr->isChecked());
settings.setValue(key + attrib + "value", sb_ubr->value());
attrib = "boe-interest/";
settings.setValue(key + attrib + "isset", cbx_boe_loan_int->isChecked());
settings.setValue(key + attrib + "value", sb_boe_loan_int->value());
attrib = "bus-interest/";
settings.setValue(key + attrib + "isset", cbx_bus_loan_int->isChecked());
settings.setValue(key + attrib + "value", sb_bus_loan_int->value());
attrib = "loan-prob/";
settings.setValue(key + attrib + "isset", cbx_loan_prob->isChecked());
settings.setValue(key + attrib + "value", cb_loan_prob->currentIndex());
return true;
}