src/EditRecipeTab2.cpp

changeset 283
242a68fa7186
parent 229
815ee118ad49
child 284
33bb98c33e6a
equal deleted inserted replaced
282:d1d208a857b0 283:242a68fa7186
19 19
20 20
21 21
22 bool EditRecipe::ferment_sort_test(const Fermentables &D1, const Fermentables &D2) 22 bool EditRecipe::ferment_sort_test(const Fermentables &D1, const Fermentables &D2)
23 { 23 {
24 if (D1.f_added > D2.f_added) 24 if (D1.added > D2.added)
25 return false; 25 return false;
26 if (D1.f_added < D2.f_added) 26 if (D1.added < D2.added)
27 return true; 27 return true;
28 return (D1.f_amount >= D2.f_amount) && (D1.f_color < D2.f_color); 28 return (D1.amount >= D2.amount) && (D1.color < D2.color);
29 } 29 }
30 30
31 31
32 void EditRecipe::to100Fermentables(int row) 32 void EditRecipe::to100Fermentables(int row)
33 { 33 {
34 if (recipe->fermentables.at(row).f_adjust_to_total_100) { 34 if (recipe->fermentables.at(row).adjust_to_total_100) {
35 QWidget *pWidget = new QWidget(); 35 QWidget *pWidget = new QWidget();
36 QLabel *label = new QLabel; 36 QLabel *label = new QLabel;
37 label->setPixmap(QPixmap(":icons/silk/tick.png")); 37 label->setPixmap(QPixmap(":icons/silk/tick.png"));
38 QHBoxLayout *pLayout = new QHBoxLayout(pWidget); 38 QHBoxLayout *pLayout = new QHBoxLayout(pWidget);
39 pLayout->addWidget(label); 39 pLayout->addWidget(label);
76 ui->fermentablesTable->verticalHeader()->hide(); 76 ui->fermentablesTable->verticalHeader()->hide();
77 ui->fermentablesTable->setRowCount(recipe->fermentables.size()); 77 ui->fermentablesTable->setRowCount(recipe->fermentables.size());
78 78
79 for (int i = 0; i < recipe->fermentables.size(); i++) { 79 for (int i = 0; i < recipe->fermentables.size(); i++) {
80 80
81 ui->fermentablesTable->setItem(i, 0, new QTableWidgetItem(recipe->fermentables.at(i).f_supplier)); 81 ui->fermentablesTable->setItem(i, 0, new QTableWidgetItem(recipe->fermentables.at(i).supplier));
82 ui->fermentablesTable->setItem(i, 1, new QTableWidgetItem(recipe->fermentables.at(i).f_name)); 82 ui->fermentablesTable->setItem(i, 1, new QTableWidgetItem(recipe->fermentables.at(i).name));
83 83
84 w = QString("%1").arg(recipe->fermentables.at(i).f_color, 1, 'f', 0, '0'); 84 w = QString("%1").arg(recipe->fermentables.at(i).color, 1, 'f', 0, '0');
85 item = new QTableWidgetItem(w); 85 item = new QTableWidgetItem(w);
86 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 86 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
87 ui->fermentablesTable->setItem(i, 2, item); 87 ui->fermentablesTable->setItem(i, 2, item);
88 88
89 item = new QTableWidgetItem(fermentable_types[recipe->fermentables.at(i).f_type]); 89 item = new QTableWidgetItem(fermentable_types[recipe->fermentables.at(i).type]);
90 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); 90 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
91 ui->fermentablesTable->setItem(i, 3, item); 91 ui->fermentablesTable->setItem(i, 3, item);
92 92
93 item = new QTableWidgetItem(fermentable_graintypes[recipe->fermentables.at(i).f_graintype]); 93 item = new QTableWidgetItem(fermentable_graintypes[recipe->fermentables.at(i).graintype]);
94 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); 94 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
95 ui->fermentablesTable->setItem(i, 4, item); 95 ui->fermentablesTable->setItem(i, 4, item);
96 96
97 item = new QTableWidgetItem(fermentable_added[recipe->fermentables.at(i).f_added]); 97 item = new QTableWidgetItem(fermentable_added[recipe->fermentables.at(i).added]);
98 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); 98 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
99 ui->fermentablesTable->setItem(i, 5, item); 99 ui->fermentablesTable->setItem(i, 5, item);
100 100
101 item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables.at(i).f_yield, 2, 'f', 1, '0')); 101 item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables.at(i).yield, 2, 'f', 1, '0'));
102 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 102 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
103 ui->fermentablesTable->setItem(i, 6, item); 103 ui->fermentablesTable->setItem(i, 6, item);
104 104
105 item = new QTableWidgetItem(QString("%1 Kg").arg(recipe->fermentables.at(i).f_amount, 4, 'f', 3, '0')); 105 item = new QTableWidgetItem(QString("%1 Kg").arg(recipe->fermentables.at(i).amount, 4, 'f', 3, '0'));
106 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 106 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
107 ui->fermentablesTable->setItem(i, 7, item); 107 ui->fermentablesTable->setItem(i, 7, item);
108 108
109 if (recipe->fermentables.at(i).f_added < 4) { 109 if (recipe->fermentables.at(i).added < 4) {
110 item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables.at(i).f_percentage, 2, 'f', 1, '0')); 110 item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables.at(i).percentage, 2, 'f', 1, '0'));
111 } else { 111 } else {
112 item = new QTableWidgetItem(QString("")); // Blank for bottling and kegging. 112 item = new QTableWidgetItem(QString("")); // Blank for bottling and kegging.
113 } 113 }
114 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 114 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
115 ui->fermentablesTable->setItem(i, 8, item); 115 ui->fermentablesTable->setItem(i, 8, item);
217 } 217 }
218 qDebug() << " adjust to 100" << recipe->fermentables_use100; 218 qDebug() << " adjust to 100" << recipe->fermentables_use100;
219 219
220 recipe->mashs_kg = 0; 220 recipe->mashs_kg = 0;
221 for (i = 0; i < recipe->fermentables.size(); i++) { 221 for (i = 0; i < recipe->fermentables.size(); i++) {
222 if (recipe->fermentables.at(i).f_type == 1 && recipe->fermentables.at(i).f_added < 4) // Sugars 222 if (recipe->fermentables.at(i).type == 1 && recipe->fermentables.at(i).added < 4) // Sugars
223 psugar += recipe->fermentables.at(i).f_percentage; 223 psugar += recipe->fermentables.at(i).percentage;
224 if (recipe->fermentables.at(i).f_graintype == 2 && recipe->fermentables.at(i).f_added < 4) // Crystal/Cara 224 if (recipe->fermentables.at(i).graintype == 2 && recipe->fermentables.at(i).added < 4) // Crystal/Cara
225 pcara += recipe->fermentables.at(i).f_percentage; 225 pcara += recipe->fermentables.at(i).percentage;
226 d = recipe->fermentables.at(i).f_amount * (recipe->fermentables.at(i).f_yield / 100) * (1 - recipe->fermentables.at(i).f_moisture / 100); 226 d = recipe->fermentables.at(i).amount * (recipe->fermentables.at(i).yield / 100) * (1 - recipe->fermentables.at(i).moisture / 100);
227 if (recipe->fermentables.at(i).f_added == 0) { // Mash 227 if (recipe->fermentables.at(i).added == 0) { // Mash
228 if (mvol > 0) { // If mash volume is known 228 if (mvol > 0) { // If mash volume is known
229 mvol += recipe->fermentables.at(i).f_amount * recipe->fermentables.at(i).f_moisture / 100; 229 mvol += recipe->fermentables.at(i).amount * recipe->fermentables.at(i).moisture / 100;
230 s += d; 230 s += d;
231 } 231 }
232 d = ui->efficiencyEdit->value() / 100 * d; 232 d = ui->efficiencyEdit->value() / 100 * d;
233 sugarsm += d; 233 sugarsm += d;
234 recipe->mashs_kg += recipe->fermentables.at(i).f_amount; 234 recipe->mashs_kg += recipe->fermentables.at(i).amount;
235 } 235 }
236 if (recipe->fermentables.at(i).f_added == 0 || recipe->fermentables.at(i).f_added == 1) // Mash or boil 236 if (recipe->fermentables.at(i).added == 0 || recipe->fermentables.at(i).added == 1) // Mash or boil
237 sugarsf += d; 237 sugarsf += d;
238 if (recipe->fermentables.at(i).f_added == 2 || recipe->fermentables.at(i).f_added == 3) { // Fermentation or lagering 238 if (recipe->fermentables.at(i).added == 2 || recipe->fermentables.at(i).added == 3) { // Fermentation or lagering
239 x = (recipe->fermentables.at(i).f_yield / 100) * (1 - recipe->fermentables.at(i).f_moisture / 100); 239 x = (recipe->fermentables.at(i).yield / 100) * (1 - recipe->fermentables.at(i).moisture / 100);
240 addedS += recipe->fermentables.at(i).f_amount * x; 240 addedS += recipe->fermentables.at(i).amount * x;
241 addedmass += recipe->fermentables.at(i).f_amount; 241 addedmass += recipe->fermentables.at(i).amount;
242 vol += (x * sugardensity + (1 - x) * 1) * recipe->fermentables.at(i).f_amount; 242 vol += (x * sugardensity + (1 - x) * 1) * recipe->fermentables.at(i).amount;
243 } 243 }
244 if (recipe->fermentables.at(i).f_added == 0 && 244 if (recipe->fermentables.at(i).added == 0 &&
245 (recipe->fermentables.at(i).f_type == 0 || recipe->fermentables.at(i).f_type == 4) && 245 (recipe->fermentables.at(i).type == 0 || recipe->fermentables.at(i).type == 4) &&
246 recipe->fermentables.at(i).f_color < 50) { 246 recipe->fermentables.at(i).color < 50) {
247 lintner += recipe->fermentables.at(i).f_diastatic_power * recipe->fermentables.at(i).f_amount; 247 lintner += recipe->fermentables.at(i).diastatic_power * recipe->fermentables.at(i).amount;
248 } 248 }
249 if (recipe->fermentables.at(i).f_added < 4) { 249 if (recipe->fermentables.at(i).added < 4) {
250 colort += recipe->fermentables.at(i).f_amount * Utils::ebc_to_srm(recipe->fermentables.at(i).f_color); 250 colort += recipe->fermentables.at(i).amount * Utils::ebc_to_srm(recipe->fermentables.at(i).color);
251 colorh += recipe->fermentables.at(i).f_amount * recipe->fermentables.at(i).f_color * Utils::get_kt(recipe->fermentables.at(i).f_color); 251 colorh += recipe->fermentables.at(i).amount * recipe->fermentables.at(i).color * Utils::get_kt(recipe->fermentables.at(i).color);
252 colorn += (recipe->fermentables.at(i).f_percentage / 100) * recipe->fermentables.at(i).f_color; // For 8.6 Pt wort. 252 colorn += (recipe->fermentables.at(i).percentage / 100) * recipe->fermentables.at(i).color; // For 8.6 Pt wort.
253 } 253 }
254 } 254 }
255 qDebug() << " colort" << colort << "colorh" << colorh << "colorn" << colorn; 255 qDebug() << " colort" << colort << "colorh" << colorh << "colorn" << colorn;
256 qDebug() << " psugar" << psugar << "pcara" << pcara << "mvol" << mvol; 256 qDebug() << " psugar" << psugar << "pcara" << pcara << "mvol" << mvol;
257 qDebug() << " sugarsf" << sugarsf << "sugarsm" << sugarsm; 257 qDebug() << " sugarsf" << sugarsf << "sugarsm" << sugarsm;
349 ui->calEdit->setValue(round((alc + sug) / (12 * 0.0295735296))); 349 ui->calEdit->setValue(round((alc + sug) / (12 * 0.0295735296)));
350 350
351 // Bottle priming 351 // Bottle priming
352 double priming_total = 0; 352 double priming_total = 0;
353 for (i = 0; i < recipe->fermentables.size(); i++) { 353 for (i = 0; i < recipe->fermentables.size(); i++) {
354 if (recipe->fermentables.at(i).f_added == 4) { 354 if (recipe->fermentables.at(i).added == 4) {
355 priming_total += ((recipe->fermentables.at(i).f_yield / 100) * (1 - recipe->fermentables.at(i).f_moisture / 100)) * 355 priming_total += ((recipe->fermentables.at(i).yield / 100) * (1 - recipe->fermentables.at(i).moisture / 100)) *
356 recipe->fermentables.at(i).f_amount; 356 recipe->fermentables.at(i).amount;
357 qDebug() << " priming" << recipe->fermentables.at(i).f_amount << "total" << priming_total; 357 qDebug() << " priming" << recipe->fermentables.at(i).amount << "total" << priming_total;
358 } 358 }
359 } 359 }
360 double grl = priming_total * 1000.0 * (1 / recipe->batch_size); 360 double grl = priming_total * 1000.0 * (1 / recipe->batch_size);
361 double volco2 = grl * 0.510; 361 double volco2 = grl * 0.510;
362 qDebug() << " priming gr/l" << grl << "volco2" << volco2; 362 qDebug() << " priming gr/l" << grl << "volco2" << volco2;
379 double d, amount; 379 double d, amount;
380 double efficiency = recipe->efficiency; 380 double efficiency = recipe->efficiency;
381 double sug = Utils::sg_to_plato(og) * recipe->batch_size * og / 100.0; // total amount of sugars in kg. 381 double sug = Utils::sg_to_plato(og) * recipe->batch_size * og / 100.0; // total amount of sugars in kg.
382 382
383 for (i = 0; i < recipe->fermentables.size(); i++) { 383 for (i = 0; i < recipe->fermentables.size(); i++) {
384 if (recipe->fermentables.at(i).f_added < 4) { 384 if (recipe->fermentables.at(i).added < 4) {
385 d = recipe->fermentables.at(i).f_percentage / 100.0 * 385 d = recipe->fermentables.at(i).percentage / 100.0 *
386 (recipe->fermentables.at(i).f_yield / 100.0) * 386 (recipe->fermentables.at(i).yield / 100.0) *
387 (1 - recipe->fermentables.at(i).f_moisture / 100.0); 387 (1 - recipe->fermentables.at(i).moisture / 100.0);
388 if (recipe->fermentables.at(i).f_added == 0) // Mash 388 if (recipe->fermentables.at(i).added == 0) // Mash
389 d = efficiency / 100.0 * d; 389 d = efficiency / 100.0 * d;
390 tot += d; 390 tot += d;
391 } 391 }
392 } 392 }
393 if (tot) 393 if (tot)
394 totmass = round((sug / tot) * 1000.0) / 1000.0; 394 totmass = round((sug / tot) * 1000.0) / 1000.0;
395 395
396 if (totmass) { 396 if (totmass) {
397 for (i = 0; i < recipe->fermentables.size(); i++) { 397 for (i = 0; i < recipe->fermentables.size(); i++) {
398 amount = round(recipe->fermentables.at(i).f_percentage * 10.0 * totmass) / 1000.0; 398 amount = round(recipe->fermentables.at(i).percentage * 10.0 * totmass) / 1000.0;
399 recipe->fermentables[i].f_amount = amount; 399 recipe->fermentables[i].amount = amount;
400 } 400 }
401 } 401 }
402 } 402 }
403 403
404 404
473 Fermentables newf; 473 Fermentables newf;
474 474
475 qDebug() << "Add fermentable row"; 475 qDebug() << "Add fermentable row";
476 476
477 for (int i = 0; i < recipe->fermentables.size(); i++) { 477 for (int i = 0; i < recipe->fermentables.size(); i++) {
478 if (recipe->fermentables.at(i).f_amount == 0 && recipe->fermentables.at(i).f_color == 0) 478 if (recipe->fermentables.at(i).amount == 0 && recipe->fermentables.at(i).color == 0)
479 return; // Add only one at a time. 479 return; // Add only one at a time.
480 } 480 }
481 481
482 newf.f_name = "Select one"; 482 newf.name = "Select one";
483 newf.f_origin = ""; 483 newf.origin = "";
484 newf.f_supplier = ""; 484 newf.supplier = "";
485 newf.f_amount = 0; 485 newf.amount = 0;
486 newf.f_cost = 0; 486 newf.cost = 0;
487 newf.f_type = 0; 487 newf.type = 0;
488 newf.f_yield = 0; 488 newf.yield = 0;
489 newf.f_color = 0; 489 newf.color = 0;
490 newf.f_coarse_fine_diff = 0; 490 newf.coarse_fine_diff = 0;
491 newf.f_moisture = 0; 491 newf.moisture = 0;
492 newf.f_diastatic_power = 0; 492 newf.diastatic_power = 0;
493 newf.f_protein = 0; 493 newf.protein = 0;
494 newf.f_dissolved_protein = 0; 494 newf.dissolved_protein = 0;
495 newf.f_max_in_batch = 100; 495 newf.max_in_batch = 100;
496 newf.f_graintype = 0; 496 newf.graintype = 0;
497 newf.f_added = 0; 497 newf.added = 0;
498 newf.f_recommend_mash = true; 498 newf.recommend_mash = true;
499 newf.f_add_after_boil = false; 499 newf.add_after_boil = false;
500 newf.f_adjust_to_total_100 = false; 500 newf.adjust_to_total_100 = false;
501 newf.f_percentage = 0; 501 newf.percentage = 0;
502 newf.f_di_ph = 0; 502 newf.di_ph = 0;
503 newf.f_acid_to_ph_57 = 0; 503 newf.acid_to_ph_57 = 0;
504 504
505 recipe->fermentables.append(newf); 505 recipe->fermentables.append(newf);
506 emit refreshAll(); 506 emit refreshAll();
507 } 507 }
508 508
517 qDebug() << "Delete fermentable row" << row << recipe->fermentables.size(); 517 qDebug() << "Delete fermentable row" << row << recipe->fermentables.size();
518 518
519 if (recipe->fermentables.size() < 1) 519 if (recipe->fermentables.size() < 1)
520 return; 520 return;
521 521
522 int rc = QMessageBox::warning(this, tr("Delete fermentable"), tr("Delete %1").arg(recipe->fermentables.at(row).f_name), 522 int rc = QMessageBox::warning(this, tr("Delete fermentable"), tr("Delete %1").arg(recipe->fermentables.at(row).name),
523 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); 523 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
524 if (rc == QMessageBox::No) 524 if (rc == QMessageBox::No)
525 return; 525 return;
526 526
527 recipe->fermentables.removeAt(row); 527 recipe->fermentables.removeAt(row);
529 /* 529 /*
530 * Recalculate the percentages on the rows left. 530 * Recalculate the percentages on the rows left.
531 */ 531 */
532 double total = 0; 532 double total = 0;
533 for (int i = 0; i < recipe->fermentables.size(); i++) 533 for (int i = 0; i < recipe->fermentables.size(); i++)
534 if (recipe->fermentables.at(i).f_added < 4) // Only before bottle/kegging 534 if (recipe->fermentables.at(i).added < 4) // Only before bottle/kegging
535 total += recipe->fermentables.at(i).f_amount; 535 total += recipe->fermentables.at(i).amount;
536 for (int i = 0; i < recipe->fermentables.size(); i++) 536 for (int i = 0; i < recipe->fermentables.size(); i++)
537 if (recipe->fermentables.at(i).f_added < 4) 537 if (recipe->fermentables.at(i).added < 4)
538 recipe->fermentables[i].f_percentage = recipe->fermentables.at(i).f_amount / total * 100; 538 recipe->fermentables[i].percentage = recipe->fermentables.at(i).amount / total * 100;
539 539
540 is_changed(); 540 is_changed();
541 emit refreshAll(); 541 emit refreshAll();
542 } 542 }
543 543
545 void EditRecipe::ferment_amount_changed(double val) 545 void EditRecipe::ferment_amount_changed(double val)
546 { 546 {
547 QTableWidgetItem *item; 547 QTableWidgetItem *item;
548 double total = 0, perc; 548 double total = 0, perc;
549 549
550 if (recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).f_added < 4) 550 if (recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).added < 4)
551 return; 551 return;
552 552
553 qDebug() << "ferment_amount_changed()" << recipe->fermentables_row << val; 553 qDebug() << "ferment_amount_changed()" << recipe->fermentables_row << val;
554 554
555 recipe->fermentables[recipe->fermentables_row].f_amount = val; 555 recipe->fermentables[recipe->fermentables_row].amount = val;
556 item = new QTableWidgetItem(QString("%1 Kg").arg(val, 4, 'f', 3, '0')); 556 item = new QTableWidgetItem(QString("%1 Kg").arg(val, 4, 'f', 3, '0'));
557 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 557 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
558 ui->fermentablesTable->setItem(recipe->fermentables_row, 7, item); 558 ui->fermentablesTable->setItem(recipe->fermentables_row, 7, item);
559 559
560 for (int i = 0; i < recipe->fermentables.size(); i++) 560 for (int i = 0; i < recipe->fermentables.size(); i++)
561 if (recipe->fermentables.at(i).f_added < 4) // Only before bottle/kegging 561 if (recipe->fermentables.at(i).added < 4) // Only before bottle/kegging
562 total += recipe->fermentables.at(i).f_amount; 562 total += recipe->fermentables.at(i).amount;
563 /* 563 /*
564 * Recalculate the percentages 564 * Recalculate the percentages
565 */ 565 */
566 for (int i = 0; i < recipe->fermentables.size(); i++) { 566 for (int i = 0; i < recipe->fermentables.size(); i++) {
567 if (recipe->fermentables.at(i).f_added < 4) { 567 if (recipe->fermentables.at(i).added < 4) {
568 perc = recipe->fermentables.at(i).f_amount / total * 100; 568 perc = recipe->fermentables.at(i).amount / total * 100;
569 recipe->fermentables[i].f_percentage = perc; 569 recipe->fermentables[i].percentage = perc;
570 item = new QTableWidgetItem(QString("%1%").arg(perc, 2, 'f', 1, '0')); 570 item = new QTableWidgetItem(QString("%1%").arg(perc, 2, 'f', 1, '0'));
571 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 571 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
572 ui->fermentablesTable->setItem(i, 8, item); 572 ui->fermentablesTable->setItem(i, 8, item);
573 if (i == recipe->fermentables_row) 573 if (i == recipe->fermentables_row)
574 this->pctEdit->setValue(perc); 574 this->pctEdit->setValue(perc);
590 /* 590 /*
591 * Since we have arrived here, adjust_to_100 is active and 591 * Since we have arrived here, adjust_to_100 is active and
592 * this is not the entry to be adjusted to 100. 592 * this is not the entry to be adjusted to 100.
593 */ 593 */
594 for (int i = 0; i < recipe->fermentables.size(); i++) { 594 for (int i = 0; i < recipe->fermentables.size(); i++) {
595 if (recipe->fermentables.at(i).f_added < 4) // Only before bottle/kegging 595 if (recipe->fermentables.at(i).added < 4) // Only before bottle/kegging
596 total += recipe->fermentables.at(i).f_amount; 596 total += recipe->fermentables.at(i).amount;
597 if (recipe->fermentables.at(i).f_adjust_to_total_100) 597 if (recipe->fermentables.at(i).adjust_to_total_100)
598 row100 = i; 598 row100 = i;
599 } 599 }
600 double oldperc = recipe->fermentables.at(recipe->fermentables_row).f_percentage; 600 double oldperc = recipe->fermentables.at(recipe->fermentables_row).percentage;
601 double diffp = val - oldperc; 601 double diffp = val - oldperc;
602 double diffw = (diffp / 100) * total; 602 double diffw = (diffp / 100) * total;
603 qDebug() << "row100" << row100 << "total" << total << "diff kg" << diffw << "diff %" << diffp; 603 qDebug() << "row100" << row100 << "total" << total << "diff kg" << diffw << "diff %" << diffp;
604 604
605 recipe->fermentables[recipe->fermentables_row].f_percentage += diffp; 605 recipe->fermentables[recipe->fermentables_row].percentage += diffp;
606 recipe->fermentables[recipe->fermentables_row].f_amount += diffw; 606 recipe->fermentables[recipe->fermentables_row].amount += diffw;
607 recipe->fermentables[row100].f_percentage -= diffp; 607 recipe->fermentables[row100].percentage -= diffp;
608 recipe->fermentables[row100].f_amount -= diffw; 608 recipe->fermentables[row100].amount -= diffw;
609 609
610 item = new QTableWidgetItem(QString("%1 Kg").arg(recipe->fermentables[recipe->fermentables_row].f_amount, 4, 'f', 3, '0')); 610 item = new QTableWidgetItem(QString("%1 Kg").arg(recipe->fermentables[recipe->fermentables_row].amount, 4, 'f', 3, '0'));
611 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 611 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
612 ui->fermentablesTable->setItem(recipe->fermentables_row, 7, item); 612 ui->fermentablesTable->setItem(recipe->fermentables_row, 7, item);
613 this->famountEdit->setValue(recipe->fermentables[recipe->fermentables_row].f_amount); 613 this->famountEdit->setValue(recipe->fermentables[recipe->fermentables_row].amount);
614 614
615 item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables[recipe->fermentables_row].f_percentage, 2, 'f', 1, '0')); 615 item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables[recipe->fermentables_row].percentage, 2, 'f', 1, '0'));
616 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 616 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
617 ui->fermentablesTable->setItem(recipe->fermentables_row, 8, item); 617 ui->fermentablesTable->setItem(recipe->fermentables_row, 8, item);
618 618
619 item = new QTableWidgetItem(QString("%1 Kg").arg(recipe->fermentables[row100].f_amount, 4, 'f', 3, '0')); 619 item = new QTableWidgetItem(QString("%1 Kg").arg(recipe->fermentables[row100].amount, 4, 'f', 3, '0'));
620 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 620 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
621 ui->fermentablesTable->setItem(row100, 7, item); 621 ui->fermentablesTable->setItem(row100, 7, item);
622 622
623 item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables[row100].f_percentage, 2, 'f', 1, '0')); 623 item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables[row100].percentage, 2, 'f', 1, '0'));
624 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 624 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
625 ui->fermentablesTable->setItem(row100, 8, item); 625 ui->fermentablesTable->setItem(row100, 8, item);
626 626
627 is_changed(); 627 is_changed();
628 } 628 }
630 630
631 void EditRecipe::ferment_to100_changed(bool val) 631 void EditRecipe::ferment_to100_changed(bool val)
632 { 632 {
633 qDebug() << "ferment_to100_changed()" << recipe->fermentables_row << val << recipe->fermentables_use100; 633 qDebug() << "ferment_to100_changed()" << recipe->fermentables_row << val << recipe->fermentables_use100;
634 634
635 if (recipe->fermentables.at(recipe->fermentables_row).f_added >= 4) { 635 if (recipe->fermentables.at(recipe->fermentables_row).added >= 4) {
636 const QSignalBlocker blocker1(to100Edit); 636 const QSignalBlocker blocker1(to100Edit);
637 recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 = false; 637 recipe->fermentables[recipe->fermentables_row].adjust_to_total_100 = false;
638 to100Edit->setChecked(false); 638 to100Edit->setChecked(false);
639 return; 639 return;
640 } 640 }
641 641
642 /* 642 /*
646 * 3. There is another one selected, deselect and select this one. 646 * 3. There is another one selected, deselect and select this one.
647 */ 647 */
648 if (! recipe->fermentables_use100 && val) { 648 if (! recipe->fermentables_use100 && val) {
649 /* Scenario 1. */ 649 /* Scenario 1. */
650 recipe->fermentables_use100 = true; 650 recipe->fermentables_use100 = true;
651 recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 = true; 651 recipe->fermentables[recipe->fermentables_row].adjust_to_total_100 = true;
652 pctEdit->setReadOnly(false); 652 pctEdit->setReadOnly(false);
653 famountEdit->setReadOnly(true); 653 famountEdit->setReadOnly(true);
654 } else if (recipe->fermentables_use100 && recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 && ! val) { 654 } else if (recipe->fermentables_use100 && recipe->fermentables[recipe->fermentables_row].adjust_to_total_100 && ! val) {
655 /* Scenario 2. */ 655 /* Scenario 2. */
656 recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 = false; 656 recipe->fermentables[recipe->fermentables_row].adjust_to_total_100 = false;
657 recipe->fermentables_use100 = false; 657 recipe->fermentables_use100 = false;
658 pctEdit->setReadOnly(true); 658 pctEdit->setReadOnly(true);
659 famountEdit->setReadOnly(false); 659 famountEdit->setReadOnly(false);
660 } else if (recipe->fermentables_use100 && ! recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 && val) { 660 } else if (recipe->fermentables_use100 && ! recipe->fermentables[recipe->fermentables_row].adjust_to_total_100 && val) {
661 /* Scenario 3. */ 661 /* Scenario 3. */
662 for (int i = 0; i < recipe->fermentables.size(); i++) { 662 for (int i = 0; i < recipe->fermentables.size(); i++) {
663 recipe->fermentables[i].f_adjust_to_total_100 = false; 663 recipe->fermentables[i].adjust_to_total_100 = false;
664 } 664 }
665 recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 = true; 665 recipe->fermentables[recipe->fermentables_row].adjust_to_total_100 = true;
666 } else { 666 } else {
667 qDebug() << "bug"; 667 qDebug() << "bug";
668 return; 668 return;
669 } 669 }
670 670
704 qDebug() << "found" << query.value(2).toString() << query.value(0).toString(); 704 qDebug() << "found" << query.value(2).toString() << query.value(0).toString();
705 705
706 /* 706 /*
707 * Replace the fermentable record contents 707 * Replace the fermentable record contents
708 */ 708 */
709 recipe->fermentables[recipe->fermentables_row].f_name = query.value(0).toString(); 709 recipe->fermentables[recipe->fermentables_row].name = query.value(0).toString();
710 recipe->fermentables[recipe->fermentables_row].f_origin = query.value(1).toString(); 710 recipe->fermentables[recipe->fermentables_row].origin = query.value(1).toString();
711 recipe->fermentables[recipe->fermentables_row].f_supplier = query.value(2).toString(); 711 recipe->fermentables[recipe->fermentables_row].supplier = query.value(2).toString();
712 recipe->fermentables[recipe->fermentables_row].f_cost = query.value(3).toDouble(); 712 recipe->fermentables[recipe->fermentables_row].cost = query.value(3).toDouble();
713 recipe->fermentables[recipe->fermentables_row].f_type = query.value(4).toInt(); 713 recipe->fermentables[recipe->fermentables_row].type = query.value(4).toInt();
714 recipe->fermentables[recipe->fermentables_row].f_yield = query.value(5).toDouble(); 714 recipe->fermentables[recipe->fermentables_row].yield = query.value(5).toDouble();
715 recipe->fermentables[recipe->fermentables_row].f_color = query.value(6).toDouble(); 715 recipe->fermentables[recipe->fermentables_row].color = query.value(6).toDouble();
716 recipe->fermentables[recipe->fermentables_row].f_coarse_fine_diff = query.value(7).toDouble(); 716 recipe->fermentables[recipe->fermentables_row].coarse_fine_diff = query.value(7).toDouble();
717 recipe->fermentables[recipe->fermentables_row].f_moisture = query.value(8).toDouble(); 717 recipe->fermentables[recipe->fermentables_row].moisture = query.value(8).toDouble();
718 recipe->fermentables[recipe->fermentables_row].f_diastatic_power = query.value(9).toDouble(); 718 recipe->fermentables[recipe->fermentables_row].diastatic_power = query.value(9).toDouble();
719 recipe->fermentables[recipe->fermentables_row].f_protein = query.value(10).toDouble(); 719 recipe->fermentables[recipe->fermentables_row].protein = query.value(10).toDouble();
720 recipe->fermentables[recipe->fermentables_row].f_dissolved_protein = query.value(11).toDouble(); 720 recipe->fermentables[recipe->fermentables_row].dissolved_protein = query.value(11).toDouble();
721 recipe->fermentables[recipe->fermentables_row].f_max_in_batch = query.value(12).toDouble(); 721 recipe->fermentables[recipe->fermentables_row].max_in_batch = query.value(12).toDouble();
722 recipe->fermentables[recipe->fermentables_row].f_graintype = query.value(13).toInt(); 722 recipe->fermentables[recipe->fermentables_row].graintype = query.value(13).toInt();
723 recipe->fermentables[recipe->fermentables_row].f_recommend_mash = query.value(14).toInt() ? true:false; 723 recipe->fermentables[recipe->fermentables_row].recommend_mash = query.value(14).toInt() ? true:false;
724 recipe->fermentables[recipe->fermentables_row].f_add_after_boil = query.value(15).toInt() ? true:false; 724 recipe->fermentables[recipe->fermentables_row].add_after_boil = query.value(15).toInt() ? true:false;
725 recipe->fermentables[recipe->fermentables_row].f_di_ph = query.value(16).toDouble(); 725 recipe->fermentables[recipe->fermentables_row].di_ph = query.value(16).toDouble();
726 recipe->fermentables[recipe->fermentables_row].f_acid_to_ph_57 = query.value(17).toDouble(); 726 recipe->fermentables[recipe->fermentables_row].acid_to_ph_57 = query.value(17).toDouble();
727 727
728 /* 728 /*
729 * Update the visible fields 729 * Update the visible fields
730 */ 730 */
731 fnameEdit->setText(recipe->fermentables.at(recipe->fermentables_row).f_name); 731 fnameEdit->setText(recipe->fermentables.at(recipe->fermentables_row).name);
732 fsupplierEdit->setText(recipe->fermentables.at(recipe->fermentables_row).f_supplier); 732 fsupplierEdit->setText(recipe->fermentables.at(recipe->fermentables_row).supplier);
733 fmaxEdit->setValue(recipe->fermentables.at(recipe->fermentables_row).f_max_in_batch); 733 fmaxEdit->setValue(recipe->fermentables.at(recipe->fermentables_row).max_in_batch);
734 734
735 ui->fermentablesTable->setItem(recipe->fermentables_row, 0, new QTableWidgetItem(recipe->fermentables.at(recipe->fermentables_row).f_supplier)); 735 ui->fermentablesTable->setItem(recipe->fermentables_row, 0, new QTableWidgetItem(recipe->fermentables.at(recipe->fermentables_row).supplier));
736 ui->fermentablesTable->setItem(recipe->fermentables_row, 1, new QTableWidgetItem(recipe->fermentables.at(recipe->fermentables_row).f_name)); 736 ui->fermentablesTable->setItem(recipe->fermentables_row, 1, new QTableWidgetItem(recipe->fermentables.at(recipe->fermentables_row).name));
737 737
738 w = QString("%1").arg(recipe->fermentables.at(recipe->fermentables_row).f_color, 1, 'f', 0, '0'); 738 w = QString("%1").arg(recipe->fermentables.at(recipe->fermentables_row).color, 1, 'f', 0, '0');
739 item = new QTableWidgetItem(w); 739 item = new QTableWidgetItem(w);
740 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 740 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
741 ui->fermentablesTable->setItem(recipe->fermentables_row, 2, item); 741 ui->fermentablesTable->setItem(recipe->fermentables_row, 2, item);
742 742
743 item = new QTableWidgetItem(fermentable_types[recipe->fermentables.at(recipe->fermentables_row).f_type]); 743 item = new QTableWidgetItem(fermentable_types[recipe->fermentables.at(recipe->fermentables_row).type]);
744 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); 744 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
745 ui->fermentablesTable->setItem(recipe->fermentables_row, 3, item); 745 ui->fermentablesTable->setItem(recipe->fermentables_row, 3, item);
746 746
747 item = new QTableWidgetItem(fermentable_graintypes[recipe->fermentables.at(recipe->fermentables_row).f_graintype]); 747 item = new QTableWidgetItem(fermentable_graintypes[recipe->fermentables.at(recipe->fermentables_row).graintype]);
748 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); 748 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
749 ui->fermentablesTable->setItem(recipe->fermentables_row, 4, item); 749 ui->fermentablesTable->setItem(recipe->fermentables_row, 4, item);
750 750
751 item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables.at(recipe->fermentables_row).f_yield, 2, 'f', 1, '0')); 751 item = new QTableWidgetItem(QString("%1%").arg(recipe->fermentables.at(recipe->fermentables_row).yield, 2, 'f', 1, '0'));
752 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 752 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
753 ui->fermentablesTable->setItem(recipe->fermentables_row, 6, item); 753 ui->fermentablesTable->setItem(recipe->fermentables_row, 6, item);
754 754
755 calcFermentables(); 755 calcFermentables();
756 is_changed(); 756 is_changed();
783 783
784 void EditRecipe::ferment_added_changed(int val) 784 void EditRecipe::ferment_added_changed(int val)
785 { 785 {
786 qDebug() << "ferment_added_changed()" << recipe->fermentables_row << val; 786 qDebug() << "ferment_added_changed()" << recipe->fermentables_row << val;
787 787
788 recipe->fermentables[recipe->fermentables_row].f_added = val; 788 recipe->fermentables[recipe->fermentables_row].added = val;
789 QTableWidgetItem *item = new QTableWidgetItem(fermentable_added[val]); 789 QTableWidgetItem *item = new QTableWidgetItem(fermentable_added[val]);
790 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); 790 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
791 ui->fermentablesTable->setItem(recipe->fermentables_row, 5, item); 791 ui->fermentablesTable->setItem(recipe->fermentables_row, 5, item);
792 792
793 famountEdit->setReadOnly(recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).f_added < 4); 793 famountEdit->setReadOnly(recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).added < 4);
794 pctEdit->setReadOnly(! (recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).f_added < 4)); 794 pctEdit->setReadOnly(! (recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).added < 4));
795 795
796 double total = 0; 796 double total = 0;
797 for (int i = 0; i < recipe->fermentables.size(); i++) 797 for (int i = 0; i < recipe->fermentables.size(); i++)
798 if (recipe->fermentables.at(i).f_added < 4) // Only before bottle/kegging 798 if (recipe->fermentables.at(i).added < 4) // Only before bottle/kegging
799 total += recipe->fermentables.at(i).f_amount; 799 total += recipe->fermentables.at(i).amount;
800 for (int i = 0; i < recipe->fermentables.size(); i++) 800 for (int i = 0; i < recipe->fermentables.size(); i++)
801 if (recipe->fermentables.at(i).f_added < 4) 801 if (recipe->fermentables.at(i).added < 4)
802 recipe->fermentables[i].f_percentage = recipe->fermentables.at(i).f_amount / total * 100; 802 recipe->fermentables[i].percentage = recipe->fermentables.at(i).amount / total * 100;
803 803
804 is_changed(); 804 is_changed();
805 emit refreshAll(); 805 emit refreshAll();
806 } 806 }
807 807
877 fselectEdit->setObjectName(QString::fromUtf8("fselectEdit")); 877 fselectEdit->setObjectName(QString::fromUtf8("fselectEdit"));
878 fselectEdit->setGeometry(QRect(160, 70, 371, 23)); 878 fselectEdit->setGeometry(QRect(160, 70, 371, 23));
879 879
880 fnameEdit = new QLineEdit(dialog); 880 fnameEdit = new QLineEdit(dialog);
881 fnameEdit->setObjectName(QString::fromUtf8("fnameEdit")); 881 fnameEdit->setObjectName(QString::fromUtf8("fnameEdit"));
882 fnameEdit->setText(recipe->fermentables.at(recipe->fermentables_row).f_name); 882 fnameEdit->setText(recipe->fermentables.at(recipe->fermentables_row).name);
883 fnameEdit->setGeometry(QRect(160, 10, 511, 23)); 883 fnameEdit->setGeometry(QRect(160, 10, 511, 23));
884 fnameEdit->setReadOnly(true); 884 fnameEdit->setReadOnly(true);
885 fsupplierEdit = new QLineEdit(dialog); 885 fsupplierEdit = new QLineEdit(dialog);
886 fsupplierEdit->setObjectName(QString::fromUtf8("fsupplierEdit")); 886 fsupplierEdit->setObjectName(QString::fromUtf8("fsupplierEdit"));
887 fsupplierEdit->setText(recipe->fermentables.at(recipe->fermentables_row).f_supplier); 887 fsupplierEdit->setText(recipe->fermentables.at(recipe->fermentables_row).supplier);
888 fsupplierEdit->setGeometry(QRect(160, 40, 511, 23)); 888 fsupplierEdit->setGeometry(QRect(160, 40, 511, 23));
889 fsupplierEdit->setReadOnly(true); 889 fsupplierEdit->setReadOnly(true);
890 famountEdit = new QDoubleSpinBox(dialog); 890 famountEdit = new QDoubleSpinBox(dialog);
891 famountEdit->setObjectName(QString::fromUtf8("famountEdit")); 891 famountEdit->setObjectName(QString::fromUtf8("famountEdit"));
892 famountEdit->setGeometry(QRect(160, 100, 121, 24)); 892 famountEdit->setGeometry(QRect(160, 100, 121, 24));
893 famountEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); 893 famountEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
894 famountEdit->setAccelerated(true); 894 famountEdit->setAccelerated(true);
895 famountEdit->setDecimals(3); 895 famountEdit->setDecimals(3);
896 famountEdit->setReadOnly(recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).f_added < 4); 896 famountEdit->setReadOnly(recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).added < 4);
897 famountEdit->setMaximum(100000.0); 897 famountEdit->setMaximum(100000.0);
898 famountEdit->setSingleStep(0.0010); 898 famountEdit->setSingleStep(0.0010);
899 famountEdit->setValue(recipe->fermentables.at(recipe->fermentables_row).f_amount); 899 famountEdit->setValue(recipe->fermentables.at(recipe->fermentables_row).amount);
900 900
901 pctEdit = new QDoubleSpinBox(dialog); 901 pctEdit = new QDoubleSpinBox(dialog);
902 pctEdit->setObjectName(QString::fromUtf8("pctEdit")); 902 pctEdit->setObjectName(QString::fromUtf8("pctEdit"));
903 pctEdit->setGeometry(QRect(160, 130, 121, 24)); 903 pctEdit->setGeometry(QRect(160, 130, 121, 24));
904 pctEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); 904 pctEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
905 pctEdit->setAccelerated(true); 905 pctEdit->setAccelerated(true);
906 pctEdit->setDecimals(1); 906 pctEdit->setDecimals(1);
907 if (recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).f_added < 4) { 907 if (recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).added < 4) {
908 if (recipe->fermentables.at(recipe->fermentables_row).f_adjust_to_total_100) 908 if (recipe->fermentables.at(recipe->fermentables_row).adjust_to_total_100)
909 pctEdit->setReadOnly(true); 909 pctEdit->setReadOnly(true);
910 else 910 else
911 pctEdit->setReadOnly(false); 911 pctEdit->setReadOnly(false);
912 } else { 912 } else {
913 pctEdit->setReadOnly(true); 913 pctEdit->setReadOnly(true);
914 } 914 }
915 pctEdit->setMaximum(100.0); 915 pctEdit->setMaximum(100.0);
916 pctEdit->setSingleStep(0.1); 916 pctEdit->setSingleStep(0.1);
917 pctEdit->setValue(recipe->fermentables.at(recipe->fermentables_row).f_percentage); 917 pctEdit->setValue(recipe->fermentables.at(recipe->fermentables_row).percentage);
918 918
919 faddedEdit = new QComboBox(dialog); 919 faddedEdit = new QComboBox(dialog);
920 faddedEdit->setObjectName(QString::fromUtf8("faddedEdit")); 920 faddedEdit->setObjectName(QString::fromUtf8("faddedEdit"));
921 faddedEdit->setGeometry(QRect(160, 190, 161, 23)); 921 faddedEdit->setGeometry(QRect(160, 190, 161, 23));
922 faddedEdit->addItem(tr("Mash")); 922 faddedEdit->addItem(tr("Mash"));
923 faddedEdit->addItem(tr("Boil")); 923 faddedEdit->addItem(tr("Boil"));
924 faddedEdit->addItem(tr("Fermentation")); 924 faddedEdit->addItem(tr("Fermentation"));
925 faddedEdit->addItem(tr("Lagering")); 925 faddedEdit->addItem(tr("Lagering"));
926 faddedEdit->addItem(tr("Bottle")); 926 faddedEdit->addItem(tr("Bottle"));
927 faddedEdit->addItem(tr("Kegs")); 927 faddedEdit->addItem(tr("Kegs"));
928 faddedEdit->setCurrentIndex(recipe->fermentables.at(recipe->fermentables_row).f_added); 928 faddedEdit->setCurrentIndex(recipe->fermentables.at(recipe->fermentables_row).added);
929 929
930 to100Edit = new QCheckBox(dialog); 930 to100Edit = new QCheckBox(dialog);
931 to100Edit->setObjectName(QString::fromUtf8("to100Edit")); 931 to100Edit->setObjectName(QString::fromUtf8("to100Edit"));
932 to100Edit->setGeometry(QRect(160, 160, 85, 21)); 932 to100Edit->setGeometry(QRect(160, 160, 85, 21));
933 to100Edit->setChecked(recipe->fermentables.at(recipe->fermentables_row).f_adjust_to_total_100); 933 to100Edit->setChecked(recipe->fermentables.at(recipe->fermentables_row).adjust_to_total_100);
934 934
935 finstockEdit = new QCheckBox(dialog); 935 finstockEdit = new QCheckBox(dialog);
936 finstockEdit->setObjectName(QString::fromUtf8("instockEdit")); 936 finstockEdit->setObjectName(QString::fromUtf8("instockEdit"));
937 finstockEdit->setGeometry(QRect(655, 70, 85, 21)); 937 finstockEdit->setGeometry(QRect(655, 70, 85, 21));
938 finstockEdit->setChecked(true); 938 finstockEdit->setChecked(true);
942 fmaxEdit->setGeometry(QRect(550, 130, 121, 24)); 942 fmaxEdit->setGeometry(QRect(550, 130, 121, 24));
943 fmaxEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); 943 fmaxEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
944 fmaxEdit->setReadOnly(true); 944 fmaxEdit->setReadOnly(true);
945 fmaxEdit->setButtonSymbols(QAbstractSpinBox::NoButtons); 945 fmaxEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
946 fmaxEdit->setDecimals(1); 946 fmaxEdit->setDecimals(1);
947 fmaxEdit->setValue(recipe->fermentables.at(recipe->fermentables_row).f_max_in_batch); 947 fmaxEdit->setValue(recipe->fermentables.at(recipe->fermentables_row).max_in_batch);
948 948
949 ferment_instock_changed(true); 949 ferment_instock_changed(true);
950 950
951 connect(fselectEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::ferment_select_changed); 951 connect(fselectEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::ferment_select_changed);
952 connect(famountEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::ferment_amount_changed); 952 connect(famountEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::ferment_amount_changed);
965 /* 965 /*
966 * Recalculate the percentages 966 * Recalculate the percentages
967 */ 967 */
968 double total = 0; 968 double total = 0;
969 for (int i = 0; i < recipe->fermentables.size(); i++) 969 for (int i = 0; i < recipe->fermentables.size(); i++)
970 if (recipe->fermentables.at(i).f_added < 4) // Only before bottle/kegging 970 if (recipe->fermentables.at(i).added < 4) // Only before bottle/kegging
971 total += recipe->fermentables.at(i).f_amount; 971 total += recipe->fermentables.at(i).amount;
972 recipe->fermentables_use100 = false; 972 recipe->fermentables_use100 = false;
973 for (int i = 0; i < recipe->fermentables.size(); i++) { 973 for (int i = 0; i < recipe->fermentables.size(); i++) {
974 if (recipe->fermentables.at(i).f_adjust_to_total_100) 974 if (recipe->fermentables.at(i).adjust_to_total_100)
975 recipe->fermentables_use100 = true; 975 recipe->fermentables_use100 = true;
976 if (recipe->fermentables.at(i).f_added < 4) { 976 if (recipe->fermentables.at(i).added < 4) {
977 recipe->fermentables[i].f_percentage = recipe->fermentables.at(i).f_amount / total * 100; 977 recipe->fermentables[i].percentage = recipe->fermentables.at(i).amount / total * 100;
978 } 978 }
979 } 979 }
980 } 980 }
981 981
982 disconnect(fselectEdit, nullptr, nullptr, nullptr); 982 disconnect(fselectEdit, nullptr, nullptr, nullptr);

mercurial