Mon, 18 Apr 2022 20:00:49 +0200
Added calcYeast(). Added show svg from calcFermentables() on the yeast tab. Fixed wrong data displayed in the yeast table. Show estimated needed dry yeast or starters.
127 | 1 | /** |
2 | * EditRecipe.cpp is part of bmsapp. | |
3 | * | |
129
a9c19eaab018
Blocked hop table edit. Implemented add and delete hop rows. Started the ui of the water tab.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
4 | * Tab 2, fermentables |
127 | 5 | * |
6 | * bmsapp is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * bmsapp is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | ||
21 | ||
22 | bool EditRecipe::ferment_sort_test(const Fermentables &D1, const Fermentables &D2) | |
23 | { | |
24 | return (D1.f_added <= D2.f_added) && (D1.f_amount >= D2.f_amount) && (D1.f_color < D2.f_color); | |
25 | } | |
26 | ||
27 | ||
28 | void EditRecipe::to100Fermentables(int row) | |
29 | { | |
30 | if (recipe->fermentables.at(row).f_adjust_to_total_100) { | |
31 | QWidget *pWidget = new QWidget(); | |
32 | QLabel *label = new QLabel; | |
33 | label->setPixmap(QPixmap(":icons/silk/tick.png")); | |
34 | QHBoxLayout *pLayout = new QHBoxLayout(pWidget); | |
35 | pLayout->addWidget(label); | |
36 | pLayout->setAlignment(Qt::AlignCenter); | |
37 | pLayout->setContentsMargins(0, 0, 0, 0); | |
38 | pWidget->setLayout(pLayout); | |
39 | ui->fermentablesTable->setCellWidget(row, 9, pWidget); | |
40 | } else { | |
41 | ui->fermentablesTable->removeCellWidget(row, 9); | |
42 | } | |
43 | } | |
44 | ||
45 | ||
46 | void EditRecipe::refreshFermentables() | |
47 | { | |
48 | QString w; | |
49 | QWidget* pWidget; | |
50 | QHBoxLayout* pLayout; | |
51 | QTableWidgetItem *item; | |
52 | ||
53 | qDebug() << "refreshFermentables" << recipe->fermentables.size(); | |
54 | std::sort(recipe->fermentables.begin(), recipe->fermentables.end(), ferment_sort_test); | |
55 | ||
56 | /* | |
57 | * During filling the table turn off the cellChanged signal because every cell that is filled | |
58 | * triggers the cellChanged signal. The QTableWidget has no better signal to use. | |
59 | */ | |
60 | this->ignoreChanges = true; | |
61 | ||
62 | const QStringList labels({tr("Supplier"), tr("Fermentable"), tr("EBC"), tr("Type"), tr("Graintype"), tr("When"), tr("Yield"), | |
63 | tr("Amount"), tr("Procent"), tr("100%"), tr("Delete"), tr("Edit") }); | |
64 | ui->fermentablesTable->setColumnCount(12); | |
65 | ui->fermentablesTable->setColumnWidth(0, 150); /* Supplier */ | |
66 | ui->fermentablesTable->setColumnWidth(1, 225); /* Fermentable */ | |
67 | ui->fermentablesTable->setColumnWidth(2, 50); /* Color */ | |
68 | ui->fermentablesTable->setColumnWidth(3, 75); /* Type */ | |
69 | ui->fermentablesTable->setColumnWidth(4, 75); /* Graintype */ | |
70 | ui->fermentablesTable->setColumnWidth(5, 82); /* Added */ | |
71 | ui->fermentablesTable->setColumnWidth(6, 60); /* Yield */ | |
72 | ui->fermentablesTable->setColumnWidth(7, 90); /* Amount */ | |
73 | ui->fermentablesTable->setColumnWidth(8, 60); /* Procent */ | |
74 | ui->fermentablesTable->setColumnWidth(9, 50); /* 100% */ | |
75 | ui->fermentablesTable->setColumnWidth(10, 80); /* Delete */ | |
76 | ui->fermentablesTable->setColumnWidth(11, 80); /* Edit */ | |
77 | ui->fermentablesTable->setHorizontalHeaderLabels(labels); | |
78 | ui->fermentablesTable->verticalHeader()->hide(); | |
79 | ui->fermentablesTable->setRowCount(recipe->fermentables.size()); | |
80 | ||
81 | for (int i = 0; i < recipe->fermentables.size(); i++) { | |
82 | ||
83 | ui->fermentablesTable->setItem(i, 0, new QTableWidgetItem(recipe->fermentables.at(i).f_supplier)); | |
84 | ui->fermentablesTable->setItem(i, 1, new QTableWidgetItem(recipe->fermentables.at(i).f_name)); | |
85 | ||
86 | w = QString("%1").arg(recipe->fermentables.at(i).f_color, 1, 'f', 0, '0'); | |
87 | item = new QTableWidgetItem(w); | |
88 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
89 | ui->fermentablesTable->setItem(i, 2, item); | |
90 | ||
91 | item = new QTableWidgetItem(f_types[recipe->fermentables.at(i).f_type]); | |
92 | item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); | |
93 | ui->fermentablesTable->setItem(i, 3, item); | |
94 | ||
95 | item = new QTableWidgetItem(f_graintypes[recipe->fermentables.at(i).f_graintype]); | |
96 | item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); | |
97 | ui->fermentablesTable->setItem(i, 4, item); | |
98 | ||
99 | item = new QTableWidgetItem(f_added[recipe->fermentables.at(i).f_added]); | |
100 | item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); | |
101 | ui->fermentablesTable->setItem(i, 5, item); | |
102 | ||
103 | item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables.at(i).f_yield, 2, 'f', 1, '0')); | |
104 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
105 | ui->fermentablesTable->setItem(i, 6, item); | |
106 | ||
107 | item = new QTableWidgetItem(QString("%1 Kg").arg(recipe->fermentables.at(i).f_amount, 4, 'f', 3, '0')); | |
108 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
109 | ui->fermentablesTable->setItem(i, 7, item); | |
110 | ||
111 | if (recipe->fermentables.at(i).f_added < 4) { | |
112 | item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables.at(i).f_percentage, 2, 'f', 1, '0')); | |
113 | } else { | |
114 | item = new QTableWidgetItem(QString("")); // Blank for bottling and kegging. | |
115 | } | |
116 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
117 | ui->fermentablesTable->setItem(i, 8, item); | |
118 | ||
119 | to100Fermentables(i); | |
120 | ||
121 | /* Add the Delete row button */ | |
122 | pWidget = new QWidget(); | |
123 | QPushButton* btn_dele = new QPushButton(); | |
124 | btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */ | |
125 | btn_dele->setText(tr("Delete")); | |
139
f947c6988e91
Fixed complains about missing signals. Added add misc row, misc amount changed, misc time changed, misc select changed and misc instock changed. Silence false changed trigger.
Michiel Broek <mbroek@mbse.eu>
parents:
132
diff
changeset
|
126 | connect(btn_dele, SIGNAL(clicked()), this, SLOT(deleteFermentRow_clicked())); |
127 | 127 | pLayout = new QHBoxLayout(pWidget); |
128 | pLayout->addWidget(btn_dele); | |
129 | pLayout->setContentsMargins(5, 0, 5, 0); | |
130 | pWidget->setLayout(pLayout); | |
131 | ui->fermentablesTable->setCellWidget(i, 10, pWidget); | |
132 | ||
133 | pWidget = new QWidget(); | |
134 | QPushButton* btn_edit = new QPushButton(); | |
135 | btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */ | |
136 | btn_edit->setText(tr("Edit")); | |
139
f947c6988e91
Fixed complains about missing signals. Added add misc row, misc amount changed, misc time changed, misc select changed and misc instock changed. Silence false changed trigger.
Michiel Broek <mbroek@mbse.eu>
parents:
132
diff
changeset
|
137 | connect(btn_edit, SIGNAL(clicked()), this, SLOT(editFermentRow_clicked())); |
127 | 138 | pLayout = new QHBoxLayout(pWidget); |
139 | pLayout->addWidget(btn_edit); | |
140 | pLayout->setContentsMargins(5, 0, 5, 0); | |
141 | pWidget->setLayout(pLayout); | |
142 | ui->fermentablesTable->setCellWidget(i, 11, pWidget); | |
143 | } | |
144 | this->ignoreChanges = false; | |
145 | } | |
146 | ||
147 | ||
148 | void EditRecipe::calcFermentables() | |
149 | { | |
150 | int i; | |
151 | double psugar = 0, pcara = 0, d, s = 0, x, color; | |
152 | double vol = 0; // Volume sugars after boil | |
153 | double addedS = 0; // Added sugars after boil | |
154 | double addedmass = 0; // Added mass after boil | |
155 | double mvol = 0; // Mash volume | |
156 | double lintner = 0; // Total recipe lintner | |
157 | double mashkg = 0; | |
158 | double sugarsf = 0; // fermentable sugars mash + boil | |
159 | double sugarsm = 0; // fermentable sugars in mash | |
160 | double sugardensity = 1.611; // kg/l in solution | |
161 | double mashtime = 0; // Total mash time | |
162 | double mashtemp = 0; // Average mash temperature | |
163 | double mashinfuse = 0; // Mash infuse amount | |
164 | double colort = 0; // Colors srm * vol totals | |
165 | double colorh = 0; // Colors ebc * vol * kt | |
166 | double colorn = 0; // Colors ebc * pt * pct | |
167 | ||
168 | qDebug() << "calcFermentables()"; | |
169 | ||
170 | /* | |
171 | * Get average mashtemp and mashtime from the Mash schedule. | |
172 | * It is possible that the schedule is not (yet) present. | |
173 | */ | |
174 | if (recipe->mashs.size() > 0) { | |
175 | for (i = 0; i < recipe->mashs.size(); i++) { | |
176 | if (recipe->mashs.at(i).step_type == 0) // Infusion | |
177 | mashinfuse += recipe->mashs.at(i).step_infuse_amount; | |
178 | if (recipe->mashs.at(i).step_temp < 75) { // Ignore mashout | |
179 | mashtime += recipe->mashs.at(i).step_time; | |
180 | mashtemp += recipe->mashs.at(i).step_time * recipe->mashs.at(i).step_temp; | |
181 | } | |
182 | } | |
183 | mashtemp = mashtemp / mashtime; | |
184 | mvol = mashinfuse; | |
185 | qDebug() << " mash time" << mashtime << "temp" << mashtemp << "infuse" << mashinfuse; | |
186 | } else { | |
187 | qDebug() << " no mash schedule"; | |
188 | } | |
189 | ||
190 | if (recipe->fermentables.size() < 1) { | |
191 | qDebug() << " no fermentables, return."; | |
192 | recipe->est_og = 0.980; | |
193 | ui->est_ogEdit->setValue(0.980); | |
194 | ui->est_og2Edit->setValue(0.980); | |
195 | ui->est_og3Edit->setValue(0.980); | |
196 | ui->est_ogShow->setValue(0.980); | |
197 | recipe->est_color = 0; | |
198 | ui->est_colorEdit->setValue(0); | |
199 | ui->est_colorEdit->setStyleSheet(Utils::ebc_to_style(0)); | |
200 | ui->est_color2Edit->setValue(0); | |
201 | ui->est_color2Edit->setStyleSheet(Utils::ebc_to_style(0)); | |
202 | ui->est_colorShow->setValue(0); | |
203 | ui->perc_mashShow->setValue(0); | |
204 | ui->perc_sugarsShow->setValue(0); | |
205 | ui->perc_caraShow->setValue(0); | |
206 | ui->lintnerShow->setValue(0); | |
207 | recipe->est_fg = 0.980; | |
208 | ui->est_fgEdit->setValue(0.980); | |
209 | ui->est_fg3Edit->setValue(0.980); | |
210 | ui->est_fgShow->setValue(0.980); | |
211 | ui->est_abvEdit->setValue(0); | |
212 | ui->est_abv2Edit->setValue(0); | |
213 | ui->est_abvShow->setValue(0); | |
214 | recipe->est_abv = 0; | |
215 | ui->calEdit->setValue(0); | |
216 | return; | |
217 | } | |
218 | qDebug() << " adjust to 100" << recipe->fermentables_use100; | |
219 | ||
220 | for (i = 0; i < recipe->fermentables.size(); i++) { | |
221 | if (recipe->fermentables.at(i).f_type == 1 && recipe->fermentables.at(i).f_added < 4) // Sugars | |
222 | psugar += recipe->fermentables.at(i).f_percentage; | |
223 | if (recipe->fermentables.at(i).f_graintype == 2 && recipe->fermentables.at(i).f_added < 4) // Crystal/Cara | |
224 | pcara += recipe->fermentables.at(i).f_percentage; | |
225 | d = recipe->fermentables.at(i).f_amount * (recipe->fermentables.at(i).f_yield / 100) * (1 - recipe->fermentables.at(i).f_moisture / 100); | |
226 | if (recipe->fermentables.at(i).f_added == 0) { // Mash | |
227 | if (mvol > 0) { // If mash volume is known | |
228 | mvol += recipe->fermentables.at(i).f_amount * recipe->fermentables.at(i).f_moisture / 100; | |
229 | s += d; | |
230 | } | |
231 | d = ui->efficiencyEdit->value() / 100 * d; | |
232 | sugarsm += d; | |
233 | mashkg += recipe->fermentables.at(i).f_amount; | |
234 | } | |
235 | if (recipe->fermentables.at(i).f_added == 0 || recipe->fermentables.at(i).f_added == 1) // Mash or boil | |
236 | sugarsf += d; | |
237 | if (recipe->fermentables.at(i).f_added == 2 || recipe->fermentables.at(i).f_added == 3) { // Fermentation or lagering | |
238 | x = (recipe->fermentables.at(i).f_yield / 100) * (1 - recipe->fermentables.at(i).f_moisture / 100); | |
239 | addedS += recipe->fermentables.at(i).f_amount * x; | |
240 | addedmass += recipe->fermentables.at(i).f_amount; | |
241 | vol += (x * sugardensity + (1 - x) * 1) * recipe->fermentables.at(i).f_amount; | |
242 | } | |
243 | if (recipe->fermentables.at(i).f_added == 0 && | |
244 | (recipe->fermentables.at(i).f_type == 0 || recipe->fermentables.at(i).f_type == 4) && | |
245 | recipe->fermentables.at(i).f_color < 50) { | |
246 | lintner += recipe->fermentables.at(i).f_diastatic_power * recipe->fermentables.at(i).f_amount; | |
247 | } | |
248 | if (recipe->fermentables.at(i).f_added < 4) { | |
249 | colort += recipe->fermentables.at(i).f_amount * Utils::ebc_to_srm(recipe->fermentables.at(i).f_color); | |
250 | colorh += recipe->fermentables.at(i).f_amount * recipe->fermentables.at(i).f_color * Utils::get_kt(recipe->fermentables.at(i).f_color); | |
251 | colorn += (recipe->fermentables.at(i).f_percentage / 100) * recipe->fermentables.at(i).f_color; // For 8.6 Pt wort. | |
252 | } | |
253 | } | |
254 | qDebug() << " colort" << colort << "colorh" << colorh << "colorn" << colorn; | |
255 | qDebug() << " psugar" << psugar << "pcara" << pcara << "mvol" << mvol; | |
256 | qDebug() << " sugarsf" << sugarsf << "sugarsm" << sugarsm; | |
257 | ||
258 | double og = Utils::estimate_sg(sugarsf + addedS, ui->batch_sizeEdit->value()); | |
259 | qDebug() << " OG" << ui->est_ogEdit->value() << og; | |
260 | recipe->est_og = og; | |
261 | ui->est_ogEdit->setValue(og); | |
262 | ui->est_og2Edit->setValue(og); | |
263 | ui->est_og3Edit->setValue(og); | |
264 | ui->est_ogShow->setValue(og); | |
265 | ||
266 | recipe->preboil_sg = Utils::estimate_sg(sugarsm, ui->boil_sizeEdit->value()); | |
267 | qDebug() << " preboil SG" << recipe->preboil_sg; | |
268 | ||
269 | /* | |
270 | * Color of the wort | |
271 | */ | |
272 | if (ui->color_methodEdit->currentIndex() == 4) { // Naudts | |
273 | color = round(((Utils::sg_to_plato(og) / 8.6) * colorn) + (ui->boil_timeEdit->value() / 60)); | |
274 | } else if (ui->color_methodEdit->currentIndex() == 3) { // Hans Halberstadt | |
275 | double bv = 0.925; // Beer loss efficiency | |
276 | double sr = 0.95; // Mash and sparge efficiency | |
277 | color = round((4.46 * bv * sr) / ui->batch_sizeEdit->value() * colorh); | |
278 | } else { | |
279 | double cw = colort / ui->batch_sizeEdit->value() * 8.34436; | |
280 | color = Utils::kw_to_ebc(ui->color_methodEdit->currentIndex(), cw); | |
281 | } | |
282 | qDebug() << " color" << ui->est_colorEdit->value() << color << recipe->est_color; | |
283 | recipe->est_color = color; | |
284 | ui->est_colorEdit->setValue(color); | |
285 | ui->est_colorEdit->setStyleSheet(Utils::ebc_to_style(color)); | |
286 | ui->est_color2Edit->setValue(color); | |
287 | ui->est_color2Edit->setStyleSheet(Utils::ebc_to_style(color)); | |
288 | ui->est_colorShow->setValue(color); | |
289 | ||
290 | /* | |
291 | * We don't have a equipment profile in recipes, | |
292 | * so we assume a certain guessed mashtun size. | |
293 | */ | |
294 | ui->perc_mashShow->setValue(round(mashkg / (ui->boil_sizeEdit->value() / 3) * 100)); | |
295 | ui->perc_sugarsShow->setValue(round(psugar)); | |
296 | ui->perc_caraShow->setValue(round(pcara)); | |
297 | qDebug() << " lintner" << lintner << " mashkg" << mashkg << "final" << round(lintner / mashkg); | |
298 | ui->lintnerShow->setValue(round(lintner / mashkg)); | |
299 | ||
300 | /* | |
301 | * Calculate the apparant attenuation. | |
302 | */ | |
303 | double svg = 0; | |
304 | if (recipe->yeasts.size() > 0) { | |
305 | for (i = 0; i < recipe->yeasts.size(); i++) { | |
306 | if (recipe->yeasts.at(i).y_use == 0) { // Used in primary | |
307 | if (recipe->yeasts.at(i).y_attenuation > svg) | |
308 | svg = recipe->yeasts.at(i).y_attenuation; // Take the highest if multiple yeasts. | |
309 | } | |
310 | // TODO: brett or others in secondary. | |
311 | } | |
312 | qDebug() << " SVG" << svg; | |
313 | } | |
314 | if (svg == 0) | |
315 | svg = 77.0; | |
142
1caa15a0eefc
Added calcYeast(). Added show svg from calcFermentables() on the yeast tab. Fixed wrong data displayed in the yeast table. Show estimated needed dry yeast or starters.
Michiel Broek <mbroek@mbse.eu>
parents:
139
diff
changeset
|
316 | ui->est_svgEdit->setValue(svg); |
127 | 317 | |
318 | double fg; | |
319 | if (mashkg > 0 && mashinfuse > 0 && mashtime > 0 && mashtemp > 0) | |
320 | fg = Utils::estimate_fg(psugar, pcara, mashinfuse / mashkg, mashtime, mashtemp, svg, og); | |
321 | else | |
322 | fg = Utils::estimate_fg(psugar, pcara, 0, 0, 0, svg, og); | |
323 | qDebug() << " FG" << ui->est_fgEdit->value() << fg; | |
324 | recipe->est_fg = fg; | |
325 | ui->est_fgEdit->setValue(fg); | |
326 | ui->est_fg3Edit->setValue(fg); | |
327 | ui->est_fgShow->setValue(fg); | |
328 | ||
329 | double abv = Utils::abvol(og, fg); | |
330 | qDebug() << " ABV" << ui->est_abvEdit->value() << abv; | |
331 | ui->est_abvEdit->setValue(abv); | |
332 | ui->est_abv2Edit->setValue(abv); | |
333 | ui->est_abvShow->setValue(abv); | |
334 | recipe->est_abv = abv; | |
335 | ||
336 | /* | |
337 | * Calculate kilocalories/liter. Formula from brouwhulp. | |
338 | * Take the alcohol and sugar parts and then combine. | |
339 | */ | |
340 | double alc = 1881.22 * fg * (og - fg) / (1.775 - og); | |
341 | double sug = 3550 * fg * (0.1808 * og + 0.8192 * fg - 1.0004); | |
342 | ui->calEdit->setValue(round((alc + sug) / (12 * 0.0295735296))); | |
343 | } | |
344 | ||
345 | ||
139
f947c6988e91
Fixed complains about missing signals. Added add misc row, misc amount changed, misc time changed, misc select changed and misc instock changed. Silence false changed trigger.
Michiel Broek <mbroek@mbse.eu>
parents:
132
diff
changeset
|
346 | void EditRecipe::ferment_perc_mash_valueChanged(int value) |
127 | 347 | { |
348 | if (value < 90) | |
349 | ui->perc_mashShow->setStyleSheet(bar_green); | |
350 | else if (value < 100) | |
351 | ui->perc_mashShow->setStyleSheet(bar_orange); | |
352 | else | |
353 | ui->perc_mashShow->setStyleSheet(bar_red); | |
354 | } | |
355 | ||
356 | ||
139
f947c6988e91
Fixed complains about missing signals. Added add misc row, misc amount changed, misc time changed, misc select changed and misc instock changed. Silence false changed trigger.
Michiel Broek <mbroek@mbse.eu>
parents:
132
diff
changeset
|
357 | void EditRecipe::ferment_perc_sugars_valueChanged(int value) |
127 | 358 | { |
359 | if (value < 20) | |
360 | ui->perc_sugarsShow->setStyleSheet(bar_green); | |
361 | else | |
362 | ui->perc_sugarsShow->setStyleSheet(bar_red); | |
363 | } | |
364 | ||
365 | ||
139
f947c6988e91
Fixed complains about missing signals. Added add misc row, misc amount changed, misc time changed, misc select changed and misc instock changed. Silence false changed trigger.
Michiel Broek <mbroek@mbse.eu>
parents:
132
diff
changeset
|
366 | void EditRecipe::ferment_perc_cara_valueChanged(int value) |
127 | 367 | { |
368 | if (value < 25) | |
369 | ui->perc_caraShow->setStyleSheet(bar_green); | |
370 | else | |
371 | ui->perc_caraShow->setStyleSheet(bar_red); | |
372 | } | |
373 | ||
374 | ||
139
f947c6988e91
Fixed complains about missing signals. Added add misc row, misc amount changed, misc time changed, misc select changed and misc instock changed. Silence false changed trigger.
Michiel Broek <mbroek@mbse.eu>
parents:
132
diff
changeset
|
375 | void EditRecipe::ferment_lintner_valueChanged(int value) |
127 | 376 | { |
377 | if (value < 30) | |
378 | ui->lintnerShow->setStyleSheet(bar_red); | |
379 | else if (value < 40) | |
380 | ui->lintnerShow->setStyleSheet(bar_orange); | |
381 | else | |
382 | ui->lintnerShow->setStyleSheet(bar_green); | |
383 | } | |
384 | ||
385 | ||
139
f947c6988e91
Fixed complains about missing signals. Added add misc row, misc amount changed, misc time changed, misc select changed and misc instock changed. Silence false changed trigger.
Michiel Broek <mbroek@mbse.eu>
parents:
132
diff
changeset
|
386 | void EditRecipe::addFermentRow_clicked() |
127 | 387 | { |
388 | Fermentables newf; | |
389 | ||
390 | qDebug() << "Add fermentable row"; | |
391 | ||
392 | for (int i = 0; i < recipe->fermentables.size(); i++) { | |
393 | if (recipe->fermentables.at(i).f_amount == 0 && recipe->fermentables.at(i).f_color == 0) | |
394 | return; // Add only one at a time. | |
395 | } | |
396 | ||
397 | newf.f_name = "Select one"; | |
398 | newf.f_origin = ""; | |
399 | newf.f_supplier = ""; | |
400 | newf.f_amount = 0; | |
401 | newf.f_cost = 0; | |
402 | newf.f_type = 0; | |
403 | newf.f_yield = 0; | |
404 | newf.f_color = 0; | |
405 | newf.f_coarse_fine_diff = 0; | |
406 | newf.f_moisture = 0; | |
407 | newf.f_diastatic_power = 0; | |
408 | newf.f_protein = 0; | |
409 | newf.f_dissolved_protein = 0; | |
410 | newf.f_max_in_batch = 100; | |
411 | newf.f_graintype = 0; | |
412 | newf.f_added = 0; | |
413 | newf.f_recommend_mash = true; | |
414 | newf.f_add_after_boil = false; | |
415 | newf.f_adjust_to_total_100 = false; | |
416 | newf.f_percentage = 0; | |
417 | newf.f_di_ph = 0; | |
418 | newf.f_acid_to_ph_57 = 0; | |
419 | ||
420 | recipe->fermentables.append(newf); | |
421 | emit refreshAll(); | |
422 | } | |
423 | ||
424 | ||
139
f947c6988e91
Fixed complains about missing signals. Added add misc row, misc amount changed, misc time changed, misc select changed and misc instock changed. Silence false changed trigger.
Michiel Broek <mbroek@mbse.eu>
parents:
132
diff
changeset
|
425 | void EditRecipe::deleteFermentRow_clicked() |
127 | 426 | { |
427 | QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); | |
428 | int row = pb->objectName().toInt(); | |
429 | qDebug() << "Delete fermentable row" << row << recipe->fermentables.size(); | |
430 | ||
431 | if (recipe->fermentables.size() < 1) | |
432 | return; | |
433 | ||
434 | int rc = QMessageBox::warning(this, tr("Delete fermentable"), tr("Delete %1").arg(recipe->fermentables.at(row).f_name), | |
435 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No); | |
436 | if (rc == QMessageBox::No) | |
437 | return; | |
438 | ||
439 | this->ignoreChanges = true; | |
440 | recipe->fermentables.removeAt(row); | |
441 | ||
442 | /* | |
443 | * Recalculate the percentages on the rows left. | |
444 | */ | |
445 | double total = 0; | |
446 | for (int i = 0; i < recipe->fermentables.size(); i++) | |
447 | if (recipe->fermentables.at(i).f_added < 4) // Only before bottle/kegging | |
448 | total += recipe->fermentables.at(i).f_amount; | |
449 | for (int i = 0; i < recipe->fermentables.size(); i++) | |
450 | if (recipe->fermentables.at(i).f_added < 4) | |
451 | recipe->fermentables[i].f_percentage = recipe->fermentables.at(i).f_amount / total * 100; | |
452 | ||
453 | this->ignoreChanges = false; | |
132
9ede9c75cb54
Added miscs popup editor. No edit functions yet. Delete misc row added.
Michiel Broek <mbroek@mbse.eu>
parents:
129
diff
changeset
|
454 | is_changed(); |
127 | 455 | emit refreshAll(); |
456 | } | |
457 | ||
458 | ||
459 | void EditRecipe::ferment_amount_changed(double val) | |
460 | { | |
461 | QTableWidgetItem *item; | |
462 | double total = 0, perc; | |
463 | ||
464 | if (recipe->fermentables_use100) | |
465 | return; | |
466 | ||
467 | qDebug() << "ferment_amount_changed()" << recipe->fermentables_row << val; | |
468 | this->ignoreChanges = true; | |
469 | ||
470 | recipe->fermentables[recipe->fermentables_row].f_amount = val; | |
471 | item = new QTableWidgetItem(QString("%1 Kg").arg(val, 4, 'f', 3, '0')); | |
472 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
473 | ui->fermentablesTable->setItem(recipe->fermentables_row, 7, item); | |
474 | ||
475 | for (int i = 0; i < recipe->fermentables.size(); i++) | |
476 | if (recipe->fermentables.at(i).f_added < 4) // Only before bottle/kegging | |
477 | total += recipe->fermentables.at(i).f_amount; | |
478 | /* | |
479 | * Recalculate the percentages | |
480 | */ | |
481 | for (int i = 0; i < recipe->fermentables.size(); i++) { | |
482 | if (recipe->fermentables.at(i).f_added < 4) { | |
483 | perc = recipe->fermentables.at(i).f_amount / total * 100; | |
484 | recipe->fermentables[i].f_percentage = perc; | |
485 | item = new QTableWidgetItem(QString("%1%").arg(perc, 2, 'f', 1, '0')); | |
486 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
487 | ui->fermentablesTable->setItem(i, 8, item); | |
488 | if (i == recipe->fermentables_row) | |
489 | this->pctEdit->setValue(perc); | |
490 | } | |
491 | } | |
492 | this->ignoreChanges = false; | |
493 | is_changed(); | |
494 | } | |
495 | ||
496 | ||
497 | void EditRecipe::ferment_pct_changed(double val) | |
498 | { | |
499 | QTableWidgetItem *item; | |
500 | double total = 0, row100 = -1; | |
501 | ||
502 | if (! recipe->fermentables_use100) | |
503 | return; | |
504 | ||
505 | qDebug() << "ferment_pct_changed()" << recipe->fermentables_row << val; | |
506 | /* | |
507 | * Since we have arrived here, adjust_to_100 is active and | |
508 | * this is not the entry to be adjusted to 100. | |
509 | */ | |
510 | for (int i = 0; i < recipe->fermentables.size(); i++) { | |
511 | if (recipe->fermentables.at(i).f_added < 4) // Only before bottle/kegging | |
512 | total += recipe->fermentables.at(i).f_amount; | |
513 | if (recipe->fermentables.at(i).f_adjust_to_total_100) | |
514 | row100 = i; | |
515 | } | |
516 | double oldperc = recipe->fermentables.at(recipe->fermentables_row).f_percentage; | |
517 | double diffp = val - oldperc; | |
518 | double diffw = (diffp / 100) * total; | |
519 | qDebug() << "row100" << row100 << "total" << total << "diff kg" << diffw << "diff %" << diffp; | |
520 | ||
521 | this->ignoreChanges = true; | |
522 | recipe->fermentables[recipe->fermentables_row].f_percentage += diffp; | |
523 | recipe->fermentables[recipe->fermentables_row].f_amount += diffw; | |
524 | recipe->fermentables[row100].f_percentage -= diffp; | |
525 | recipe->fermentables[row100].f_amount -= diffw; | |
526 | ||
527 | item = new QTableWidgetItem(QString("%1 Kg").arg(recipe->fermentables[recipe->fermentables_row].f_amount, 4, 'f', 3, '0')); | |
528 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
529 | ui->fermentablesTable->setItem(recipe->fermentables_row, 7, item); | |
530 | this->famountEdit->setValue(recipe->fermentables[recipe->fermentables_row].f_amount); | |
531 | ||
532 | item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables[recipe->fermentables_row].f_percentage, 2, 'f', 1, '0')); | |
533 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
534 | ui->fermentablesTable->setItem(recipe->fermentables_row, 8, item); | |
535 | ||
536 | item = new QTableWidgetItem(QString("%1 Kg").arg(recipe->fermentables[row100].f_amount, 4, 'f', 3, '0')); | |
537 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
538 | ui->fermentablesTable->setItem(row100, 7, item); | |
539 | ||
540 | item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables[row100].f_percentage, 2, 'f', 1, '0')); | |
541 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
542 | ui->fermentablesTable->setItem(row100, 8, item); | |
543 | ||
544 | this->ignoreChanges = false; | |
545 | is_changed(); | |
546 | } | |
547 | ||
548 | ||
549 | void EditRecipe::ferment_to100_changed(bool val) | |
550 | { | |
551 | qDebug() << "ferment_to100_changed()" << recipe->fermentables_row << val << recipe->fermentables_use100; | |
552 | ||
553 | /* | |
554 | * Three scenario's. | |
555 | * 1. There is no fermentable selected yet, just mark it. | |
556 | * 2. There is current one is selected, deselect it. | |
557 | * 3. There is another one selected, deselect and select this one. | |
558 | */ | |
559 | if (! recipe->fermentables_use100 && val) { | |
560 | /* Scenario 1. */ | |
561 | recipe->fermentables_use100 = true; | |
562 | recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 = true; | |
563 | pctEdit->setReadOnly(false); | |
564 | famountEdit->setReadOnly(true); | |
565 | } else if (recipe->fermentables_use100 && recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 && ! val) { | |
566 | /* Scenario 2. */ | |
567 | recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 = false; | |
568 | recipe->fermentables_use100 = false; | |
569 | pctEdit->setReadOnly(true); | |
570 | famountEdit->setReadOnly(false); | |
571 | } else if (recipe->fermentables_use100 && ! recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 && val) { | |
572 | /* Scenario 3. */ | |
573 | for (int i = 0; i < recipe->fermentables.size(); i++) { | |
574 | recipe->fermentables[i].f_adjust_to_total_100 = false; | |
575 | } | |
576 | recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 = true; | |
577 | } else { | |
578 | qDebug() << "bug"; | |
579 | return; | |
580 | } | |
581 | ||
582 | this->ignoreChanges = true; | |
583 | for (int i = 0; i < recipe->fermentables.size(); i++) { | |
584 | to100Fermentables(i); | |
585 | } | |
586 | this->ignoreChanges = false; | |
587 | is_changed(); | |
588 | } | |
589 | ||
590 | void EditRecipe::ferment_select_changed(int val) | |
591 | { | |
592 | QSqlQuery query; | |
593 | bool instock = finstockEdit->isChecked(); | |
594 | QString w; | |
595 | QTableWidgetItem *item; | |
596 | ||
597 | if (val < 1) | |
598 | return; | |
599 | ||
600 | qDebug() << "ferment_select_changed()" << recipe->fermentables_row << val << instock; | |
601 | ||
602 | /* | |
603 | * Search the fermentable pointed by the index and instock flag. | |
604 | */ | |
605 | QString sql = "SELECT name,origin,supplier,cost,type,yield,color,coarse_fine_diff,moisture,diastatic_power,protein,dissolved_protein,max_in_batch," | |
606 | "graintype,recommend_mash,add_after_boil,di_ph,acid_to_ph_57 FROM inventory_fermentables "; | |
607 | if (instock) | |
608 | sql.append("WHERE inventory > 0 "); | |
609 | sql.append("ORDER BY supplier,name"); | |
610 | query.prepare(sql); | |
611 | query.exec(); | |
612 | query.first(); | |
613 | for (int i = 0; i < (val - 1); i++) { | |
614 | query.next(); | |
615 | } | |
616 | qDebug() << "found" << query.value(2).toString() << query.value(0).toString(); | |
617 | ||
618 | /* | |
619 | * Replace the fermentable record contents | |
620 | */ | |
621 | this->ignoreChanges = true; | |
622 | recipe->fermentables[recipe->fermentables_row].f_name = query.value(0).toString(); | |
623 | recipe->fermentables[recipe->fermentables_row].f_origin = query.value(1).toString(); | |
624 | recipe->fermentables[recipe->fermentables_row].f_supplier = query.value(2).toString(); | |
625 | recipe->fermentables[recipe->fermentables_row].f_cost = query.value(3).toDouble(); | |
626 | recipe->fermentables[recipe->fermentables_row].f_type = query.value(4).toInt(); | |
627 | recipe->fermentables[recipe->fermentables_row].f_yield = query.value(5).toDouble(); | |
628 | recipe->fermentables[recipe->fermentables_row].f_color = query.value(6).toDouble(); | |
629 | recipe->fermentables[recipe->fermentables_row].f_coarse_fine_diff = query.value(7).toDouble(); | |
630 | recipe->fermentables[recipe->fermentables_row].f_moisture = query.value(8).toDouble(); | |
631 | recipe->fermentables[recipe->fermentables_row].f_diastatic_power = query.value(9).toDouble(); | |
632 | recipe->fermentables[recipe->fermentables_row].f_protein = query.value(10).toDouble(); | |
633 | recipe->fermentables[recipe->fermentables_row].f_dissolved_protein = query.value(11).toDouble(); | |
634 | recipe->fermentables[recipe->fermentables_row].f_max_in_batch = query.value(12).toDouble(); | |
635 | recipe->fermentables[recipe->fermentables_row].f_graintype = query.value(13).toInt(); | |
636 | recipe->fermentables[recipe->fermentables_row].f_recommend_mash = query.value(14).toInt() ? true:false; | |
637 | recipe->fermentables[recipe->fermentables_row].f_add_after_boil = query.value(15).toInt() ? true:false; | |
638 | recipe->fermentables[recipe->fermentables_row].f_di_ph = query.value(16).toDouble(); | |
639 | recipe->fermentables[recipe->fermentables_row].f_acid_to_ph_57 = query.value(17).toDouble(); | |
640 | ||
641 | /* | |
642 | * Update the visible fields | |
643 | */ | |
644 | fnameEdit->setText(recipe->fermentables.at(recipe->fermentables_row).f_name); | |
645 | fsupplierEdit->setText(recipe->fermentables.at(recipe->fermentables_row).f_supplier); | |
646 | fmaxEdit->setValue(recipe->fermentables.at(recipe->fermentables_row).f_max_in_batch); | |
647 | ||
648 | ui->fermentablesTable->setItem(recipe->fermentables_row, 0, new QTableWidgetItem(recipe->fermentables.at(recipe->fermentables_row).f_supplier)); | |
649 | ui->fermentablesTable->setItem(recipe->fermentables_row, 1, new QTableWidgetItem(recipe->fermentables.at(recipe->fermentables_row).f_name)); | |
650 | ||
651 | w = QString("%1").arg(recipe->fermentables.at(recipe->fermentables_row).f_color, 1, 'f', 0, '0'); | |
652 | item = new QTableWidgetItem(w); | |
653 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
654 | ui->fermentablesTable->setItem(recipe->fermentables_row, 2, item); | |
655 | ||
656 | item = new QTableWidgetItem(f_types[recipe->fermentables.at(recipe->fermentables_row).f_type]); | |
657 | item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); | |
658 | ui->fermentablesTable->setItem(recipe->fermentables_row, 3, item); | |
659 | ||
660 | item = new QTableWidgetItem(f_graintypes[recipe->fermentables.at(recipe->fermentables_row).f_graintype]); | |
661 | item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); | |
662 | ui->fermentablesTable->setItem(recipe->fermentables_row, 4, item); | |
663 | ||
664 | item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables.at(recipe->fermentables_row).f_yield, 2, 'f', 1, '0')); | |
665 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
666 | ui->fermentablesTable->setItem(recipe->fermentables_row, 6, item); | |
667 | ||
668 | this->ignoreChanges = false; | |
669 | calcFermentables(); | |
670 | is_changed(); | |
671 | } | |
672 | ||
673 | ||
674 | void EditRecipe::ferment_instock_changed(bool val) | |
675 | { | |
676 | QSqlQuery query; | |
677 | ||
678 | qDebug() << "ferment_instock_changed()" << recipe->fermentables_row << val; | |
679 | ||
680 | this->fselectEdit->setCurrentIndex(-1); | |
681 | this->fselectEdit->clear(); | |
682 | QString sql = "SELECT supplier,name,color,inventory FROM inventory_fermentables "; | |
683 | if (val) | |
684 | sql.append("WHERE inventory > 0 "); | |
685 | sql.append("ORDER BY supplier,name"); | |
686 | query.prepare(sql); | |
687 | query.exec(); | |
688 | query.first(); | |
689 | this->fselectEdit->addItem(""); // Start with empty value | |
690 | for (int i = 0; i < query.size(); i++) { | |
691 | this->fselectEdit->addItem(query.value(0).toString()+" - "+query.value(1).toString()+" ("+query.value(2).toString()+" EBC) "+ | |
692 | QString("%1 kg").arg(query.value(3).toDouble(), 4, 'f', 3, '0')); | |
693 | query.next(); | |
694 | } | |
695 | } | |
696 | ||
697 | ||
698 | void EditRecipe::ferment_added_changed(int val) | |
699 | { | |
700 | qDebug() << "ferment_added_changed()" << recipe->fermentables_row << val; | |
701 | ||
702 | this->ignoreChanges = true; | |
703 | recipe->fermentables[recipe->fermentables_row].f_added = val; | |
704 | QTableWidgetItem *item = new QTableWidgetItem(f_added[val]); | |
705 | item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); | |
706 | ui->fermentablesTable->setItem(recipe->fermentables_row, 5, item); | |
707 | ||
708 | double total = 0; | |
709 | for (int i = 0; i < recipe->fermentables.size(); i++) | |
710 | if (recipe->fermentables.at(i).f_added < 4) // Only before bottle/kegging | |
711 | total += recipe->fermentables.at(i).f_amount; | |
712 | for (int i = 0; i < recipe->fermentables.size(); i++) | |
713 | if (recipe->fermentables.at(i).f_added < 4) | |
714 | recipe->fermentables[i].f_percentage = recipe->fermentables.at(i).f_amount / total * 100; | |
715 | ||
716 | this->ignoreChanges = false; | |
717 | is_changed(); | |
718 | emit refreshAll(); | |
719 | } | |
720 | ||
721 | ||
139
f947c6988e91
Fixed complains about missing signals. Added add misc row, misc amount changed, misc time changed, misc select changed and misc instock changed. Silence false changed trigger.
Michiel Broek <mbroek@mbse.eu>
parents:
132
diff
changeset
|
722 | void EditRecipe::editFermentRow_clicked() |
127 | 723 | { |
724 | QSqlQuery query; | |
725 | ||
726 | QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); | |
727 | recipe->fermentables_row = pb->objectName().toInt(); | |
728 | qDebug() << "Edit fermentable row" << recipe->fermentables_row; | |
729 | Fermentables backup = recipe->fermentables.at(recipe->fermentables_row); | |
730 | ||
731 | QDialog* dialog = new QDialog(this); | |
732 | dialog->resize(738, 287); | |
733 | QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); | |
734 | buttonBox->setObjectName(QString::fromUtf8("buttonBox")); | |
735 | buttonBox->setGeometry(QRect(30, 240, 671, 32)); | |
736 | buttonBox->setLayoutDirection(Qt::LeftToRight); | |
737 | buttonBox->setOrientation(Qt::Horizontal); | |
738 | buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); | |
739 | buttonBox->setCenterButtons(true); | |
740 | QLabel *nameLabel = new QLabel(dialog); | |
741 | nameLabel->setObjectName(QString::fromUtf8("nameLabel")); | |
742 | nameLabel->setText(tr("Current ingredient:")); | |
743 | nameLabel->setGeometry(QRect(10, 10, 141, 20)); | |
744 | nameLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); | |
745 | QLabel *supplierLabel = new QLabel(dialog); | |
746 | supplierLabel->setObjectName(QString::fromUtf8("supplierLabel")); | |
747 | supplierLabel->setText(tr("Supplier:")); | |
748 | supplierLabel->setGeometry(QRect(10, 40, 141, 20)); | |
749 | supplierLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); | |
750 | QLabel *amountLabel = new QLabel(dialog); | |
751 | amountLabel->setObjectName(QString::fromUtf8("amountLabel")); | |
752 | amountLabel->setText(tr("Amount in kg:")); | |
753 | amountLabel->setGeometry(QRect(10, 100, 141, 20)); | |
754 | amountLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); | |
755 | QLabel *pctLabel = new QLabel(dialog); | |
756 | pctLabel->setObjectName(QString::fromUtf8("pctLabel")); | |
757 | pctLabel->setText(tr("Percentage in batch:")); | |
758 | pctLabel->setGeometry(QRect(10, 130, 141, 20)); | |
759 | pctLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); | |
760 | QLabel *to100Label = new QLabel(dialog); | |
761 | to100Label->setObjectName(QString::fromUtf8("to100Label")); | |
762 | to100Label->setText(tr("Auto fill to 100%:")); | |
763 | to100Label->setGeometry(QRect(10, 160, 141, 20)); | |
764 | to100Label->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); | |
765 | QLabel *addedLabel = new QLabel(dialog); | |
766 | addedLabel->setObjectName(QString::fromUtf8("addedLabel")); | |
767 | addedLabel->setText(tr("Use at:")); | |
768 | addedLabel->setGeometry(QRect(10, 190, 141, 20)); | |
769 | addedLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); | |
770 | QLabel *selectLabel = new QLabel(dialog); | |
771 | selectLabel->setObjectName(QString::fromUtf8("selectLabel")); | |
772 | selectLabel->setText(tr("Select ingredient:")); | |
773 | selectLabel->setGeometry(QRect(10, 70, 141, 20)); | |
774 | selectLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); | |
775 | QLabel *instockLabel = new QLabel(dialog); | |
776 | instockLabel->setObjectName(QString::fromUtf8("instockLabel")); | |
777 | instockLabel->setText(tr("In stock:")); | |
778 | instockLabel->setGeometry(QRect(525, 70, 121, 20)); | |
779 | instockLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); | |
780 | QLabel *maxLabel = new QLabel(dialog); | |
781 | maxLabel->setObjectName(QString::fromUtf8("maxLabel")); | |
782 | maxLabel->setText(tr("Max in batch:")); | |
783 | maxLabel->setGeometry(QRect(420, 130, 121, 20)); | |
784 | maxLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); | |
785 | ||
786 | fselectEdit = new QComboBox(dialog); | |
787 | fselectEdit->setObjectName(QString::fromUtf8("fselectEdit")); | |
788 | fselectEdit->setGeometry(QRect(160, 70, 371, 23)); | |
789 | ||
790 | fnameEdit = new QLineEdit(dialog); | |
791 | fnameEdit->setObjectName(QString::fromUtf8("fnameEdit")); | |
792 | fnameEdit->setText(recipe->fermentables.at(recipe->fermentables_row).f_name); | |
793 | fnameEdit->setGeometry(QRect(160, 10, 511, 23)); | |
794 | fnameEdit->setReadOnly(true); | |
795 | fsupplierEdit = new QLineEdit(dialog); | |
796 | fsupplierEdit->setObjectName(QString::fromUtf8("fsupplierEdit")); | |
797 | fsupplierEdit->setText(recipe->fermentables.at(recipe->fermentables_row).f_supplier); | |
798 | fsupplierEdit->setGeometry(QRect(160, 40, 511, 23)); | |
799 | fsupplierEdit->setReadOnly(true); | |
800 | famountEdit = new QDoubleSpinBox(dialog); | |
801 | famountEdit->setObjectName(QString::fromUtf8("famountEdit")); | |
802 | famountEdit->setGeometry(QRect(160, 100, 121, 24)); | |
803 | famountEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); | |
804 | famountEdit->setAccelerated(true); | |
805 | famountEdit->setDecimals(3); | |
806 | famountEdit->setReadOnly(recipe->fermentables_use100); | |
807 | famountEdit->setMaximum(100000.0); | |
808 | famountEdit->setSingleStep(0.0010); | |
809 | famountEdit->setValue(recipe->fermentables.at(recipe->fermentables_row).f_amount); | |
810 | ||
811 | pctEdit = new QDoubleSpinBox(dialog); | |
812 | pctEdit->setObjectName(QString::fromUtf8("pctEdit")); | |
813 | pctEdit->setGeometry(QRect(160, 130, 121, 24)); | |
814 | pctEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); | |
815 | pctEdit->setAccelerated(true); | |
816 | pctEdit->setDecimals(1); | |
817 | if (recipe->fermentables_use100) { | |
818 | if (recipe->fermentables.at(recipe->fermentables_row).f_adjust_to_total_100) | |
819 | pctEdit->setReadOnly(true); | |
820 | else | |
821 | pctEdit->setReadOnly(false); | |
822 | } else { | |
823 | pctEdit->setReadOnly(true); | |
824 | } | |
825 | pctEdit->setMaximum(100.0); | |
826 | pctEdit->setSingleStep(0.1); | |
827 | pctEdit->setValue(recipe->fermentables.at(recipe->fermentables_row).f_percentage); | |
828 | ||
829 | faddedEdit = new QComboBox(dialog); | |
830 | faddedEdit->setObjectName(QString::fromUtf8("faddedEdit")); | |
831 | faddedEdit->setGeometry(QRect(160, 190, 161, 23)); | |
832 | faddedEdit->addItem(tr("Mash")); | |
833 | faddedEdit->addItem(tr("Boil")); | |
834 | faddedEdit->addItem(tr("Fermentation")); | |
835 | faddedEdit->addItem(tr("Lagering")); | |
836 | faddedEdit->addItem(tr("Bottle")); | |
837 | faddedEdit->addItem(tr("Kegs")); | |
838 | faddedEdit->setCurrentIndex(recipe->fermentables.at(recipe->fermentables_row).f_added); | |
839 | ||
840 | to100Edit = new QCheckBox(dialog); | |
841 | to100Edit->setObjectName(QString::fromUtf8("to100Edit")); | |
842 | to100Edit->setGeometry(QRect(160, 160, 85, 21)); | |
843 | to100Edit->setChecked(recipe->fermentables.at(recipe->fermentables_row).f_adjust_to_total_100); | |
844 | ||
845 | finstockEdit = new QCheckBox(dialog); | |
846 | finstockEdit->setObjectName(QString::fromUtf8("instockEdit")); | |
847 | finstockEdit->setGeometry(QRect(655, 70, 85, 21)); | |
848 | finstockEdit->setChecked(true); | |
849 | ||
850 | fmaxEdit = new QDoubleSpinBox(dialog); | |
851 | fmaxEdit->setObjectName(QString::fromUtf8("fmaxEdit")); | |
852 | fmaxEdit->setGeometry(QRect(550, 130, 121, 24)); | |
853 | fmaxEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); | |
854 | fmaxEdit->setReadOnly(true); | |
855 | fmaxEdit->setButtonSymbols(QAbstractSpinBox::NoButtons); | |
856 | fmaxEdit->setDecimals(1); | |
857 | fmaxEdit->setValue(recipe->fermentables.at(recipe->fermentables_row).f_max_in_batch); | |
858 | ||
859 | ferment_instock_changed(true); | |
860 | ||
861 | connect(fselectEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::ferment_select_changed); | |
862 | connect(famountEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::ferment_amount_changed); | |
863 | connect(pctEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::ferment_pct_changed); | |
864 | connect(faddedEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::ferment_added_changed); | |
865 | connect(to100Edit, &QCheckBox::stateChanged, this, &EditRecipe::ferment_to100_changed); | |
866 | connect(finstockEdit, &QCheckBox::stateChanged, this, &EditRecipe::ferment_instock_changed); | |
867 | connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); | |
868 | connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); | |
869 | ||
870 | dialog->setModal(true); | |
871 | dialog->exec(); | |
872 | if (dialog->result() == QDialog::Rejected) { | |
873 | qDebug() << "reject and rollback"; | |
874 | recipe->fermentables[recipe->fermentables_row] = backup; | |
875 | /* | |
876 | * Recalculate the percentages | |
877 | */ | |
878 | double total = 0; | |
879 | for (int i = 0; i < recipe->fermentables.size(); i++) | |
880 | if (recipe->fermentables.at(i).f_added < 4) // Only before bottle/kegging | |
881 | total += recipe->fermentables.at(i).f_amount; | |
882 | recipe->fermentables_use100 = false; | |
883 | for (int i = 0; i < recipe->fermentables.size(); i++) { | |
884 | if (recipe->fermentables.at(i).f_adjust_to_total_100) | |
885 | recipe->fermentables_use100 = true; | |
886 | if (recipe->fermentables.at(i).f_added < 4) { | |
887 | recipe->fermentables[i].f_percentage = recipe->fermentables.at(i).f_amount / total * 100; | |
888 | } | |
889 | } | |
890 | } | |
891 | ||
892 | disconnect(fselectEdit, nullptr, nullptr, nullptr); | |
893 | disconnect(famountEdit, nullptr, nullptr, nullptr); | |
894 | disconnect(pctEdit, nullptr, nullptr, nullptr); | |
895 | disconnect(faddedEdit, nullptr, nullptr, nullptr); | |
896 | disconnect(to100Edit, nullptr, nullptr, nullptr); | |
897 | disconnect(finstockEdit, nullptr, nullptr, nullptr); | |
898 | disconnect(buttonBox, nullptr, nullptr, nullptr); | |
899 | ||
900 | emit refreshAll(); | |
901 | } | |
902 | ||
903 |