src/EditProduct.cpp

changeset 529
7c9fb24bcc07
parent 527
84091b9cb800
child 530
a4d5daae8389
equal deleted inserted replaced
528:50b057ae50aa 529:7c9fb24bcc07
31 31
32 EditProduct::EditProduct(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditProduct) 32 EditProduct::EditProduct(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditProduct)
33 { 33 {
34 QSqlQuery query, wquery, yquery; 34 QSqlQuery query, wquery, yquery;
35 35
36 qDebug() << "EditProduct record:" << id;
37 product = new Product; 36 product = new Product;
38 ui->setupUi(this); 37 ui->setupUi(this);
39 product->fermentables_row = product->hops_row = product->miscs_row = product->yeasts_row = product->mashs_row = -1; 38 product->fermentables_row = product->hops_row = product->miscs_row = product->yeasts_row = product->mashs_row = -1;
40 product->fermentables_use100 = false; 39 product->fermentables_use100 = false;
41 product->boil_absorb = product->ferment_absorb = 0; 40 product->boil_absorb = product->ferment_absorb = 0;
183 product->eq_tun_volume = product->eq_tun_height = 20; 182 product->eq_tun_volume = product->eq_tun_height = 20;
184 product->eq_tun_weight = 2; 183 product->eq_tun_weight = 2;
185 product->eq_top_up_water = 0; 184 product->eq_top_up_water = 0;
186 product->eq_trub_loss = 0.5; 185 product->eq_trub_loss = 0.5;
187 product->eq_evap_rate = 1.8; 186 product->eq_evap_rate = 1.8;
188 // product->eq_calc_boil_volume = true;
189 product->eq_top_up_kettle = 0; 187 product->eq_top_up_kettle = 0;
190 // product->eq_hop_utilization = 100;
191 // product->eq_lauter_volume = product->eq_lauter_height =
192 product->eq_kettle_volume = product->eq_kettle_height = product->eq_mash_volume = 20; 188 product->eq_kettle_volume = product->eq_kettle_height = product->eq_mash_volume = 20;
193 product->eq_lauter_deadspace = 0.5; 189 product->eq_lauter_deadspace = 0.5;
194 product->eq_mash_max = 6; 190 product->eq_mash_max = 6;
195 product->eq_efficiency = 75; 191 product->eq_efficiency = 75;
196 product->birth = QDate::currentDate(); 192 product->birth = QDate::currentDate();
401 query.bindValue(":record", my_default_water); 397 query.bindValue(":record", my_default_water);
402 query.exec(); 398 query.exec();
403 found = query.first(); 399 found = query.first();
404 } 400 }
405 if (found) { 401 if (found) {
406 product->w1_calcium = query.value(3).toDouble(); 402 product->w1_calcium = query.value("calcium").toDouble();
407 product->w1_magnesium = query.value(8).toDouble(); 403 product->w1_magnesium = query.value("magnesium").toDouble();
408 product->w1_total_alkalinity = query.value(11).toDouble(); 404 product->w1_total_alkalinity = query.value("total_alkalinity").toDouble();
409 product->w1_sodium = query.value(7).toDouble(); 405 product->w1_sodium = query.value("sodium").toDouble();
410 product->w1_chloride = query.value(6).toDouble(); 406 product->w1_chloride = query.value("chloride").toDouble();
411 product->w1_sulfate = query.value(5).toDouble(); 407 product->w1_sulfate = query.value("sulfate").toDouble();
412 product->w1_ph = query.value(9).toDouble(); 408 product->w1_ph = query.value("ph").toDouble();
413 ui->w1_nameEdit->setCurrentIndex(query.value(0).toInt()); 409 ui->w1_nameEdit->setCurrentIndex(query.value("record").toInt());
414 } else { 410 } else {
415 product->w1_calcium = 0; 411 product->w1_calcium = 0;
416 product->w1_magnesium = 0; 412 product->w1_magnesium = 0;
417 product->w1_total_alkalinity = 0; 413 product->w1_total_alkalinity = 0;
418 product->w1_sodium = 0; 414 product->w1_sodium = 0;
437 } else if (product->w2_name != "") { 433 } else if (product->w2_name != "") {
438 query.prepare("SELECT * FROM inventory_waters WHERE name=:water"); 434 query.prepare("SELECT * FROM inventory_waters WHERE name=:water");
439 query.bindValue(":water", product->w2_name); 435 query.bindValue(":water", product->w2_name);
440 query.exec(); 436 query.exec();
441 if (query.first()) { 437 if (query.first()) {
442 product->w2_calcium = query.value(3).toDouble(); 438 product->w2_calcium = query.value("calcium").toDouble();
443 product->w2_magnesium = query.value(8).toDouble(); 439 product->w2_magnesium = query.value("magnesium").toDouble();
444 product->w2_total_alkalinity = query.value(11).toDouble(); 440 product->w2_total_alkalinity = query.value("total_alkalinity").toDouble();
445 product->w2_sodium = query.value(7).toDouble(); 441 product->w2_sodium = query.value("sodium").toDouble();
446 product->w2_chloride = query.value(6).toDouble(); 442 product->w2_chloride = query.value("chloride").toDouble();
447 product->w2_sulfate = query.value(5).toDouble(); 443 product->w2_sulfate = query.value("sulfate").toDouble();
448 product->w2_ph = query.value(9).toDouble(); 444 product->w2_ph = query.value("ph").toDouble();
449 ui->w2_nameEdit->setCurrentIndex(query.value(0).toInt()); 445 ui->w2_nameEdit->setCurrentIndex(query.value("record").toInt());
450 } else { 446 } else {
451 product->w2_calcium = 0; 447 product->w2_calcium = 0;
452 product->w2_magnesium = 0; 448 product->w2_magnesium = 0;
453 product->w2_total_alkalinity = 0; 449 product->w2_total_alkalinity = 0;
454 product->w2_sodium = 0; 450 product->w2_sodium = 0;
516 ui->sp_acidpercEdit->setValue(product->sparge_acid_perc); 512 ui->sp_acidpercEdit->setValue(product->sparge_acid_perc);
517 check_waters(); 513 check_waters();
518 514
519 /* 515 /*
520 * At this point, see if we must upgrade the whole water part. 516 * At this point, see if we must upgrade the whole water part.
521 * Old is separated brew and sparge water.
522 * New is total water and divide into brew/sparge/spare water.
523 * Calculate brewing salts on the total.
524 */ 517 */
525 if (product->sparge_source != 2) { 518 // if (product->sparge_source != 2) {
519 if (product->sparge_volume != (product->brew_sparge_est + product->eq_HLT_deadspace)) {
526 qDebug() << "== Water settings upgrade =="; 520 qDebug() << "== Water settings upgrade ==";
527 qDebug() << " w1" << product->w1_amount << "w2" << product->w2_amount << "wg" << product->wg_amount << "sp" << product->sparge_volume << "se" << product->brew_sparge_est; 521 qDebug() << " sp" << product->sparge_volume << "se" << product->brew_sparge_est;
528 qDebug() << " HLT " << product->eq_HLT_volume << " deadspace" << product->eq_HLT_deadspace; 522 qDebug() << " HLT " << product->eq_HLT_volume << " deadspace" << product->eq_HLT_deadspace;
529 double infused = 0; 523 qDebug() << " fixed sparge supply" << (product->brew_sparge_est + product->eq_HLT_deadspace);
530 for (int i = 0; i < product->mashs.size(); i++) {
531 if (product->mashs.at(i).step_type == 0) { // Infusion
532 infused += product->mashs.at(i).step_infuse_amount;
533 }
534 }
535 qDebug() << " mash infusion" << infused;
536 /*
537 double bs_cacl2 = 0, ss_cacl2 = 0;
538 double bs_caso4 = 0, ss_caso4 = 0;
539 double bs_mgso4 = 0, ss_mgso4 = 0;
540 double bs_nacl = 0, ss_nacl = 0;
541 double bs_mgcl2 = 0, ss_mgcl2 = 0;
542 double bs_nahco3 = 0;
543 double bs_caco3 = 0;
544
545 for (int i = 0; i < product->miscs.size(); i++) {
546 if (product->miscs.at(i).type == MISC_TYPES_WATER_AGENT && product->miscs.at(i).use_use == MISC_USES_MASH) {
547 if (product->miscs.at(i).name == "CaCl2") {
548 bs_cacl2 = product->miscs.at(i).amount;
549 } else if (product->miscs.at(i).name == "CaSO4") {
550 bs_caso4 = product->miscs.at(i).amount;
551 } else if (product->miscs.at(i).name == "MgSO4") {
552 bs_mgso4 = product->miscs.at(i).amount;
553 } else if (product->miscs.at(i).name == "NaCl") {
554 bs_nacl = product->miscs.at(i).amount;
555 } else if (product->miscs.at(i).name == "MgCl2") {
556 bs_mgcl2 = product->miscs.at(i).amount;
557 } else if (product->miscs.at(i).name == "NaHCO3") {
558 bs_nahco3 = product->miscs.at(i).amount;
559 } else if (product->miscs.at(i).name == "CaCO3") {
560 bs_caco3 = product->miscs.at(i).amount;
561 }
562 } else if (product->miscs.at(i).type == MISC_TYPES_WATER_AGENT && product->miscs.at(i).use_use == MISC_USES_SPARGE) {
563 if (product->miscs.at(i).name == "CaCl2") {
564 ss_cacl2 = product->miscs.at(i).amount;
565 } else if (product->miscs.at(i).name == "CaSO4") {
566 ss_caso4 = product->miscs.at(i).amount;
567 } else if (product->miscs.at(i).name == "MgSO4") {
568 ss_mgso4 = product->miscs.at(i).amount;
569 } else if (product->miscs.at(i).name == "NaCl") {
570 ss_nacl = product->miscs.at(i).amount;
571 } else if (product->miscs.at(i).name == "MgCl2") {
572 ss_mgcl2 = product->miscs.at(i).amount;
573 }
574 }
575 }
576 if ((bs_cacl2 + ss_cacl2) > 0)
577 qDebug() << " CaCl2" << bs_cacl2 << ss_cacl2;
578 if ((bs_caso4 + ss_caso4) > 0)
579 qDebug() << " CaSO4" << bs_caso4 << ss_caso4;
580 if ((bs_mgso4 + ss_mgso4) > 0)
581 qDebug() << " MgSO4" << bs_mgso4 << ss_mgso4;
582 if ((bs_nacl + ss_nacl) > 0)
583 qDebug() << " NaCl" << bs_nacl << ss_nacl;
584 if ((bs_mgcl2 + ss_mgcl2) > 0)
585 qDebug() << " MgCl2" << bs_mgcl2 << ss_mgcl2;
586 if (bs_nahco3 > 0)
587 qDebug() << " NaHCO3" << bs_nahco3;
588 if (bs_caco3 > 0)
589 qDebug() << " CaCO3" << bs_caco3;
590 */
591 } 524 }
592 525
593 // Tab brewday. 526 // Tab brewday.
594 updateBrewday(); 527 updateBrewday();
595 ui->brew_mashphEdit->setValue(product->brew_mash_ph); 528 ui->brew_mashphEdit->setValue(product->brew_mash_ph);
688 ui->taste_headEdit->setText(product->taste_head); 621 ui->taste_headEdit->setText(product->taste_head);
689 ui->taste_aromaEdit->setText(product->taste_aroma); 622 ui->taste_aromaEdit->setText(product->taste_aroma);
690 ui->taste_tasteEdit->setText(product->taste_taste); 623 ui->taste_tasteEdit->setText(product->taste_taste);
691 ui->taste_mouthfeelEdit->setText(product->taste_mouthfeel); 624 ui->taste_mouthfeelEdit->setText(product->taste_mouthfeel);
692 ui->taste_aftertasteEdit->setText(product->taste_aftertaste); 625 ui->taste_aftertasteEdit->setText(product->taste_aftertaste);
693
694 qDebug() << "== Start connecting ==";
695 626
696 // Global signals 627 // Global signals
697 connect(ui->tabWidget, &QTabWidget::currentChanged, this, &EditProduct::tab_changed); 628 connect(ui->tabWidget, &QTabWidget::currentChanged, this, &EditProduct::tab_changed);
698 629
699 // All signals from tab "Generic" 630 // All signals from tab "Generic"
893 } 824 }
894 825
895 826
896 EditProduct::~EditProduct() 827 EditProduct::~EditProduct()
897 { 828 {
898 qDebug() << "EditProduct done start";
899 delete ui; 829 delete ui;
900 emit entry_changed(); 830 emit entry_changed();
901 qDebug() << "EditProduct done final"; 831 qDebug() << "EditProduct done";
902 } 832 }
903 833
904 834
905 void EditProduct::tab_changed() 835 void EditProduct::tab_changed()
906 { 836 {

mercurial