src/EditRecipe.cpp

changeset 141
eea8a9e7e1f6
parent 139
f947c6988e91
child 142
1caa15a0eefc
--- a/src/EditRecipe.cpp	Sun Apr 17 10:50:48 2022 +0200
+++ b/src/EditRecipe.cpp	Mon Apr 18 10:55:33 2022 +0200
@@ -266,7 +266,7 @@
 	    } else if (miscs.isArray()) {
 		for (int i = 0; i < miscs.array().size(); i++) {
 		    QJsonObject obj = miscs.array().at(i).toObject();
-		    qDebug() << i << obj;
+		    //qDebug() << i << obj;
 		    Miscs m;
 		    m.m_name = obj["m_name"].toString();
 		    m.m_amount = obj["m_amount"].toDouble();
@@ -283,7 +283,6 @@
             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);
@@ -330,9 +329,35 @@
 		    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
+		    if (y.y_tolerance == 0) {	// More and better tests?
+			/*
+			 * Possible data upgrade needed.
+			 */
+			query.prepare("SELECT tolerance,cells,sta1,bacteria,harvest_top,harvest_time,pitch_temperature,"
+				      "pofpos,zymocide,gr_hl_lo,sg_lo,gr_hl_hi,sg_hi "
+				      "FROM inventory_yeasts WHERE name=:name AND laboratory=:laboratory AND product_id=:product_id");
+			query.bindValue(":name", y.y_name);
+			query.bindValue(":laboratory", y.y_laboratory);
+			query.bindValue(":product_id", y.y_product_id);
+            		query.exec();
+            		if (query.first()) {
+			    y.y_tolerance = query.value(0).toDouble();
+			    y.y_cells = query.value(1).toDouble();
+			    y.y_sta1 = query.value(2).toInt() ? true:false;
+			    y.y_bacteria = query.value(3).toInt() ? true:false;
+			    y.y_harvest_top = query.value(4).toInt() ? true:false;
+			    y.y_harvest_time = query.value(5).toInt();
+			    y.y_pitch_temperature = query.value(6).toDouble();
+			    y.y_pofpos = query.value(7).toInt() ? true:false;
+			    y.y_zymocide = query.value(8).toInt();
+			    y.y_gr_hl_lo = query.value(9).toInt();
+			    y.y_sg_lo = query.value(10).toDouble();
+			    y.y_gr_hl_hi = query.value(11).toInt();
+			    y.y_sg_hi = query.value(12).toDouble();
+			} else {
+			    qDebug() << y.y_name << y.y_product_id << "not found for upgrade";
+			}
+		    }
 		    recipe->yeasts.append(y);
 		}
 		qDebug() << "yeasts" << recipe->yeasts.size();
@@ -341,6 +366,7 @@
             qDebug() << "empty yeasts";
         }
 
+qDebug() << query.value(88).toString();
 	const auto& ma_json = query.value(88).toString();
         if (!ma_json.trimmed().isEmpty()) {
             const auto& formattedJson = QString("%1").arg(ma_json);
@@ -643,6 +669,8 @@
     connect(ui->addMisc, SIGNAL(clicked()), this, SLOT(addMiscRow_clicked()));
 
     // All signals from tab "Yeasts"
+    ui->yeastsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
+    connect(ui->addYeast, SIGNAL(clicked()), this, SLOT(addYeastRow_clicked()));
 
     // All signals from tab "Mash"
 

mercurial