--- a/src/EditProductTab9.cpp Sun May 15 11:27:06 2022 +0200 +++ b/src/EditProductTab9.cpp Sun May 15 20:57:03 2022 +0200 @@ -133,6 +133,58 @@ } +void EditProduct::calcEfficiencyBeforeBoil() +{ + double m = 0; + double tot; + double result = 0; + + if (product->fermentables.size() == 0) + return; // no fermentables loaded yet + for (int i = 0; i < product->fermentables.size(); i++) { + if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_MASH) { + m += product->fermentables.at(i).f_amount * (product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100); + } + } + tot = Utils::sg_to_plato(product->brew_preboil_sg) * (product->brew_preboil_volume / 1.04) * product->brew_preboil_sg * 10 / 1000; + + if (m > 0) + result = round((tot / m * 100) * 10.0) / 10.0; + + if (result < 0) + result = 0; + ui->brew_preboileffShow->setValue(result); +} + + +void EditProduct::brew_preboilsg_changed(double val) +{ + if (product->brew_preboil_sg == 0) { + product->brew_preboil_sg = product->preboil_sg; + const QSignalBlocker blocker1(ui->brew_preboilsgEdit); + ui->brew_preboilsgEdit->setValue(product->preboil_sg); + } else { + product->brew_preboil_sg = val; + } + is_changed(); + calcEfficiencyBeforeBoil(); +} + + +void EditProduct::brew_preboilvol_changed(double val) +{ + if (product->brew_preboil_volume == 0) { + product->brew_preboil_volume = product->boil_size * 1.04; + const QSignalBlocker blocker1(ui->brew_preboilvolEdit); + ui->brew_preboilvolEdit->setValue(product->boil_size * 1.04); + } else { + product->brew_preboil_volume = val; + } + is_changed(); + calcEfficiencyBeforeBoil(); +} + + void EditProduct::brew_aboilph_changed(double val) { if (product->brew_aboil_ph == 0) { @@ -146,3 +198,57 @@ } +void EditProduct::calcEfficiencyAfterBoil() +{ + double m = 0; // Sugars added at mash + double b = 0; // Sugars added at boil + double result = 0; + + if (product->fermentables.size() == 0) + return; // no fermentables loaded yet + for (int i = 0; i < product->fermentables.size(); i++) { + if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_MASH) { + m += product->fermentables.at(i).f_amount * (product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100); + } else if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_BOIL) { + b += product->fermentables.at(i).f_amount * (product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100); + } + } + double tot = Utils::sg_to_plato(product->brew_aboil_sg) * (product->brew_aboil_volume / 1.04) * product->brew_aboil_sg * 10 / 1000; + tot -= b; // total sugars in wort minus added sugars. + + if (m > 0) + result = round((tot / m * 100) * 10.0) / 10.0; + product->brew_aboil_efficiency = result; + ui->brew_aboileffShow->setValue(result); + calcFermentables(); // This will also recalculate all volumes. +} + + +void EditProduct::brew_aboilsg_changed(double val) +{ + if (product->brew_aboil_sg == 0) { + product->brew_aboil_sg = product->est_og3; + const QSignalBlocker blocker1(ui->brew_aboilsgEdit); + ui->brew_aboilsgEdit->setValue(product->est_og3); + } else { + product->brew_aboil_sg = val; + } + is_changed(); + calcEfficiencyAfterBoil(); +} + + +void EditProduct::brew_aboilvol_changed(double val) +{ + if (product->brew_aboil_volume == 0) { + product->brew_aboil_volume = product->batch_size * 1.04; + const QSignalBlocker blocker1(ui->brew_aboilvolEdit); + ui->brew_aboilvolEdit->setValue(product->batch_size * 1.04); + } else { + product->brew_aboil_volume = val; + } + is_changed(); + calcEfficiencyAfterBoil(); +} + +