src/EditRecipeTab5.cpp

changeset 496
9db6080a4783
parent 478
a3653722b0d6
--- a/src/EditRecipeTab5.cpp	Sun Feb 12 15:05:28 2023 +0100
+++ b/src/EditRecipeTab5.cpp	Thu Apr 20 17:23:44 2023 +0200
@@ -318,6 +318,7 @@
     bool instock = yinstockEdit->isChecked();
     QString w;
     QTableWidgetItem *item;
+    int oldform = recipe->yeasts.at(recipe->yeasts_row).form;
 
     if (val < 1)
         return;
@@ -342,51 +343,61 @@
         query.next();
     }
 #ifdef DEBUG_YEAST
-    qDebug() << "found" << query.value(0).toString() << query.value(2).toString();
+    qDebug() << "found" << query.value("name").toString() << query.value("product_id").toString();
 #endif
 
     /*
      * Replace the yeast record contents
      */
-    recipe->yeasts[recipe->yeasts_row].name = query.value(0).toString();
-    recipe->yeasts[recipe->yeasts_row].laboratory = query.value(1).toString();
-    recipe->yeasts[recipe->yeasts_row].product_id = query.value(2).toString();
-    recipe->yeasts[recipe->yeasts_row].type = query.value(3).toInt();
-    recipe->yeasts[recipe->yeasts_row].form = query.value(4).toInt();
-    recipe->yeasts[recipe->yeasts_row].min_temperature = query.value(5).toDouble();
-    recipe->yeasts[recipe->yeasts_row].max_temperature = query.value(6).toDouble();
-    recipe->yeasts[recipe->yeasts_row].flocculation = query.value(7).toInt();
-    recipe->yeasts[recipe->yeasts_row].attenuation = query.value(8).toDouble();
-    recipe->yeasts[recipe->yeasts_row].cells = query.value(9).toDouble();
-    recipe->yeasts[recipe->yeasts_row].tolerance = query.value(10).toDouble();
-    recipe->yeasts[recipe->yeasts_row].sta1 = query.value(11).toInt() ? true:false;
-    recipe->yeasts[recipe->yeasts_row].bacteria = query.value(12).toInt() ? true:false;
-    recipe->yeasts[recipe->yeasts_row].harvest_top = query.value(13).toInt() ? true:false;
-    recipe->yeasts[recipe->yeasts_row].harvest_time = query.value(14).toInt();
-    recipe->yeasts[recipe->yeasts_row].pitch_temperature = query.value(15).toDouble();
-    recipe->yeasts[recipe->yeasts_row].pofpos = query.value(16).toInt() ? true:false;
-    recipe->yeasts[recipe->yeasts_row].zymocide = query.value(17).toInt();
-    recipe->yeasts[recipe->yeasts_row].gr_hl_lo = query.value(18).toInt();
-    recipe->yeasts[recipe->yeasts_row].sg_lo = query.value(19).toDouble();
-    recipe->yeasts[recipe->yeasts_row].gr_hl_hi = query.value(20).toInt();
-    recipe->yeasts[recipe->yeasts_row].sg_hi = query.value(21).toDouble();
-    recipe->yeasts[recipe->yeasts_row].cost = query.value(22).toDouble();
+    recipe->yeasts[recipe->yeasts_row].name = query.value("name").toString();
+    recipe->yeasts[recipe->yeasts_row].laboratory = query.value("laboratory").toString();
+    recipe->yeasts[recipe->yeasts_row].product_id = query.value("product_id").toString();
+    recipe->yeasts[recipe->yeasts_row].type = query.value("type").toInt();
+    recipe->yeasts[recipe->yeasts_row].form = query.value("form").toInt();
+    recipe->yeasts[recipe->yeasts_row].min_temperature = query.value("min_temperature").toDouble();
+    recipe->yeasts[recipe->yeasts_row].max_temperature = query.value("max_temperature").toDouble();
+    recipe->yeasts[recipe->yeasts_row].flocculation = query.value("flocculation").toInt();
+    recipe->yeasts[recipe->yeasts_row].attenuation = query.value("attenuation").toDouble();
+    recipe->yeasts[recipe->yeasts_row].cells = query.value("cells").toDouble();
+    recipe->yeasts[recipe->yeasts_row].tolerance = query.value("tolerance").toDouble();
+    recipe->yeasts[recipe->yeasts_row].sta1 = query.value("sta1").toInt() ? true:false;
+    recipe->yeasts[recipe->yeasts_row].bacteria = query.value("bacteria").toInt() ? true:false;
+    recipe->yeasts[recipe->yeasts_row].harvest_top = query.value("harvest_top").toInt() ? true:false;
+    recipe->yeasts[recipe->yeasts_row].harvest_time = query.value("harvest_time").toInt();
+    recipe->yeasts[recipe->yeasts_row].pitch_temperature = query.value("pitch_temperature").toDouble();
+    recipe->yeasts[recipe->yeasts_row].pofpos = query.value("pofpos").toInt() ? true:false;
+    recipe->yeasts[recipe->yeasts_row].zymocide = query.value("zymocide").toInt();
+    recipe->yeasts[recipe->yeasts_row].gr_hl_lo = query.value("gr_hl_lo").toInt();
+    recipe->yeasts[recipe->yeasts_row].sg_lo = query.value("sg_lo").toDouble();
+    recipe->yeasts[recipe->yeasts_row].gr_hl_hi = query.value("gr_hl_hi").toInt();
+    recipe->yeasts[recipe->yeasts_row].sg_hi = query.value("sg_hi").toDouble();
+    recipe->yeasts[recipe->yeasts_row].cost = query.value("cost").toDouble();
 
     /*
      * Update the visible fields
      */
+    const QSignalBlocker blocker1(yamountEdit);
     ynameEdit->setText(recipe->yeasts.at(recipe->yeasts_row).name);
     ylaboratoryEdit->setText(recipe->yeasts.at(recipe->yeasts_row).laboratory);
     yproduct_idEdit->setText(recipe->yeasts.at(recipe->yeasts_row).product_id);
-    if (recipe->yeasts.at(recipe->yeasts_row).form == 0) {
+    if (recipe->yeasts.at(recipe->yeasts_row).form == YEAST_FORMS_LIQUID) {
+	if (oldform != YEAST_FORMS_LIQUID)
+            recipe->yeasts[recipe->yeasts_row].amount = 1;
+	yamountEdit->setValue(recipe->yeasts[recipe->yeasts_row].amount);
 	yamountEdit->setDecimals(0);
 	yamountEdit->setSingleStep(1.0);
 	yamountLabel->setText(tr("Total packs:"));
-    } else if (recipe->yeasts.at(recipe->yeasts_row).form == 1) {
+    } else if ((recipe->yeasts.at(recipe->yeasts_row).form == YEAST_FORMS_DRY) || (recipe->yeasts.at(recipe->yeasts_row).form == YEAST_FORMS_DRIED)) {
+	if (oldform == YEAST_FORMS_LIQUID)
+            recipe->yeasts[recipe->yeasts_row].amount = 0.01;
+	yamountEdit->setValue(recipe->yeasts[recipe->yeasts_row].amount * 1000.0);
 	yamountEdit->setDecimals(1);
     	yamountEdit->setSingleStep(0.5);
 	yamountLabel->setText(tr("Amount in gr:"));
     } else {
+	if (oldform == YEAST_FORMS_LIQUID)
+            recipe->yeasts[recipe->yeasts_row].amount = 0.01;
+	yamountEdit->setValue(recipe->yeasts[recipe->yeasts_row].amount * 1000.0);
 	yamountEdit->setDecimals(1);
 	yamountEdit->setSingleStep(0.5);
 	yamountLabel->setText(tr("Amount in ml:"));
@@ -416,7 +427,7 @@
     item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
     ui->yeastsTable->setItem(recipe->yeasts_row, 8, item);
 
-    if (recipe->yeasts.at(product->yeasts_row).use != YEAST_USE_BOTTLE && recipe->yeasts.at(product->yeasts_row).sta1) {
+    if (recipe->yeasts.at(recipe->yeasts_row).use != YEAST_USE_BOTTLE && recipe->yeasts.at(recipe->yeasts_row).sta1) {
         QWidget *pWidget = new QWidget();
         QLabel *label = new QLabel;
         label->setPixmap(QPixmap(":icons/silk/tick.png"));
@@ -425,9 +436,9 @@
         pLayout->setAlignment(Qt::AlignCenter);
         pLayout->setContentsMargins(0, 0, 0, 0);
         pWidget->setLayout(pLayout);
-        ui->yeastsTable->setCellWidget(product->yeasts_row, 9, pWidget);
+        ui->yeastsTable->setCellWidget(recipe->yeasts_row, 9, pWidget);
     } else {
-        ui->yeastsTable->removeCellWidget(product->yeasts_row, 9);
+        ui->yeastsTable->removeCellWidget(recipe->yeasts_row, 9);
     }
 
     is_changed();

mercurial