Fri, 08 Jul 2022 13:24:45 +0200
Removed old experiment to calculate flameout and whirlpool ibu's. Changed Tinseth calculation to use a time window so you can select the ibu contribution during a specified time. Added ibu_method Tinset++. Added calculation extensions for Tinseth++, this calculates the flameout and whirlpool effects on all hops. During cooling is to be done.
24 | 1 | /** |
2 | * EditHop.cpp is part of bmsapp. | |
3 | * | |
4 | * bmsapp is free software: you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation, either version 3 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * bmsapp is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | #include "EditHop.h" | |
18 | #include "../ui/ui_EditHop.h" | |
90
2396457a8167
Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents:
60
diff
changeset
|
19 | #include "MainWindow.h" |
24 | 20 | |
21 | ||
22 | EditHop::EditHop(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditHop) | |
23 | { | |
24 | QSqlQuery query; | |
25 | ||
26 | qDebug() << "EditHop record:" << id; | |
27 | ui->setupUi(this); | |
28 | this->recno = id; | |
29 | ||
30 | WindowTitle(); | |
31 | ||
32 | ui->typeEdit->addItem(tr("Bittering")); | |
33 | ui->typeEdit->addItem(tr("Aroma")); | |
34 | ui->typeEdit->addItem(tr("Both")); | |
35 | ||
36 | ui->formEdit->addItem(tr("Pellet")); | |
37 | ui->formEdit->addItem(tr("Plug")); | |
38 | ui->formEdit->addItem(tr("Leaf")); | |
39 | ui->formEdit->addItem(tr("Leaf Wet")); /* Not in beerxml */ | |
40 | ui->formEdit->addItem(tr("Cryo")); /* Not in beerxml */ | |
300
2a97905cb637
Added hop co2 extract form. Added hop add at bottling needed for iso and tetra hop.
Michiel Broek <mbroek@mbse.eu>
parents:
292
diff
changeset
|
41 | ui->formEdit->addItem(tr("Extract")); /* CO2 extract */ |
24 | 42 | |
43 | if (id >= 0) { | |
44 | query.prepare("SELECT * FROM inventory_hops WHERE record = :recno"); | |
45 | query.bindValue(":recno", id); | |
46 | query.exec(); | |
47 | query.next(); | |
48 | ||
49 | ui->nameEdit->setText(query.value(1).toString()); | |
50 | ui->alphaEdit->setValue(query.value(2).toDouble()); | |
51 | ui->betaEdit->setValue(query.value(3).toDouble()); | |
52 | ui->humuleneEdit->setValue(query.value(4).toDouble()); | |
53 | ui->caryEdit->setValue(query.value(5).toDouble()); | |
54 | ui->cohumuloneEdit->setValue(query.value(6).toDouble()); | |
55 | ui->myrceneEdit->setValue(query.value(7).toDouble()); | |
56 | ui->hsiEdit->setValue(query.value(8).toDouble()); | |
57 | ui->typeEdit->setCurrentIndex(query.value(9).toInt()); | |
58 | ui->formEdit->setCurrentIndex(query.value(10).toInt()); | |
59 | ui->notesEdit->setPlainText(query.value(11).toString()); | |
60 | ui->originEdit->setText(query.value(12).toString()); | |
61 | ui->substitutesEdit->setText(query.value(13).toString()); | |
62 | ui->alwaysEdit->setChecked(query.value(14).toInt() ? true:false); | |
63 | ui->inventoryEdit->setValue(query.value(15).toDouble()); | |
64 | ui->costEdit->setValue(query.value(16).toDouble()); | |
65 | ui->valueEdit->setValue(query.value(15).toDouble() * query.value(16).toDouble()); | |
66 | if (query.value(17).toString().length() == 10) { | |
67 | ui->prodEdit->setDate(query.value(17).toDate()); | |
68 | } else { | |
69 | ui->prodEdit->clear(); | |
70 | } | |
71 | if (query.value(18).toString().length() == 10) { | |
72 | ui->thtEdit->setDate(query.value(18).toDate()); | |
73 | } else { | |
74 | ui->thtEdit->clear(); | |
75 | } | |
76 | ui->oilEdit->setValue(query.value(19).toDouble()); | |
77 | } else { | |
78 | /* Set some defaults */ | |
79 | ui->typeEdit->setCurrentIndex(0); | |
80 | ui->formEdit->setCurrentIndex(0); | |
81 | ui->prodEdit->clear(); | |
82 | ui->thtEdit->clear(); | |
83 | } | |
84 | connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditHop::is_changed); | |
85 | connect(ui->alphaEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed); | |
86 | connect(ui->betaEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed); | |
87 | connect(ui->humuleneEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed); | |
88 | connect(ui->caryEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed); | |
89 | connect(ui->cohumuloneEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed); | |
90 | connect(ui->myrceneEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed); | |
91 | connect(ui->hsiEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed); | |
92 | connect(ui->typeEdit, &QComboBox::currentTextChanged, this, &EditHop::is_changed); | |
93 | connect(ui->formEdit, &QComboBox::currentTextChanged, this, &EditHop::is_changed); | |
94 | connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed())); | |
95 | connect(ui->originEdit, &QLineEdit::textChanged, this, &EditHop::is_changed); | |
96 | connect(ui->substitutesEdit, &QLineEdit::textChanged, this, &EditHop::is_changed); | |
97 | connect(ui->alwaysEdit, &QCheckBox::stateChanged, this, &EditHop::is_changed); | |
98 | connect(ui->inventoryEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed); | |
99 | connect(ui->costEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed); | |
100 | connect(ui->prodEdit, &QDateEdit::dateChanged, this, &EditHop::is_changed); | |
292
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
101 | connect(ui->prodButton1, SIGNAL(clicked()), this, SLOT(prod_date_today())); |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
102 | connect(ui->prodButton2, SIGNAL(clicked()), this, SLOT(prod_date_clear())); |
24 | 103 | connect(ui->thtEdit, &QDateEdit::dateChanged, this, &EditHop::is_changed); |
292
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
104 | connect(ui->thtButton1, SIGNAL(clicked()), this, SLOT(tht_date_today())); |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
105 | connect(ui->thtButton2, SIGNAL(clicked()), this, SLOT(tht_date_clear())); |
24 | 106 | connect(ui->oilEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed); |
107 | ||
108 | ui->saveButton->setEnabled(false); | |
109 | ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && id >= 0) ? true:false); | |
110 | } | |
111 | ||
112 | ||
113 | EditHop::~EditHop() | |
114 | { | |
115 | qDebug() << "EditHop done"; | |
116 | delete ui; | |
117 | emit entry_changed(); | |
118 | } | |
119 | ||
120 | ||
121 | /* | |
122 | * Window header, mark any change with '**' | |
123 | */ | |
124 | void EditHop::WindowTitle() | |
125 | { | |
126 | QString txt; | |
127 | ||
128 | if (this->recno < 0) { | |
129 | txt = QString(tr("BMSapp - Add new hop")); | |
130 | } else { | |
131 | txt = QString(tr("BMSapp - Edit hop %1").arg(this->recno)); | |
132 | } | |
133 | ||
134 | if (this->textIsChanged) { | |
135 | txt.append((QString(" **"))); | |
136 | } | |
137 | setWindowTitle(txt); | |
138 | } | |
139 | ||
140 | ||
141 | void EditHop::on_saveButton_clicked() | |
142 | { | |
143 | QSqlQuery query; | |
144 | ||
145 | /* If there are errors in the form, show a message and do "return;" */ | |
146 | if (ui->nameEdit->text().length() < 2) { | |
147 | QMessageBox::warning(this, tr("Edit Hop"), tr("Name empty or too short.")); | |
148 | return; | |
149 | } | |
150 | if (ui->originEdit->text().length() < 2) { | |
151 | QMessageBox::warning(this, tr("Edit Hop"), tr("Origin empty or too short.")); | |
152 | return; | |
153 | } | |
154 | ||
155 | if (this->textIsChanged) { | |
156 | if (this->recno == -1) { | |
157 | query.prepare("INSERT INTO inventory_hops SET name=:name, alpha=:alpha, beta=:beta, " | |
158 | "humulene=:humulene, caryophyllene=:cary, cohumulone=:cohumulone, myrcene=:myrcene, " | |
159 | "hsi=:hsi, type=:type, form=:form, notes=:notes, origin=:origin, substitutes=:substitutes, " | |
160 | "always_on_stock=:always, inventory=:inventory, cost=:cost, production_date=:prod, " | |
161 | "tht_date=:tht, total_oil=:oil, uuid = :uuid"); | |
162 | } else { | |
163 | query.prepare("UPDATE inventory_hops SET name=:name, alpha=:alpha, beta=:beta, " | |
164 | "humulene=:humulene, caryophyllene=:cary, cohumulone=:cohumulone, myrcene=:myrcene, " | |
165 | "hsi=:hsi, type=:type, form=:form, notes=:notes, origin=:origin, substitutes=:substitutes, " | |
166 | "always_on_stock=:always, inventory=:inventory, cost=:cost, production_date=:prod, " | |
167 | "tht_date=:tht, total_oil=:oil WHERE record = :recno"); | |
168 | } | |
169 | query.bindValue(":name", ui->nameEdit->text()); | |
170 | query.bindValue(":alpha", QString("%1").arg(ui->alphaEdit->value(), 2, 'f', 1, '0')); | |
171 | query.bindValue(":beta", QString("%1").arg(ui->betaEdit->value(), 2, 'f', 1, '0')); | |
172 | query.bindValue(":humulene", QString("%1").arg(ui->humuleneEdit->value(), 2, 'f', 1, '0')); | |
173 | query.bindValue(":cary", QString("%1").arg(ui->caryEdit->value(), 2, 'f', 1, '0')); | |
174 | query.bindValue(":cohumulone", QString("%1").arg(ui->cohumuloneEdit->value(), 2, 'f', 1, '0')); | |
175 | query.bindValue(":myrcene", QString("%1").arg(ui->myrceneEdit->value(), 2, 'f', 1, '0')); | |
176 | query.bindValue(":hsi", QString("%1").arg(ui->hsiEdit->value(), 2, 'f', 1, '0')); | |
177 | query.bindValue(":type", ui->typeEdit->currentIndex()); | |
178 | query.bindValue(":form", ui->formEdit->currentIndex()); | |
179 | query.bindValue(":notes", ui->notesEdit->toPlainText()); | |
180 | query.bindValue(":origin", ui->originEdit->text()); | |
181 | query.bindValue(":substitutes", ui->substitutesEdit->text()); | |
182 | query.bindValue(":always", ui->alwaysEdit->isChecked() ? 1:0); | |
183 | query.bindValue(":inventory", QString("%1").arg(ui->inventoryEdit->value(), 5, 'f', 4, '0')); | |
184 | query.bindValue(":cost", QString("%1").arg(ui->costEdit->value(), 3, 'f', 2, '0')); | |
185 | /* Uses https://www.qtcentre.org/threads/17295-How-to-put-empty-value-in-QDateEdit */ | |
186 | query.bindValue(":prod", ui->prodEdit->nullDate()); | |
187 | query.bindValue(":tht", ui->thtEdit->nullDate()); | |
188 | query.bindValue(":oil", QString("%1").arg(ui->oilEdit->value(), 2, 'f', 1, '0')); | |
189 | if (this->recno == -1) { | |
190 | query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); | |
191 | } else { | |
192 | query.bindValue(":recno", this->recno); | |
193 | } | |
194 | query.exec(); | |
195 | if (query.lastError().isValid()) { | |
196 | qDebug() << "EditHop" << query.lastError(); | |
197 | QMessageBox::warning(this, tr("Database error"), | |
198 | tr("MySQL error: %1\n%2\n%3") | |
199 | .arg(query.lastError().nativeErrorCode()) | |
200 | .arg(query.lastError().driverText()) | |
201 | .arg(query.lastError().databaseText())); | |
202 | } else { | |
203 | qDebug() << "EditHop Saved"; | |
204 | } | |
205 | } | |
206 | ||
207 | ui->saveButton->setEnabled(false); | |
208 | this->textIsChanged = false; | |
209 | WindowTitle(); | |
210 | } | |
211 | ||
212 | ||
213 | void EditHop::on_deleteButton_clicked() | |
214 | { | |
215 | QSqlQuery query; | |
216 | ||
217 | query.prepare("DELETE FROM inventory_hops WHERE record = :recno"); | |
218 | query.bindValue(":recno", this->recno); | |
219 | query.exec(); | |
220 | if (query.lastError().isValid()) { | |
221 | qDebug() << "EditHop" << query.lastError(); | |
222 | QMessageBox::warning(this, tr("Database error"), | |
223 | tr("MySQL error: %1\n%2\n%3") | |
224 | .arg(query.lastError().nativeErrorCode()) | |
225 | .arg(query.lastError().driverText()) | |
226 | .arg(query.lastError().databaseText())); | |
227 | } else { | |
228 | qDebug() << "EditHop Deleted" << this->recno; | |
229 | } | |
230 | ||
231 | this->close(); | |
232 | this->setResult(1); | |
233 | } | |
234 | ||
235 | ||
236 | void EditHop::is_changed() | |
237 | { | |
238 | ui->valueEdit->setValue(ui->inventoryEdit->value() * ui->costEdit->value()); | |
239 | ui->saveButton->setEnabled(true); | |
240 | ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && this->recno >= 0) ? true:false); | |
241 | this->textIsChanged = true; | |
242 | WindowTitle(); | |
243 | } | |
244 | ||
245 | ||
246 | void EditHop::on_quitButton_clicked() | |
247 | { | |
248 | if (this->textIsChanged) { | |
60
0d65238ebedc
Updated translations and some messages.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
249 | int rc = QMessageBox::warning(this, tr("Hop changed"), tr("This hop has been modified. Save changes?"), |
24 | 250 | QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); |
251 | switch (rc) { | |
252 | case QMessageBox::Save: | |
253 | on_saveButton_clicked(); | |
254 | break; /* Saved and then Quit */ | |
255 | case QMessageBox::Discard: | |
256 | break; /* Quit without Save */ | |
257 | case QMessageBox::Cancel: | |
258 | return; /* Return to the editor page */ | |
259 | } | |
260 | } | |
261 | ||
262 | this->close(); | |
263 | this->setResult(1); | |
264 | } | |
292
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
265 | |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
266 | |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
267 | void EditHop::prod_date_clear() |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
268 | { |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
269 | ui->prodEdit->setDate(QDate()); |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
270 | is_changed(); |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
271 | } |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
272 | |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
273 | |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
274 | void EditHop::prod_date_today() |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
275 | { |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
276 | ui->prodEdit->setDate(QDate::currentDate()); |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
277 | is_changed(); |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
278 | } |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
279 | |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
280 | |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
281 | void EditHop::tht_date_clear() |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
282 | { |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
283 | ui->thtEdit->setDate(QDate()); |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
284 | is_changed(); |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
285 | } |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
286 | |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
287 | |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
288 | void EditHop::tht_date_today() |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
289 | { |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
290 | ui->thtEdit->setDate(QDate::currentDate()); |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
291 | is_changed(); |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
292 | } |
b6ec2e275736
Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
293 |