Completed read MySQL recipe record. Mash schedule moved to recipe QList.

Wed, 06 Apr 2022 12:10:33 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 06 Apr 2022 12:10:33 +0200
changeset 109
1ce50e72a6b1
parent 108
ecfcbee4a9b2
child 110
224be4d9f8eb

Completed read MySQL recipe record. Mash schedule moved to recipe QList.

src/EditRecipe.cpp file | annotate | diff | comparison | revisions
src/EditRecipe.h file | annotate | diff | comparison | revisions
ui/EditRecipe.ui file | annotate | diff | comparison | revisions
--- a/src/EditRecipe.cpp	Tue Apr 05 22:28:35 2022 +0200
+++ b/src/EditRecipe.cpp	Wed Apr 06 12:10:33 2022 +0200
@@ -27,6 +27,9 @@
     qDebug() << "EditRecipe record:" << id;
     recipe = new Recipe;
     ui->setupUi(this);
+    recipe->fermentables_records = recipe->hops_records = recipe->misc_records = recipe->yeasts_records = recipe->mashs_records = 0;
+    recipe->fermentables_current = recipe->hops_current = recipe->misc_current = recipe->yeasts_current = recipe->mashs_current = -1;
+    recipe->fermentables_use100 = false;
     this->recno = id;
 
     WindowTitle();
@@ -81,7 +84,6 @@
 	recipe->st_carb_max = query.value(18).toDouble();
 	recipe->st_abv_min = query.value(19).toDouble();
 	recipe->st_abv_max = query.value(20).toDouble();
-
 	recipe->name = query.value(21).toString();
 	recipe->notes = query.value(22).toString();
 	recipe->type = query.value(23).toInt();
@@ -98,120 +100,55 @@
 	recipe->ibu_method = query.value(34).toInt();
 	recipe->est_carb = query.value(35).toDouble();
 
-	ui->lockedEdit->setChecked(recipe->locked);
-	ui->st_nameEdit->setText(recipe->st_name);
-	ui->st_groupEdit->setText(recipe->st_letter);
-	ui->st_guideEdit->setText(recipe->st_guide);
-	ui->st_catEdit->setText(recipe->st_category);
-	ui->st_catnrEdit->setText(QString("%1").arg(recipe->st_category_number));
-	ui->st_typeEdit->setText(s_types[recipe->st_type]);
-
-	ui->nameEdit->setText(query.value(21).toString());
-	ui->notesEdit->setPlainText(query.value(22).toString());
-	ui->typeEdit->setCurrentIndex(query.value(23).toInt());
-	ui->batch_sizeEdit->setValue(query.value(24).toDouble());
-	ui->boil_sizeEdit->setValue(query.value(25).toDouble());
-	ui->boil_timeEdit->setValue(query.value(26).toInt());
-	ui->efficiencyEdit->setValue(query.value(27).toDouble());
-
-	ui->est_ogEdit->setValue(query.value(28).toDouble());
-	ui->est_og2Edit->setValue(query.value(28).toDouble());
-	ui->est_og3Edit->setValue(query.value(28).toDouble());
-	ui->est_ogShow->setRange(query.value(9).toDouble(), query.value(10).toDouble());
-	ui->est_ogShow->setPrecision(3);
-	ui->est_ogShow->setMarkerTextIsValue(true);
-	ui->est_ogShow->setValue(query.value(28).toDouble());
-
-	ui->est_fgEdit->setValue(query.value(29).toDouble());
-	ui->est_fg3Edit->setValue(query.value(29).toDouble());
-        ui->est_fgShow->setRange(query.value(11).toDouble(), query.value(12).toDouble());
-        ui->est_fgShow->setPrecision(3);
-        ui->est_fgShow->setMarkerTextIsValue(true);
-        ui->est_fgShow->setValue(query.value(29).toDouble());
-
-	ui->est_abvEdit->setValue(query.value(30).toDouble());
-	ui->est_abv2Edit->setValue(query.value(30).toDouble());
-        ui->est_abvShow->setRange(query.value(19).toDouble(), query.value(20).toDouble());
-        ui->est_abvShow->setPrecision(1);
-        ui->est_abvShow->setMarkerTextIsValue(true);
-        ui->est_abvShow->setValue(query.value(30).toDouble());
-
-	//QColor color = Utils::ebc_to_color(query.value(31).toInt());
-	ui->est_colorEdit->setValue(query.value(31).toDouble());
-	ui->est_colorEdit->setStyleSheet(Utils::ebc_to_style(query.value(31).toInt()));
-	ui->est_color2Edit->setValue(query.value(31).toDouble());
-        ui->est_color2Edit->setStyleSheet(Utils::ebc_to_style(query.value(31).toInt()));
-        ui->est_colorShow->setPrecision(0);
-        ui->est_colorShow->setMarkerTextIsValue(true);
-	ui->est_colorShow->setRange(query.value(15).toDouble(), query.value(16).toDouble());
-        ui->est_colorShow->setValue(query.value(31).toDouble());
-
-	ui->color_methodEdit->setCurrentIndex(query.value(32).toInt());
-
-	ui->est_ibuEdit->setValue(query.value(33).toDouble());
-	ui->est_ibu2Edit->setValue(query.value(33).toDouble());
-        ui->est_ibuShow->setPrecision(0);
-        ui->est_ibuShow->setMarkerTextIsValue(true);
-        ui->est_ibuShow->setRange(query.value(13).toDouble(), query.value(14).toDouble());
-        ui->est_ibuShow->setValue(query.value(33).toDouble());
+	recipe->sparge_temp = query.value(36).toDouble();
+	recipe->sparge_ph = query.value(37).toDouble();
+	recipe->sparge_volume = query.value(38).toDouble();
+	recipe->sparge_source = query.value(39).toInt();
+	recipe->sparge_acid_type = query.value(40).toInt();
+	recipe->sparge_acid_perc = query.value(41).toDouble();
+	recipe->sparge_acid_amount = query.value(42).toDouble();
+	recipe->mash_ph = query.value(43).toDouble();
+	recipe->mash_name = query.value(44).toDouble();
+	recipe->calc_acid = query.value(45).toInt() ? true:false;
 
-	ui->ibu_methodEdit->setCurrentIndex(query.value(34).toInt());
-
-	ui->est_carbEdit->setValue(query.value(35).toDouble());
-        ui->est_carbShow->setPrecision(1);
-        ui->est_carbShow->setMarkerTextIsValue(true);
-        ui->est_carbShow->setRange(query.value(17).toDouble(), query.value(18).toDouble());
-        ui->est_carbShow->setValue(query.value(35).toDouble());
-
-	// 36 sparge_temp
-	// 37 sparge_ph
-	// 38 sparge_volume
-	// 39 sparge_source
-	// 40 sparge_acid_type
-	// 41 sparge_acid_perc
-	// 42 sparge_acid_amount
-	// 43 mash_ph
-	// 44 mash_name
-	// 45 calc_acid
-	// 46 w1_name
-	// 47 w1_amount
-	// 48 w1_calcium
-	// 49 w1_sulfate
-	// 50 w1_chloride
-	// 51 w1_sodium
-	// 52 w1_magnesium
-	// 53 w1_total_alkalinity
-	// 54 w1_ph
-	// 55 w1_cost
-	// 56 w2_name
-	// 57 w2_amount
-	// 58 w2_calcium
-	// 59 w2_sulfate
-	// 60 w2_chloride
-	// 61 w2_sodium
-	// 62 w2_magnesium
-	// 63 w2_total_alkalinity
-	// 64 w2_ph
-	// 65 w2_cost
-	// 66 wg_amount
-	// 67 wg_calcium
-	// 68 wg_sulfate
-	// 69 wg_chloride
-	// 70 wg_sodium
-	// 71 wg_magnesium
-	// 72 wg_total_alkalinity
-	// 73 wg_ph
-	// 74 wb_calcium
-	// 75 wb_sulfate
-	// 76 wb_chloride
-	// 77 wb_sodium
-	// 78 wb_magnesium
-	// 79 wb_total_alkalinity
-	// 80 wb_ph
-	// 81 wa_acid_name
-	// 82 wa_acid_perc
-	// 83 wa_base_name
-
+	recipe->w1_name = query.value(46).toString();
+	recipe->w1_amount = query.value(47).toDouble();
+	recipe->w1_calcium = query.value(48).toDouble();
+	recipe->w1_sulfate = query.value(49).toDouble();
+	recipe->w1_chloride = query.value(50).toDouble();
+	recipe->w1_sodium = query.value(51).toDouble();
+	recipe->w1_magnesium = query.value(52).toDouble();
+	recipe->w1_total_alkalinity = query.value(53).toDouble();
+	recipe->w1_ph = query.value(54).toDouble();
+	recipe->w1_cost = query.value(55).toDouble();
+	recipe->w2_name = query.value(56).toString();
+        recipe->w2_amount = query.value(57).toDouble();
+        recipe->w2_calcium = query.value(58).toDouble();
+        recipe->w2_sulfate = query.value(59).toDouble();
+        recipe->w2_chloride = query.value(60).toDouble();
+        recipe->w2_sodium = query.value(61).toDouble();
+        recipe->w2_magnesium = query.value(62).toDouble();
+        recipe->w2_total_alkalinity = query.value(63).toDouble();
+        recipe->w2_ph = query.value(64).toDouble();
+        recipe->w2_cost = query.value(65).toDouble();
+	recipe->wg_amount = query.value(66).toDouble();
+        recipe->wg_calcium = query.value(67).toDouble();
+        recipe->wg_sulfate = query.value(68).toDouble();
+        recipe->wg_chloride = query.value(69).toDouble();
+        recipe->wg_sodium = query.value(70).toDouble();
+        recipe->wg_magnesium = query.value(71).toDouble();
+        recipe->wg_total_alkalinity = query.value(72).toDouble();
+        recipe->wg_ph = query.value(73).toDouble();
+	recipe->wb_calcium = query.value(74).toDouble();
+        recipe->wb_sulfate = query.value(75).toDouble();
+        recipe->wb_chloride = query.value(76).toDouble();
+        recipe->wb_sodium = query.value(77).toDouble();
+        recipe->wb_magnesium = query.value(78).toDouble();
+        recipe->wb_total_alkalinity = query.value(79).toDouble();
+        recipe->wb_ph = query.value(80).toDouble();
+	recipe->wa_acid_name = query.value(81).toInt();
+        recipe->wa_acid_perc = query.value(82).toDouble();
+        recipe->wa_base_name = query.value(83).toInt();
 
 	QJsonParseError parseError;
         const auto& f_json = query.value(84).toString();
@@ -257,23 +194,180 @@
 	const auto& ma_json = query.value(88).toString();
         if (!ma_json.trimmed().isEmpty()) {
             const auto& formattedJson = QString("%1").arg(ma_json);
-            this->mashs = QJsonDocument::fromJson(formattedJson.toUtf8(),  &parseError);
+            QJsonDocument mashs = QJsonDocument::fromJson(formattedJson.toUtf8(),  &parseError);
             if (parseError.error != QJsonParseError::NoError)
                 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
+
+	    if (mashs.isArray()) {
+        	for (int i = 0; i < mashs.array().size(); i++) {
+            	    QJsonObject obj = mashs.array().at(i).toObject();
+
+		    qDebug() << i << obj;
+		    Mashs m;
+		    m.step_name = obj["step_name"].toString();
+		    m.step_type = obj["step_type"].toInt();
+		    m.step_volume = obj["step_volume"].toDouble();
+		    m.step_infuse_amount = obj["step_infuse_amount"].toDouble();
+		    m.step_infuse_temp = obj["step_infuse_temp"].toDouble();
+		    m.step_temp = obj["step_temp"].toDouble();
+		    m.step_time = obj["step_time"].toDouble();
+		    m.ramp_time = obj["ramp_time"].toDouble();
+		    m.end_temp = obj["end_temp"].toDouble();
+		    m.step_wg_ratio = obj["step_wg_ratio"].toDouble();
+		    recipe->mashs.append(m);
+		}
+	    }
         } else {
             qDebug() << "empty mashs";
         }
+	recipe->mashs_records = recipe->mashs.size();
+
+//	qDebug() << query.value(88).toString();
+//	if (recipe->mashs.size()) {
+	    qDebug() << recipe->mashs.size();
+//	}
+	//qDebug() << recipe->mashs;
+
     } else {
 	/* Set some defaults */
+	recipe->locked = false;
+	recipe->st_name = "";
+	recipe->st_letter = "";
+	recipe->st_guide = "";
+	recipe->st_category = "";
+	recipe->st_category_number = 0;
+	recipe->st_type = 0;
+	recipe->st_og_min = 1.025; recipe->st_og_max = 1.100;
+	recipe->st_fg_min = 1.000; recipe->st_fg_max = 1.020;
+	recipe->st_ibu_min = 5; recipe->st_ibu_max = 200;
+	recipe->st_color_min = 3; recipe->st_color_max = 100;
+	recipe->st_carb_min = 1.0; recipe->st_carb_max = 4.5;
+	recipe->st_abv_min = 1; recipe->st_abv_max = 15;
+	recipe->efficiency = 75;
+	recipe->batch_size = 20;
+	recipe->boil_size = 24;
+	recipe->boil_time = 60;
+	recipe->type = 2;
+	recipe->sparge_temp = 80;
+        recipe->sparge_ph = 5.4;
+        recipe->sparge_volume = 8;
+        recipe->sparge_source = 0;
+        recipe->sparge_acid_type = 0;
+        recipe->sparge_acid_perc = 80;
+        recipe->sparge_acid_amount = 0;
+        recipe->mash_ph = 5.4;
+        recipe->mash_name = "";
+        recipe->calc_acid = true;
+	recipe->w1_name = "";
+        recipe->w1_amount = 0;
+        recipe->w1_calcium = 0;
+        recipe->w1_sulfate = 0;
+        recipe->w1_chloride = 0;
+        recipe->w1_sodium = 0;
+        recipe->w1_magnesium = 0;
+        recipe->w1_total_alkalinity = 0;
+        recipe->w1_ph = 7;
+        recipe->w1_cost = 0;
+        recipe->w2_name = "";
+        recipe->w2_amount = 0;
+        recipe->w2_calcium = 0;
+        recipe->w2_sulfate = 0;
+        recipe->w2_chloride = 0;
+        recipe->w2_sodium = 0;
+        recipe->w2_magnesium = 0;
+        recipe->w2_total_alkalinity = 0;
+        recipe->w2_ph = 7;
+        recipe->w2_cost = 0;
+        recipe->wg_amount = 0;
+        recipe->wg_calcium = 0;
+        recipe->wg_sulfate = 0;
+        recipe->wg_chloride = 0;
+        recipe->wg_sodium = 0;
+        recipe->wg_magnesium = 0;
+        recipe->wg_total_alkalinity = 0;
+        recipe->wg_ph = 7;
+        recipe->wb_calcium = 0;
+        recipe->wb_sulfate = 0;
+        recipe->wb_chloride = 0;
+        recipe->wb_sodium = 0;
+        recipe->wb_magnesium = 0;
+        recipe->wb_total_alkalinity = 0;
+        recipe->wb_ph = 7;
+	recipe->wa_acid_name = 0;
+	recipe->wa_acid_perc = 80;
+	recipe->wa_base_name = 0;
 
 	const auto& formattedJson = QString("[]");
 	this->fermentables = QJsonDocument::fromJson(formattedJson.toUtf8());
 	this->hops = QJsonDocument::fromJson(formattedJson.toUtf8());
 	this->miscs = QJsonDocument::fromJson(formattedJson.toUtf8());
 	this->yeasts = QJsonDocument::fromJson(formattedJson.toUtf8());
-	this->mashs = QJsonDocument::fromJson(formattedJson.toUtf8());
     }
 
+    ui->lockedEdit->setChecked(recipe->locked);
+    ui->st_nameEdit->setText(recipe->st_name);
+    ui->st_groupEdit->setText(recipe->st_letter);
+    ui->st_guideEdit->setText(recipe->st_guide);
+    ui->st_catEdit->setText(recipe->st_category);
+    ui->st_catnrEdit->setText(QString("%1").arg(recipe->st_category_number));
+    ui->st_typeEdit->setText(s_types[recipe->st_type]);
+
+    ui->nameEdit->setText(recipe->name);
+    ui->notesEdit->setPlainText(recipe->notes);
+    ui->typeEdit->setCurrentIndex(recipe->type);
+    ui->batch_sizeEdit->setValue(recipe->batch_size);
+    ui->boil_sizeEdit->setValue(recipe->boil_size);
+    ui->boil_timeEdit->setValue(recipe->boil_time);
+    ui->efficiencyEdit->setValue(recipe->efficiency);
+
+    ui->est_ogEdit->setValue(recipe->est_og);
+    ui->est_og2Edit->setValue(recipe->est_og);
+    ui->est_og3Edit->setValue(recipe->est_og);
+    ui->est_ogShow->setRange(recipe->st_og_min, recipe->st_og_max);
+    ui->est_ogShow->setPrecision(3);
+    ui->est_ogShow->setMarkerTextIsValue(true);
+    ui->est_ogShow->setValue(recipe->est_og);
+
+    ui->est_fgEdit->setValue(recipe->est_fg);
+    ui->est_fg3Edit->setValue(recipe->est_fg);
+    ui->est_fgShow->setRange(recipe->st_fg_min, recipe->st_fg_max);
+    ui->est_fgShow->setPrecision(3);
+    ui->est_fgShow->setMarkerTextIsValue(true);
+    ui->est_fgShow->setValue(recipe->est_fg);
+
+    ui->est_abvEdit->setValue(recipe->est_abv);
+    ui->est_abv2Edit->setValue(recipe->est_abv);
+    ui->est_abvShow->setRange(recipe->st_abv_min, recipe->st_abv_max);
+    ui->est_abvShow->setPrecision(1);
+    ui->est_abvShow->setMarkerTextIsValue(true);
+    ui->est_abvShow->setValue(recipe->est_abv);
+
+    ui->est_colorEdit->setValue(recipe->est_color);
+    ui->est_colorEdit->setStyleSheet(Utils::ebc_to_style(recipe->est_color));
+    ui->est_color2Edit->setValue(recipe->est_color);
+    ui->est_color2Edit->setStyleSheet(Utils::ebc_to_style(recipe->est_color));
+    ui->est_colorShow->setPrecision(0);
+    ui->est_colorShow->setMarkerTextIsValue(true);
+    ui->est_colorShow->setRange(recipe->st_color_min, recipe->st_color_max);
+    ui->est_colorShow->setValue(recipe->est_color);
+
+    ui->color_methodEdit->setCurrentIndex(recipe->color_method);
+
+    ui->est_ibuEdit->setValue(recipe->est_ibu);
+    ui->est_ibu2Edit->setValue(recipe->est_ibu);
+    ui->est_ibuShow->setPrecision(0);
+    ui->est_ibuShow->setMarkerTextIsValue(true);
+    ui->est_ibuShow->setRange(recipe->st_ibu_min, recipe->st_ibu_max);
+    ui->est_ibuShow->setValue(recipe->est_ibu);
+
+    ui->ibu_methodEdit->setCurrentIndex(recipe->ibu_method);
+
+    ui->est_carbEdit->setValue(recipe->est_carb);
+    ui->est_carbShow->setPrecision(1);
+    ui->est_carbShow->setMarkerTextIsValue(true);
+    ui->est_carbShow->setRange(recipe->st_carb_min, recipe->st_carb_max);
+    ui->est_carbShow->setValue(recipe->est_carb);
+
     // All signals from tab "Generic"
     connect(ui->lockedEdit, &QCheckBox::stateChanged, this, &EditRecipe::is_changed);
     connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditRecipe::is_changed);
@@ -519,14 +613,13 @@
      * Get average mashtemp and mashtime from the Mash schedule.
      * It is possible that the schedule is not (yet) present.
      */
-    if (this->mashs.array().size() > 0) {
-	for (i = 0; i < this->mashs.array().size(); i++) {
-	    obj = this->mashs.array().at(i).toObject();
-	    if (obj["step_type"].toInt() == 0)			// Infusion
-		mashinfuse += obj["step_infuse_amount"].toDouble();
-	    if (obj["step_temp"].toDouble() < 75) {		// Ignore mashout
-		mashtime += obj["step_time"].toDouble();
-		mashtemp += obj["step_time"].toDouble() * obj["step_temp"].toDouble();
+    if (recipe->mashs.size() > 0) {
+	for (i = 0; i < recipe->mashs.size(); i++) {
+	    if (recipe->mashs.at(i).step_type == 0)		// Infusion
+		mashinfuse += recipe->mashs.at(i).step_infuse_amount;
+	    if (recipe->mashs.at(i).step_temp < 75) {		// Ignore mashout
+		mashtime += recipe->mashs.at(i).step_time;
+		mashtemp += recipe->mashs.at(i).step_time * recipe->mashs.at(i).step_temp;
 	    }
 	}
 	mashtemp = mashtemp / mashtime;
--- a/src/EditRecipe.h	Tue Apr 05 22:28:35 2022 +0200
+++ b/src/EditRecipe.h	Wed Apr 06 12:10:33 2022 +0200
@@ -118,7 +118,7 @@
     double	step_temp;
     double	step_time;
     double	ramp_time;
-    double	end_time;
+    double	end_temp;
     double	step_wg_ratio;		// May not be present
 };
 
@@ -174,7 +174,7 @@
     double	sparge_acid_perc;
     double	sparge_acid_amount;
     double	mash_ph;
-    double	mash_name;
+    QString	mash_name;
     bool	calc_acid;
 
     QString	w1_name;			///< Water source 1
@@ -221,6 +221,23 @@
     QList<Miscs>	miscs;
     QList<Yeasts>	yeasts;
     QList<Mashs>	mashs;
+
+    /*
+     * These are not in the MySL database, but are global variables
+     * that belong with the loaded recipe data and are present to
+     * make things easier.
+     */
+    int		fermentables_records;	///< Total records
+    int		fermentables_current;	///< Current record, -1 is invalid.
+    bool	fermentables_use100;	///< Use percentages instead of amount
+    int		hops_records;
+    int		hops_current;
+    int		misc_records;
+    int		misc_current;
+    int		yeasts_records;
+    int		yeasts_current;
+    int		mashs_records;
+    int		mashs_current;
 };
 
 
@@ -280,7 +297,7 @@
     /*
      * Variables for popup ingredients editing.
      */
-    QJsonDocument fermentables, hops, miscs, yeasts, mashs;
+    QJsonDocument fermentables, hops, miscs, yeasts;
     QJsonObject work, backup;
     QComboBox *selectEdit, *addedEdit;
     QLineEdit *nameEdit, *supplierEdit;
--- a/ui/EditRecipe.ui	Tue Apr 05 22:28:35 2022 +0200
+++ b/ui/EditRecipe.ui	Wed Apr 06 12:10:33 2022 +0200
@@ -95,7 +95,7 @@
        <enum>QTabWidget::Rounded</enum>
       </property>
       <property name="currentIndex">
-       <number>0</number>
+       <number>1</number>
       </property>
       <property name="elideMode">
        <enum>Qt::ElideNone</enum>
@@ -824,7 +824,7 @@
         <widget class="QLabel" name="est_ibuLabel">
          <property name="geometry">
           <rect>
-           <x>20</x>
+           <x>10</x>
            <y>80</y>
            <width>111</width>
            <height>20</height>

mercurial