# HG changeset patch # User Michiel Broek # Date 1653043655 -7200 # Node ID 37bac72eff617617e95e99087d28dc8d730b6e4f # Parent c5a3beb15eef4cf408dafc3410e8c2cc974e5bb1 Added keg priming and forced carbonation. diff -r c5a3beb15eef -r 37bac72eff61 src/EditProduct.cpp --- a/src/EditProduct.cpp Thu May 19 22:29:24 2022 +0200 +++ b/src/EditProduct.cpp Fri May 20 12:47:35 2022 +0200 @@ -1001,6 +1001,14 @@ ui->bottle_sug_waterEdit->setValue(product->bottle_priming_water); ui->bottle_tempEdit->setValue(product->bottle_carbonation_temp); + ui->keg_volumeEdit->setValue(product->keg_amount); + ui->keg_carbEdit->setValue(product->keg_carbonation); + ui->keg_sug_amountShow->setValue(product->keg_priming_amount); + ui->keg_sug_waterEdit->setValue(product->keg_priming_water); + ui->keg_tempEdit->setValue(product->keg_carbonation_temp); + ui->keg_forcedEdit->setChecked(product->keg_forced_carb); + ui->keg_barShow->setValue(product->keg_pressure); + // Tab taste. ui->taste_dateEdit->setText(product->taste_date.toString("dd MMM yyyy")); ui->taste_rateEdit->setValue(product->taste_rate); @@ -1155,6 +1163,12 @@ connect(ui->bottle_sugarEdit, QOverload::of(&QComboBox::currentIndexChanged), this, &EditProduct::bottle_sugar_changed); connect(ui->bottle_sug_waterEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::bottle_water_changed); connect(ui->bottle_tempEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::bottle_temp_changed); + connect(ui->keg_volumeEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::kegs_volume_changed); + connect(ui->keg_carbEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::kegs_co2_changed); + connect(ui->keg_sugarEdit, QOverload::of(&QComboBox::currentIndexChanged), this, &EditProduct::kegs_sugar_changed); + connect(ui->keg_sug_waterEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::kegs_water_changed); + connect(ui->keg_tempEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::kegs_temp_changed); + connect(ui->keg_forcedEdit, &QCheckBox::stateChanged, this, &EditProduct::kegs_forced_changed); /* All signals from tab Tasting */ diff -r c5a3beb15eef -r 37bac72eff61 src/EditProductTab11.cpp --- a/src/EditProductTab11.cpp Thu May 19 22:29:24 2022 +0200 +++ b/src/EditProductTab11.cpp Fri May 20 12:47:35 2022 +0200 @@ -171,7 +171,89 @@ ui->bottle_barShow->setValue(0); } + ui->keg_sugarLabel->setEnabled(! product->keg_forced_carb); + ui->keg_sugarEdit->setEnabled(! product->keg_forced_carb); + ui->keg_sug_weightLabel->setEnabled(! product->keg_forced_carb); + ui->keg_sug_weightShow->setEnabled(! product->keg_forced_carb); + ui->keg_sug_waterLabel->setEnabled(! product->keg_forced_carb); + ui->keg_sug_waterEdit->setEnabled(! product->keg_forced_carb); + ui->keg_sug_amountLabel->setEnabled(! product->keg_forced_carb); + ui->keg_sug_amountShow->setEnabled(! product->keg_forced_carb); + // keg_amount keg_carbonation keg_priming_sugar keg_priming_amount keg_priming_water keg_carbonation_temp keg_forced_carb keg_pressure + found1 = false; + if (product->keg_amount) { + + double Pressure = CarbCO2ToPressure(product->keg_carbonation, product->keg_carbonation_temp); + if (Pressure < 0) + Pressure = 0; + product->keg_pressure = Pressure; + ui->keg_barShow->setValue(Pressure); + + if (! product->keg_forced_carb) { + for (i = 0; i < product->fermentables.size(); i++) { + if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_KEGS) { + found1 = true; + break; + } + } + if (found1) { + SFactor = 1 / ((product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100)); + qDebug() << " kegs sugar" << product->fermentables.at(i).f_name << SFactor << TSec; + + query.prepare("SELECT name,supplier FROM inventory_fermentables WHERE type = '1' OR type = '3' ORDER BY name"); // Sugars or dry extract + query.exec(); + j = 0; + found2 = false; + while (query.next()) { + j++; + if (query.value(0).toString() == product->fermentables.at(i).f_name && query.value(1).toString() == product->fermentables.at(i).f_supplier) { + ui->keg_sugarEdit->setCurrentIndex(j); + product->keg_priming_sugar = j; + found2 = true; + break; + } + } + if (! found2) { + ui->keg_sugarEdit->setCurrentIndex(0); // Make sure not selected + product->fermentables.removeAt(i); // Remove false fermentable + refreshFermentables(); + } else { + product->keg_priming_amount = CarbCO2toS(product->keg_carbonation, TSec, SFactor); + ui->keg_sug_amountShow->setValue(product->keg_priming_amount); + double total = round(product->keg_priming_amount * product->keg_amount * 100.0) / 100000.0; + qDebug() << " total" << total << product->fermentables.at(i).f_amount; + if (total != product->fermentables.at(i).f_amount) { + qDebug() << " update priming sugar" << total; + product->fermentables[i].f_amount = total; + refreshFermentables(); + ui->keg_sug_weightShow->setValue(total * 1000); + is_changed(); + } + + double pabv = product->final_abv + (product->keg_priming_amount * (1 / SFactor) * 0.47) / 7.907; + double pvol = product->keg_amount - (pabv * product->keg_amount) / 100; + talc = product->keg_amount - pvol; + tvol = pvol + product->keg_priming_water; + ui->keg_abvShow->setValue(talc / (tvol + talc) * 100); + ui->keg_barShow->setValue(GetPressure(product->keg_carbonation, TSec, product->keg_carbonation_temp)); + } + } // if priming sugar. + if (! found1) { + qDebug() << " no keg priming"; + ui->keg_sug_amountShow->setValue(0); + ui->keg_sug_weightShow->setValue(0); + ui->keg_abvShow->setValue(0); + } + } else { + /* + * Forced carbonation + */ + ui->keg_abvShow->setValue(product->final_abv); + ui->keg_sug_amountShow->setValue(0); + ui->keg_sug_weightShow->setValue(0); + } + } // if keg_amount } @@ -202,6 +284,11 @@ void EditProduct::pack_volume_changed(double val) { + /* + * If the total volume is decreased, check if the + * bottle and kegs amount need to be lowered as well. + */ + product->package_volume = val; calcPack(); is_changed(); @@ -246,6 +333,15 @@ void EditProduct::bottle_volume_changed(double val) { + /* + * Check if kegs volume plus this new volume fits in the package volume. + */ + if ((val + product->keg_amount) > product->package_volume) { + double kegs = product->package_volume - val; + const QSignalBlocker blocker1(ui->keg_volumeEdit); + product->keg_amount = kegs; + ui->keg_volumeEdit->setValue(kegs); + } product->bottle_amount = val; calcPack(); is_changed(); @@ -335,31 +431,131 @@ void EditProduct::kegs_volume_changed(double val) { + /* + * Check if bottle volume plus this new volume fits in the package volume. + */ + if ((val + product->bottle_amount) > product->package_volume) { + double bottle = product->package_volume - val; + const QSignalBlocker blocker1(ui->bottle_volumeEdit); + product->bottle_amount = bottle; + ui->bottle_volumeEdit->setValue(bottle); + } + product->keg_amount = val; + calcPack(); + is_changed(); } void EditProduct::kegs_co2_changed(double val) { + product->keg_carbonation = val; + calcPack(); + is_changed(); } void EditProduct::kegs_sugar_changed(int val) { + Fermentables newf; + QSqlQuery query; + + qDebug() << "kegs_sugar_changed" << product->keg_priming_sugar << val; + for (int i = 0; i < product->fermentables.size(); i++) { + if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_KEGS) { + product->fermentables.removeAt(i); + refreshFermentables(); + break; + } + } + + /* + * Search the sugar pointed by the index. + */ + QString sql = "SELECT name,origin,supplier,cost,type,yield,color,coarse_fine_diff,moisture,diastatic_power,protein,dissolved_protein,max_in_batch," + "graintype,recommend_mash,add_after_boil,di_ph,acid_to_ph_57,inventory FROM inventory_fermentables " + "WHERE type = '1' OR type = '3' ORDER BY name"; + query.prepare(sql); + query.exec(); + query.first(); + for (int i = 0; i < (val - 1); i++) { + query.next(); + } + + newf.f_name = query.value(0).toString(); + newf.f_origin = query.value(1).toString(); + newf.f_supplier = query.value(2).toString(); + newf.f_cost = query.value(3).toDouble(); + newf.f_type = query.value(4).toInt(); + newf.f_yield = query.value(5).toDouble(); + newf.f_color = query.value(6).toDouble(); + newf.f_coarse_fine_diff = query.value(7).toDouble(); + newf.f_moisture = query.value(8).toDouble(); + newf.f_diastatic_power = query.value(9).toDouble(); + newf.f_protein = query.value(10).toDouble(); + newf.f_dissolved_protein = query.value(11).toDouble(); + newf.f_max_in_batch = query.value(12).toDouble(); + newf.f_graintype = query.value(13).toInt(); + newf.f_recommend_mash = query.value(14).toInt() ? true:false; + newf.f_add_after_boil = true; + newf.f_di_ph = query.value(16).toDouble(); + newf.f_acid_to_ph_57 = query.value(17).toDouble(); + newf.f_inventory = query.value(18).toDouble(); + newf.f_amount = 0; + newf.f_added = FERMENTABLE_ADDED_KEGS; + + product->fermentables.append(newf); + refreshFermentables(); + const QSignalBlocker blocker1(ui->keg_sugarEdit); + calcPack(); + is_changed(); } void EditProduct::kegs_water_changed(double val) { + product->keg_priming_water = val; + calcPack(); + is_changed(); } void EditProduct::kegs_forced_changed(bool val) { + qDebug() << "kegs_forced_changed" << val; + + product->keg_forced_carb = val; + if (val) { + /* + * Make sure to remove priming sugars. + */ + for (int i = 0; i < product->fermentables.size(); i++) { + if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_KEGS) { + product->fermentables.removeAt(i); + refreshFermentables(); + break; + } + } + product->keg_priming_sugar = 0; + product->keg_priming_amount = 0; + product->keg_priming_water = 0; + const QSignalBlocker blocker1(ui->keg_sugarEdit); + const QSignalBlocker blocker2(ui->keg_sug_waterEdit); + ui->keg_sugarEdit->setCurrentIndex(0); + ui->keg_sug_weightShow->setValue(0); + ui->keg_sug_waterEdit->setValue(0); + ui->keg_sug_amountShow->setValue(0); + } + + calcPack(); + is_changed(); } void EditProduct::kegs_temp_changed(double val) { + product->keg_carbonation_temp = val; + calcPack(); + is_changed(); } diff -r c5a3beb15eef -r 37bac72eff61 ui/EditProduct.ui --- a/ui/EditProduct.ui Thu May 19 22:29:24 2022 +0200 +++ b/ui/EditProduct.ui Fri May 20 12:47:35 2022 +0200 @@ -9535,7 +9535,7 @@ 30.000000000000000 - 0.010000000000000 + 0.100000000000000 @@ -9871,6 +9871,9 @@ + + true + 10 @@ -9887,6 +9890,9 @@ + + true + 170 @@ -10068,6 +10074,9 @@ + + true + 170 @@ -10102,7 +10111,7 @@ 30.000000000000000 - 0.010000000000000 + 0.100000000000000