136 pd = ProtonDeficit(pH); |
136 pd = ProtonDeficit(pH); |
137 } |
137 } |
138 pH = round(pH * 1000000) / 1000000.0; |
138 pH = round(pH * 1000000) / 1000000.0; |
139 qDebug() << " MashpH() n:" << n << "pH:" << pH; |
139 qDebug() << " MashpH() n:" << n << "pH:" << pH; |
140 return pH; |
140 return pH; |
|
141 } |
|
142 |
|
143 |
|
144 void EditProduct::setButtons(bool locked) |
|
145 { |
|
146 if (locked) { |
|
147 /* |
|
148 * If the brew is done, disable the buttons and that's it. |
|
149 */ |
|
150 ui->w1_spButton->setDisabled(true); |
|
151 ui->w2_spButton->setDisabled(true); |
|
152 ui->wg_spButton->setDisabled(true); |
|
153 return; |
|
154 } |
|
155 ui->w1_spButton->setDisabled(false); |
|
156 |
|
157 const QSignalBlocker blocker1(ui->w1_spButton); |
|
158 const QSignalBlocker blocker2(ui->w2_spButton); |
|
159 const QSignalBlocker blocker3(ui->wg_spButton); |
|
160 |
|
161 if (product->w2_name != "") { |
|
162 ui->w2_spButton->setDisabled(false); |
|
163 if (product->w2_amount > 0.1 && product->w2_ph > 5) { |
|
164 /* |
|
165 * Water 2 is valid and used for mash, mixed is available. |
|
166 */ |
|
167 ui->wg_spButton->setDisabled(false); |
|
168 } else { |
|
169 /* |
|
170 * No mixed water for mash. We can still sparge with source 2. |
|
171 */ |
|
172 ui->wg_spButton->setDisabled(true); |
|
173 if (product->sparge_source == 2) { |
|
174 /* |
|
175 * If mixed was selected, switch to source 2. |
|
176 */ |
|
177 product->sparge_source = 1; |
|
178 ui->w2_spButton->setChecked(true); |
|
179 } |
|
180 } |
|
181 } else { |
|
182 ui->w2_spButton->setDisabled(true); |
|
183 ui->wg_spButton->setDisabled(true); |
|
184 product->sparge_source = 0; // Fallback to source 1 |
|
185 ui->w1_spButton->setChecked(true); |
|
186 } |
141 } |
187 } |
142 |
188 |
143 |
189 |
144 void EditProduct::calcWater() |
190 void EditProduct::calcWater() |
145 { |
191 { |
427 double Source_pH = product->w1_ph; |
473 double Source_pH = product->w1_ph; |
428 double Source_alkalinity = product->w1_total_alkalinity; |
474 double Source_alkalinity = product->w1_total_alkalinity; |
429 |
475 |
430 qDebug() << "calcSparge()"; |
476 qDebug() << "calcSparge()"; |
431 |
477 |
432 const QSignalBlocker blocker2(ui->w1_spButton); |
478 setButtons(product->stage > PROD_STAGE_BREW); |
433 const QSignalBlocker blocker3(ui->w2_spButton); |
479 |
434 const QSignalBlocker blocker4(ui->wg_spButton); |
480 if (product->sparge_source == 1 && product->w2_ph > 0.0) { |
435 |
481 Source_pH = product->w2_ph; |
436 // Select watersource or fallback to the first source. |
482 Source_alkalinity = product->w2_total_alkalinity; |
437 if (product->sparge_source == 1) { // Source 2 |
483 ui->sp_caEdit->setValue(product->w2_calcium); |
438 if (product->w2_ph > 0.0 && product->w2_amount > 0) { |
484 ui->sp_mgEdit->setValue(product->w2_magnesium); |
439 Source_pH = product->w2_ph; |
485 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(product->w2_total_alkalinity, product->w2_ph)); |
440 Source_alkalinity = product->w2_total_alkalinity; |
486 ui->sp_caco3Edit->setValue(product->w2_total_alkalinity); |
441 ui->sp_caEdit->setValue(product->w2_calcium); |
487 ui->sp_naEdit->setValue(product->w2_sodium); |
442 ui->sp_mgEdit->setValue(product->w2_magnesium); |
488 ui->sp_clEdit->setValue(product->w2_chloride); |
443 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(product->w2_total_alkalinity, product->w2_ph)); |
489 ui->sp_so4Edit->setValue(product->w2_sulfate); |
444 ui->sp_caco3Edit->setValue(product->w2_total_alkalinity); |
490 ui->sp_phShow->setValue(product->w2_ph); |
445 ui->sp_naEdit->setValue(product->w2_sodium); |
491 ui->sp_hardnessEdit->setValue(Utils::Hardness(product->w2_calcium, product->w2_magnesium)); |
446 ui->sp_clEdit->setValue(product->w2_chloride); |
492 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(product->w2_total_alkalinity, product->w2_calcium, product->w2_magnesium)); |
447 ui->sp_so4Edit->setValue(product->w2_sulfate); |
493 } else if (product->sparge_source == 2 && product->w2_ph > 0.0) { |
448 ui->sp_phShow->setValue(product->w2_ph); |
494 Source_pH = product->wg_ph; |
449 ui->sp_hardnessEdit->setValue(Utils::Hardness(product->w2_calcium, product->w2_magnesium)); |
495 Source_alkalinity = product->wg_total_alkalinity; |
450 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(product->w2_total_alkalinity, product->w2_calcium, product->w2_magnesium)); |
496 ui->sp_caEdit->setValue(product->wg_calcium); |
451 ui->w2_spButton->setChecked(true); |
497 ui->sp_mgEdit->setValue(product->wg_magnesium); |
452 } else { |
498 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(product->wg_total_alkalinity, product->wg_ph)); |
453 product->sparge_source = 0; // Fallback to source 1 |
499 ui->sp_caco3Edit->setValue(product->wg_total_alkalinity); |
454 ui->w1_spButton->setChecked(true); |
500 ui->sp_naEdit->setValue(product->wg_sodium); |
455 } |
501 ui->sp_clEdit->setValue(product->wg_chloride); |
456 } else if (product->sparge_source == 2) { // Mixed |
502 ui->sp_so4Edit->setValue(product->wg_sulfate); |
457 if (product->w2_ph > 0.0 && product->w2_amount > 0) { |
503 ui->sp_phShow->setValue(product->wg_ph); |
458 Source_pH = product->wg_ph; |
504 ui->sp_hardnessEdit->setValue(Utils::Hardness(product->wg_calcium, product->wg_magnesium)); |
459 Source_alkalinity = product->wg_total_alkalinity; |
505 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(product->wg_total_alkalinity, product->wg_calcium, product->wg_magnesium)); |
460 ui->sp_caEdit->setValue(product->wg_calcium); |
506 } else { |
461 ui->sp_mgEdit->setValue(product->wg_magnesium); |
|
462 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(product->wg_total_alkalinity, product->wg_ph)); |
|
463 ui->sp_caco3Edit->setValue(product->wg_total_alkalinity); |
|
464 ui->sp_naEdit->setValue(product->wg_sodium); |
|
465 ui->sp_clEdit->setValue(product->wg_chloride); |
|
466 ui->sp_so4Edit->setValue(product->wg_sulfate); |
|
467 ui->sp_phShow->setValue(product->wg_ph); |
|
468 ui->sp_hardnessEdit->setValue(Utils::Hardness(product->wg_calcium, product->wg_magnesium)); |
|
469 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(product->wg_total_alkalinity, product->wg_calcium, product->wg_magnesium)); |
|
470 ui->wg_spButton->setChecked(true); |
|
471 } else { |
|
472 product->sparge_source = 0; // Fallback to source 1 |
|
473 ui->w1_spButton->setChecked(true); |
|
474 } |
|
475 } |
|
476 if (product->sparge_source == 0) { |
|
477 ui->sp_caEdit->setValue(product->w1_calcium); |
507 ui->sp_caEdit->setValue(product->w1_calcium); |
478 ui->sp_mgEdit->setValue(product->w1_magnesium); |
508 ui->sp_mgEdit->setValue(product->w1_magnesium); |
479 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(product->w1_total_alkalinity, product->w1_ph)); |
509 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(product->w1_total_alkalinity, product->w1_ph)); |
480 ui->sp_caco3Edit->setValue(product->w1_total_alkalinity); |
510 ui->sp_caco3Edit->setValue(product->w1_total_alkalinity); |
481 ui->sp_naEdit->setValue(product->w1_sodium); |
511 ui->sp_naEdit->setValue(product->w1_sodium); |
482 ui->sp_clEdit->setValue(product->w1_chloride); |
512 ui->sp_clEdit->setValue(product->w1_chloride); |
483 ui->sp_so4Edit->setValue(product->w1_sulfate); |
513 ui->sp_so4Edit->setValue(product->w1_sulfate); |
484 ui->sp_phShow->setValue(product->w1_ph); |
514 ui->sp_phShow->setValue(product->w1_ph); |
485 ui->sp_hardnessEdit->setValue(Utils::Hardness(product->w1_calcium, product->w1_magnesium)); |
515 ui->sp_hardnessEdit->setValue(Utils::Hardness(product->w1_calcium, product->w1_magnesium)); |
486 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(product->w1_total_alkalinity, product->w1_calcium, product->w1_magnesium)); |
516 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(product->w1_total_alkalinity, product->w1_calcium, product->w1_magnesium)); |
487 ui->w1_spButton->setChecked(true); |
|
488 } |
517 } |
489 // The spargewater is set. |
518 // The spargewater is set. |
490 |
519 |
491 int AT = product->sparge_acid_type; |
520 int AT = product->sparge_acid_type; |
492 if (AT < 0 || AT >= my_acids.size()) { |
521 if (AT < 0 || AT >= my_acids.size()) { |