Load yeasts in QList.

Wed, 06 Apr 2022 21:23:00 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 06 Apr 2022 21:23:00 +0200
changeset 111
04f5a7c5a1dc
parent 110
224be4d9f8eb
child 112
9e0dfa78f349

Load yeasts in QList.

src/EditRecipe.cpp file | annotate | diff | comparison | revisions
src/EditRecipe.h file | annotate | diff | comparison | revisions
--- a/src/EditRecipe.cpp	Wed Apr 06 20:26:47 2022 +0200
+++ b/src/EditRecipe.cpp	Wed Apr 06 21:23:00 2022 +0200
@@ -216,9 +216,44 @@
 	const auto& y_json = query.value(87).toString();
         if (!y_json.trimmed().isEmpty()) {
             const auto& formattedJson = QString("%1").arg(y_json);
-            this->yeasts = QJsonDocument::fromJson(formattedJson.toUtf8(),  &parseError);
-            if (parseError.error != QJsonParseError::NoError)
+            QJsonDocument yeasts = QJsonDocument::fromJson(formattedJson.toUtf8(),  &parseError);
+            if (parseError.error != QJsonParseError::NoError) {
                 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
+	    } else if (yeasts.isArray()) {
+		for (int i = 0; i < yeasts.array().size(); i++) {
+		    QJsonObject obj = yeasts.array().at(i).toObject();
+		    qDebug() << i << obj;
+		    Yeasts y;
+		    y.y_name = obj["y_name"].toString();
+		    y.y_laboratory = obj["y_laboratory"].toString();
+		    y.y_product_id = obj["y_product_id"].toString();
+		    y.y_amount = obj["y_amount"].toDouble();
+		    y.y_type = obj["y_type"].toInt();
+		    y.y_form = obj["y_form"].toInt();
+		    y.y_min_temperature = obj["y_min_temperature"].toDouble();
+		    y.y_max_temperature = obj["y_max_temperature"].toDouble();
+		    y.y_flocculation = obj["y_flocculation"].toInt();
+		    y.y_attenuation = obj["y_attenuation"].toDouble();
+		    y.y_cells = obj["y_cells"].toDouble();
+		    y.y_tolerance = obj["y_tolerance"].toDouble();
+		    y.y_inventory = obj["y_inventory"].toDouble();
+		    y.y_use = obj["y_use"].toInt();
+		    y.y_sta1 = obj["y_sta1"].toInt() ? true:false;
+		    y.y_bacteria = obj["y_bacteria"].toInt() ? true:false;
+		    y.y_harvest_top = obj["y_harvest_top"].toInt() ? true:false;
+		    y.y_harvest_time = obj["y_harvest_time"].toInt();
+		    y.y_pitch_temperature = obj["y_pitch_temperature"].toDouble();
+		    y.y_pofpos = obj["y_pofpos"].toInt() ? true:false;
+		    y.y_zymocide = obj["y_zymocide"].toInt();
+		    y.y_gr_hl_lo = obj["y_gr_hl_lo"].toInt();
+		    y.y_sg_lo = obj["y_sg_lo"].toDouble();
+		    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();
+		    recipe->yeasts.append(y);
+		}
+		qDebug() << "yeasts" << recipe->yeasts.size();
+	    }
         } else {
             qDebug() << "empty yeasts";
         }
@@ -324,7 +359,6 @@
 	const auto& formattedJson = QString("[]");
 	this->hops = QJsonDocument::fromJson(formattedJson.toUtf8());
 	this->miscs = QJsonDocument::fromJson(formattedJson.toUtf8());
-	this->yeasts = QJsonDocument::fromJson(formattedJson.toUtf8());
     }
 
     ui->lockedEdit->setChecked(recipe->locked);
@@ -606,7 +640,6 @@
     double	colort = 0;		// Colors srm * vol totals
     double	colorh = 0;		// Colors ebc * vol * kt
     double	colorn = 0;		// Colors ebc * pt * pct
-    QJsonObject obj;
 
     qDebug() << "calcFermentables()";
 
@@ -716,12 +749,11 @@
      * Calculate the apparant attenuation.
      */
     double svg = 0;
-    if (this->yeasts.array().size() > 0) {
-        for (i = 0; i < this->yeasts.array().size(); i++) {
-            obj = this->yeasts.array().at(i).toObject();
-	    if (obj["y_use"].toInt() == 0) {			// Used in primary
-		if (obj["y_attenuation"].toDouble() > svg)
-		    svg = obj["y_attenuation"].toDouble();	// Take the highest if multiple yeasts.
+    if (recipe->yeasts.size() > 0) {
+        for (i = 0; i < recipe->yeasts.size(); i++) {
+	    if (recipe->yeasts.at(i).y_use == 0) {		// Used in primary
+		if (recipe->yeasts.at(i).y_attenuation > svg)
+		    svg = recipe->yeasts.at(i).y_attenuation;	// Take the highest if multiple yeasts.
 	    }
 	    // TODO: brett or others in secondary.
 	}
--- a/src/EditRecipe.h	Wed Apr 06 20:26:47 2022 +0200
+++ b/src/EditRecipe.h	Wed Apr 06 21:23:00 2022 +0200
@@ -96,13 +96,13 @@
     bool	y_sta1;
     bool	y_bacteria;
     bool	y_harvest_top;
-    double	y_harvest_time;
+    int		y_harvest_time;
     double	y_pitch_temperature;
     bool	y_pofpos;
     int		y_zymocide;
-    double	y_gr_hl_lo;
+    int		y_gr_hl_lo;
     double	y_sg_lo;
-    double	y_gr_hl_hi;
+    int		y_gr_hl_hi;
     double	y_sg_hi;
     double	y_cost;
 };
@@ -290,7 +290,7 @@
     /*
      * Variables for popup ingredients editing.
      */
-    QJsonDocument hops, miscs, yeasts;
+    QJsonDocument hops, miscs;
     QComboBox *selectEdit, *addedEdit;
     QLineEdit *nameEdit, *supplierEdit;
     QDoubleSpinBox *amountEdit, *pctEdit, *maxEdit;

mercurial