144 |
144 |
145 |
145 |
146 void EditProduct::setButtons(bool locked) |
146 void EditProduct::setButtons(bool locked) |
147 { |
147 { |
148 if (locked) { |
148 if (locked) { |
149 /* |
149 /* |
150 * If the brew is done, disable the buttons and that's it. |
150 * If the brew is done, disable the buttons and that's it. |
151 */ |
151 */ |
152 ui->w1_spButton->setDisabled(true); |
152 ui->w1_spButton->setDisabled(true); |
153 ui->w2_spButton->setDisabled(true); |
153 ui->w2_spButton->setDisabled(true); |
154 ui->wg_spButton->setDisabled(true); |
154 ui->wg_spButton->setDisabled(true); |
155 return; |
155 return; |
156 } |
156 } |
157 ui->w1_spButton->setDisabled(false); |
157 ui->w1_spButton->setDisabled(false); |
158 |
158 |
159 const QSignalBlocker blocker1(ui->w1_spButton); |
159 const QSignalBlocker blocker1(ui->w1_spButton); |
160 const QSignalBlocker blocker2(ui->w2_spButton); |
160 const QSignalBlocker blocker2(ui->w2_spButton); |
161 const QSignalBlocker blocker3(ui->wg_spButton); |
161 const QSignalBlocker blocker3(ui->wg_spButton); |
162 |
162 |
163 if (product->w2_name != "") { |
163 if (product->w2_name != "") { |
164 ui->w2_spButton->setDisabled(false); |
164 ui->w2_spButton->setDisabled(false); |
165 if (product->w2_amount > 0.1 && product->w2_ph > 5) { |
165 if (product->w2_amount > 0.1 && product->w2_ph > 5) { |
166 /* |
166 /* |
167 * Water 2 is valid and used for mash, mixed is available. |
167 * Water 2 is valid and used for mash, mixed is available. |
168 */ |
168 */ |
169 ui->wg_spButton->setDisabled(false); |
169 ui->wg_spButton->setDisabled(false); |
170 } else { |
170 } else { |
171 /* |
171 /* |
172 * No mixed water for mash. We can still sparge with source 2. |
172 * No mixed water for mash. We can still sparge with source 2. |
173 */ |
173 */ |
174 ui->wg_spButton->setDisabled(true); |
174 ui->wg_spButton->setDisabled(true); |
175 if (product->sparge_source == 2) { |
175 if (product->sparge_source == 2) { |
177 * If mixed was selected, switch to source 2. |
177 * If mixed was selected, switch to source 2. |
178 */ |
178 */ |
179 product->sparge_source = 1; |
179 product->sparge_source = 1; |
180 ui->w2_spButton->setChecked(true); |
180 ui->w2_spButton->setChecked(true); |
181 } |
181 } |
182 } |
182 } |
183 } else { |
183 } else { |
184 ui->w2_spButton->setDisabled(true); |
184 ui->w2_spButton->setDisabled(true); |
185 ui->wg_spButton->setDisabled(true); |
185 ui->wg_spButton->setDisabled(true); |
186 product->sparge_source = 0; // Fallback to source 1 |
186 product->sparge_source = 0; // Fallback to source 1 |
187 ui->w1_spButton->setChecked(true); |
187 ui->w1_spButton->setChecked(true); |
188 } |
188 } |
189 } |
189 } |
|
190 |
190 |
191 |
191 |
192 |
192 void EditProduct::calcBU() |
193 void EditProduct::calcBU() |
193 { |
194 { |
194 if (product->stage < PROD_STAGE_WAIT) |
195 if (product->stage < PROD_STAGE_WAIT) |
301 ui->wg_hardnessEdit->setValue(Utils::Hardness(calcium, magnesium)); |
302 ui->wg_hardnessEdit->setValue(Utils::Hardness(calcium, magnesium)); |
302 ui->wg_raEdit->setValue(Utils::ResidualAlkalinity(total_alkalinity, calcium, magnesium)); |
303 ui->wg_raEdit->setValue(Utils::ResidualAlkalinity(total_alkalinity, calcium, magnesium)); |
303 |
304 |
304 /* Save mixed water ions for later */ |
305 /* Save mixed water ions for later */ |
305 double wg_calcium = calcium; |
306 double wg_calcium = calcium; |
|
307 double wg_magnesium = magnesium; |
306 double wg_sodium = sodium; |
308 double wg_sodium = sodium; |
307 double wg_total_alkalinity = total_alkalinity; |
309 double wg_total_alkalinity = total_alkalinity; |
308 double wg_chloride = chloride; |
310 double wg_chloride = chloride; |
309 double wg_sulfate = sulfate; |
311 double wg_sulfate = sulfate; |
310 double wg_bicarbonate = bicarbonate; |
312 double wg_bicarbonate = bicarbonate; |
492 } |
494 } |
493 ui->wb_phEdit->setStyleSheet((ph < 5.2 || ph > 5.6) ? "background-color: red":"background-color: green"); |
495 ui->wb_phEdit->setStyleSheet((ph < 5.2 || ph > 5.6) ? "background-color: red":"background-color: green"); |
494 ui->wb_hco3Edit->setStyleSheet((bicarbonate > 250) ? "background-color: red":"background-color: green"); |
496 ui->wb_hco3Edit->setStyleSheet((bicarbonate > 250) ? "background-color: red":"background-color: green"); |
495 ui->wb_caco3Edit->setStyleSheet((bicarbonate > 250) ? "background-color: red":"background-color: green"); |
497 ui->wb_caco3Edit->setStyleSheet((bicarbonate > 250) ? "background-color: red":"background-color: green"); |
496 |
498 |
|
499 /* Calculate Actual Adjustments */ |
|
500 product->aa_calcium = calcium - product->wg_calcium; |
|
501 product->aa_magnesium = magnesium - product->wg_magnesium; |
|
502 product->aa_bicarbonate = bicarbonate - wg_bicarbonate; |
|
503 product->aa_sodium = sodium - product->wg_sodium; |
|
504 product->aa_chloride = chloride - product->wg_chloride; |
|
505 product->aa_sulfate = sulfate - product->wg_sulfate; |
|
506 product->aa_hardness = Utils::Hardness(calcium, magnesium) - Utils::Hardness(wg_calcium, wg_magnesium); |
|
507 |
|
508 if (product->tw_name != "") { |
|
509 /* Calculate Target Adjustments */ |
|
510 product->ta_calcium = product->tw_calcium - product->wg_calcium; |
|
511 product->ta_magnesium = product->tw_magnesium - product->wg_magnesium; |
|
512 product->ta_bicarbonate = Utils::Bicarbonate(product->tw_total_alkalinity, product->tw_ph) - wg_bicarbonate; |
|
513 product->ta_sodium = product->tw_sodium - product->wg_sodium; |
|
514 product->ta_chloride = product->tw_chloride - product->wg_chloride; |
|
515 product->ta_sulfate = product->tw_sulfate - product->wg_sulfate; |
|
516 product->ta_hardness = Utils::Hardness(product->tw_calcium, product->tw_magnesium) - Utils::Hardness(product->wg_calcium, product->wg_magnesium); |
|
517 } else { |
|
518 product->ta_calcium = product->ta_magnesium = product->ta_bicarbonate = product->ta_sodium = 0; |
|
519 product->ta_chloride = product->ta_sulfate = product->ta_hardness = 0; |
|
520 } |
|
521 |
|
522 waterTreated_Show(ui->wx_Select->isChecked()); |
|
523 waterAdjust_Show(false); |
497 calcSparge(); |
524 calcSparge(); |
498 } |
525 } |
499 |
526 |
500 |
527 |
501 /* |
528 /* |
543 product->ws_sulfate += (ui->ss_caso4Edit->value() * MMSO4 / MMCaSO4 * 1000 + ui->ss_mgso4Edit->value() * MMSO4 / MMMgSO4 * 1000) / product->sparge_volume; |
570 product->ws_sulfate += (ui->ss_caso4Edit->value() * MMSO4 / MMCaSO4 * 1000 + ui->ss_mgso4Edit->value() * MMSO4 / MMMgSO4 * 1000) / product->sparge_volume; |
544 product->ws_chloride += (2 * ui->ss_cacl2Edit->value() * MMCl / MMCaCl2 * 1000 + ui->ss_naclEdit->value() * MMCl / MMNaCl * 1000 + |
571 product->ws_chloride += (2 * ui->ss_cacl2Edit->value() * MMCl / MMCaCl2 * 1000 + ui->ss_naclEdit->value() * MMCl / MMNaCl * 1000 + |
545 ui->ss_mgcl2Edit->value() * MMCl / MMMgCl2 * 1000) / product->sparge_volume; |
572 ui->ss_mgcl2Edit->value() * MMCl / MMMgCl2 * 1000) / product->sparge_volume; |
546 } |
573 } |
547 |
574 |
548 /* Show the spargewater with salt additions. */ |
575 waterTreated_Show(ui->wx_Select->isChecked()); |
549 ui->sp_caEdit->setValue(product->ws_calcium); |
|
550 ui->sp_mgEdit->setValue(product->ws_magnesium); |
|
551 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(product->ws_total_alkalinity, Source_pH)); |
|
552 ui->sp_caco3Edit->setValue(product->ws_total_alkalinity); |
|
553 ui->sp_naEdit->setValue(product->ws_sodium); |
|
554 ui->sp_clEdit->setValue(product->ws_chloride); |
|
555 ui->sp_so4Edit->setValue(product->ws_sulfate); |
|
556 ui->sp_phShow->setValue(product->sparge_ph); |
|
557 ui->sp_hardnessEdit->setValue(Utils::Hardness(product->ws_calcium, product->ws_magnesium)); |
|
558 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(product->ws_total_alkalinity, product->ws_calcium, product->ws_magnesium)); |
|
559 |
576 |
560 int AT = product->sparge_acid_type; |
577 int AT = product->sparge_acid_type; |
561 if (AT < 0 || AT >= my_acids.size()) { |
578 if (AT < 0 || AT >= my_acids.size()) { |
562 AT = 0; |
579 AT = 0; |
563 product->sparge_acid_type = 0; |
580 product->sparge_acid_type = 0; |
628 ui->preboil_phEdit->setValue(product->est_preboil_ph); |
645 ui->preboil_phEdit->setValue(product->est_preboil_ph); |
629 ui->brew_preboilphShow->setValue(product->est_preboil_ph); |
646 ui->brew_preboilphShow->setValue(product->est_preboil_ph); |
630 } |
647 } |
631 |
648 |
632 |
649 |
|
650 |
633 void EditProduct::sp_group_changed(int val) |
651 void EditProduct::sp_group_changed(int val) |
634 { |
652 { |
635 if (val != product->sparge_source) { |
653 if (val != product->sparge_source) { |
636 product->sparge_source = val; |
654 product->sparge_source = val; |
637 calcSparge(); |
655 calcSparge(); |
638 is_changed(); |
656 is_changed(); |
639 } |
657 } |
640 } |
658 } |
|
659 |
|
660 |
|
661 |
|
662 void EditProduct::waterAdjust_Show(bool val) |
|
663 { |
|
664 if (val) { |
|
665 ui->waterAdjust->setText(tr("Target Water Adjustment")); |
|
666 ui->aa_caEdit->setValue(product->ta_calcium); |
|
667 ui->aa_mgEdit->setValue(product->ta_magnesium); |
|
668 ui->aa_hco3Edit->setValue(product->ta_bicarbonate); |
|
669 ui->aa_naEdit->setValue(product->ta_sodium); |
|
670 ui->aa_clEdit->setValue(product->ta_chloride); |
|
671 ui->aa_so4Edit->setValue(product->ta_sulfate); |
|
672 ui->aa_hardnessEdit->setValue(product->ta_hardness); |
|
673 } else { |
|
674 ui->waterAdjust->setText(tr("Actual Water Adjustment")); |
|
675 ui->aa_caEdit->setValue(product->aa_calcium); |
|
676 ui->aa_mgEdit->setValue(product->aa_magnesium); |
|
677 ui->aa_hco3Edit->setValue(product->aa_bicarbonate); |
|
678 ui->aa_naEdit->setValue(product->aa_sodium); |
|
679 ui->aa_clEdit->setValue(product->aa_chloride); |
|
680 ui->aa_so4Edit->setValue(product->aa_sulfate); |
|
681 ui->aa_hardnessEdit->setValue(product->aa_hardness); |
|
682 } |
|
683 } |
|
684 |
|
685 |
|
686 |
|
687 void EditProduct::waterTreated_Show(bool val) |
|
688 { |
|
689 double calcium, magnesium, total_alkalinity, sodium; |
|
690 double chloride, sulfate, ph, volume, bicarbonate; |
|
691 |
|
692 qDebug() << " wx_Select->isChecked()" << ui->wx_Select->isChecked(); |
|
693 |
|
694 if (val) { |
|
695 ui->wx_Select->setText(tr("Treated Sparge Water")); |
|
696 calcium = product->ws_calcium; |
|
697 magnesium = product->ws_magnesium; |
|
698 total_alkalinity = product->ws_total_alkalinity; |
|
699 sodium = product->ws_sodium; |
|
700 chloride = product->ws_chloride; |
|
701 sulfate = product->ws_sulfate; |
|
702 ph = product->sparge_ph; |
|
703 volume = product->sparge_volume; |
|
704 } else { |
|
705 ui->wx_Select->setText(tr("Treated Mash Water")); |
|
706 calcium = product->wb_calcium; |
|
707 magnesium = product->wb_magnesium; |
|
708 total_alkalinity = product->wb_total_alkalinity; |
|
709 sodium = product->wb_sodium; |
|
710 chloride = product->wb_chloride; |
|
711 sulfate = product->wb_sulfate; |
|
712 ph = product->wb_ph; |
|
713 volume = product->wg_amount; |
|
714 } |
|
715 |
|
716 bicarbonate = Utils::Bicarbonate(total_alkalinity, ph); |
|
717 ui->wx_caEdit->setValue(calcium); |
|
718 ui->wx_mgEdit->setValue(magnesium); |
|
719 ui->wx_hco3Edit->setValue(bicarbonate); |
|
720 ui->wx_caco3Edit->setValue(total_alkalinity); |
|
721 ui->wx_naEdit->setValue(sodium); |
|
722 ui->wx_clEdit->setValue(chloride); |
|
723 ui->wx_so4Edit->setValue(sulfate); |
|
724 ui->wx_hardnessEdit->setValue(Utils::Hardness(calcium, magnesium)); |
|
725 ui->wx_raEdit->setValue(Utils::ResidualAlkalinity(total_alkalinity, calcium, magnesium)); |
|
726 ui->wx_phEdit->setValue(ph); |
|
727 ui->wx_volEdit->setValue(volume); |
|
728 |
|
729 ui->wx_caEdit->setStyleSheet((calcium < 40 || calcium > 150) ? "background-color: red":"background-color: green"); |
|
730 ui->wx_mgEdit->setStyleSheet((magnesium < 5 || magnesium > 40) ? "background-color: red":"background-color: green"); |
|
731 ui->wx_naEdit->setStyleSheet((sodium > 150) ? "background-color: red":"background-color: green"); |
|
732 |
|
733 /* |
|
734 * Both chloride and sulfate should be above 50 according to |
|
735 * John Palmer. So the Cl/SO4 ratio calculation will work. |
|
736 */ |
|
737 ui->wx_clEdit->setStyleSheet((chloride <= 50 || chloride > 150) ? "background-color: red":"background-color: green"); |
|
738 ui->wx_so4Edit->setStyleSheet((sulfate <= 50 || sulfate > 400) ? "background-color: red":"background-color: green"); |
|
739 |
|
740 /* |
|
741 * (cloride + sulfate) > 500 is too high |
|
742 */ |
|
743 if ((chloride + sulfate) > 500) { |
|
744 ui->wx_clEdit->setStyleSheet("background-color: red"); |
|
745 ui->wx_so4Edit->setStyleSheet("background-color: red"); |
|
746 } |
|
747 ui->wx_phEdit->setStyleSheet((ph < 5.2 || ph > 5.6) ? "background-color: red":"background-color: green"); |
|
748 ui->wx_hco3Edit->setStyleSheet((bicarbonate > 250) ? "background-color: red":"background-color: green"); |
|
749 ui->wx_caco3Edit->setStyleSheet((bicarbonate > 250) ? "background-color: red":"background-color: green"); |
|
750 } |
|
751 |
641 |
752 |
642 |
753 |
643 void EditProduct::sp_volume_changed(double val) |
754 void EditProduct::sp_volume_changed(double val) |
644 { |
755 { |
645 if (! product->calc_acid) { |
756 if (! product->calc_acid) { |
1079 { |
1190 { |
1080 QSqlQuery query; |
1191 QSqlQuery query; |
1081 |
1192 |
1082 if (val == 0) { |
1193 if (val == 0) { |
1083 /* Clear values */ |
1194 /* Clear values */ |
1084 ui->wt_caEdit->setValue(0); |
1195 product->tw_name = ""; |
1085 ui->wt_mgEdit->setValue(0); |
1196 product->tw_calcium = 0; |
1086 ui->wt_hco3Edit->setValue(0); |
1197 product->tw_sulfate = 0; |
1087 ui->wt_caco3Edit->setValue(0); |
1198 product->tw_chloride = 0; |
1088 ui->wt_naEdit->setValue(0); |
1199 product->tw_sodium = 0; |
1089 ui->wt_clEdit->setValue(0); |
1200 product->tw_magnesium = 0; |
1090 ui->wt_so4Edit->setValue(0); |
1201 product->tw_total_alkalinity = 0; |
1091 ui->wt_hardnessEdit->setValue(0); |
1202 product->tw_ph = 7; |
1092 ui->wt_raEdit->setValue(0); |
1203 ui->tw_hco3Edit->setValue(0); |
|
1204 ui->tw_hardnessEdit->setValue(0); |
|
1205 ui->tw_raEdit->setValue(0); |
1093 } else { |
1206 } else { |
1094 query.prepare("SELECT * FROM profile_water ORDER BY name"); |
1207 query.prepare("SELECT * FROM profile_water ORDER BY name"); |
1095 query.exec(); |
1208 query.exec(); |
1096 query.first(); |
1209 query.first(); |
1097 for (int i = 0; i < (val - 1); i++) { |
1210 for (int i = 0; i < (val - 1); i++) { |
1098 query.next(); |
1211 query.next(); |
1099 } |
1212 } |
1100 ui->wt_caEdit->setValue(query.value("calcium").toDouble()); |
1213 product->tw_name = query.value("name").toString(); |
1101 ui->wt_mgEdit->setValue(query.value("magnesium").toDouble()); |
1214 product->tw_calcium = query.value("calcium").toDouble(); |
1102 ui->wt_hco3Edit->setValue(query.value("bicarbonate").toDouble()); |
1215 product->tw_sulfate = query.value("sulfate").toDouble(); |
1103 ui->wt_caco3Edit->setValue(query.value("total_alkalinity").toDouble()); |
1216 product->tw_chloride = query.value("chloride").toDouble(); |
1104 ui->wt_naEdit->setValue(query.value("sodium").toDouble()); |
1217 product->tw_sodium = query.value("sodium").toDouble(); |
1105 ui->wt_clEdit->setValue(query.value("chloride").toDouble()); |
1218 product->tw_magnesium = query.value("magnesium").toDouble(); |
1106 ui->wt_so4Edit->setValue(query.value("sulfate").toDouble()); |
1219 product->tw_total_alkalinity = query.value("total_alkalinity").toDouble(); |
1107 ui->wt_hardnessEdit->setValue(Utils::Hardness(query.value("calcium").toDouble(), query.value("magnesium").toDouble())); |
1220 product->tw_ph = query.value("ph").toDouble(); |
1108 ui->wt_raEdit->setValue(Utils::ResidualAlkalinity(query.value("total_alkalinity").toDouble(), query.value("calcium").toDouble(), query.value("magnesium").toDouble())); |
1221 ui->tw_hco3Edit->setValue(query.value("bicarbonate").toDouble()); |
1109 } |
1222 ui->tw_hardnessEdit->setValue(Utils::Hardness(query.value("calcium").toDouble(), query.value("magnesium").toDouble())); |
|
1223 ui->tw_raEdit->setValue(Utils::ResidualAlkalinity(query.value("total_alkalinity").toDouble(), query.value("calcium").toDouble(), query.value("magnesium").toDouble())); |
|
1224 } |
|
1225 |
|
1226 ui->tw_caEdit->setValue(product->tw_calcium); |
|
1227 ui->tw_mgEdit->setValue(product->tw_magnesium); |
|
1228 ui->tw_caco3Edit->setValue(product->tw_total_alkalinity); |
|
1229 ui->tw_naEdit->setValue(product->tw_sodium); |
|
1230 ui->tw_clEdit->setValue(product->tw_chloride); |
|
1231 ui->tw_so4Edit->setValue(product->tw_sulfate); |
|
1232 ui->tw_phEdit->setValue(product->tw_ph); |
|
1233 |
|
1234 is_changed(); |
1110 calcWater(); |
1235 calcWater(); |
1111 } |
1236 } |
1112 |
1237 |
1113 |
1238 |
1114 void EditProduct::adjustWaters(double factor) |
1239 void EditProduct::adjustWaters(double factor) |