src/EditRecipeTab5.cpp

changeset 284
33bb98c33e6a
parent 171
6cd2d808d863
child 299
8021e09ab6a3
equal deleted inserted replaced
283:242a68fa7186 284:33bb98c33e6a
18 */ 18 */
19 19
20 20
21 bool EditRecipe::yeast_sort_test(const Yeasts &D1, const Yeasts &D2) 21 bool EditRecipe::yeast_sort_test(const Yeasts &D1, const Yeasts &D2)
22 { 22 {
23 if (D1.y_use > D2.y_use) 23 if (D1.use > D2.use)
24 return false; 24 return false;
25 if (D1.y_use < D2.y_use) 25 if (D1.use < D2.use)
26 return true; 26 return true;
27 return (D1.y_amount > D2.y_amount); 27 return (D1.amount > D2.amount);
28 } 28 }
29 29
30 30
31 void EditRecipe::refreshYeasts() 31 void EditRecipe::refreshYeasts()
32 { 32 {
58 ui->yeastsTable->verticalHeader()->hide(); 58 ui->yeastsTable->verticalHeader()->hide();
59 ui->yeastsTable->setRowCount(recipe->yeasts.size()); 59 ui->yeastsTable->setRowCount(recipe->yeasts.size());
60 60
61 for (int i = 0; i < recipe->yeasts.size(); i++) { 61 for (int i = 0; i < recipe->yeasts.size(); i++) {
62 62
63 ui->yeastsTable->setItem(i, 0, new QTableWidgetItem(recipe->yeasts.at(i).y_name)); 63 ui->yeastsTable->setItem(i, 0, new QTableWidgetItem(recipe->yeasts.at(i).name));
64 ui->yeastsTable->setItem(i, 1, new QTableWidgetItem(recipe->yeasts.at(i).y_laboratory)); 64 ui->yeastsTable->setItem(i, 1, new QTableWidgetItem(recipe->yeasts.at(i).laboratory));
65 ui->yeastsTable->setItem(i, 2, new QTableWidgetItem(recipe->yeasts.at(i).y_product_id)); 65 ui->yeastsTable->setItem(i, 2, new QTableWidgetItem(recipe->yeasts.at(i).product_id));
66 66
67 item = new QTableWidgetItem(yeast_forms[recipe->yeasts.at(i).y_form]); 67 item = new QTableWidgetItem(yeast_forms[recipe->yeasts.at(i).form]);
68 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); 68 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
69 ui->yeastsTable->setItem(i, 3, item); 69 ui->yeastsTable->setItem(i, 3, item);
70 70
71 item = new QTableWidgetItem(yeast_use[recipe->yeasts.at(i).y_use]); 71 item = new QTableWidgetItem(yeast_use[recipe->yeasts.at(i).use]);
72 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); 72 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
73 ui->yeastsTable->setItem(i, 4, item); 73 ui->yeastsTable->setItem(i, 4, item);
74 74
75 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).y_min_temperature, 2, 'f', 1, '0')); 75 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).min_temperature, 2, 'f', 1, '0'));
76 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 76 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
77 ui->yeastsTable->setItem(i, 5, item); 77 ui->yeastsTable->setItem(i, 5, item);
78 78
79 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).y_max_temperature, 2, 'f', 1, '0')); 79 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).max_temperature, 2, 'f', 1, '0'));
80 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 80 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
81 ui->yeastsTable->setItem(i, 6, item); 81 ui->yeastsTable->setItem(i, 6, item);
82 82
83 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).y_tolerance, 2, 'f', 1, '0')); 83 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).tolerance, 2, 'f', 1, '0'));
84 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 84 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
85 ui->yeastsTable->setItem(i, 7, item); 85 ui->yeastsTable->setItem(i, 7, item);
86 86
87 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).y_attenuation, 2, 'f', 1, '0')); 87 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).attenuation, 2, 'f', 1, '0'));
88 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 88 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
89 ui->yeastsTable->setItem(i, 8, item); 89 ui->yeastsTable->setItem(i, 8, item);
90 90
91 if (recipe->yeasts.at(i).y_form == 0) 91 if (recipe->yeasts.at(i).form == 0)
92 item = new QTableWidgetItem(QString("%1 pack").arg(recipe->yeasts.at(i).y_amount, 1, 'f', 0, '0')); 92 item = new QTableWidgetItem(QString("%1 pack").arg(recipe->yeasts.at(i).amount, 1, 'f', 0, '0'));
93 else if (recipe->yeasts.at(i).y_form == 1) 93 else if (recipe->yeasts.at(i).form == 1)
94 item = new QTableWidgetItem(QString("%1 gr").arg(recipe->yeasts.at(i).y_amount * 1000.0, 3, 'f', 2, '0')); 94 item = new QTableWidgetItem(QString("%1 gr").arg(recipe->yeasts.at(i).amount * 1000.0, 3, 'f', 2, '0'));
95 else 95 else
96 item = new QTableWidgetItem(QString("%1 ml").arg(recipe->yeasts.at(i).y_amount * 1000.0, 3, 'f', 2, '0')); 96 item = new QTableWidgetItem(QString("%1 ml").arg(recipe->yeasts.at(i).amount * 1000.0, 3, 'f', 2, '0'));
97 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 97 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
98 ui->yeastsTable->setItem(i, 9, item); 98 ui->yeastsTable->setItem(i, 9, item);
99 99
100 pWidget = new QWidget(); 100 pWidget = new QWidget();
101 QPushButton* btn_dele = new QPushButton(); 101 QPushButton* btn_dele = new QPushButton();
139 139
140 if (recipe->yeasts.size() == 0) 140 if (recipe->yeasts.size() == 0)
141 return; // No yeast in recipe. 141 return; // No yeast in recipe.
142 142
143 for (int i = 0; i < recipe->yeasts.size(); i++) { 143 for (int i = 0; i < recipe->yeasts.size(); i++) {
144 if (recipe->yeasts.at(i).y_use == 0) { // Primary 144 if (recipe->yeasts.at(i).use == 0) { // Primary
145 if (recipe->yeasts.at(i).y_form == 1) { 145 if (recipe->yeasts.at(i).form == 1) {
146 /* 146 /*
147 * Dry yeast, build the formule with the yeast parameters. 147 * Dry yeast, build the formule with the yeast parameters.
148 * Based on https://www.lallemandbrewing.com/en/canada/brewers-corner/brewing-tools/pitching-rate-calculator/ 148 * Based on https://www.lallemandbrewing.com/en/canada/brewers-corner/brewing-tools/pitching-rate-calculator/
149 */ 149 */
150 ui->yeastProcedure->setCurrentIndex(2); 150 ui->yeastProcedure->setCurrentIndex(2);
151 ui->lo_gr_hlEdit->setValue(recipe->yeasts.at(i).y_gr_hl_lo); 151 ui->lo_gr_hlEdit->setValue(recipe->yeasts.at(i).gr_hl_lo);
152 ui->hi_gr_hlEdit->setValue(recipe->yeasts.at(i).y_gr_hl_hi); 152 ui->hi_gr_hlEdit->setValue(recipe->yeasts.at(i).gr_hl_hi);
153 ui->lo_sgEdit->setValue(recipe->yeasts.at(i).y_sg_lo); 153 ui->lo_sgEdit->setValue(recipe->yeasts.at(i).sg_lo);
154 ui->hi_sgEdit->setValue(recipe->yeasts.at(i).y_sg_hi); 154 ui->hi_sgEdit->setValue(recipe->yeasts.at(i).sg_hi);
155 double og = recipe->yeasts.at(i).y_sg_lo; 155 double og = recipe->yeasts.at(i).sg_lo;
156 double f1 = recipe->yeasts.at(i).y_gr_hl_lo / 100.0; 156 double f1 = recipe->yeasts.at(i).gr_hl_lo / 100.0;
157 double f2 = round(f1 / 5 * 1000000.0) / 1000000.0; 157 double f2 = round(f1 / 5 * 1000000.0) / 1000000.0;
158 double multiplier = (sg <= og) ? f1 : (f1 + f2 * (sg - og) / 0.008); 158 double multiplier = (sg <= og) ? f1 : (f1 + f2 * (sg - og) / 0.008);
159 qDebug() << " sg:" << sg << "og:" << og << "f1:" << f1 << "f2:" << f2 << "multiplier:" << multiplier; 159 qDebug() << " sg:" << sg << "og:" << og << "f1:" << f1 << "f2:" << f2 << "multiplier:" << multiplier;
160 double yeast_grams = round(volume * multiplier * 100.0) / 100.0; // * (100 / dataRecord.starter_viability), 2); 160 double yeast_grams = round(volume * multiplier * 100.0) / 100.0; // * (100 / dataRecord.starter_viability), 2);
161 double yeast_gr_hl = round((yeast_grams / (volume * 0.01)) * 100.0) / 100.0; 161 double yeast_gr_hl = round((yeast_grams / (volume * 0.01)) * 100.0) / 100.0;
168 * Liquid, slant, culture etc. 168 * Liquid, slant, culture etc.
169 * pitchrate see https://www.brewersfriend.com/yeast-pitch-rate-and-starter-calculator/ 169 * pitchrate see https://www.brewersfriend.com/yeast-pitch-rate-and-starter-calculator/
170 * and http://braukaiser.com/blog/blog/2012/11/03/estimating-yeast-growth/ 170 * and http://braukaiser.com/blog/blog/2012/11/03/estimating-yeast-growth/
171 */ 171 */
172 ui->yeastProcedure->setCurrentIndex(1); 172 ui->yeastProcedure->setCurrentIndex(1);
173 if (recipe->yeasts.at(i).y_type == 0) { // Lager yeast 173 if (recipe->yeasts.at(i).type == 0) { // Lager yeast
174 pitchrate = 1.5; 174 pitchrate = 1.5;
175 if (sg > 1.060) 175 if (sg > 1.060)
176 pitchrate = 2.0; 176 pitchrate = 2.0;
177 } else if (recipe->yeasts.at(i).y_type == 6) { // Real Kveik 177 } else if (recipe->yeasts.at(i).type == 6) { // Real Kveik
178 pitchrate = 0.075; 178 pitchrate = 0.075;
179 } else { 179 } else {
180 pitchrate = 0.75; 180 pitchrate = 0.75;
181 if (sg > 1.060) 181 if (sg > 1.060)
182 pitchrate = 1.0; 182 pitchrate = 1.0;
183 } 183 }
184 if (recipe->yeasts.at(i).y_form == 0) 184 if (recipe->yeasts.at(i).form == 0)
185 initcells = (recipe->yeasts.at(i).y_cells / 1000000000) * recipe->yeasts.at(i).y_amount * 0.97; // 97% viability assumed. 185 initcells = (recipe->yeasts.at(i).cells / 1000000000) * recipe->yeasts.at(i).amount * 0.97; // 97% viability assumed.
186 else 186 else
187 initcells = (recipe->yeasts.at(i).y_cells / 1000000) * recipe->yeasts.at(i).y_amount * 0.97; 187 initcells = (recipe->yeasts.at(i).cells / 1000000) * recipe->yeasts.at(i).amount * 0.97;
188 188
189 double needed = round(pitchrate * volume * plato * 10.0) / 10.0; 189 double needed = round(pitchrate * volume * plato * 10.0) / 10.0;
190 double starter = 0; 190 double starter = 0;
191 if (needed > initcells) { 191 if (needed > initcells) {
192 maybe_starter = true; 192 maybe_starter = true;
211 Yeasts newy; 211 Yeasts newy;
212 212
213 qDebug() << "Add yeast row"; 213 qDebug() << "Add yeast row";
214 214
215 for (int i = 0; i < recipe->yeasts.size(); i++) { 215 for (int i = 0; i < recipe->yeasts.size(); i++) {
216 if (recipe->yeasts.at(i).y_amount == 0) 216 if (recipe->yeasts.at(i).amount == 0)
217 return; // Add only one at a time. 217 return; // Add only one at a time.
218 } 218 }
219 219
220 newy.y_name = "Select one"; 220 newy.name = "Select one";
221 newy.y_laboratory = ""; 221 newy.laboratory = "";
222 newy.y_product_id = ""; 222 newy.product_id = "";
223 newy.y_amount = 0; 223 newy.amount = 0;
224 newy.y_type = 0; 224 newy.type = 0;
225 newy.y_form = 0; 225 newy.form = 0;
226 newy.y_min_temperature = 0; 226 newy.min_temperature = 0;
227 newy.y_max_temperature = 0; 227 newy.max_temperature = 0;
228 newy.y_flocculation = 0; 228 newy.flocculation = 0;
229 newy.y_attenuation = 0; 229 newy.attenuation = 0;
230 newy.y_cells = 0; 230 newy.cells = 0;
231 newy.y_tolerance = 0; 231 newy.tolerance = 0;
232 newy.y_inventory = 0; 232 newy.inventory = 0;
233 newy.y_use = 0; 233 newy.use = 0;
234 newy.y_sta1 = false; 234 newy.sta1 = false;
235 newy.y_bacteria = false; 235 newy.bacteria = false;
236 newy.y_harvest_top = false; 236 newy.harvest_top = false;
237 newy.y_harvest_time = 0; 237 newy.harvest_time = 0;
238 newy.y_pitch_temperature = 0; 238 newy.pitch_temperature = 0;
239 newy.y_pofpos = false; 239 newy.pofpos = false;
240 newy.y_zymocide = 0; 240 newy.zymocide = 0;
241 newy.y_gr_hl_lo = 0; 241 newy.gr_hl_lo = 0;
242 newy.y_sg_lo = 0; 242 newy.sg_lo = 0;
243 newy.y_gr_hl_hi = 0; 243 newy.gr_hl_hi = 0;
244 newy.y_sg_hi = 0; 244 newy.sg_hi = 0;
245 newy.y_cost = 0; 245 newy.cost = 0;
246 246
247 recipe->yeasts.append(newy); 247 recipe->yeasts.append(newy);
248 emit refreshAll(); 248 emit refreshAll();
249 } 249 }
250 250
256 256
257 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); 257 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
258 int row = pb->objectName().toInt(); 258 int row = pb->objectName().toInt();
259 qDebug() << "Delete yeast row" << row << recipe->yeasts.size(); 259 qDebug() << "Delete yeast row" << row << recipe->yeasts.size();
260 260
261 int rc = QMessageBox::warning(this, tr("Delete yeast"), tr("Delete %1").arg(recipe->yeasts.at(row).y_name), 261 int rc = QMessageBox::warning(this, tr("Delete yeast"), tr("Delete %1").arg(recipe->yeasts.at(row).name),
262 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); 262 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
263 if (rc == QMessageBox::No) 263 if (rc == QMessageBox::No)
264 return; 264 return;
265 265
266 recipe->yeasts.removeAt(row); 266 recipe->yeasts.removeAt(row);
273 { 273 {
274 QTableWidgetItem *item; 274 QTableWidgetItem *item;
275 275
276 qDebug() << "yeast_amount_changed()" << recipe->yeasts_row << val; 276 qDebug() << "yeast_amount_changed()" << recipe->yeasts_row << val;
277 277
278 if (recipe->yeasts.at(recipe->yeasts_row).y_form == 0) { 278 if (recipe->yeasts.at(recipe->yeasts_row).form == 0) {
279 recipe->yeasts[recipe->yeasts_row].y_amount = val; 279 recipe->yeasts[recipe->yeasts_row].amount = val;
280 item = new QTableWidgetItem(QString("%1 pack").arg(val, 1, 'f', 0, '0')); 280 item = new QTableWidgetItem(QString("%1 pack").arg(val, 1, 'f', 0, '0'));
281 } else if (recipe->yeasts.at(recipe->yeasts_row).y_form == 1) { 281 } else if (recipe->yeasts.at(recipe->yeasts_row).form == 1) {
282 recipe->yeasts[recipe->yeasts_row].y_amount = val / 1000.0; 282 recipe->yeasts[recipe->yeasts_row].amount = val / 1000.0;
283 item = new QTableWidgetItem(QString("%1 gr").arg(val, 3, 'f', 2, '0')); 283 item = new QTableWidgetItem(QString("%1 gr").arg(val, 3, 'f', 2, '0'));
284 } else { 284 } else {
285 recipe->yeasts[recipe->yeasts_row].y_amount = val / 1000.0; 285 recipe->yeasts[recipe->yeasts_row].amount = val / 1000.0;
286 item = new QTableWidgetItem(QString("%1 ml").arg(val, 3, 'f', 2, '0')); 286 item = new QTableWidgetItem(QString("%1 ml").arg(val, 3, 'f', 2, '0'));
287 } 287 }
288 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 288 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
289 ui->yeastsTable->setItem(recipe->yeasts_row, 9, item); 289 ui->yeastsTable->setItem(recipe->yeasts_row, 9, item);
290 290
308 /* 308 /*
309 * Search the yeast pointed by the index and instock flag. 309 * Search the yeast pointed by the index and instock flag.
310 */ 310 */
311 QString sql = "SELECT name,laboratory,product_id,type,form,min_temperature,max_temperature,flocculation,attenuation," 311 QString sql = "SELECT name,laboratory,product_id,type,form,min_temperature,max_temperature,flocculation,attenuation,"
312 "cells,tolerance,sta1,bacteria,harvest_top,harvest_time,pitch_temperature,pofpos,zymocide," 312 "cells,tolerance,sta1,bacteria,harvest_top,harvest_time,pitch_temperature,pofpos,zymocide,"
313 "gr_hl_lo,sg_lo,gr_hl_hi,sg_hi,cost FROM inventory_yeasts "; 313 "gr_hl_lo,sg_lo,gr_hl_hi,sg_hi,cost FROM inventoryeasts ";
314 if (instock) 314 if (instock)
315 sql.append("WHERE inventory > 0 "); 315 sql.append("WHERE inventory > 0 ");
316 sql.append("ORDER BY laboratory,product_id,name"); 316 sql.append("ORDER BY laboratory,product_id,name");
317 query.prepare(sql); 317 query.prepare(sql);
318 query.exec(); 318 query.exec();
323 qDebug() << "found" << query.value(0).toString() << query.value(2).toString(); 323 qDebug() << "found" << query.value(0).toString() << query.value(2).toString();
324 324
325 /* 325 /*
326 * Replace the yeast record contents 326 * Replace the yeast record contents
327 */ 327 */
328 recipe->yeasts[recipe->yeasts_row].y_name = query.value(0).toString(); 328 recipe->yeasts[recipe->yeasts_row].name = query.value(0).toString();
329 recipe->yeasts[recipe->yeasts_row].y_laboratory = query.value(1).toString(); 329 recipe->yeasts[recipe->yeasts_row].laboratory = query.value(1).toString();
330 recipe->yeasts[recipe->yeasts_row].y_product_id = query.value(2).toString(); 330 recipe->yeasts[recipe->yeasts_row].product_id = query.value(2).toString();
331 recipe->yeasts[recipe->yeasts_row].y_type = query.value(3).toInt(); 331 recipe->yeasts[recipe->yeasts_row].type = query.value(3).toInt();
332 recipe->yeasts[recipe->yeasts_row].y_form = query.value(4).toInt(); 332 recipe->yeasts[recipe->yeasts_row].form = query.value(4).toInt();
333 recipe->yeasts[recipe->yeasts_row].y_min_temperature = query.value(5).toDouble(); 333 recipe->yeasts[recipe->yeasts_row].min_temperature = query.value(5).toDouble();
334 recipe->yeasts[recipe->yeasts_row].y_max_temperature = query.value(6).toDouble(); 334 recipe->yeasts[recipe->yeasts_row].max_temperature = query.value(6).toDouble();
335 recipe->yeasts[recipe->yeasts_row].y_flocculation = query.value(7).toInt(); 335 recipe->yeasts[recipe->yeasts_row].flocculation = query.value(7).toInt();
336 recipe->yeasts[recipe->yeasts_row].y_attenuation = query.value(8).toDouble(); 336 recipe->yeasts[recipe->yeasts_row].attenuation = query.value(8).toDouble();
337 recipe->yeasts[recipe->yeasts_row].y_cells = query.value(9).toDouble(); 337 recipe->yeasts[recipe->yeasts_row].cells = query.value(9).toDouble();
338 recipe->yeasts[recipe->yeasts_row].y_tolerance = query.value(10).toDouble(); 338 recipe->yeasts[recipe->yeasts_row].tolerance = query.value(10).toDouble();
339 recipe->yeasts[recipe->yeasts_row].y_sta1 = query.value(11).toInt() ? true:false; 339 recipe->yeasts[recipe->yeasts_row].sta1 = query.value(11).toInt() ? true:false;
340 recipe->yeasts[recipe->yeasts_row].y_bacteria = query.value(12).toInt() ? true:false; 340 recipe->yeasts[recipe->yeasts_row].bacteria = query.value(12).toInt() ? true:false;
341 recipe->yeasts[recipe->yeasts_row].y_harvest_top = query.value(13).toInt() ? true:false; 341 recipe->yeasts[recipe->yeasts_row].harvest_top = query.value(13).toInt() ? true:false;
342 recipe->yeasts[recipe->yeasts_row].y_harvest_time = query.value(14).toInt(); 342 recipe->yeasts[recipe->yeasts_row].harvest_time = query.value(14).toInt();
343 recipe->yeasts[recipe->yeasts_row].y_pitch_temperature = query.value(15).toDouble(); 343 recipe->yeasts[recipe->yeasts_row].pitch_temperature = query.value(15).toDouble();
344 recipe->yeasts[recipe->yeasts_row].y_pofpos = query.value(16).toInt() ? true:false; 344 recipe->yeasts[recipe->yeasts_row].pofpos = query.value(16).toInt() ? true:false;
345 recipe->yeasts[recipe->yeasts_row].y_zymocide = query.value(17).toInt(); 345 recipe->yeasts[recipe->yeasts_row].zymocide = query.value(17).toInt();
346 recipe->yeasts[recipe->yeasts_row].y_gr_hl_lo = query.value(18).toInt(); 346 recipe->yeasts[recipe->yeasts_row].gr_hl_lo = query.value(18).toInt();
347 recipe->yeasts[recipe->yeasts_row].y_sg_lo = query.value(19).toDouble(); 347 recipe->yeasts[recipe->yeasts_row].sg_lo = query.value(19).toDouble();
348 recipe->yeasts[recipe->yeasts_row].y_gr_hl_hi = query.value(20).toInt(); 348 recipe->yeasts[recipe->yeasts_row].gr_hl_hi = query.value(20).toInt();
349 recipe->yeasts[recipe->yeasts_row].y_sg_hi = query.value(21).toDouble(); 349 recipe->yeasts[recipe->yeasts_row].sg_hi = query.value(21).toDouble();
350 recipe->yeasts[recipe->yeasts_row].y_cost = query.value(22).toDouble(); 350 recipe->yeasts[recipe->yeasts_row].cost = query.value(22).toDouble();
351 351
352 /* 352 /*
353 * Update the visible fields 353 * Update the visible fields
354 */ 354 */
355 ynameEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_name); 355 ynameEdit->setText(recipe->yeasts.at(recipe->yeasts_row).name);
356 ylaboratoryEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_laboratory); 356 ylaboratoryEdit->setText(recipe->yeasts.at(recipe->yeasts_row).laboratory);
357 yproduct_idEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_product_id); 357 yproduct_idEdit->setText(recipe->yeasts.at(recipe->yeasts_row).product_id);
358 if (recipe->yeasts.at(recipe->yeasts_row).y_form == 0) { 358 if (recipe->yeasts.at(recipe->yeasts_row).form == 0) {
359 yamountEdit->setDecimals(0); 359 yamountEdit->setDecimals(0);
360 yamountEdit->setSingleStep(1.0); 360 yamountEdit->setSingleStep(1.0);
361 yamountLabel->setText(tr("Total packs:")); 361 yamountLabel->setText(tr("Total packs:"));
362 } else if (recipe->yeasts.at(recipe->yeasts_row).y_form == 1) { 362 } else if (recipe->yeasts.at(recipe->yeasts_row).form == 1) {
363 yamountEdit->setDecimals(1); 363 yamountEdit->setDecimals(1);
364 yamountEdit->setSingleStep(0.5); 364 yamountEdit->setSingleStep(0.5);
365 yamountLabel->setText(tr("Amount in gr:")); 365 yamountLabel->setText(tr("Amount in gr:"));
366 } else { 366 } else {
367 yamountEdit->setDecimals(1); 367 yamountEdit->setDecimals(1);
368 yamountEdit->setSingleStep(0.5); 368 yamountEdit->setSingleStep(0.5);
369 yamountLabel->setText(tr("Amount in ml:")); 369 yamountLabel->setText(tr("Amount in ml:"));
370 } 370 }
371 371
372 ui->yeastsTable->setItem(recipe->yeasts_row, 0, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).y_name)); 372 ui->yeastsTable->setItem(recipe->yeasts_row, 0, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).name));
373 ui->yeastsTable->setItem(recipe->yeasts_row, 1, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).y_laboratory)); 373 ui->yeastsTable->setItem(recipe->yeasts_row, 1, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).laboratory));
374 ui->yeastsTable->setItem(recipe->yeasts_row, 2, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).y_product_id)); 374 ui->yeastsTable->setItem(recipe->yeasts_row, 2, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).product_id));
375 375
376 item = new QTableWidgetItem(yeast_forms[recipe->yeasts.at(recipe->yeasts_row).y_form]); 376 item = new QTableWidgetItem(yeast_forms[recipe->yeasts.at(recipe->yeasts_row).form]);
377 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); 377 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
378 ui->yeastsTable->setItem(recipe->yeasts_row, 3, item); 378 ui->yeastsTable->setItem(recipe->yeasts_row, 3, item);
379 379
380 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).y_min_temperature, 2, 'f', 1, '0')); 380 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).min_temperature, 2, 'f', 1, '0'));
381 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 381 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
382 ui->yeastsTable->setItem(recipe->yeasts_row, 5, item); 382 ui->yeastsTable->setItem(recipe->yeasts_row, 5, item);
383 383
384 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).y_max_temperature, 2, 'f', 1, '0')); 384 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).max_temperature, 2, 'f', 1, '0'));
385 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 385 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
386 ui->yeastsTable->setItem(recipe->yeasts_row, 6, item); 386 ui->yeastsTable->setItem(recipe->yeasts_row, 6, item);
387 387
388 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).y_tolerance, 2, 'f', 1, '0')); 388 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).tolerance, 2, 'f', 1, '0'));
389 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 389 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
390 ui->yeastsTable->setItem(recipe->yeasts_row, 7, item); 390 ui->yeastsTable->setItem(recipe->yeasts_row, 7, item);
391 391
392 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).y_attenuation, 2, 'f', 1, '0')); 392 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).attenuation, 2, 'f', 1, '0'));
393 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 393 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
394 ui->yeastsTable->setItem(recipe->yeasts_row, 8, item); 394 ui->yeastsTable->setItem(recipe->yeasts_row, 8, item);
395 395
396 calcYeast(); 396 calcYeast();
397 is_changed(); 397 is_changed();
404 404
405 qDebug() << "yeast_instock_changed()" << recipe->yeasts_row << val; 405 qDebug() << "yeast_instock_changed()" << recipe->yeasts_row << val;
406 406
407 this->yselectEdit->setCurrentIndex(-1); 407 this->yselectEdit->setCurrentIndex(-1);
408 this->yselectEdit->clear(); 408 this->yselectEdit->clear();
409 QString sql = "SELECT name,laboratory,product_id,inventory FROM inventory_yeasts "; 409 QString sql = "SELECT name,laboratory,product_id,inventory FROM inventoryeasts ";
410 if (val) 410 if (val)
411 sql.append("WHERE inventory > 0 "); 411 sql.append("WHERE inventory > 0 ");
412 sql.append("ORDER BY laboratory,product_id,name"); 412 sql.append("ORDER BY laboratory,product_id,name");
413 query.prepare(sql); 413 query.prepare(sql);
414 query.exec(); 414 query.exec();
424 424
425 void EditRecipe::yeast_useat_changed(int val) 425 void EditRecipe::yeast_useat_changed(int val)
426 { 426 {
427 qDebug() << "yeast_useat_changed()" << recipe->yeasts_row << val; 427 qDebug() << "yeast_useat_changed()" << recipe->yeasts_row << val;
428 428
429 recipe->yeasts[recipe->yeasts_row].y_use = val; 429 recipe->yeasts[recipe->yeasts_row].use = val;
430 QTableWidgetItem *item = new QTableWidgetItem(yeast_use[val]); 430 QTableWidgetItem *item = new QTableWidgetItem(yeast_use[val]);
431 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); 431 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
432 ui->yeastsTable->setItem(recipe->yeasts_row, 5, item); 432 ui->yeastsTable->setItem(recipe->yeasts_row, 5, item);
433 is_changed(); 433 is_changed();
434 emit refreshAll(); 434 emit refreshAll();
482 instockLabel->setText(tr("In stock:")); 482 instockLabel->setText(tr("In stock:"));
483 instockLabel->setGeometry(QRect(525,100, 121, 20)); 483 instockLabel->setGeometry(QRect(525,100, 121, 20));
484 instockLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); 484 instockLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
485 yamountLabel = new QLabel(dialog); 485 yamountLabel = new QLabel(dialog);
486 yamountLabel->setObjectName(QString::fromUtf8("amountLabel")); 486 yamountLabel->setObjectName(QString::fromUtf8("amountLabel"));
487 if (recipe->yeasts.at(recipe->yeasts_row).y_form == 0) 487 if (recipe->yeasts.at(recipe->yeasts_row).form == 0)
488 yamountLabel->setText(tr("Total packs:")); 488 yamountLabel->setText(tr("Total packs:"));
489 else if (recipe->yeasts.at(recipe->yeasts_row).y_form == 1) 489 else if (recipe->yeasts.at(recipe->yeasts_row).form == 1)
490 yamountLabel->setText(tr("Amount in gr:")); 490 yamountLabel->setText(tr("Amount in gr:"));
491 else 491 else
492 yamountLabel->setText(tr("Amount in ml:")); 492 yamountLabel->setText(tr("Amount in ml:"));
493 yamountLabel->setGeometry(QRect(10, 130, 141, 20)); 493 yamountLabel->setGeometry(QRect(10, 130, 141, 20));
494 yamountLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); 494 yamountLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
498 useatLabel->setGeometry(QRect(10, 160, 141, 20)); 498 useatLabel->setGeometry(QRect(10, 160, 141, 20));
499 useatLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); 499 useatLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
500 500
501 ynameEdit = new QLineEdit(dialog); 501 ynameEdit = new QLineEdit(dialog);
502 ynameEdit->setObjectName(QString::fromUtf8("ynameEdit")); 502 ynameEdit->setObjectName(QString::fromUtf8("ynameEdit"));
503 ynameEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_name); 503 ynameEdit->setText(recipe->yeasts.at(recipe->yeasts_row).name);
504 ynameEdit->setGeometry(QRect(160, 10, 511, 23)); 504 ynameEdit->setGeometry(QRect(160, 10, 511, 23));
505 ynameEdit->setReadOnly(true); 505 ynameEdit->setReadOnly(true);
506 ylaboratoryEdit = new QLineEdit(dialog); 506 ylaboratoryEdit = new QLineEdit(dialog);
507 ylaboratoryEdit->setObjectName(QString::fromUtf8("ylaboratoryEdit")); 507 ylaboratoryEdit->setObjectName(QString::fromUtf8("ylaboratoryEdit"));
508 ylaboratoryEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_laboratory); 508 ylaboratoryEdit->setText(recipe->yeasts.at(recipe->yeasts_row).laboratory);
509 ylaboratoryEdit->setGeometry(QRect(160, 40, 511, 23)); 509 ylaboratoryEdit->setGeometry(QRect(160, 40, 511, 23));
510 ylaboratoryEdit->setReadOnly(true); 510 ylaboratoryEdit->setReadOnly(true);
511 yproduct_idEdit = new QLineEdit(dialog); 511 yproduct_idEdit = new QLineEdit(dialog);
512 yproduct_idEdit->setObjectName(QString::fromUtf8("yproduct_idEdit")); 512 yproduct_idEdit->setObjectName(QString::fromUtf8("yproduct_idEdit"));
513 yproduct_idEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_product_id); 513 yproduct_idEdit->setText(recipe->yeasts.at(recipe->yeasts_row).product_id);
514 yproduct_idEdit->setGeometry(QRect(160, 70, 511, 23)); 514 yproduct_idEdit->setGeometry(QRect(160, 70, 511, 23));
515 yproduct_idEdit->setReadOnly(true); 515 yproduct_idEdit->setReadOnly(true);
516 yselectEdit = new QComboBox(dialog); 516 yselectEdit = new QComboBox(dialog);
517 yselectEdit->setObjectName(QString::fromUtf8("selectEdit")); 517 yselectEdit->setObjectName(QString::fromUtf8("selectEdit"));
518 yselectEdit->setGeometry(QRect(160,100, 371, 23)); 518 yselectEdit->setGeometry(QRect(160,100, 371, 23));
523 yamountEdit = new QDoubleSpinBox(dialog); 523 yamountEdit = new QDoubleSpinBox(dialog);
524 yamountEdit->setObjectName(QString::fromUtf8("yamountEdit")); 524 yamountEdit->setObjectName(QString::fromUtf8("yamountEdit"));
525 yamountEdit->setGeometry(QRect(160, 130, 121, 24)); 525 yamountEdit->setGeometry(QRect(160, 130, 121, 24));
526 yamountEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); 526 yamountEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
527 yamountEdit->setAccelerated(true); 527 yamountEdit->setAccelerated(true);
528 if (recipe->yeasts.at(recipe->yeasts_row).y_form == 0) { 528 if (recipe->yeasts.at(recipe->yeasts_row).form == 0) {
529 yamountEdit->setDecimals(0); 529 yamountEdit->setDecimals(0);
530 yamountEdit->setSingleStep(1.0); 530 yamountEdit->setSingleStep(1.0);
531 yamountEdit->setValue(recipe->yeasts.at(recipe->yeasts_row).y_amount); 531 yamountEdit->setValue(recipe->yeasts.at(recipe->yeasts_row).amount);
532 } else if (recipe->yeasts.at(recipe->yeasts_row).y_form == 1) { 532 } else if (recipe->yeasts.at(recipe->yeasts_row).form == 1) {
533 yamountEdit->setDecimals(1); 533 yamountEdit->setDecimals(1);
534 yamountEdit->setSingleStep(0.5); 534 yamountEdit->setSingleStep(0.5);
535 yamountEdit->setValue(recipe->yeasts.at(recipe->yeasts_row).y_amount * 1000.0); 535 yamountEdit->setValue(recipe->yeasts.at(recipe->yeasts_row).amount * 1000.0);
536 } else { 536 } else {
537 yamountEdit->setDecimals(1); 537 yamountEdit->setDecimals(1);
538 yamountEdit->setSingleStep(0.5); 538 yamountEdit->setSingleStep(0.5);
539 yamountEdit->setValue(recipe->yeasts.at(recipe->yeasts_row).y_amount * 1000.0); 539 yamountEdit->setValue(recipe->yeasts.at(recipe->yeasts_row).amount * 1000.0);
540 } 540 }
541 yamountEdit->setMaximum(1000000000.0); 541 yamountEdit->setMaximum(1000000000.0);
542 useatEdit = new QComboBox(dialog); 542 useatEdit = new QComboBox(dialog);
543 useatEdit->setObjectName(QString::fromUtf8("useatEdit")); 543 useatEdit->setObjectName(QString::fromUtf8("useatEdit"));
544 useatEdit->setGeometry(QRect(160, 160, 161, 23)); 544 useatEdit->setGeometry(QRect(160, 160, 161, 23));
545 useatEdit->addItem(tr("Primary")); 545 useatEdit->addItem(tr("Primary"));
546 useatEdit->addItem(tr("Secondary")); 546 useatEdit->addItem(tr("Secondary"));
547 useatEdit->addItem(tr("Tertiary")); 547 useatEdit->addItem(tr("Tertiary"));
548 useatEdit->addItem(tr("Bottle")); 548 useatEdit->addItem(tr("Bottle"));
549 useatEdit->setCurrentIndex(recipe->yeasts.at(recipe->yeasts_row).y_use); 549 useatEdit->setCurrentIndex(recipe->yeasts.at(recipe->yeasts_row).use);
550 550
551 yeast_instock_changed(true); 551 yeast_instock_changed(true);
552 552
553 connect(yselectEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::yeast_select_changed); 553 connect(yselectEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::yeast_select_changed);
554 connect(yamountEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::yeast_amount_changed); 554 connect(yamountEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::yeast_amount_changed);
582 582
583 if (recipe->yeasts.size() == 0) 583 if (recipe->yeasts.size() == 0)
584 return; 584 return;
585 585
586 for (int i = 0; i < recipe->yeasts.size(); i++) { 586 for (int i = 0; i < recipe->yeasts.size(); i++) {
587 if (recipe->yeasts.at(i).y_form == 1) { // Only adjust dry yeast 587 if (recipe->yeasts.at(i).form == 1) { // Only adjust dry yeast
588 amount = recipe->yeasts.at(i).y_amount * factor; 588 amount = recipe->yeasts.at(i).amount * factor;
589 recipe->yeasts[i].y_amount = amount; 589 recipe->yeasts[i].amount = amount;
590 } 590 }
591 } 591 }
592 } 592 }
593 593

mercurial