# HG changeset patch # User Michiel Broek # Date 1658222259 -7200 # Node ID ec8de79f6ff632965e043bb5bdebf26c8a358615 # Parent b70cfa20ac468c1b6ef1a7b056cf5d4caaa81f07 Improved selection logic for the sparge water. diff -r b70cfa20ac46 -r ec8de79f6ff6 src/EditProduct.h --- a/src/EditProduct.h Mon Jul 18 19:28:21 2022 +0200 +++ b/src/EditProduct.h Tue Jul 19 11:17:39 2022 +0200 @@ -298,6 +298,7 @@ double AcidRequired(double ZpH, Fermentables F); double ProtonDeficit(double pHZ); double MashpH(); + void setButtons(bool locked); void calcWater(); void calcSparge(); double GetBUGU(); diff -r b70cfa20ac46 -r ec8de79f6ff6 src/EditProductTab1.cpp --- a/src/EditProductTab1.cpp Mon Jul 18 19:28:21 2022 +0200 +++ b/src/EditProductTab1.cpp Tue Jul 19 11:17:39 2022 +0200 @@ -324,9 +324,6 @@ ui->sp_phEdit->setButtonSymbols(QAbstractSpinBox::NoButtons); ui->sp_acidvolEdit->setReadOnly(true); ui->sp_acidvolEdit->setButtonSymbols(QAbstractSpinBox::NoButtons); - ui->w1_spButton->setDisabled(true); - ui->w2_spButton->setDisabled(true); - ui->wg_spButton->setDisabled(true); } else { ui->mw_phEdit->setReadOnly(! product->calc_acid); ui->mw_phEdit->setButtonSymbols(product->calc_acid ? QAbstractSpinBox::UpDownArrows : QAbstractSpinBox::NoButtons); @@ -338,6 +335,7 @@ ui->sp_acidvolEdit->setButtonSymbols(product->calc_acid ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows); } ui->mw_autoEdit->setDisabled(stage > PROD_STAGE_BREW); + setButtons(stage > PROD_STAGE_BREW); /* Tab 9, brewday */ ui->tabWidget->setTabEnabled(8, stage > PROD_STAGE_PLAN); diff -r b70cfa20ac46 -r ec8de79f6ff6 src/EditProductTab8.cpp --- a/src/EditProductTab8.cpp Mon Jul 18 19:28:21 2022 +0200 +++ b/src/EditProductTab8.cpp Tue Jul 19 11:17:39 2022 +0200 @@ -141,6 +141,52 @@ } +void EditProduct::setButtons(bool locked) +{ + if (locked) { + /* + * If the brew is done, disable the buttons and that's it. + */ + ui->w1_spButton->setDisabled(true); + ui->w2_spButton->setDisabled(true); + ui->wg_spButton->setDisabled(true); + return; + } + ui->w1_spButton->setDisabled(false); + + const QSignalBlocker blocker1(ui->w1_spButton); + const QSignalBlocker blocker2(ui->w2_spButton); + const QSignalBlocker blocker3(ui->wg_spButton); + + if (product->w2_name != "") { + ui->w2_spButton->setDisabled(false); + if (product->w2_amount > 0.1 && product->w2_ph > 5) { + /* + * Water 2 is valid and used for mash, mixed is available. + */ + ui->wg_spButton->setDisabled(false); + } else { + /* + * No mixed water for mash. We can still sparge with source 2. + */ + ui->wg_spButton->setDisabled(true); + if (product->sparge_source == 2) { + /* + * If mixed was selected, switch to source 2. + */ + product->sparge_source = 1; + ui->w2_spButton->setChecked(true); + } + } + } else { + ui->w2_spButton->setDisabled(true); + ui->wg_spButton->setDisabled(true); + product->sparge_source = 0; // Fallback to source 1 + ui->w1_spButton->setChecked(true); + } +} + + void EditProduct::calcWater() { double liters = 0; @@ -429,51 +475,35 @@ qDebug() << "calcSparge()"; - const QSignalBlocker blocker2(ui->w1_spButton); - const QSignalBlocker blocker3(ui->w2_spButton); - const QSignalBlocker blocker4(ui->wg_spButton); + setButtons(product->stage > PROD_STAGE_BREW); - // Select watersource or fallback to the first source. - if (product->sparge_source == 1) { // Source 2 - if (product->w2_ph > 0.0 && product->w2_amount > 0) { - Source_pH = product->w2_ph; - Source_alkalinity = product->w2_total_alkalinity; - ui->sp_caEdit->setValue(product->w2_calcium); - ui->sp_mgEdit->setValue(product->w2_magnesium); - ui->sp_hco3Edit->setValue(Utils::Bicarbonate(product->w2_total_alkalinity, product->w2_ph)); - ui->sp_caco3Edit->setValue(product->w2_total_alkalinity); - ui->sp_naEdit->setValue(product->w2_sodium); - ui->sp_clEdit->setValue(product->w2_chloride); - ui->sp_so4Edit->setValue(product->w2_sulfate); - ui->sp_phShow->setValue(product->w2_ph); - ui->sp_hardnessEdit->setValue(Utils::Hardness(product->w2_calcium, product->w2_magnesium)); - ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(product->w2_total_alkalinity, product->w2_calcium, product->w2_magnesium)); - ui->w2_spButton->setChecked(true); - } else { - product->sparge_source = 0; // Fallback to source 1 - ui->w1_spButton->setChecked(true); - } - } else if (product->sparge_source == 2) { // Mixed - if (product->w2_ph > 0.0 && product->w2_amount > 0) { - Source_pH = product->wg_ph; - Source_alkalinity = product->wg_total_alkalinity; - ui->sp_caEdit->setValue(product->wg_calcium); - ui->sp_mgEdit->setValue(product->wg_magnesium); - ui->sp_hco3Edit->setValue(Utils::Bicarbonate(product->wg_total_alkalinity, product->wg_ph)); - ui->sp_caco3Edit->setValue(product->wg_total_alkalinity); - ui->sp_naEdit->setValue(product->wg_sodium); - ui->sp_clEdit->setValue(product->wg_chloride); - ui->sp_so4Edit->setValue(product->wg_sulfate); - ui->sp_phShow->setValue(product->wg_ph); - ui->sp_hardnessEdit->setValue(Utils::Hardness(product->wg_calcium, product->wg_magnesium)); - ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(product->wg_total_alkalinity, product->wg_calcium, product->wg_magnesium)); - ui->wg_spButton->setChecked(true); - } else { - product->sparge_source = 0; // Fallback to source 1 - ui->w1_spButton->setChecked(true); - } - } - if (product->sparge_source == 0) { + if (product->sparge_source == 1 && product->w2_ph > 0.0) { + Source_pH = product->w2_ph; + Source_alkalinity = product->w2_total_alkalinity; + ui->sp_caEdit->setValue(product->w2_calcium); + ui->sp_mgEdit->setValue(product->w2_magnesium); + ui->sp_hco3Edit->setValue(Utils::Bicarbonate(product->w2_total_alkalinity, product->w2_ph)); + ui->sp_caco3Edit->setValue(product->w2_total_alkalinity); + ui->sp_naEdit->setValue(product->w2_sodium); + ui->sp_clEdit->setValue(product->w2_chloride); + ui->sp_so4Edit->setValue(product->w2_sulfate); + ui->sp_phShow->setValue(product->w2_ph); + ui->sp_hardnessEdit->setValue(Utils::Hardness(product->w2_calcium, product->w2_magnesium)); + ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(product->w2_total_alkalinity, product->w2_calcium, product->w2_magnesium)); + } else if (product->sparge_source == 2 && product->w2_ph > 0.0) { + Source_pH = product->wg_ph; + Source_alkalinity = product->wg_total_alkalinity; + ui->sp_caEdit->setValue(product->wg_calcium); + ui->sp_mgEdit->setValue(product->wg_magnesium); + ui->sp_hco3Edit->setValue(Utils::Bicarbonate(product->wg_total_alkalinity, product->wg_ph)); + ui->sp_caco3Edit->setValue(product->wg_total_alkalinity); + ui->sp_naEdit->setValue(product->wg_sodium); + ui->sp_clEdit->setValue(product->wg_chloride); + ui->sp_so4Edit->setValue(product->wg_sulfate); + ui->sp_phShow->setValue(product->wg_ph); + ui->sp_hardnessEdit->setValue(Utils::Hardness(product->wg_calcium, product->wg_magnesium)); + ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(product->wg_total_alkalinity, product->wg_calcium, product->wg_magnesium)); + } else { ui->sp_caEdit->setValue(product->w1_calcium); ui->sp_mgEdit->setValue(product->w1_magnesium); ui->sp_hco3Edit->setValue(Utils::Bicarbonate(product->w1_total_alkalinity, product->w1_ph)); @@ -484,7 +514,6 @@ ui->sp_phShow->setValue(product->w1_ph); ui->sp_hardnessEdit->setValue(Utils::Hardness(product->w1_calcium, product->w1_magnesium)); ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(product->w1_total_alkalinity, product->w1_calcium, product->w1_magnesium)); - ui->w1_spButton->setChecked(true); } // The spargewater is set. diff -r b70cfa20ac46 -r ec8de79f6ff6 src/EditRecipe.h --- a/src/EditRecipe.h Mon Jul 18 19:28:21 2022 +0200 +++ b/src/EditRecipe.h Tue Jul 19 11:17:39 2022 +0200 @@ -177,6 +177,7 @@ double AcidRequired(double ZpH, Fermentables F); double ProtonDeficit(double pHZ); double MashpH(); + void setButtons(bool locked); void calcWater(); void calcSparge(); double GetBUGU(); diff -r b70cfa20ac46 -r ec8de79f6ff6 src/EditRecipeTab1.cpp --- a/src/EditRecipeTab1.cpp Mon Jul 18 19:28:21 2022 +0200 +++ b/src/EditRecipeTab1.cpp Tue Jul 19 11:17:39 2022 +0200 @@ -254,9 +254,6 @@ ui->sp_phEdit->setButtonSymbols(QAbstractSpinBox::NoButtons); ui->sp_acidvolEdit->setReadOnly(true); ui->sp_acidvolEdit->setButtonSymbols(QAbstractSpinBox::NoButtons); - ui->w1_spButton->setDisabled(true); - ui->w2_spButton->setDisabled(true); - ui->wg_spButton->setDisabled(true); } else { ui->mw_phEdit->setReadOnly(! recipe->calc_acid); ui->mw_phEdit->setButtonSymbols(recipe->calc_acid ? QAbstractSpinBox::UpDownArrows : QAbstractSpinBox::NoButtons); @@ -268,6 +265,7 @@ ui->sp_acidvolEdit->setButtonSymbols(recipe->calc_acid ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows); } ui->mw_autoEdit->setDisabled(val); + setButtons(val); } diff -r b70cfa20ac46 -r ec8de79f6ff6 src/EditRecipeTab7.cpp --- a/src/EditRecipeTab7.cpp Mon Jul 18 19:28:21 2022 +0200 +++ b/src/EditRecipeTab7.cpp Tue Jul 19 11:17:39 2022 +0200 @@ -68,16 +68,16 @@ * If the acid_to_ph_5.7 is unknown from the maltster, guess the required acid. */ switch (F.graintype) { - case 0: // Base, Special, Kilned - case 3: - case 5: C1 = 0.014 * F.color - 34.192; - break; - case 2: C1 = -0.0597 * F.color - 32.457; // Crystal - break; - case 1: C1 = 0.0107 * F.color - 54.768; // Roast - break; - case 4: C1 = -149; // Sour malt - break; + case FERMENTABLE_GRAINTYPE_BASE: + case FERMENTABLE_GRAINTYPE_KILNED: + case FERMENTABLE_GRAINTYPE_SPECIAL: C1 = 0.014 * F.color - 34.192; + break; + case FERMENTABLE_GRAINTYPE_CRYSTAL: C1 = -0.0597 * F.color - 32.457; + break; + case FERMENTABLE_GRAINTYPE_ROAST: C1 = 0.0107 * F.color - 54.768; + break; + case FERMENTABLE_GRAINTYPE_SOUR_MALT: C1 = -149; + break; } } return C1; @@ -105,7 +105,7 @@ if (recipe->fermentables.size()) { for (i = 0; i < recipe->fermentables.size(); i++) { F = recipe->fermentables.at(i); - if (F.added == 0 && F.graintype != 6) { // Added == Mash && graintype != No Malt + if (F.added == FERMENTABLE_ADDED_MASH && F.graintype != FERMENTABLE_GRAINTYPE_NO_MALT) { x = AcidRequired(pHZ, F) * F.amount; Result += x; } @@ -141,6 +141,52 @@ } +void EditRecipe::setButtons(bool locked) +{ + if (locked) { + /* + * If recipe is locked, disable the buttons and that's it. + */ + ui->w1_spButton->setDisabled(true); + ui->w2_spButton->setDisabled(true); + ui->wg_spButton->setDisabled(true); + return; + } + ui->w1_spButton->setDisabled(false); + + const QSignalBlocker blocker1(ui->w1_spButton); + const QSignalBlocker blocker2(ui->w2_spButton); + const QSignalBlocker blocker3(ui->wg_spButton); + + if (recipe->w2_name != "") { + ui->w2_spButton->setDisabled(false); + if (recipe->w2_amount > 0.1 && recipe->w2_ph > 5) { + /* + * Water 2 is valid and used for mash, mixed is available. + */ + ui->wg_spButton->setDisabled(false); + } else { + /* + * No mixed water for mash. We can still sparge with source 2. + */ + ui->wg_spButton->setDisabled(true); + if (recipe->sparge_source == 2) { + /* + * If mixed was selected, switch to source 2. + */ + recipe->sparge_source = 1; + ui->w2_spButton->setChecked(true); + } + } + } else { + ui->w2_spButton->setDisabled(true); + ui->wg_spButton->setDisabled(true); + recipe->sparge_source = 0; // Fallback to source 1 + ui->w1_spButton->setChecked(true); + } +} + + void EditRecipe::calcWater() { double liters = 0; @@ -428,63 +474,45 @@ double Source_alkalinity = recipe->w1_total_alkalinity; qDebug() << "calcSparge()"; - - const QSignalBlocker blocker2(ui->w1_spButton); - const QSignalBlocker blocker3(ui->w2_spButton); - const QSignalBlocker blocker4(ui->wg_spButton); + setButtons(recipe->locked); - // Select watersource or fallback to the first source. - if (recipe->sparge_source == 1) { // Source 2 - if (recipe->w2_ph > 0.0 && recipe->w2_amount > 0) { - Source_pH = recipe->w2_ph; - Source_alkalinity = recipe->w2_total_alkalinity; - ui->sp_caEdit->setValue(recipe->w2_calcium); - ui->sp_mgEdit->setValue(recipe->w2_magnesium); - ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w2_total_alkalinity, recipe->w2_ph)); - ui->sp_caco3Edit->setValue(recipe->w2_total_alkalinity); - ui->sp_naEdit->setValue(recipe->w2_sodium); - ui->sp_clEdit->setValue(recipe->w2_chloride); - ui->sp_so4Edit->setValue(recipe->w2_sulfate); - ui->sp_phShow->setValue(recipe->w2_ph); - ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w2_calcium, recipe->w2_magnesium)); - ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w2_total_alkalinity, recipe->w2_calcium, recipe->w2_magnesium)); - ui->w2_spButton->setChecked(true); - } else { - recipe->sparge_source = 0; // Fallback to source 1 - ui->w1_spButton->setChecked(true); - } - } else if (recipe->sparge_source == 2) { // Mixed - if (recipe->w2_ph > 0.0 && recipe->w2_amount > 0) { - Source_pH = recipe->wg_ph; - Source_alkalinity = recipe->wg_total_alkalinity; - ui->sp_caEdit->setValue(recipe->wg_calcium); - ui->sp_mgEdit->setValue(recipe->wg_magnesium); - ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->wg_total_alkalinity, recipe->wg_ph)); - ui->sp_caco3Edit->setValue(recipe->wg_total_alkalinity); - ui->sp_naEdit->setValue(recipe->wg_sodium); - ui->sp_clEdit->setValue(recipe->wg_chloride); - ui->sp_so4Edit->setValue(recipe->wg_sulfate); - ui->sp_phShow->setValue(recipe->wg_ph); - ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->wg_calcium, recipe->wg_magnesium)); - ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->wg_total_alkalinity, recipe->wg_calcium, recipe->wg_magnesium)); - ui->wg_spButton->setChecked(true); - } else { - recipe->sparge_source = 0; // Fallback to source 1 - ui->w1_spButton->setChecked(true); - } - } - if (recipe->sparge_source == 0) { - ui->sp_caEdit->setValue(recipe->w1_calcium); - ui->sp_mgEdit->setValue(recipe->w1_magnesium); - ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w1_total_alkalinity, recipe->w1_ph)); - ui->sp_caco3Edit->setValue(recipe->w1_total_alkalinity); - ui->sp_naEdit->setValue(recipe->w1_sodium); - ui->sp_clEdit->setValue(recipe->w1_chloride); - ui->sp_so4Edit->setValue(recipe->w1_sulfate); - ui->sp_phShow->setValue(recipe->w1_ph); - ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w1_calcium, recipe->w1_magnesium)); - ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w1_total_alkalinity, recipe->w1_calcium, recipe->w1_magnesium)); - ui->w1_spButton->setChecked(true); + if (recipe->sparge_source == 1 && recipe->w2_ph > 0.0) { + Source_pH = recipe->w2_ph; + Source_alkalinity = recipe->w2_total_alkalinity; + ui->sp_caEdit->setValue(recipe->w2_calcium); + ui->sp_mgEdit->setValue(recipe->w2_magnesium); + ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w2_total_alkalinity, recipe->w2_ph)); + ui->sp_caco3Edit->setValue(recipe->w2_total_alkalinity); + ui->sp_naEdit->setValue(recipe->w2_sodium); + ui->sp_clEdit->setValue(recipe->w2_chloride); + ui->sp_so4Edit->setValue(recipe->w2_sulfate); + ui->sp_phShow->setValue(recipe->w2_ph); + ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w2_calcium, recipe->w2_magnesium)); + ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w2_total_alkalinity, recipe->w2_calcium, recipe->w2_magnesium)); + } else if (recipe->sparge_source == 2 && recipe->w2_ph > 0.0) { + Source_pH = recipe->wg_ph; + Source_alkalinity = recipe->wg_total_alkalinity; + ui->sp_caEdit->setValue(recipe->wg_calcium); + ui->sp_mgEdit->setValue(recipe->wg_magnesium); + ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->wg_total_alkalinity, recipe->wg_ph)); + ui->sp_caco3Edit->setValue(recipe->wg_total_alkalinity); + ui->sp_naEdit->setValue(recipe->wg_sodium); + ui->sp_clEdit->setValue(recipe->wg_chloride); + ui->sp_so4Edit->setValue(recipe->wg_sulfate); + ui->sp_phShow->setValue(recipe->wg_ph); + ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->wg_calcium, recipe->wg_magnesium)); + ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->wg_total_alkalinity, recipe->wg_calcium, recipe->wg_magnesium)); + } else { + ui->sp_caEdit->setValue(recipe->w1_calcium); + ui->sp_mgEdit->setValue(recipe->w1_magnesium); + ui->sp_hco3Edit->setValue(Utils::Bicarbonate(recipe->w1_total_alkalinity, recipe->w1_ph)); + ui->sp_caco3Edit->setValue(recipe->w1_total_alkalinity); + ui->sp_naEdit->setValue(recipe->w1_sodium); + ui->sp_clEdit->setValue(recipe->w1_chloride); + ui->sp_so4Edit->setValue(recipe->w1_sulfate); + ui->sp_phShow->setValue(recipe->w1_ph); + ui->sp_hardnessEdit->setValue(Utils::Hardness(recipe->w1_calcium, recipe->w1_magnesium)); + ui->sp_raEdit->setValue(Utils::ResidualAlkalinity(recipe->w1_total_alkalinity, recipe->w1_calcium, recipe->w1_magnesium)); } // The spargewater is set.