-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrootsconfigframe.cpp
More file actions
139 lines (117 loc) · 4.58 KB
/
rootsconfigframe.cpp
File metadata and controls
139 lines (117 loc) · 4.58 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
/* Copyright (c) 2013 Mike Dusseault
*
* This file is part of QMentat.
*
* QMentat is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QMentat is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QMentat. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rootsconfigframe.h"
#include "ui_rootsconfigframe.h"
#include "bigfixedpoint.h"
#include "qbigfixedvalidator.h"
#include "rootsmodule.h"
RootsConfigFrame::RootsConfigFrame(QWidget *parent) :
QFrame(parent),
ui(new Ui::RootsConfigFrame)
{
ui->setupUi(this);
QBigFixedValidator *numValidator = new QBigFixedValidator(
BigFixedPoint(QString("0")),
BigFixedPoint(QString("99999999999999999999999999999999999999999999")),
this);
ui->minNumberLineEdit->setValidator(numValidator);
ui->maxNumberLineEdit->setValidator(numValidator);
QIntValidator *decimalsValidator = new QIntValidator(0, 100, this);
ui->decimalPlacesLineEdit->setValidator(decimalsValidator);
QIntValidator *rootValidator = new QIntValidator(1, 1000, this);
ui->minRootLineEdit->setValidator(rootValidator);
ui->maxRootLineEdit->setValidator(rootValidator);
this->module = 0;
}
RootsConfigFrame::~RootsConfigFrame()
{
delete ui;
}
void RootsConfigFrame::setModule(RootsModule *mod)
{
this->module = mod;
}
void RootsConfigFrame::setMinimum(const QString& min)
{
ui->minNumberLineEdit->setText(min);
}
void RootsConfigFrame::setMaximum(const QString& max)
{
ui->maxNumberLineEdit->setText(max);
}
void RootsConfigFrame::setRootMinimum(int min)
{
ui->minRootLineEdit->setText(QString("%1").arg(min));
}
void RootsConfigFrame::setRootMaximum(int max)
{
ui->maxRootLineEdit->setText(QString("%1").arg(max));
}
void RootsConfigFrame::setDecimalPlaces(int decimals)
{
ui->decimalPlacesLineEdit->setText(QString("%1").arg(decimals));
}
void RootsConfigFrame::setRoundingMode(int mode)
{
ui->roundingComboBox->setCurrentIndex(mode);
}
void RootsConfigFrame::setIntegersOnly(bool intsOnly)
{
ui->integerResultCheckBox->setChecked(intsOnly);
ui->decimalPlacesLineEdit->setEnabled(!intsOnly);
ui->roundingComboBox->setEnabled(!intsOnly);
}
void RootsConfigFrame::on_integerResultCheckBox_stateChanged(int state)
{
bool intsOnly = (state == Qt::Checked);
ui->decimalPlacesLineEdit->setEnabled(!intsOnly);
ui->roundingComboBox->setEnabled(!intsOnly);
}
bool RootsConfigFrame::applyConfig()
{
int integersOnly = ui->integerResultCheckBox->isChecked();
int rounding = ui->roundingComboBox->currentIndex() == 1;
int decimalPlaces = ui->decimalPlacesLineEdit->text().toInt();
QString str = ui->minNumberLineEdit->text();
BigFixedPoint firstMin(str.remove(QLocale::system().groupSeparator()));
str = ui->maxNumberLineEdit->text();
BigFixedPoint firstMax(str.remove(QLocale::system().groupSeparator()));
int rootMin = ui->minRootLineEdit->text().toInt();
int rootMax = ui->maxRootLineEdit->text().toInt();
if (integersOnly
&& !module->isRangeOk(firstMin, firstMax, rootMin, rootMax)) {
QMessageBox::warning(this, tr("Range Validation Error"), tr("There are no possible answers for the ranges you have entered."), QMessageBox::Ok);
return false;
} else if (rootMin <= 0) {
QMessageBox::warning(this, tr("Range Validation Error"), tr("Minimum of root must be greater than zero."), QMessageBox::Ok);
return false;
} else if (rootMax <= 0) {
QMessageBox::warning(this, tr("Range Validation Error"), tr("Maximum of root must be greater than zero."), QMessageBox::Ok);
return false;
} else if (firstMax < firstMin) {
QMessageBox::warning(this, tr("Range Validation Error"), tr("Maximum of base number is smaller than the minimum."), QMessageBox::Ok);
return false;
} else if (rootMax < rootMin) {
QMessageBox::warning(this, tr("Range Validation Error"), tr("Maximum root is smaller than the minimum."), QMessageBox::Ok);
return false;
} else {
module->setSettings(firstMin, firstMax, rootMin, rootMax,
integersOnly, decimalPlaces, rounding);
}
return true;
}