# HG changeset patch # User Michiel Broek # Date 1652992164 -7200 # Node ID c5a3beb15eef4cf408dafc3410e8c2cc974e5bb1 # Parent 54828816233fbcfea8ca06496bdf46a5a2038587 Replace priming sugar implemented. diff -r 54828816233f -r c5a3beb15eef src/EditProductTab11.cpp --- a/src/EditProductTab11.cpp Thu May 19 20:50:36 2022 +0200 +++ b/src/EditProductTab11.cpp Thu May 19 22:29:24 2022 +0200 @@ -154,7 +154,7 @@ is_changed(); } - double pabv = product->final_abv + product->bottle_priming_amount * 0.47 / 7.907; + double pabv = product->final_abv + (product->bottle_priming_amount * (1 / SFactor) * 0.47) / 7.907; double pvol = product->bottle_amount - (pabv * product->bottle_amount) / 100; talc = product->bottle_amount - pvol; tvol = pvol + product->bottle_priming_water; @@ -262,6 +262,58 @@ void EditProduct::bottle_sugar_changed(int val) { + Fermentables newf; + QSqlQuery query; + + qDebug() << "bottle_sugar_changed" << product->bottle_priming_sugar << val; + for (int i = 0; i < product->fermentables.size(); i++) { + if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_BOTTLE) { + 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_BOTTLE; + + product->fermentables.append(newf); + refreshFermentables(); + const QSignalBlocker blocker1(ui->bottle_sugarEdit); + calcPack(); + is_changed(); }