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 EditRecipe::setButtons(bool locked) |
|
145 { |
|
146 if (locked) { |
|
147 /* |
|
148 * If recipe is locked, 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 (recipe->w2_name != "") { |
|
162 ui->w2_spButton->setDisabled(false); |
|
163 if (recipe->w2_amount > 0.1 && recipe->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 (recipe->sparge_source == 2) { |
|
174 /* |
|
175 * If mixed was selected, switch to source 2. |
|
176 */ |
|
177 recipe->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 recipe->sparge_source = 0; // Fallback to source 1 |
|
185 ui->w1_spButton->setChecked(true); |
|
186 } |
141 } |
187 } |
142 |
188 |
143 |
189 |
144 void EditRecipe::calcWater() |
190 void EditRecipe::calcWater() |
145 { |
191 { |
426 double TargetpH = recipe->sparge_ph; |
472 double TargetpH = recipe->sparge_ph; |
427 double Source_pH = recipe->w1_ph; |
473 double Source_pH = recipe->w1_ph; |
428 double Source_alkalinity = recipe->w1_total_alkalinity; |
474 double Source_alkalinity = recipe->w1_total_alkalinity; |
429 |
475 |
430 qDebug() << "calcSparge()"; |
476 qDebug() << "calcSparge()"; |
431 |
477 setButtons(recipe->locked); |
432 const QSignalBlocker blocker2(ui->w1_spButton); |
478 |
433 const QSignalBlocker blocker3(ui->w2_spButton); |
479 if (recipe->sparge_source == 1 && recipe->w2_ph > 0.0) { |
434 const QSignalBlocker blocker4(ui->wg_spButton); |
480 Source_pH = recipe->w2_ph; |
435 |
481 Source_alkalinity = recipe->w2_total_alkalinity; |
436 // Select watersource or fallback to the first source. |
482 ui->sp_caEdit->setValue(recipe->w2_calcium); |
437 if (recipe->sparge_source == 1) { // Source 2 |
483 ui->sp_mgEdit->setValue(recipe->w2_magnesium); |
438 if (recipe->w2_ph > 0.0 && recipe->w2_amount > 0) { |
484 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w2_total_alkalinity, recipe->w2_ph)); |
439 Source_pH = recipe->w2_ph; |
485 ui->sp_caco3Edit->setValue(recipe->w2_total_alkalinity); |
440 Source_alkalinity = recipe->w2_total_alkalinity; |
486 ui->sp_naEdit->setValue(recipe->w2_sodium); |
441 ui->sp_caEdit->setValue(recipe->w2_calcium); |
487 ui->sp_clEdit->setValue(recipe->w2_chloride); |
442 ui->sp_mgEdit->setValue(recipe->w2_magnesium); |
488 ui->sp_so4Edit->setValue(recipe->w2_sulfate); |
443 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w2_total_alkalinity, recipe->w2_ph)); |
489 ui->sp_phShow->setValue(recipe->w2_ph); |
444 ui->sp_caco3Edit->setValue(recipe->w2_total_alkalinity); |
490 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w2_calcium, recipe->w2_magnesium)); |
445 ui->sp_naEdit->setValue(recipe->w2_sodium); |
491 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w2_total_alkalinity, recipe->w2_calcium, recipe->w2_magnesium)); |
446 ui->sp_clEdit->setValue(recipe->w2_chloride); |
492 } else if (recipe->sparge_source == 2 && recipe->w2_ph > 0.0) { |
447 ui->sp_so4Edit->setValue(recipe->w2_sulfate); |
493 Source_pH = recipe->wg_ph; |
448 ui->sp_phShow->setValue(recipe->w2_ph); |
494 Source_alkalinity = recipe->wg_total_alkalinity; |
449 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w2_calcium, recipe->w2_magnesium)); |
495 ui->sp_caEdit->setValue(recipe->wg_calcium); |
450 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w2_total_alkalinity, recipe->w2_calcium, recipe->w2_magnesium)); |
496 ui->sp_mgEdit->setValue(recipe->wg_magnesium); |
451 ui->w2_spButton->setChecked(true); |
497 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->wg_total_alkalinity, recipe->wg_ph)); |
452 } else { |
498 ui->sp_caco3Edit->setValue(recipe->wg_total_alkalinity); |
453 recipe->sparge_source = 0; // Fallback to source 1 |
499 ui->sp_naEdit->setValue(recipe->wg_sodium); |
454 ui->w1_spButton->setChecked(true); |
500 ui->sp_clEdit->setValue(recipe->wg_chloride); |
455 } |
501 ui->sp_so4Edit->setValue(recipe->wg_sulfate); |
456 } else if (recipe->sparge_source == 2) { // Mixed |
502 ui->sp_phShow->setValue(recipe->wg_ph); |
457 if (recipe->w2_ph > 0.0 && recipe->w2_amount > 0) { |
503 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->wg_calcium, recipe->wg_magnesium)); |
458 Source_pH = recipe->wg_ph; |
504 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->wg_total_alkalinity, recipe->wg_calcium, recipe->wg_magnesium)); |
459 Source_alkalinity = recipe->wg_total_alkalinity; |
505 } else { |
460 ui->sp_caEdit->setValue(recipe->wg_calcium); |
506 ui->sp_caEdit->setValue(recipe->w1_calcium); |
461 ui->sp_mgEdit->setValue(recipe->wg_magnesium); |
507 ui->sp_mgEdit->setValue(recipe->w1_magnesium); |
462 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->wg_total_alkalinity, recipe->wg_ph)); |
508 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w1_total_alkalinity, recipe->w1_ph)); |
463 ui->sp_caco3Edit->setValue(recipe->wg_total_alkalinity); |
509 ui->sp_caco3Edit->setValue(recipe->w1_total_alkalinity); |
464 ui->sp_naEdit->setValue(recipe->wg_sodium); |
510 ui->sp_naEdit->setValue(recipe->w1_sodium); |
465 ui->sp_clEdit->setValue(recipe->wg_chloride); |
511 ui->sp_clEdit->setValue(recipe->w1_chloride); |
466 ui->sp_so4Edit->setValue(recipe->wg_sulfate); |
512 ui->sp_so4Edit->setValue(recipe->w1_sulfate); |
467 ui->sp_phShow->setValue(recipe->wg_ph); |
513 ui->sp_phShow->setValue(recipe->w1_ph); |
468 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->wg_calcium, recipe->wg_magnesium)); |
514 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w1_calcium, recipe->w1_magnesium)); |
469 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->wg_total_alkalinity, recipe->wg_calcium, recipe->wg_magnesium)); |
515 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w1_total_alkalinity, recipe->w1_calcium, recipe->w1_magnesium)); |
470 ui->wg_spButton->setChecked(true); |
|
471 } else { |
|
472 recipe->sparge_source = 0; // Fallback to source 1 |
|
473 ui->w1_spButton->setChecked(true); |
|
474 } |
|
475 } |
|
476 if (recipe->sparge_source == 0) { |
|
477 ui->sp_caEdit->setValue(recipe->w1_calcium); |
|
478 ui->sp_mgEdit->setValue(recipe->w1_magnesium); |
|
479 ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w1_total_alkalinity, recipe->w1_ph)); |
|
480 ui->sp_caco3Edit->setValue(recipe->w1_total_alkalinity); |
|
481 ui->sp_naEdit->setValue(recipe->w1_sodium); |
|
482 ui->sp_clEdit->setValue(recipe->w1_chloride); |
|
483 ui->sp_so4Edit->setValue(recipe->w1_sulfate); |
|
484 ui->sp_phShow->setValue(recipe->w1_ph); |
|
485 ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w1_calcium, recipe->w1_magnesium)); |
|
486 ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w1_total_alkalinity, recipe->w1_calcium, recipe->w1_magnesium)); |
|
487 ui->w1_spButton->setChecked(true); |
|
488 } |
516 } |
489 // The spargewater is set. |
517 // The spargewater is set. |
490 |
518 |
491 int AT = recipe->sparge_acid_type; |
519 int AT = recipe->sparge_acid_type; |
492 if (AT < 0 || AT >= my_acids.size()) { |
520 if (AT < 0 || AT >= my_acids.size()) { |