Added global variables, C++ lovers will hate that. Added global acid data. Fixed several load and save errors in the json arrays in the recipe record. Added first part of the miscs table. The first part of the water tab has values.

Tue, 12 Apr 2022 21:03:19 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 12 Apr 2022 21:03:19 +0200
changeset 131
0115b97e8c39
parent 130
8544f1e28208
child 132
9ede9c75cb54

Added global variables, C++ lovers will hate that. Added global acid data. Fixed several load and save errors in the json arrays in the recipe record. Added first part of the miscs table. The first part of the water tab has values.

CMakeLists.txt file | annotate | diff | comparison | revisions
src/EditRecipe.cpp file | annotate | diff | comparison | revisions
src/EditRecipe.h file | annotate | diff | comparison | revisions
src/EditRecipeTab3.cpp file | annotate | diff | comparison | revisions
src/EditRecipeTab4.cpp file | annotate | diff | comparison | revisions
src/EditRecipeTab7.cpp file | annotate | diff | comparison | revisions
src/MainWindow.cpp file | annotate | diff | comparison | revisions
src/MainWindow.h file | annotate | diff | comparison | revisions
src/Utils.cpp file | annotate | diff | comparison | revisions
src/global.cpp file | annotate | diff | comparison | revisions
src/global.h file | annotate | diff | comparison | revisions
ui/EditRecipe.ui file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Mon Apr 11 22:32:04 2022 +0200
+++ b/CMakeLists.txt	Tue Apr 12 21:03:19 2022 +0200
@@ -186,6 +186,7 @@
     ${SRCDIR}/database/database.cpp
     ${SRCDIR}/RangedSlider.cpp
     ${SRCDIR}/NullDateEdit.cpp
+    ${SRCDIR}/global.cpp
   )
 
   set( HDRS
@@ -221,6 +222,7 @@
     ${SRCDIR}/database/database.h
     ${SRCDIR}/RangedSlider.h
     ${SRCDIR}/NullDateEdit.h
+    ${SRCDIR}/global.h
   )
 
   set( UIS
--- 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;
--- a/src/EditRecipe.h	Mon Apr 11 22:32:04 2022 +0200
+++ b/src/EditRecipe.h	Tue Apr 12 21:03:19 2022 +0200
@@ -267,6 +267,7 @@
     void refreshMiscs();
     void refreshYeasts();
     void refreshMashs();
+    void refreshWaters();
     void refreshAll();
     void ferment_amount_changed(double val);
     void ferment_pct_changed(double val);
@@ -302,6 +303,8 @@
     QStringList h_types = { tr("Bittering"), tr("Aroma"), tr("Both") };
     QStringList h_forms = { tr("Pellet"), tr("Plug"), tr("Leaf"), tr("Leaf wet"), tr("Cryo") };
     QStringList h_useat = { tr("Mash"), tr("First wort"), tr("Boil"), tr("Aroma"), tr("Whirlpool"), tr("Dry hop") };
+    QStringList m_types = { tr("Spice"), tr("Herb"), tr("Flavor"), tr("Fining"), tr("Water agent"), tr("Yeast nutrient"), tr("Other") };
+    QStringList m_uses = { tr("Starter"), tr("Mash"), tr("Boil"), tr("Primary"), tr("Secondary"), tr("Bottling") };
     QString bar_red = "QProgressBar::chunk {background: #FF0000;}";
     QString bar_orange = "QProgressBar::chunk {background: #EB7331;}";
     QString bar_green = "QProgressBar::chunk {background: #008C00;}";
@@ -327,6 +330,7 @@
     void to100Fermentables(int row);
     static bool ferment_sort_test(const Fermentables &D1, const Fermentables &D2);
     static bool hop_sort_test(const Hops &D1, const Hops &D2);
+    static bool misc_sort_test(const Miscs &D1, const Miscs &D2);
     void WindowTitle();
     void calcFermentables();
     void calcIBUs();
--- a/src/EditRecipeTab3.cpp	Mon Apr 11 22:32:04 2022 +0200
+++ b/src/EditRecipeTab3.cpp	Tue Apr 12 21:03:19 2022 +0200
@@ -57,13 +57,13 @@
     ui->hopsTable->setColumnCount(11);
     ui->hopsTable->setColumnWidth(0, 150);     /* Origin	*/
     ui->hopsTable->setColumnWidth(1, 225);     /* Hop		*/
-    ui->hopsTable->setColumnWidth(2,  75);     /* Type		*/
-    ui->hopsTable->setColumnWidth(3,  75);     /* Form          */
+    ui->hopsTable->setColumnWidth(2,  84);     /* Type		*/
+    ui->hopsTable->setColumnWidth(3,  84);     /* Form          */
     ui->hopsTable->setColumnWidth(4,  75);     /* Alpha%	*/
     ui->hopsTable->setColumnWidth(5,  75);     /* Added         */
     ui->hopsTable->setColumnWidth(6,  75);     /* Time		*/
     ui->hopsTable->setColumnWidth(7,  60);     /* IBU		*/
-    ui->hopsTable->setColumnWidth(8,  75);     /* Amount	*/
+    ui->hopsTable->setColumnWidth(8,  90);     /* Amount	*/
     ui->hopsTable->setColumnWidth(9,  80);     /* Delete        */
     ui->hopsTable->setColumnWidth(10, 80);     /* Edit          */
     ui->hopsTable->setHorizontalHeaderLabels(labels);
--- a/src/EditRecipeTab4.cpp	Mon Apr 11 22:32:04 2022 +0200
+++ b/src/EditRecipeTab4.cpp	Tue Apr 12 21:03:19 2022 +0200
@@ -18,8 +18,157 @@
  */
 
 
-void EditRecipe::refreshMiscs()
+bool EditRecipe::misc_sort_test(const Miscs &D1, const Miscs &D2)
 {
+    if (D1.m_use_use > D2.m_use_use)
+	return false;
+    if (D1.m_use_use < D2.m_use_use)
+	return true;
+    if (D1.m_type > D2.m_type)
+	return false;
+    if (D1.m_type < D2.m_type)
+	return true;
+    return (D1.m_amount > D2.m_amount);
 }
 
 
+void EditRecipe::refreshMiscs()
+{
+    QString w;
+    QWidget* pWidget;
+    QHBoxLayout* pLayout;
+    QTableWidgetItem *item;
+
+    qDebug() << "refreshMiscs" << recipe->miscs.size();
+    std::sort(recipe->miscs.begin(), recipe->miscs.end(), misc_sort_test);
+
+    /*
+     * During filling the table turn off the cellChanged signal because every cell that is filled
+     * triggers the cellChanged signal. The QTableWidget has no better signal to use.
+     */
+    this->ignoreChanges = true;
+
+    const QStringList labels({tr("Ingredient"), tr("Type"), tr("Use at"), tr("Time"), tr("Amount"), tr("Delete"), tr("Edit") });
+
+    ui->miscsTable->setColumnCount(7);
+    ui->miscsTable->setColumnWidth(0, 300);	/* Ingredient	*/
+    ui->miscsTable->setColumnWidth(1, 100);	/* Type		*/
+    ui->miscsTable->setColumnWidth(2, 100);	/* Added	*/
+    ui->miscsTable->setColumnWidth(3,  75);	/* Time		*/
+    ui->miscsTable->setColumnWidth(4,  90);	/* Amount	*/
+    ui->miscsTable->setColumnWidth(5,  80);	/* Delete	*/
+    ui->miscsTable->setColumnWidth(6,  80);	/* Edit		*/
+    ui->miscsTable->setHorizontalHeaderLabels(labels);
+    ui->miscsTable->verticalHeader()->hide();
+    ui->miscsTable->setRowCount(recipe->miscs.size());
+
+    ui->mw_acidPick->setCurrentIndex(-1);
+
+    for (int i = 0; i < recipe->miscs.size(); i++) {
+
+	ui->miscsTable->setItem(i, 0, new QTableWidgetItem(recipe->miscs.at(i).m_name));
+
+	item = new QTableWidgetItem(m_types[recipe->miscs.at(i).m_type]);
+        item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
+        ui->miscsTable->setItem(i, 1, item);
+
+	item = new QTableWidgetItem(m_uses[recipe->miscs.at(i).m_use_use]);
+        item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
+        ui->miscsTable->setItem(i, 2, item);
+
+	if (recipe->miscs.at(i).m_use_use == 2) {	// Boil
+	    item = new QTableWidgetItem(QString("%1 min.").arg(recipe->miscs.at(i).m_time, 1, 'f', 0, '0'));
+	} else if (recipe->miscs.at(i).m_use_use == 3 || recipe->miscs.at(i).m_use_use == 4) {	// Primary or secondary
+	    item = new QTableWidgetItem(QString("%1 days.").arg(recipe->miscs.at(i).m_time / 1440, 1, 'f', 0, '0'));
+	} else {
+	    item = new QTableWidgetItem(QString(""));
+	}
+	item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+        ui->miscsTable->setItem(i, 3, item);
+
+	if (recipe->miscs.at(i).m_amount_is_weight)
+	    item = new QTableWidgetItem(QString("%1 gr").arg(recipe->miscs.at(i).m_amount * 1000.0, 2, 'f', 1, '0'));
+	else
+	    item = new QTableWidgetItem(QString("%1 ml").arg(recipe->miscs.at(i).m_amount * 1000.0, 2, 'f', 1, '0'));
+	item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+        ui->miscsTable->setItem(i, 4, item);
+
+	/*
+	 * Add the Delete and Edit row buttons.
+	 * Not for water agents, these are set on the water tab.
+	 */
+	if (recipe->miscs.at(i).m_type == 4) {
+	    ui->miscsTable->removeCellWidget(i, 5);
+	    ui->miscsTable->removeCellWidget(i, 6);
+	} else {
+            pWidget = new QWidget();
+            QPushButton* btn_dele = new QPushButton();
+            btn_dele->setObjectName(QString("%1").arg(i));  /* Send row with the button */
+            btn_dele->setText(tr("Delete"));
+            connect(btn_dele, SIGNAL(clicked()), this, SLOT(on_deleteFermentRow_clicked()));
+            pLayout = new QHBoxLayout(pWidget);
+            pLayout->addWidget(btn_dele);
+            pLayout->setContentsMargins(5, 0, 5, 0);
+            pWidget->setLayout(pLayout);
+            ui->miscsTable->setCellWidget(i, 5, pWidget);
+
+            pWidget = new QWidget();
+            QPushButton* btn_edit = new QPushButton();
+            btn_edit->setObjectName(QString("%1").arg(i));  /* Send row with the button */
+            btn_edit->setText(tr("Edit"));
+            connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editFermentRow_clicked()));
+            pLayout = new QHBoxLayout(pWidget);
+            pLayout->addWidget(btn_edit);
+            pLayout->setContentsMargins(5, 0, 5, 0);
+            pWidget->setLayout(pLayout);
+            ui->miscsTable->setCellWidget(i, 6, pWidget);
+	}
+
+	/*
+	 * Update the water agents.
+	 */
+	if (recipe->miscs.at(i).m_type == 4) {
+	    if (recipe->miscs.at(i).m_name == "CaCl2") {
+		ui->bs_cacl2Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0);
+	    } else if (recipe->miscs.at(i).m_name == "CaSO4") {
+		ui->bs_caso4Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0);
+	    } else if (recipe->miscs.at(i).m_name == "MgSO4") {
+		ui->bs_mgso4Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0);
+	    } else if (recipe->miscs.at(i).m_name == "NaCl") {
+		ui->bs_naclEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0);
+	    } else if (recipe->miscs.at(i).m_name == "MgCl2") {
+		ui->bs_mgcl2Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0);
+	    } else if (recipe->miscs.at(i).m_name == "NaHCO3") {
+		ui->bs_nahco3Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0);
+	    } else if (recipe->miscs.at(i).m_name == "CaCO3") {
+		ui->bs_caco3Edit->setValue(recipe->miscs.at(i).m_amount * 1000.0);
+	    } else if (recipe->miscs.at(i).m_name == "Melkzuur" || recipe->miscs.at(i).m_name == "Lactic") {
+		recipe->wa_acid_name = 0;
+		recipe->wa_acid_perc = my_acids.at(0).AcidPrc;
+		ui->mw_acidPick->setCurrentIndex(0);
+		ui->mw_acidpercEdit->setValue(my_acids.at(0).AcidPrc);
+		ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0);
+	    } else if (recipe->miscs.at(i).m_name == "Zoutzuur" || recipe->miscs.at(i).m_name == "Hydrochloric") {
+                recipe->wa_acid_name = 1;
+                recipe->wa_acid_perc = my_acids.at(1).AcidPrc;
+		ui->mw_acidPick->setCurrentIndex(1);
+                ui->mw_acidpercEdit->setValue(my_acids.at(1).AcidPrc);
+                ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0);
+	    } else if (recipe->miscs.at(i).m_name == "Fosforzuur" || recipe->miscs.at(i).m_name == "Phosphoric") {
+                recipe->wa_acid_name = 2;
+                recipe->wa_acid_perc = my_acids.at(2).AcidPrc;
+		ui->mw_acidPick->setCurrentIndex(2);
+                ui->mw_acidpercEdit->setValue(my_acids.at(2).AcidPrc);
+                ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0);
+	    } else if (recipe->miscs.at(i).m_name == "Zwavelzuur" || recipe->miscs.at(i).m_name == "Sulfuric") {
+                recipe->wa_acid_name = 3;
+                recipe->wa_acid_perc = my_acids.at(3).AcidPrc;
+		ui->mw_acidPick->setCurrentIndex(3);
+                ui->mw_acidpercEdit->setValue(my_acids.at(3).AcidPrc);
+                ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0);
+	    }
+	}
+    }
+}
+
+
--- a/src/EditRecipeTab7.cpp	Mon Apr 11 22:32:04 2022 +0200
+++ b/src/EditRecipeTab7.cpp	Tue Apr 12 21:03:19 2022 +0200
@@ -18,4 +18,61 @@
  */
 
 
+void EditRecipe::refreshWaters()
+{
+    // recipe->w1_name
+    ui->w1_volEdit->setValue(recipe->w1_amount);
+    ui->w1_caEdit->setValue(recipe->w1_calcium);
+    ui->w1_mgEdit->setValue(recipe->w1_magnesium);
+    ui->w1_hco3Edit->setValue(recipe->w1_total_alkalinity * 1.22);
+    ui->w1_caco3Edit->setValue(recipe->w1_total_alkalinity);
+    ui->w1_naEdit->setValue(recipe->w1_sodium);
+    ui->w1_clEdit->setValue(recipe->w1_chloride);
+    ui->w1_so4Edit->setValue(recipe->w1_sulfate);
+    ui->w1_phEdit->setValue(recipe->w1_ph);
 
+    // recipe->w2_name
+    ui->w2_volEdit->setValue(recipe->w2_amount);
+    ui->w2_caEdit->setValue(recipe->w2_calcium);
+    ui->w2_mgEdit->setValue(recipe->w2_magnesium);
+    ui->w2_hco3Edit->setValue(recipe->w2_total_alkalinity * 1.22);
+    ui->w2_caco3Edit->setValue(recipe->w2_total_alkalinity);
+    ui->w2_naEdit->setValue(recipe->w2_sodium);
+    ui->w2_clEdit->setValue(recipe->w2_chloride);
+    ui->w2_so4Edit->setValue(recipe->w2_sulfate);
+    ui->w2_phEdit->setValue(recipe->w2_ph);
+
+    ui->wg_volEdit->setValue(recipe->wg_amount);
+    ui->wg_caEdit->setValue(recipe->wg_calcium);
+    ui->wg_mgEdit->setValue(recipe->wg_magnesium);
+    ui->wg_hco3Edit->setValue(recipe->wg_total_alkalinity * 1.22);
+    ui->wg_caco3Edit->setValue(recipe->wg_total_alkalinity);
+    ui->wg_naEdit->setValue(recipe->wg_sodium);
+    ui->wg_clEdit->setValue(recipe->wg_chloride);
+    ui->wg_so4Edit->setValue(recipe->wg_sulfate);
+    ui->wg_phEdit->setValue(recipe->wg_ph);
+
+    ui->wb_caEdit->setValue(recipe->wb_calcium);
+    ui->wb_mgEdit->setValue(recipe->wb_magnesium);
+    ui->wb_hco3Edit->setValue(recipe->wb_total_alkalinity * 1.22);
+    ui->wb_caco3Edit->setValue(recipe->wb_total_alkalinity);
+    ui->wb_naEdit->setValue(recipe->wb_sodium);
+    ui->wb_clEdit->setValue(recipe->wb_chloride);
+    ui->wb_so4Edit->setValue(recipe->wb_sulfate);
+    ui->wb_phEdit->setValue(recipe->wb_ph);
+
+    ui->sp_volEdit->setValue(recipe->sparge_volume);
+    ui->sp_tempEdit->setValue(recipe->sparge_temp);
+    ui->sp_phEdit->setValue(recipe->sparge_ph);
+    // sparge_source
+    // sparge_acid_type
+    ui->sp_acidpercEdit->setValue(recipe->sparge_acid_perc);
+    ui->sp_acidvolEdit->setValue(recipe->sparge_acid_amount);
+
+    // calc_acid
+    ui->mw_phEdit->setValue(recipe->mash_ph);
+    // mash_name
+    //ui->mw_acidpercEdit->setValue(recipe->
+
+}
+
--- a/src/MainWindow.cpp	Mon Apr 11 22:32:04 2022 +0200
+++ b/src/MainWindow.cpp	Tue Apr 12 21:03:19 2022 +0200
@@ -33,6 +33,7 @@
 #include "../ui/ui_MainWindow.h"
 #include "database/database.h"
 #include "config.h"
+#include "global.h"
 
 #include <QApplication>
 #include <QCloseEvent>
@@ -56,6 +57,42 @@
     db->openDataBase(useDevelopOption);
 
     openWS(useDevelopOption);
+
+    Acid a;
+    a.name = "Lactic";
+    a.pK1 = 3.86;
+    a.pK2 = 20;
+    a.pK3 = 20;
+    a.MolWt = 90.08;
+    a.AcidSG = 1238;
+    a.AcidPrc = 80;
+    my_acids.append(a);
+    a.name = "Hydrochloric";
+    a.pK1 = -7;
+    a.pK2 = 20;
+    a.pK3 = 20;
+    a.MolWt = 36.46;
+    a.AcidSG = 1497;
+    a.AcidPrc = 28;
+    my_acids.append(a);
+    a.name = "Phosphoric";
+    a.pK1 = 2.12;
+    a.pK2 = 7.20;
+    a.pK3 = 12.44;
+    a.MolWt = 98.00;
+    a.AcidSG = 1982;
+    a.AcidPrc = 75;
+    my_acids.append(a);
+    a.name = "Sulfuric";
+    a.pK1 = -1;
+    a.pK2 = 1.92;
+    a.pK3 = 20;
+    a.MolWt = 98.07;
+    a.AcidSG = 1884;
+    a.AcidPrc = 93;
+    my_acids.append(a);
+
+    qDebug() << "acids" << my_acids.size();
 }
 
 
--- a/src/MainWindow.h	Mon Apr 11 22:32:04 2022 +0200
+++ b/src/MainWindow.h	Tue Apr 12 21:03:19 2022 +0200
@@ -79,17 +79,18 @@
 static IniWS wsDev;
 
 
-static QString my_brewery_name = "No-name";
-static double my_factor_mashhop = -30;
-static double my_factor_fwh = 10;
-static double my_factor_pellet = 10;
-static double my_factor_plug = 2;
-static double my_factor_wethop = -82;
-static double my_factor_cryohop = 100;
-static int my_ibu_method = 0;
-static int my_color_method = 0;
-static double my_brix_correction = 1.04;
-static double my_grain_absorbtion = 1.01;
+//struct Acid
+//{
+//    QString	name;
+//    double	pK1;
+//    double	pK2;
+//    double	pK3;
+//    double	MolWt;
+//    double	AcidSG;
+//    double	AcidPrc;
+//};
+
+//static QList<Acid>	my_acids;
 
 
 namespace Ui {
--- a/src/Utils.cpp	Mon Apr 11 22:32:04 2022 +0200
+++ b/src/Utils.cpp	Tue Apr 12 21:03:19 2022 +0200
@@ -16,6 +16,7 @@
  */
 #include "Utils.h"
 #include "MainWindow.h"
+#include "global.h"
 
 #include <QDebug>
 #include <math.h>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/global.cpp	Tue Apr 12 21:03:19 2022 +0200
@@ -0,0 +1,19 @@
+
+
+#include "global.h"
+
+QList<Acid>      my_acids;
+
+QString my_brewery_name = "No-name";
+double my_factor_mashhop = -30;
+double my_factor_fwh = 10;
+double my_factor_pellet = 10;
+double my_factor_plug = 2;
+double my_factor_wethop = -82;
+double my_factor_cryohop = 100;
+int my_ibu_method = 0;
+int my_color_method = 0;
+double my_brix_correction = 1.04;
+double my_grain_absorbtion = 1.01;
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/global.h	Tue Apr 12 21:03:19 2022 +0200
@@ -0,0 +1,32 @@
+#ifndef	_GLOBAL_H
+#define	_GLOBAL_H
+
+#include <QList>
+#include <QString>
+
+struct Acid
+{
+    QString     name;
+    double      pK1;
+    double      pK2;
+    double      pK3;
+    double      MolWt;
+    double      AcidSG;
+    double      AcidPrc;
+};
+
+extern QList<Acid>	my_acids;
+
+extern QString		my_brewery_name;
+extern double		my_factor_mashhop;
+extern double		my_factor_fwh;
+extern double		my_factor_pellet;
+extern double		my_factor_plug;
+extern double		my_factor_wethop;
+extern double		my_factor_cryohop;
+extern int		my_ibu_method;
+extern int		my_color_method;
+extern double		my_brix_correction;
+extern double		my_grain_absorbtion;
+
+#endif
--- a/ui/EditRecipe.ui	Mon Apr 11 22:32:04 2022 +0200
+++ b/ui/EditRecipe.ui	Tue Apr 12 21:03:19 2022 +0200
@@ -3270,7 +3270,7 @@
          </rect>
         </property>
         <property name="title">
-         <string>Brewing salts</string>
+         <string>Water agents</string>
         </property>
         <widget class="QLabel" name="bs_cacl2Label">
          <property name="geometry">
@@ -3282,7 +3282,7 @@
           </rect>
          </property>
          <property name="text">
-          <string>Calciumchloride (CaCl2) gr:</string>
+          <string>Calcium Chloride (CaCl2):</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3298,7 +3298,7 @@
           </rect>
          </property>
          <property name="text">
-          <string>Gips (CaSO4) gr:</string>
+          <string>Gypsym (CaSO4):</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3314,7 +3314,7 @@
           </rect>
          </property>
          <property name="text">
-          <string>Epsom zout (MgSO4) gr:</string>
+          <string>Epsom (MgSO4):</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3330,7 +3330,7 @@
           </rect>
          </property>
          <property name="text">
-          <string>Keukenzout (NaCl) gr:</string>
+          <string>Table salt (NaCl):</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3346,7 +3346,7 @@
           </rect>
          </property>
          <property name="text">
-          <string>Magnesiumchloride (MgCl2) gr:</string>
+          <string>Magnesium Chloride (MgCl2):</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3362,7 +3362,7 @@
           </rect>
          </property>
          <property name="text">
-          <string>Baksoda (NaHCO3) gr:</string>
+          <string>Baking soda (NaHCO3):</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3378,7 +3378,7 @@
           </rect>
          </property>
          <property name="text">
-          <string>Kalk (CaCO3) gr:</string>
+          <string>Chalk undissolved (CaCO3):</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3399,8 +3399,11 @@
          <property name="accelerated">
           <bool>true</bool>
          </property>
+         <property name="suffix">
+          <string> gr</string>
+         </property>
          <property name="decimals">
-          <number>1</number>
+          <number>2</number>
          </property>
          <property name="maximum">
           <double>1000.000000000000000</double>
@@ -3424,8 +3427,11 @@
          <property name="accelerated">
           <bool>true</bool>
          </property>
+         <property name="suffix">
+          <string> gr</string>
+         </property>
          <property name="decimals">
-          <number>1</number>
+          <number>2</number>
          </property>
          <property name="maximum">
           <double>1000.000000000000000</double>
@@ -3449,8 +3455,11 @@
          <property name="accelerated">
           <bool>true</bool>
          </property>
+         <property name="suffix">
+          <string> gr</string>
+         </property>
          <property name="decimals">
-          <number>1</number>
+          <number>2</number>
          </property>
          <property name="maximum">
           <double>1000.000000000000000</double>
@@ -3474,8 +3483,11 @@
          <property name="accelerated">
           <bool>true</bool>
          </property>
+         <property name="suffix">
+          <string> gr</string>
+         </property>
          <property name="decimals">
-          <number>1</number>
+          <number>2</number>
          </property>
          <property name="maximum">
           <double>1000.000000000000000</double>
@@ -3499,8 +3511,11 @@
          <property name="accelerated">
           <bool>true</bool>
          </property>
+         <property name="suffix">
+          <string> gr</string>
+         </property>
          <property name="decimals">
-          <number>1</number>
+          <number>2</number>
          </property>
          <property name="maximum">
           <double>1000.000000000000000</double>
@@ -3524,8 +3539,11 @@
          <property name="accelerated">
           <bool>true</bool>
          </property>
+         <property name="suffix">
+          <string> gr</string>
+         </property>
          <property name="decimals">
-          <number>1</number>
+          <number>2</number>
          </property>
          <property name="maximum">
           <double>1000.000000000000000</double>
@@ -3549,8 +3567,11 @@
          <property name="accelerated">
           <bool>true</bool>
          </property>
+         <property name="suffix">
+          <string> gr</string>
+         </property>
          <property name="decimals">
-          <number>1</number>
+          <number>2</number>
          </property>
          <property name="maximum">
           <double>1000.000000000000000</double>
@@ -3670,6 +3691,9 @@
          <property name="accelerated">
           <bool>true</bool>
          </property>
+         <property name="suffix">
+          <string>%</string>
+         </property>
          <property name="decimals">
           <number>0</number>
          </property>
@@ -3930,6 +3954,9 @@
          <property name="accelerated">
           <bool>true</bool>
          </property>
+         <property name="suffix">
+          <string>%</string>
+         </property>
          <property name="decimals">
           <number>0</number>
          </property>

mercurial