--- a/src/EditRecipeTab7.cpp Tue Jul 12 12:10:20 2022 +0200 +++ b/src/EditRecipeTab7.cpp Tue Jul 12 15:34:17 2022 +0200 @@ -160,6 +160,9 @@ qDebug() << "calcWater()"; + ui->w1_hardnessEdit->setValue(Utils::Hardness(recipe->w1_calcium, recipe->w1_magnesium)); + ui->w1_raEdit->setValue(Utils::RA_ppm(recipe->w1_total_alkalinity, recipe->w1_calcium, recipe->w1_magnesium)); + /* * If there is a dilute water source, mix the waters. */ @@ -172,6 +175,8 @@ sulfate = Utils::mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_sulfate, recipe->w2_sulfate); total_alkalinity = Utils::mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_total_alkalinity, recipe->w2_total_alkalinity); ph = -log10(((pow(10, -recipe->w1_ph) * recipe->w1_amount) + (pow(10, -recipe->w2_ph) * recipe->w2_amount)) / liters); + ui->w2_hardnessEdit->setValue(Utils::Hardness(recipe->w2_calcium, recipe->w2_magnesium)); + ui->w2_raEdit->setValue(Utils::RA_ppm(recipe->w2_total_alkalinity, recipe->w2_calcium, recipe->w2_magnesium)); } else { liters = recipe->w1_amount; calcium = recipe->w1_calcium; @@ -201,6 +206,8 @@ ui->wg_clEdit->setValue(chloride); ui->wg_so4Edit->setValue(sulfate); ui->wg_phEdit->setValue(ph); + ui->wg_hardnessEdit->setValue(Utils::Hardness(calcium, magnesium)); + ui->wg_raEdit->setValue(Utils::RA_ppm(total_alkalinity, calcium, magnesium)); bicarbonate = total_alkalinity * 1.22; /* Save mixed water ions for later */ @@ -375,6 +382,8 @@ ui->wb_naEdit->setValue(sodium); ui->wb_clEdit->setValue(chloride); ui->wb_so4Edit->setValue(sulfate); + ui->wb_hardnessEdit->setValue(Utils::Hardness(calcium, magnesium)); + ui->wb_raEdit->setValue(Utils::RA_ppm(total_alkalinity, calcium, magnesium)); ui->wb_caEdit->setStyleSheet((calcium < 40 || calcium > 150) ? "background-color: red":"background-color: green"); ui->wb_mgEdit->setStyleSheet((magnesium < 5 || magnesium > 40) ? "background-color: red":"background-color: green"); @@ -484,6 +493,11 @@ Acid = round(Acid * 100.0) / 100.0; recipe->sparge_acid_amount = Acid / 1000; ui->sp_acidvolEdit->setValue(Acid); + + // Finally calculate the estimate preboil pH + recipe->preboil_ph = -log10(((pow(10, -recipe->mash_ph) * recipe->wg_amount) + (pow(10, -recipe->sparge_ph) * recipe->sparge_volume)) / + (recipe->wg_amount + recipe->sparge_volume)); + ui->preboil_phEdit->setValue(recipe->preboil_ph); } @@ -660,6 +674,8 @@ ui->w1_clEdit->setValue(recipe->w1_chloride); ui->w1_so4Edit->setValue(recipe->w1_sulfate); ui->w1_phEdit->setValue(recipe->w1_ph); + ui->w1_hardnessEdit->setValue(Utils::Hardness(product->w1_calcium, product->w1_magnesium)); + ui->w1_raEdit->setValue(Utils::RA_ppm(product->w1_total_alkalinity, product->w1_calcium, product->w1_magnesium)); is_changed(); calcWater(); @@ -669,6 +685,7 @@ void EditRecipe::w2_name_changed(int val) { QSqlQuery query; + double hardness, ra_ppm; qDebug() << "w2_name_changed" << val; @@ -683,6 +700,7 @@ recipe->w2_ph = 0; recipe->w1_amount += recipe->w2_amount; recipe->w2_amount = 0; + hardness = ra_ppm = 0; } else { query.prepare("SELECT * FROM inventory_waters ORDER BY record"); query.exec(); @@ -700,6 +718,8 @@ recipe->w2_chloride = query.value(6).toDouble(); recipe->w2_sulfate = query.value(5).toDouble(); recipe->w2_ph = query.value(9).toDouble(); + hardness = Utils::Hardness(product->w2_calcium, product->w2_magnesium); + ra_ppm = Utils::RA_ppm(product->w2_total_alkalinity, product->w2_calcium, product->w2_magnesium); } ui->w1_volEdit->setValue(recipe->w1_amount); ui->w2_volEdit->setValue(recipe->w2_amount); @@ -711,6 +731,8 @@ ui->w2_clEdit->setValue(recipe->w2_chloride); ui->w2_so4Edit->setValue(recipe->w2_sulfate); ui->w2_phEdit->setValue(recipe->w2_ph); + ui->w2_hardnessEdit->setValue(hardness); + ui->w2_raEdit->setValue(ra_ppm); is_changed(); calcWater(); @@ -730,6 +752,8 @@ ui->wt_naEdit->setValue(0); ui->wt_clEdit->setValue(0); ui->wt_so4Edit->setValue(0); + ui->wt_hardnessEdit->setValue(0); + ui->wt_raEdit->setValue(0); } else { query.prepare("SELECT * FROM profile_water ORDER BY name"); query.exec(); @@ -737,13 +761,15 @@ for (int i = 0; i < (val - 1); i++) { query.next(); } - ui->wt_caEdit->setValue(query.value(2).toDouble()); - ui->wt_mgEdit->setValue(query.value(7).toDouble()); - ui->wt_hco3Edit->setValue(query.value(3).toDouble()); - ui->wt_caco3Edit->setValue(query.value(10).toDouble()); - ui->wt_naEdit->setValue(query.value(6).toDouble()); - ui->wt_clEdit->setValue(query.value(5).toDouble()); - ui->wt_so4Edit->setValue(query.value(4).toDouble()); + ui->wt_caEdit->setValue(query.value("calcium").toDouble()); + ui->wt_mgEdit->setValue(query.value("magnesium").toDouble()); + ui->wt_hco3Edit->setValue(query.value("bicarbonate").toDouble()); + ui->wt_caco3Edit->setValue(query.value("total_alkalinity").toDouble()); + ui->wt_naEdit->setValue(query.value("sodium").toDouble()); + ui->wt_clEdit->setValue(query.value("chloride").toDouble()); + ui->wt_so4Edit->setValue(query.value("sulfate").toDouble()); + ui->wt_hardnessEdit->setValue(Utils::Hardness(query.value("calcium").toDouble(), query.value("magnesium").toDouble())); + ui->wt_raEdit->setValue(Utils::RA_ppm(query.value("total_alkalinity").toDouble(), query.value("calcium").toDouble(), query.value("magnesium").toDouble())); } calcWater(); }