src/EditRecipe.cpp

changeset 131
0115b97e8c39
parent 129
a9c19eaab018
child 132
9ede9c75cb54
--- a/src/EditRecipe.cpp	Mon Apr 11 22:32:04 2022 +0200
+++ b/src/EditRecipe.cpp	Tue Apr 12 21:03:19 2022 +0200
@@ -18,6 +18,7 @@
 #include "EditRecipe.h"
 #include "../ui/ui_EditRecipe.h"
 #include "Utils.h"
+#include "global.h"
 
 
 
@@ -48,6 +49,16 @@
     ui->ibu_methodEdit->addItem("Rager");
     ui->ibu_methodEdit->addItem("Daniels");
 
+    for (int i = 0; i < my_acids.size(); i++) {
+	qDebug() << i << my_acids.at(i).name;
+	ui->mw_acidPick->addItem(my_acids.at(i).name);
+	ui->sp_acidtypeEdit->addItem(my_acids.at(i).name);
+    }
+
+    ui->sp_sourceEdit->addItem(tr("Source 1"));
+    ui->sp_sourceEdit->addItem(tr("Source 2"));
+    ui->sp_sourceEdit->addItem(tr("Mixed"));
+
     ui->beerstyleEdit->addItem("");	// First add a dummy
     query.prepare("SELECT style_guide,style_letter,name FROM profile_styles ORDER BY style_guide,style_letter,name");
     query.exec();
@@ -160,6 +171,7 @@
 	    } else if (fermentables.isArray()) {
 		for (int i = 0; i < fermentables.array().size(); i++) {
 		    QJsonObject obj = fermentables.array().at(i).toObject();
+		    qDebug() << i << obj;
 		    Fermentables f;
 		    f.f_name = obj["f_name"].toString();
 		    f.f_origin = obj["f_origin"].toString();
@@ -202,7 +214,7 @@
 	    } else if (hops.isArray()) {
 		for (int i = 0; i < hops.array().size(); i++) {
 		    QJsonObject obj = hops.array().at(i).toObject();
-		    qDebug() << i << obj;
+//		    qDebug() << i << obj;
 		    Hops h;
 		    h.h_name = obj["h_name"].toString();
 		    h.h_origin = obj["h_origin"].toString();
@@ -228,10 +240,11 @@
             qDebug() << "empty hops";
         }
 
+qDebug() << query.value(86).toString();
 	const auto& m_json = query.value(86).toString();
         if (!m_json.trimmed().isEmpty()) {
             const auto& formattedJson = QString("%1").arg(m_json);
-            QJsonDocument miscs = QJsonDocument::fromJson(formattedJson.toUtf8(),  &parseError);
+            QJsonDocument miscs = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
             if (parseError.error != QJsonParseError::NoError) {
                 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset;
 	    } else if (miscs.isArray()) {
@@ -242,7 +255,7 @@
 		    m.m_name = obj["m_name"].toString();
 		    m.m_amount = obj["m_amount"].toDouble();
 		    m.m_type = obj["m_type"].toInt();
-		    m.m_use_use = obj["m_type"].toInt();
+		    m.m_use_use = obj["m_use_use"].toInt();
 		    m.m_time = obj["m_time"].toDouble();
 		    m.m_amount_is_weight = obj["m_amount_is_weight"].toInt() ? true:false;
 		    m.m_cost = obj["m_cost"].toDouble();
@@ -254,6 +267,7 @@
             qDebug() << "empty miscs";
         }
 
+qDebug() << query.value(87).toString();
 	const auto& y_json = query.value(87).toString();
         if (!y_json.trimmed().isEmpty()) {
             const auto& formattedJson = QString("%1").arg(y_json);
@@ -265,6 +279,14 @@
 		    QJsonObject obj = yeasts.array().at(i).toObject();
 		    qDebug() << i << obj;
 		    Yeasts y;
+		    /* First some defaults for newer fields. */
+		    y.y_tolerance = y.y_harvest_time = y.y_pitch_temperature = y.y_zymocide = 0;
+                    y.y_sta1 = y.y_bacteria = y.y_harvest_top = y.y_pofpos = false;
+		    y.y_gr_hl_lo = 50;
+                    y.y_sg_lo = 1.04;
+                    y.y_gr_hl_hi = 80;
+                    y.y_sg_hi = 1.08;
+		    /* Now get what we have got */
 		    y.y_name = obj["y_name"].toString();
 		    y.y_laboratory = obj["y_laboratory"].toString();
 		    y.y_product_id = obj["y_product_id"].toString();
@@ -291,6 +313,10 @@
 		    y.y_gr_hl_hi = obj["y_gr_hl_hi"].toInt();
 		    y.y_sg_hi = obj["y_sg_hi"].toDouble();
 		    y.y_cost = obj["y_cost"].toDouble();
+
+		    // Upgrade fields from current database:
+		    // y_tolerance y_sta1 y_bacteria y_harvest_top y_harvest_time y_pitch_temperature
+		    // y_pofpos y_zymocide y_gr_hl_lo y_sg_lo y_gr_hl_hi y_sg_hi
 		    recipe->yeasts.append(y);
 		}
 		qDebug() << "yeasts" << recipe->yeasts.size();
@@ -308,7 +334,7 @@
 	    } else if (mashs.isArray()) {
         	for (int i = 0; i < mashs.array().size(); i++) {
             	    QJsonObject obj = mashs.array().at(i).toObject();
-//		    qDebug() << i << obj;
+		    qDebug() << i << obj;
 		    Mashs m;
 		    m.step_name = obj["step_name"].toString();
 		    m.step_type = obj["step_type"].toInt();
@@ -494,13 +520,11 @@
     connect(ui->addHop, SIGNAL(clicked()), this, SLOT(on_addHopRow_clicked()));
 
     // All signals from tab "Miscs"
-//    connect(ui->hopsTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int)));
+    ui->miscsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
 
     // All signals from tab "Yeasts"
-//    connect(ui->hopsTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int)));
 
     // All signals from tab "Mash"
-//    connect(ui->hopsTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int)));
 
     // All signals from tab "Water"
 
@@ -529,6 +553,7 @@
     refreshMiscs();
     refreshYeasts();
     refreshMashs();
+    refreshWaters();
 }
 
 
@@ -711,28 +736,29 @@
 	    QJsonArray array;
 	    for (int i = 0; i < recipe->fermentables.size(); i++) {
 		QJsonObject obj;
-		obj.insert("f_acid_to_ph_57", round(recipe->fermentables.at(i).f_acid_to_ph_57 * 100000) / 100000);
-		obj.insert("f_add_after_boil", recipe->fermentables.at(i).f_add_after_boil);
-		obj.insert("f_added", recipe->fermentables.at(i).f_added);
-		obj.insert("f_adjust_to_total_100", recipe->fermentables.at(i).f_adjust_to_total_100);
-		obj.insert("f_amount", round(recipe->fermentables.at(i).f_amount * 10000) / 10000);
-		obj.insert("f_coarse_fine_diff", round(recipe->fermentables.at(i).f_coarse_fine_diff * 10) / 10);
-		obj.insert("f_color", round(recipe->fermentables.at(i).f_color * 10) / 10);
-		obj.insert("f_cost", round(recipe->fermentables.at(i).f_cost * 1000) / 1000);
-		obj.insert("f_di_ph", round(recipe->fermentables.at(i).f_di_ph * 100000) / 100000);
-		obj.insert("f_diastatic_power", round(recipe->fermentables.at(i).f_diastatic_power * 100000) / 100000);
-		obj.insert("f_dissolved_protein", round(recipe->fermentables.at(i).f_dissolved_protein * 10) / 10);
-		obj.insert("f_graintype", recipe->fermentables.at(i).f_graintype);
-		obj.insert("f_max_in_batch", recipe->fermentables.at(i).f_max_in_batch);
-		obj.insert("f_moisture", round(recipe->fermentables.at(i).f_moisture * 10) / 10);
 		obj.insert("f_name", recipe->fermentables.at(i).f_name);
 		obj.insert("f_origin", recipe->fermentables.at(i).f_origin);
-		obj.insert("f_percentage", round(recipe->fermentables.at(i).f_percentage * 10) / 10);
-		obj.insert("f_protein", round(recipe->fermentables.at(i).f_protein * 10) / 10);
-		obj.insert("f_recommend_mash", recipe->fermentables.at(i).f_recommend_mash);
 		obj.insert("f_supplier", recipe->fermentables.at(i).f_supplier);
+		obj.insert("f_amount", round(recipe->fermentables.at(i).f_amount * 10000) / 10000);
+		obj.insert("f_cost", round(recipe->fermentables.at(i).f_cost * 1000) / 1000);
 		obj.insert("f_type", recipe->fermentables.at(i).f_type);
 		obj.insert("f_yield", round(recipe->fermentables.at(i).f_yield * 10) / 10);
+		obj.insert("f_color", round(recipe->fermentables.at(i).f_color * 10) / 10);
+		obj.insert("f_coarse_fine_diff", round(recipe->fermentables.at(i).f_coarse_fine_diff * 10) / 10);
+		obj.insert("f_moisture", round(recipe->fermentables.at(i).f_moisture * 10) / 10);
+		obj.insert("f_diastatic_power", round(recipe->fermentables.at(i).f_diastatic_power * 100000) / 100000);
+		obj.insert("f_protein", round(recipe->fermentables.at(i).f_protein * 10) / 10);
+		obj.insert("f_dissolved_protein", round(recipe->fermentables.at(i).f_dissolved_protein * 10) / 10);
+		obj.insert("f_max_in_batch", recipe->fermentables.at(i).f_max_in_batch);
+		obj.insert("f_graintype", recipe->fermentables.at(i).f_graintype);
+		obj.insert("f_added", recipe->fermentables.at(i).f_added);
+		obj.insert("f_recommend_mash", recipe->fermentables.at(i).f_recommend_mash ? 1:0);
+		obj.insert("f_add_after_boil", recipe->fermentables.at(i).f_add_after_boil ? 1:0);
+		obj.insert("f_adjust_to_total_100", recipe->fermentables.at(i).f_adjust_to_total_100 ? 1:0);
+		obj.insert("f_percentage", round(recipe->fermentables.at(i).f_percentage * 10) / 10);
+		obj.insert("f_di_ph", round(recipe->fermentables.at(i).f_di_ph * 100000) / 100000);
+		obj.insert("f_acid_to_ph_57", round(recipe->fermentables.at(i).f_acid_to_ph_57 * 100000) / 100000);
+		qDebug() << "fermentables_Json" << i << obj;
 		array.append(obj);      /* Append this object */
 	    }
 	    QJsonDocument doc;
@@ -754,7 +780,7 @@
 		obj.insert("h_type", recipe->hops.at(i).h_type);
 		obj.insert("h_form", recipe->hops.at(i).h_form);
 		obj.insert("h_useat", recipe->hops.at(i).h_useat);
-		obj.insert("h_time", recipe->hops.at(i).h_time);
+		obj.insert("h_time", round(recipe->hops.at(i).h_time));
 		obj.insert("h_alpha", round(recipe->hops.at(i).h_alpha * 100) / 100);
 		obj.insert("h_beta", round(recipe->hops.at(i).h_beta * 100) / 100);
 		obj.insert("h_hsi", round(recipe->hops.at(i).h_hsi * 100) / 100);
@@ -763,7 +789,7 @@
 		obj.insert("h_cohumulone", round(recipe->hops.at(i).h_cohumulone * 100) / 100);
 		obj.insert("h_myrcene", round(recipe->hops.at(i).h_myrcene * 100) / 100);
 		obj.insert("h_total_oil", round(recipe->hops.at(i).h_total_oil * 100) / 100);
-//		qDebug() << "hops_Json" << i << obj;
+		qDebug() << "hops_Json" << i << obj;
                 array.append(obj);      /* Append this object */
             }
 	    QJsonDocument doc;
@@ -781,10 +807,10 @@
 		obj.insert("m_amount", round(recipe->miscs.at(i).m_amount * 10000) / 10000);
 		obj.insert("m_type", recipe->miscs.at(i).m_type);
 		obj.insert("m_use_use", recipe->miscs.at(i).m_use_use);
-		obj.insert("m_time", recipe->miscs.at(i).m_time);
-		obj.insert("m_amount_is_weight", recipe->miscs.at(i).m_amount_is_weight);
-		obj.insert("m_cost", recipe->miscs.at(i).m_cost);
-//                qDebug() << "miscs_Json" << i << obj;
+		obj.insert("m_time", round(recipe->miscs.at(i).m_time));
+		obj.insert("m_amount_is_weight", recipe->miscs.at(i).m_amount_is_weight ? 1:0);
+		obj.insert("m_cost", round(recipe->miscs.at(i).m_cost * 10000) / 10000);
+                qDebug() << "miscs_Json" << i << obj;
                 array.append(obj);      /* Append this object */
             }
 	    QJsonDocument doc;
@@ -813,19 +839,19 @@
 		obj.insert("y_tolerance", round(recipe->yeasts.at(i).y_tolerance * 10) / 10);
 		obj.insert("y_inventory", round(recipe->yeasts.at(i).y_inventory * 10000) / 10000);
 		obj.insert("y_use", recipe->yeasts.at(i).y_use);
-		obj.insert("y_sta1", recipe->yeasts.at(i).y_sta1);
-		obj.insert("y_bacteria", recipe->yeasts.at(i).y_bacteria);
-		obj.insert("y_harvest_top", recipe->yeasts.at(i).y_harvest_top);
+		obj.insert("y_sta1", recipe->yeasts.at(i).y_sta1 ? 1:0);
+		obj.insert("y_bacteria", recipe->yeasts.at(i).y_bacteria ? 1:0);
+		obj.insert("y_harvest_top", recipe->yeasts.at(i).y_harvest_top ? 1:0);
 		obj.insert("y_harvest_time", recipe->yeasts.at(i).y_harvest_time);
 		obj.insert("y_pitch_temperature", round(recipe->yeasts.at(i).y_pitch_temperature * 10) / 10);
-		obj.insert("y_pofpos", recipe->yeasts.at(i).y_pofpos);
+		obj.insert("y_pofpos", recipe->yeasts.at(i).y_pofpos ? 1:0);
 		obj.insert("y_zymocide", recipe->yeasts.at(i).y_zymocide);
 		obj.insert("y_gr_hl_lo", recipe->yeasts.at(i).y_gr_hl_lo);
 		obj.insert("y_sg_lo", round(recipe->yeasts.at(i).y_sg_lo * 1000) / 1000);
 		obj.insert("y_gr_hl_hi", recipe->yeasts.at(i).y_gr_hl_hi);
 		obj.insert("y_sg_hi", round(recipe->yeasts.at(i).y_sg_hi * 1000) / 1000);
-		obj.insert("y_cost", recipe->yeasts.at(i).y_cost);
-//                qDebug() << "yeasts_Json" << i << obj;
+		obj.insert("y_cost", round(recipe->yeasts.at(i).y_cost * 1000) / 1000);
+                qDebug() << "yeasts_Json" << i << obj;
                 array.append(obj);      /* Append this object */
             }
 	    QJsonDocument doc;
@@ -850,7 +876,7 @@
 		obj.insert("ramp_time", round(recipe->mashs.at(i).ramp_time * 100) / 100);
 		obj.insert("end_temp", round(recipe->mashs.at(i).end_temp * 100) / 100);
 		obj.insert("step_wg_ratio", round(recipe->mashs.at(i).step_wg_ratio * 100) / 100);
-//                qDebug() << "mashs_Json" << i << obj;
+                qDebug() << "mashs_Json" << i << obj;
                 array.append(obj);      /* Append this object */
             }
 	    QJsonDocument doc;

mercurial