# HG changeset patch # User Michiel Broek # Date 1650487700 -7200 # Node ID fd568cc1dd0e8f19ff3577aba7ecae68123a2d86 # Parent d73719fa2ebbca08091cab903f073e42bb3ddfd8 Implemented the last widgets on the first tab and added the needed functions for them such as scaling the recipe. This is the last part of the recipe editor, now ready for testing. diff -r d73719fa2ebb -r fd568cc1dd0e src/EditRecipe.cpp --- a/src/EditRecipe.cpp Wed Apr 20 14:30:06 2022 +0200 +++ b/src/EditRecipe.cpp Wed Apr 20 22:48:20 2022 +0200 @@ -650,18 +650,18 @@ connect(ui->lockedEdit, &QCheckBox::stateChanged, this, &EditRecipe::is_changed); connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditRecipe::name_changed); connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(notes_changed())); - connect(ui->typeEdit, &QComboBox::currentTextChanged, this, &EditRecipe::is_changed); - connect(ui->batch_sizeEdit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed); - connect(ui->boil_timeEdit, &QSpinBox::textChanged, this, &EditRecipe::is_changed); - connect(ui->efficiencyEdit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed); - connect(ui->beerstyleEdit, &QComboBox::currentTextChanged, this, &EditRecipe::style_changed); - connect(ui->est_ogEdit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed); - connect(ui->color_methodEdit, &QComboBox::currentTextChanged, this, &EditRecipe::colormethod_changed); - connect(ui->ibu_methodEdit, &QComboBox::currentTextChanged, this, &EditRecipe::is_changed); + connect(ui->typeEdit, QOverload::of(&QComboBox::currentIndexChanged), this, &EditRecipe::brew_type_changed); + connect(ui->batch_sizeEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::batch_size_changed); + connect(ui->boil_timeEdit, QOverload::of(&QSpinBox::valueChanged), this, &EditRecipe::boil_time_changed); + connect(ui->efficiencyEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::efficiency_changed); + connect(ui->beerstyleEdit, QOverload::of(&QComboBox::currentIndexChanged), this, &EditRecipe::style_changed); + connect(ui->est_ogEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::est_og_changed); + connect(ui->color_methodEdit, QOverload::of(&QComboBox::currentIndexChanged), this, &EditRecipe::colormethod_changed); + connect(ui->ibu_methodEdit, QOverload::of(&QComboBox::currentIndexChanged), this, &EditRecipe::ibumethod_changed); // All signals from tab "Fermentables" ui->fermentablesTable->setEditTriggers(QAbstractItemView::NoEditTriggers); - connect(ui->est_og2Edit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed); + connect(ui->est_og2Edit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::est_og_changed); connect(ui->perc_mashShow, &QProgressBar::valueChanged, this, &EditRecipe::ferment_perc_mash_valueChanged); connect(ui->perc_sugarsShow, &QProgressBar::valueChanged, this, &EditRecipe::ferment_perc_sugars_valueChanged); connect(ui->perc_caraShow, &QProgressBar::valueChanged, this, &EditRecipe::ferment_perc_cara_valueChanged); diff -r d73719fa2ebb -r fd568cc1dd0e src/EditRecipe.h --- a/src/EditRecipe.h Wed Apr 20 14:30:06 2022 +0200 +++ b/src/EditRecipe.h Wed Apr 20 22:48:20 2022 +0200 @@ -262,8 +262,14 @@ void is_changed(); void name_changed(QString); void notes_changed(); - void style_changed(); - void colormethod_changed(); + void style_changed(int val); + void colormethod_changed(int val); + void ibumethod_changed(int val); + void est_og_changed(double val); + void efficiency_changed(double val); + void boil_time_changed(int val); + void batch_size_changed(double val); + void brew_type_changed(int val); void refreshFermentables(); void refreshHops(); void refreshMiscs(); @@ -389,7 +395,10 @@ void brewing_salt_sub(QString salt, double val); void set_brewing_salt(QString salt, double val); void calcFermentables(); + void calcFermentablesFromOG(double og); void calcIBUs(); + void adjustHops(double factor); + void adjustMiscs(double factor); double ZAlkalinity(double pHZ); double ZRA(double pHZ); double BufferCapacity(Fermentables F); @@ -400,9 +409,11 @@ double GetBUGU(); double GetOptSO4Clratio(); void calcYeast(); + void adjustYeasts(double factor); double infusionVol(double step_infused, double step_mashkg, double infuse_temp, double step_temp, double last_temp); double decoctionVol(double step_volume, double step_temp, double prev_temp); void calcMash(); + void adjustWaters(double factor); }; #endif diff -r d73719fa2ebb -r fd568cc1dd0e src/EditRecipeTab1.cpp --- a/src/EditRecipeTab1.cpp Wed Apr 20 14:30:06 2022 +0200 +++ b/src/EditRecipeTab1.cpp Wed Apr 20 22:48:20 2022 +0200 @@ -37,18 +37,15 @@ /* * New beerstyle is selected. */ -void EditRecipe::style_changed() +void EditRecipe::style_changed(int val) { QSqlQuery query; - if (ui->beerstyleEdit->currentIndex() < 1) - return; - query.prepare("SELECT * FROM profile_styles ORDER BY style_guide,style_letter,name"); query.exec(); query.first(); // Skip to the record index. - for (int i = 0; i < (ui->beerstyleEdit->currentIndex() - 1); i++) { + for (int i = 0; i < (val - 1); i++) { query.next(); } // Set relevant fields and update ranges. @@ -89,10 +86,89 @@ } -void EditRecipe::colormethod_changed() +void EditRecipe::colormethod_changed(int val) { + recipe->color_method = val; calcFermentables(); is_changed(); } +void EditRecipe::ibumethod_changed(int val) +{ + recipe->ibu_method = val; + calcIBUs(); + is_changed(); +} + + +void EditRecipe::est_og_changed(double val) +{ + recipe->est_og = val; + calcFermentablesFromOG(val);// Adjust fermentables amounts + calcFermentables(); // Update the recipe details + calcIBUs(); + calcMash(); + is_changed(); + emit refreshAll(); +} + + +void EditRecipe::efficiency_changed(double val) +{ + double estog = recipe->est_og; + recipe->efficiency = val; + calcFermentablesFromOG(estog); + calcFermentables(); + calcIBUs(); + is_changed(); + emit refreshAll(); +} + + +void EditRecipe::boil_time_changed(int val) +{ + qDebug() << "boil_time_changed" << val; + double new_evap = (0.1 * recipe->batch_size) * val / 60.0; + recipe->boil_size = recipe->batch_size + new_evap; + recipe->boil_time = val; + ui->boil_sizeEdit->setValue(recipe->boil_size); + calcFermentables(); + calcIBUs(); + is_changed(); +} + + +void EditRecipe::batch_size_changed(double val) +{ + qDebug() << "batch_size_changed" << val << "old" << recipe->batch_size; + + double evap = (0.1 * val) * recipe->boil_time / 60.0; + recipe->boil_size = val + evap; + double factor = val / recipe->batch_size; + ui->boil_sizeEdit->setValue(recipe->boil_size); + recipe->sparge_volume *= factor; + ui->sp_volEdit->setValue(recipe->sparge_volume); + recipe->batch_size = val; + calcFermentablesFromOG(recipe->est_og); // Keep the OG + adjustWaters(factor); + calcFermentables(); + adjustHops(factor); + adjustMiscs(factor); + adjustYeasts(factor); + calcIBUs(); + calcWater(); + //calcSparge(); + calcMash(); + is_changed(); + emit refreshAll(); +} + + +void EditRecipe::brew_type_changed(int val) +{ + recipe->type; + is_changed(); +} + + diff -r d73719fa2ebb -r fd568cc1dd0e src/EditRecipeTab2.cpp --- a/src/EditRecipeTab2.cpp Wed Apr 20 14:30:06 2022 +0200 +++ b/src/EditRecipeTab2.cpp Wed Apr 20 22:48:20 2022 +0200 @@ -270,15 +270,15 @@ /* * Color of the wort */ - if (ui->color_methodEdit->currentIndex() == 4) { // Naudts + if (recipe->color_method == 4) { // Naudts color = round(((Utils::sg_to_plato(og) / 8.6) * colorn) + (ui->boil_timeEdit->value() / 60)); - } else if (ui->color_methodEdit->currentIndex() == 3) { // Hans Halberstadt + } else if (recipe->color_method == 3) { // Hans Halberstadt double bv = 0.925; // Beer loss efficiency double sr = 0.95; // Mash and sparge efficiency color = round((4.46 * bv * sr) / ui->batch_sizeEdit->value() * colorh); } else { double cw = colort / ui->batch_sizeEdit->value() * 8.34436; - color = Utils::kw_to_ebc(ui->color_methodEdit->currentIndex(), cw); + color = Utils::kw_to_ebc(recipe->color_method, cw); } qDebug() << " color" << ui->est_colorEdit->value() << color << recipe->est_color; recipe->est_color = color; @@ -349,6 +349,39 @@ } +void EditRecipe::calcFermentablesFromOG(double og) +{ + qDebug() << "calcFermentablesFromOG" << og; + + int i; + double totmass = 0; + double tot = 0; + double d, amount; + double efficiency = recipe->efficiency; + double sug = Utils::sg_to_plato(og) * recipe->batch_size * og / 100.0; // total amount of sugars in kg. + + for (i = 0; i < recipe->fermentables.size(); i++) { + if (recipe->fermentables.at(i).f_added < 4) { + d = recipe->fermentables.at(i).f_percentage / 100.0 * + (recipe->fermentables.at(i).f_yield / 100.0) * + (1 - recipe->fermentables.at(i).f_moisture / 100.0); + if (recipe->fermentables.at(i).f_added == 0) // Mash + d = efficiency / 100.0 * d; + tot += d; + } + } + if (tot) + totmass = round((sug / tot) * 1000.0) / 1000.0; + + if (totmass) { + for (i = 0; i < recipe->fermentables.size(); i++) { + amount = round(recipe->fermentables.at(i).f_percentage * 10.0 * totmass) / 1000.0; + recipe->fermentables[i].f_amount = amount; + } + } +} + + void EditRecipe::ferment_perc_mash_valueChanged(int value) { if (value < 90) diff -r d73719fa2ebb -r fd568cc1dd0e src/EditRecipeTab3.cpp --- a/src/EditRecipeTab3.cpp Wed Apr 20 14:30:06 2022 +0200 +++ b/src/EditRecipeTab3.cpp Wed Apr 20 22:48:20 2022 +0200 @@ -202,7 +202,7 @@ hop_flavour = 100; if (hop_aroma > 100) hop_aroma = 100; - qDebug() << "ibu" << recipe->est_ibu << ibus << "flavour" << hop_flavour << "aroma" << hop_aroma; + qDebug() << "ibu" << recipe->est_ibu << ibus << "flavour" << hop_flavour << "aroma" << hop_aroma << "method" << recipe->ibu_method; recipe->est_ibu = ibus; ui->est_ibuEdit->setValue(recipe->est_ibu); @@ -632,3 +632,17 @@ } +void EditRecipe::adjustHops(double factor) +{ + double amount; + + if (recipe->hops.size() == 0) + return; + + for (int i = 0; i < recipe->hops.size(); i++) { + amount = recipe->hops.at(i).h_amount * factor; + recipe->hops[i].h_amount = amount; + } +} + + diff -r d73719fa2ebb -r fd568cc1dd0e src/EditRecipeTab4.cpp --- a/src/EditRecipeTab4.cpp Wed Apr 20 14:30:06 2022 +0200 +++ b/src/EditRecipeTab4.cpp Wed Apr 20 22:48:20 2022 +0200 @@ -638,3 +638,49 @@ emit refreshAll(); } + +void EditRecipe::adjustMiscs(double factor) +{ + double amount; + + if (recipe->miscs.size() == 0) + return; + + this->ignoreChanges = true; + for (int i = 0; i < recipe->miscs.size(); i++) { + amount = recipe->miscs.at(i).m_amount * factor; + recipe->miscs[i].m_amount = amount; + + /* + * Update the water agents. + */ + if (recipe->miscs.at(i).m_type == 4) { + if (recipe->miscs.at(i).m_name == "CaCl2") { + ui->bs_cacl2Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0); + } else if (recipe->miscs.at(i).m_name == "CaSO4") { + ui->bs_caso4Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0); + } else if (recipe->miscs.at(i).m_name == "MgSO4") { + ui->bs_mgso4Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0); + } else if (recipe->miscs.at(i).m_name == "NaCl") { + ui->bs_naclEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0); + } else if (recipe->miscs.at(i).m_name == "MgCl2") { + ui->bs_mgcl2Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0); + } else if (recipe->miscs.at(i).m_name == "NaHCO3") { + ui->bs_nahco3Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0); + } else if (recipe->miscs.at(i).m_name == "CaCO3") { + ui->bs_caco3Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0); + } else if (recipe->miscs.at(i).m_name == "Melkzuur" || recipe->miscs.at(i).m_name == "Lactic") { + ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0); + } else if (recipe->miscs.at(i).m_name == "Zoutzuur" || recipe->miscs.at(i).m_name == "Hydrochloric") { + ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0); + } else if (recipe->miscs.at(i).m_name == "Fosforzuur" || recipe->miscs.at(i).m_name == "Phosphoric") { + ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0); + } else if (recipe->miscs.at(i).m_name == "Zwavelzuur" || recipe->miscs.at(i).m_name == "Sulfuric") { + ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0); + } + } + } + this->ignoreChanges = false; +} + + diff -r d73719fa2ebb -r fd568cc1dd0e src/EditRecipeTab5.cpp --- a/src/EditRecipeTab5.cpp Wed Apr 20 14:30:06 2022 +0200 +++ b/src/EditRecipeTab5.cpp Wed Apr 20 22:48:20 2022 +0200 @@ -552,3 +552,19 @@ emit refreshAll(); } + +void EditRecipe::adjustYeasts(double factor) +{ + double amount; + + if (recipe->yeasts.size() == 0) + return; + + for (int i = 0; i < recipe->yeasts.size(); i++) { + if (recipe->yeasts.at(i).y_form == 1) { // Only adjust dry yeast + amount = recipe->yeasts.at(i).y_amount * factor; + recipe->yeasts[i].y_amount = amount; + } + } +} + diff -r d73719fa2ebb -r fd568cc1dd0e src/EditRecipeTab7.cpp --- a/src/EditRecipeTab7.cpp Wed Apr 20 14:30:06 2022 +0200 +++ b/src/EditRecipeTab7.cpp Wed Apr 20 22:48:20 2022 +0200 @@ -628,6 +628,42 @@ } +void EditRecipe::adjustWaters(double factor) +{ + int i; + double amount; + + if (recipe->mashs.size() == 0) + return; + + double mash_infuse = 0; + for (i = 0; i < recipe->mashs.size(); i++) { + if (recipe->mashs.at(i).step_type == 0) { // Infusion + amount = round(recipe->mashs.at(i).step_infuse_amount * factor * 1000000.0) / 1000000.0; + recipe->mashs[i].step_infuse_amount = amount; + mash_infuse += amount; + recipe->mashs[i].step_volume = mash_infuse; + } + } + + this->ignoreChanges = true; + if (recipe->w2_amount == 0) { + recipe->w1_amount = mash_infuse; + ui->w1_volEdit->setValue(mash_infuse); + } else { + double w1 = (recipe->w1_amount / (recipe->w1_amount + recipe->w2_amount)) * mash_infuse; + double w2 = (recipe->w2_amount / (recipe->w1_amount + recipe->w2_amount)) * mash_infuse; + recipe->w1_amount = w1; + recipe->w2_amount = w2; + ui->w1_volEdit->setValue(recipe->w1_amount); + ui->w2_volEdit->setValue(recipe->w2_amount); + } + recipe->wg_amount = mash_infuse; + ui->wg_volEdit->setValue(mash_infuse); + this->ignoreChanges = false; +} + + void EditRecipe::wb_cacl2_changed(double val) { set_brewing_salt("CaCl2", val); } void EditRecipe::wb_caso4_changed(double val) { set_brewing_salt("CaSO4", val); } void EditRecipe::wb_mgso4_changed(double val) { set_brewing_salt("MgSO4", val); } diff -r d73719fa2ebb -r fd568cc1dd0e ui/EditRecipe.ui --- a/ui/EditRecipe.ui Wed Apr 20 14:30:06 2022 +0200 +++ b/ui/EditRecipe.ui Wed Apr 20 22:48:20 2022 +0200 @@ -310,7 +310,7 @@ 1 - 0.100000000000000 + 0.500000000000000 @@ -334,6 +334,9 @@ 1536 + + 5 +