Load waters during recipe startup. Started calcWater() function. Load profile_setup record global. The print function uses the globals now too instead of loading from the database.

Thu, 14 Apr 2022 21:54:37 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 14 Apr 2022 21:54:37 +0200
changeset 133
08635b028dcf
parent 132
9ede9c75cb54
child 134
5099df8ba6c6

Load waters during recipe startup. Started calcWater() function. Load profile_setup record global. The print function uses the globals now too instead of loading from the database.

src/EditRecipe.cpp file | annotate | diff | comparison | revisions
src/EditRecipe.h 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/PrinterDialog.cpp file | annotate | diff | comparison | revisions
src/Utils.h 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/src/EditRecipe.cpp	Tue Apr 12 22:33:24 2022 +0200
+++ b/src/EditRecipe.cpp	Thu Apr 14 21:54:37 2022 +0200
@@ -24,7 +24,7 @@
 
 EditRecipe::EditRecipe(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditRecipe)
 {
-    QSqlQuery query;
+    QSqlQuery query, wquery;
 
     qDebug() << "EditRecipe record:" << id;
     recipe = new Recipe;
@@ -59,6 +59,17 @@
     ui->sp_sourceEdit->addItem(tr("Source 2"));
     ui->sp_sourceEdit->addItem(tr("Mixed"));
 
+    query.prepare("SELECT name FROM inventory_waters ORDER BY record");
+    query.exec();
+    query.first();
+    ui->w1_nameEdit->addItem("");
+    ui->w2_nameEdit->addItem("");
+    for (int i = 0; i < query.size(); i++) {
+	ui->w1_nameEdit->addItem(query.value(0).toString());
+	ui->w2_nameEdit->addItem(query.value(0).toString());
+	query.next();
+    }
+
     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();
@@ -427,6 +438,7 @@
 	recipe->wa_base_name = 0;
     }
 
+    // Tab generic.
     ui->lockedEdit->setChecked(recipe->locked);
     ui->st_nameEdit->setText(recipe->st_name);
     ui->st_groupEdit->setText(recipe->st_letter);
@@ -434,7 +446,6 @@
     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);
@@ -442,55 +453,157 @@
     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);
 
+    // Tab fermentables.
+    ui->est_og2Edit->setValue(recipe->est_og);
+    ui->est_color2Edit->setValue(recipe->est_color);
+    ui->est_color2Edit->setStyleSheet(Utils::ebc_to_style(recipe->est_color));
+
+    // Tab hops.
+    ui->est_ibu2Edit->setValue(recipe->est_ibu);
+
+    // Tab yeasts.
+    ui->est_og3Edit->setValue(recipe->est_og);
+    ui->est_fg3Edit->setValue(recipe->est_fg);
+    ui->est_abv2Edit->setValue(recipe->est_abv);
+
+    // Tab waters.
+    qDebug() << "water 1" << recipe->w1_name << "default" << my_default_water;
+    if (recipe->w1_ph > 4.0) {
+	/*
+	 * Water data seems present, use that and set the name between []
+	 */
+	ui->w1_nameEdit->setPlaceholderText(QString("["+recipe->w1_name+"]"));
+    } else {
+	bool found = false;
+	if (recipe->w1_name != "") {
+	    /*
+	     * We have a name, but do we know it?
+	     */
+	    query.prepare("SELECT * FROM inventory_waters WHERE name=:water");
+            query.bindValue(":water", recipe->w1_name);
+	    query.exec();
+	    found = query.first();
+	    qDebug() << "found name" << recipe->w1_name << found;
+	}
+	if (!found) {
+	    /*
+	     * Try to load default water
+	     */
+	    query.prepare("SELECT * FROM inventory_waters WHERE record=:record");
+	    query.bindValue(":record", my_default_water);
+	    query.exec();
+	    found = query.first();
+	    qDebug() << "found record" << my_default_water << found;
+	}
+	if (found) {
+	    qDebug() << "found record" << query.value(0).toInt();
+	    recipe->w1_calcium = query.value(3).toDouble();
+	    recipe->w1_magnesium = query.value(8).toDouble();
+	    recipe->w1_total_alkalinity = query.value(11).toDouble();
+	    recipe->w1_sodium = query.value(7).toDouble();
+	    recipe->w1_chloride = query.value(6).toDouble();
+	    recipe->w1_sulfate = query.value(5).toDouble();
+	    recipe->w1_ph = query.value(9).toDouble();
+            ui->w1_nameEdit->setCurrentIndex(query.value(0).toInt());
+	} else {
+	    recipe->w1_calcium = 0;
+	    recipe->w1_magnesium = 0;
+	    recipe->w1_total_alkalinity = 0;
+	    recipe->w1_sodium = 0;
+	    recipe->w1_chloride = 0;
+	    recipe->w1_sulfate = 0;
+	    recipe->w1_ph = 0;
+	}
+    }
+    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);
+
+    qDebug() << "water 2" << recipe->w2_name;
+    if (recipe->w2_ph  > 4.0) {
+	ui->w2_nameEdit->setPlaceholderText(QString("["+recipe->w2_name+"]"));
+    } else if (recipe->w2_name != "") {
+	query.prepare("SELECT * FROM inventory_waters WHERE name=:water");
+	query.bindValue(":water", recipe->w2_name);
+	query.exec();
+	if (query.first()) {
+	    qDebug() << "found record" << query.value(0).toInt();
+	    recipe->w2_calcium = query.value(3).toDouble();
+            recipe->w2_magnesium = query.value(8).toDouble();
+            recipe->w2_total_alkalinity = query.value(11).toDouble();
+            recipe->w2_sodium = query.value(7).toDouble();
+            recipe->w2_chloride = query.value(6).toDouble();
+            recipe->w2_sulfate = query.value(5).toDouble();
+            recipe->w2_ph = query.value(9).toDouble();
+	    ui->w2_nameEdit->setCurrentIndex(query.value(0).toInt());
+	} else {
+	    recipe->w2_calcium = 0;
+            recipe->w2_magnesium = 0;
+            recipe->w2_total_alkalinity = 0;
+            recipe->w2_sodium = 0;
+            recipe->w2_chloride = 0;
+            recipe->w2_sulfate = 0;
+            recipe->w2_ph = 0;
+	}
+    }
+    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->sp_volEdit->setValue(recipe->sparge_volume);
+    ui->sp_tempEdit->setValue(recipe->sparge_temp);
+    ui->sp_phEdit->setValue(recipe->sparge_ph);
+    ui->sp_sourceEdit->setCurrentIndex(recipe->sparge_source);
+    ui->sp_acidtypeEdit->setCurrentIndex(recipe->sparge_acid_type);
+    ui->sp_acidpercEdit->setValue(recipe->sparge_acid_perc);
+    ui->sp_acidvolEdit->setValue(recipe->sparge_acid_amount);
+
     // All signals from tab "Generic"
     connect(ui->lockedEdit, &QCheckBox::stateChanged, this, &EditRecipe::is_changed);
     connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditRecipe::name_changed);
@@ -527,6 +640,13 @@
     // All signals from tab "Mash"
 
     // All signals from tab "Water"
+    connect(ui->bs_cacl2Edit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_cacl2_changed);
+    connect(ui->bs_caso4Edit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_caso4_changed);
+    connect(ui->bs_mgso4Edit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_mgso4_changed);
+    connect(ui->bs_naclEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_nacl_changed);
+    connect(ui->bs_mgcl2Edit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_mgcl2_changed);
+    connect(ui->bs_nahco3Edit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_nahco3_changed);
+    connect(ui->bs_caco3Edit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_caco3_changed);
 
     ui->saveButton->setEnabled(false);
     ui->deleteButton->setEnabled((id >= 0) ? true:false);
@@ -554,6 +674,7 @@
     refreshYeasts();
     refreshMashs();
     refreshWaters();
+    calcWater();
 }
 
 
--- a/src/EditRecipe.h	Tue Apr 12 22:33:24 2022 +0200
+++ b/src/EditRecipe.h	Thu Apr 14 21:54:37 2022 +0200
@@ -295,6 +295,15 @@
     void on_deleteMiscRow_clicked();
     void on_editMiscRow_clicked();
 
+    void on_w2_vol_changed(double val);
+    void on_cacl2_changed(double val);
+    void on_caso4_changed(double val);
+    void on_mgso4_changed(double val);
+    void on_nacl_changed(double val);
+    void on_mgcl2_changed(double val);
+    void on_nahco3_changed(double val);
+    void on_caco3_changed(double val);
+
     void on_perc_mash_valueChanged(int value);
     void on_perc_sugars_valueChanged(int value);
     void on_perc_cara_valueChanged(int value);
@@ -340,8 +349,11 @@
     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 set_brewing_salt(QString salt, double val);
     void calcFermentables();
     void calcIBUs();
+    double mix(double v1, double v2, double c1, double c2);
+    void calcWater();
 };
 
 #endif
--- a/src/EditRecipeTab4.cpp	Tue Apr 12 22:33:24 2022 +0200
+++ b/src/EditRecipeTab4.cpp	Thu Apr 14 21:54:37 2022 +0200
@@ -171,6 +171,19 @@
 }
 
 
+void EditRecipe::set_brewing_salt(QString salt, double val)
+{
+    if (this->ignoreChanges)
+	return;
+
+    qDebug() << "set_brewing_salt" << salt << val;
+
+
+    calcWater();
+    is_changed();
+}
+
+
 void EditRecipe::on_addMiscRow_clicked()
 {
     Miscs newm;
--- a/src/EditRecipeTab7.cpp	Tue Apr 12 22:33:24 2022 +0200
+++ b/src/EditRecipeTab7.cpp	Thu Apr 14 21:54:37 2022 +0200
@@ -20,54 +20,6 @@
 
 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);
@@ -76,3 +28,128 @@
 
 }
 
+
+double EditRecipe::mix(double v1, double v2, double c1, double c2)
+{
+    if ((v1 + v2) > 0) {
+	return ((v1 * c1) + (v2 * c2)) / (v1 + v2);
+    }
+    return 0;
+}
+
+
+void EditRecipe::calcWater()
+{
+    double liters = 0;
+    double calcium = 0;
+    double magnesium = 0;
+    double sodium = 0;
+    double total_alkalinity = 0;
+    double bicarbonate = 0;
+    double chloride = 0;
+    double sulfate = 0;
+    double ph = 0;
+
+    qDebug() << "calcWater";
+
+    /*
+     * If there is a dilute water source, mix the waters.
+     */
+    if (recipe->w2_name != "") {
+	liters = recipe->w1_amount + recipe->w2_amount;
+	calcium = mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_calcium, recipe->w2_calcium);
+	magnesium = mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_magnesium, recipe->w2_magnesium);
+	sodium = mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_sodium, recipe->w2_sodium);
+	chloride = mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_chloride, recipe->w2_chloride);
+	sulfate = mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_sulfate, recipe->w2_sulfate);
+	total_alkalinity = mix(recipe->w1_amount, recipe->w2_amount, recipe->w1_total_alkalinity, recipe->w2_total_alkalinity);
+	ph = -log10(((pow(10, -recipe->w1_ph) * recipe->w1_amount) + (pow(10, -recipe->w2_ph) * recipe->w2_amount)) / liters);
+    } else {
+	liters = recipe->w1_amount;
+	calcium = recipe->w1_calcium;
+	magnesium = recipe->w1_magnesium;
+	sodium = recipe->w1_sodium;
+	chloride = recipe->w1_chloride;
+	sulfate = recipe->w1_sulfate;
+	total_alkalinity = recipe->w1_total_alkalinity;
+	ph = recipe->w1_ph;
+    }
+
+    recipe->wg_amount = liters;
+    recipe->wg_calcium = round(calcium * 10.0) / 10.0;
+    recipe->wg_magnesium = round(magnesium * 10.0) / 10.0;
+    recipe->wg_sodium = round(sodium * 10.0) / 10.0;
+    recipe->wg_chloride = round(chloride * 10.0) / 10.0;
+    recipe->wg_sulfate = round(sulfate * 10.0) / 10.0;
+    recipe->wg_total_alkalinity = round(total_alkalinity * 10.0) / 10.0;
+
+    ui->wg_volEdit->setValue(liters);
+    ui->wg_caEdit->setValue(calcium);
+    ui->wg_mgEdit->setValue(magnesium);
+    ui->wg_hco3Edit->setValue(total_alkalinity * 1.22);
+    ui->wg_caco3Edit->setValue(total_alkalinity);
+    ui->wg_naEdit->setValue(sodium);
+    ui->wg_clEdit->setValue(chloride);
+    ui->wg_so4Edit->setValue(sulfate);
+    ui->wg_phEdit->setValue(ph);
+    bicarbonate = total_alkalinity * 1.22;
+
+    /* Save mixed water ions for later */
+    double wg_calcium = calcium;
+    double wg_sodium = sodium;
+    double wg_total_alkalinity = total_alkalinity;
+    double wg_chloride = chloride;
+    double wg_sulfate = sulfate;
+    double wg_bicarbonate = bicarbonate;
+
+}
+
+
+void EditRecipe::on_w2_vol_changed(double val)
+{
+}
+
+
+void EditRecipe::on_cacl2_changed(double val)
+{
+    set_brewing_salt("CaCl2", val);
+}
+
+
+void EditRecipe::on_caso4_changed(double val)
+{
+    set_brewing_salt("CaSO4", val);
+}
+
+
+void EditRecipe::on_mgso4_changed(double val)
+{
+    set_brewing_salt("MgSO4", val);
+}
+
+
+void EditRecipe::on_nacl_changed(double val)
+{
+    set_brewing_salt("NaCl", val);
+}
+
+
+void EditRecipe::on_mgcl2_changed(double val)
+{
+    set_brewing_salt("MgCl2", val);
+}
+
+
+void EditRecipe::on_nahco3_changed(double val)
+{
+    set_brewing_salt("NaHCO3", val);
+}
+
+
+void EditRecipe::on_caco3_changed(double val)
+{
+    set_brewing_salt("CaCO3", val);
+}
+
+
+
--- a/src/MainWindow.cpp	Tue Apr 12 22:33:24 2022 +0200
+++ b/src/MainWindow.cpp	Thu Apr 14 21:54:37 2022 +0200
@@ -56,6 +56,7 @@
     db = new DataBase();
     db->openDataBase(useDevelopOption);
 
+    loadSetup();
     openWS(useDevelopOption);
 
     Acid a;
@@ -108,6 +109,32 @@
 
 
 
+void MainWindow::loadSetup()
+{
+    /*
+     * Load dedaults from the setup.
+     */
+    QSqlQuery query("SELECT * FROM profile_setup WHERE record='1'");
+    query.first();
+    my_brewery_name = query.value(1).toString();
+    my_logoByteArray = query.value(2).toByteArray();
+    my_factor_mashhop = query.value(3).toInt();
+    my_factor_fwh = query.value(4).toInt();
+    my_factor_pellet = query.value(5).toInt();
+    my_factor_plug = query.value(6).toInt();
+    my_factor_wethop = query.value(7).toInt();
+    my_factor_cryohop = query.value(8).toInt();
+    my_ibu_method = query.value(9).toInt();
+    my_color_method = query.value(10).toInt();
+    my_brix_correction = query.value(11).toDouble();
+    my_grain_absorbtion = query.value(12).toDouble();
+    my_default_water = query.value(13).toInt();
+    my_yeastlab = query.value(14).toString();
+
+    qDebug() << "loadSetup" << my_brewery_name;
+}
+
+
 bool MainWindow::openWS(bool develop)
 {
     QString server;
@@ -575,6 +602,7 @@
     delete SetupWindow;
     setWindowTitle( QString("BMSapp - %1").arg(VERSIONSTRING) );
     ui->menuBar->setVisible(true);
+    loadSetup();
 }
 
 
--- a/src/MainWindow.h	Tue Apr 12 22:33:24 2022 +0200
+++ b/src/MainWindow.h	Thu Apr 14 21:54:37 2022 +0200
@@ -161,6 +161,11 @@
     QWebSocket *webSocket;
 
     /**
+     * @brief Load profile_setup record and set global variables.
+     */
+    void loadSetup();
+
+    /**
      * @brief Open Websocket connection.
      * @param develop Is true if connect to develop server, else production.
      * @return Returns true if succes.
@@ -175,6 +180,7 @@
 
     /**
      * @brief Read user settings for the MySQL connection.
+     *        Settings in $HOME/.config/mbse/bmsapp.ini
      */
     void readsettings();
 
--- a/src/PrinterDialog.cpp	Tue Apr 12 22:33:24 2022 +0200
+++ b/src/PrinterDialog.cpp	Thu Apr 14 21:54:37 2022 +0200
@@ -16,6 +16,7 @@
  */
 #include "PrinterDialog.h"
 #include "config.h"
+#include "global.h"
 
 #include <QPrintPreviewDialog>
 #include <QDebug>
@@ -262,10 +263,6 @@
 	/*
 	 * Print yeast in the private yeast bank.
 	 */
-	query.exec("SELECT brewery_name,my_yeastlab FROM profile_setup WHERE record = '1'");
-	query.first();
-	QString my_lab = query.value(1).toString();
-	qDebug() << my_lab;
 	printHeader(&painter);
         y = 120;
 
@@ -282,7 +279,7 @@
         painter.setFont(QFont("Helvetica", 9, QFont::Normal));
 	query.prepare("SELECT name,type,form,inventory,production_date,short_desc "
 		       "FROM inventory_yeasts WHERE inventory > 0 AND laboratory = :my_lab ORDER BY product_id");
-	query.bindValue(":my_lab", my_lab);
+	query.bindValue(":my_lab", my_yeastlab);
 	query.exec();
         query.first();
 	for (int i = 0; i < query.size(); i++) {
@@ -311,11 +308,8 @@
 
 void PrinterDialog::printHeader(QPainter *painter)
 {
-    QSqlQuery query("SELECT brewery_logo,brewery_name FROM profile_setup");
-    query.first();
-    QByteArray logoByteArray = query.value(0).toByteArray();
     QPixmap outPixmap = QPixmap();
-    outPixmap.loadFromData(logoByteArray);
+    outPixmap.loadFromData(my_logoByteArray);
     int w = outPixmap.width();
     int h = outPixmap.height();
     /* Make sure to keep the logo aspect ratio */
@@ -330,11 +324,11 @@
     /* The fat header line */
     painter->setFont(QFont("Helvetica",18, QFont::Bold));
     if (p_job == PR_SUPPLIES) {
-	painter->drawText(120, 0,  500, 40, Qt::AlignLeft, tr("Inventory") + " " + query.value(1).toString());
+	painter->drawText(120, 0,  500, 40, Qt::AlignLeft, tr("Inventory") + " " + my_brewery_name);
     } else if (p_job == PR_YEASTBANK) {
-	painter->drawText(120, 0,  500, 40, Qt::AlignLeft, tr("Yeastbank") + " " + query.value(1).toString());
+	painter->drawText(120, 0,  500, 40, Qt::AlignLeft, tr("Yeastbank") + " " + my_brewery_name);
     } else {
-        painter->drawText(120, 0,  500, 40, Qt::AlignLeft, "?? " + query.value(1).toString());
+        painter->drawText(120, 0,  500, 40, Qt::AlignLeft, "?? " + my_brewery_name);
     }
     /* The first normal header line */
     painter->setFont(QFont("Helvetica",10, QFont::Normal));
--- a/src/Utils.h	Tue Apr 12 22:33:24 2022 +0200
+++ b/src/Utils.h	Thu Apr 14 21:54:37 2022 +0200
@@ -61,8 +61,6 @@
      * @return A QString with stylesheet colors.
      */
     QString ebc_to_style(int srm);
-
-//    double my_brix_correction = 1.04;
 }
 
 #endif
--- a/src/global.cpp	Tue Apr 12 22:33:24 2022 +0200
+++ b/src/global.cpp	Thu Apr 14 21:54:37 2022 +0200
@@ -5,15 +5,17 @@
 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;
+QByteArray my_logoByteArray = 0;
+int my_factor_mashhop = -30;
+int my_factor_fwh = 10;
+int my_factor_pellet = 10;
+int my_factor_plug = 2;
+int my_factor_wethop = -82;
+int 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;
+int my_default_water = -1;
+QString my_yeastlab = "";
 
-
--- a/src/global.h	Tue Apr 12 22:33:24 2022 +0200
+++ b/src/global.h	Thu Apr 14 21:54:37 2022 +0200
@@ -18,15 +18,18 @@
 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 QByteArray	my_logoByteArray;
+extern int		my_factor_mashhop;
+extern int		my_factor_fwh;
+extern int		my_factor_pellet;
+extern int		my_factor_plug;
+extern int		my_factor_wethop;
+extern int		my_factor_cryohop;
 extern int		my_ibu_method;
 extern int		my_color_method;
 extern double		my_brix_correction;
 extern double		my_grain_absorbtion;
+extern int		my_default_water;
+extern QString		my_yeastlab;
 
 #endif
--- a/ui/EditRecipe.ui	Tue Apr 12 22:33:24 2022 +0200
+++ b/ui/EditRecipe.ui	Thu Apr 14 21:54:37 2022 +0200
@@ -3185,7 +3185,7 @@
           <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
          </property>
         </widget>
-        <widget class="QComboBox" name="w1_sourceEdit">
+        <widget class="QComboBox" name="w1_nameEdit">
          <property name="geometry">
           <rect>
            <x>10</x>
@@ -3204,7 +3204,7 @@
           <string>Choose water</string>
          </property>
         </widget>
-        <widget class="QComboBox" name="w2_sourceEdit">
+        <widget class="QComboBox" name="w2_nameEdit">
          <property name="geometry">
           <rect>
            <x>10</x>
@@ -3216,6 +3216,9 @@
          <property name="toolTip">
           <string>Optional dilution water</string>
          </property>
+         <property name="placeholderText">
+          <string>Choose dilution</string>
+         </property>
         </widget>
         <widget class="QComboBox" name="wt_sourceEdit">
          <property name="geometry">
@@ -3265,7 +3268,7 @@
          <rect>
           <x>10</x>
           <y>230</y>
-          <width>291</width>
+          <width>271</width>
           <height>241</height>
          </rect>
         </property>
@@ -3277,12 +3280,15 @@
           <rect>
            <x>10</x>
            <y>20</y>
-           <width>171</width>
+           <width>151</width>
            <height>20</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Calcium Chloride</string>
+         </property>
          <property name="text">
-          <string>Calcium Chloride (CaCl2):</string>
+          <string>CaCl2:</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3293,12 +3299,15 @@
           <rect>
            <x>10</x>
            <y>50</y>
-           <width>171</width>
+           <width>151</width>
            <height>20</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Gypsym</string>
+         </property>
          <property name="text">
-          <string>Gypsym (CaSO4):</string>
+          <string>CaSO4:</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3309,12 +3318,15 @@
           <rect>
            <x>10</x>
            <y>80</y>
-           <width>171</width>
+           <width>151</width>
            <height>20</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Epsom</string>
+         </property>
          <property name="text">
-          <string>Epsom (MgSO4):</string>
+          <string>MgSO4:</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3325,12 +3337,15 @@
           <rect>
            <x>10</x>
            <y>110</y>
-           <width>171</width>
+           <width>151</width>
            <height>20</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Table salt</string>
+         </property>
          <property name="text">
-          <string>Table salt (NaCl):</string>
+          <string>NaCl:</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3341,12 +3356,15 @@
           <rect>
            <x>10</x>
            <y>140</y>
-           <width>171</width>
+           <width>151</width>
            <height>20</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Magnesium Chloride</string>
+         </property>
          <property name="text">
-          <string>Magnesium Chloride (MgCl2):</string>
+          <string>MgCl2:</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3357,12 +3375,15 @@
           <rect>
            <x>10</x>
            <y>170</y>
-           <width>171</width>
+           <width>151</width>
            <height>20</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Baking soda</string>
+         </property>
          <property name="text">
-          <string>Baking soda (NaHCO3):</string>
+          <string>NaHCO3:</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3373,12 +3394,15 @@
           <rect>
            <x>10</x>
            <y>200</y>
-           <width>171</width>
+           <width>151</width>
            <height>20</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Chalk undissolved</string>
+         </property>
          <property name="text">
-          <string>Chalk undissolved (CaCO3):</string>
+          <string>CaCO3:</string>
          </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -3387,12 +3411,15 @@
         <widget class="QDoubleSpinBox" name="bs_cacl2Edit">
          <property name="geometry">
           <rect>
-           <x>190</x>
+           <x>170</x>
            <y>20</y>
            <width>91</width>
            <height>24</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Calcium Chloride</string>
+         </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
          </property>
@@ -3415,12 +3442,15 @@
         <widget class="QDoubleSpinBox" name="bs_caso4Edit">
          <property name="geometry">
           <rect>
-           <x>190</x>
+           <x>170</x>
            <y>50</y>
            <width>91</width>
            <height>24</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Gypsym</string>
+         </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
          </property>
@@ -3443,12 +3473,15 @@
         <widget class="QDoubleSpinBox" name="bs_mgso4Edit">
          <property name="geometry">
           <rect>
-           <x>190</x>
+           <x>170</x>
            <y>80</y>
            <width>91</width>
            <height>24</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Epsom</string>
+         </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
          </property>
@@ -3471,12 +3504,15 @@
         <widget class="QDoubleSpinBox" name="bs_naclEdit">
          <property name="geometry">
           <rect>
-           <x>190</x>
+           <x>170</x>
            <y>110</y>
            <width>91</width>
            <height>24</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Table salt</string>
+         </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
          </property>
@@ -3499,12 +3535,15 @@
         <widget class="QDoubleSpinBox" name="bs_mgcl2Edit">
          <property name="geometry">
           <rect>
-           <x>190</x>
+           <x>170</x>
            <y>140</y>
            <width>91</width>
            <height>24</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Magnesium Chloride</string>
+         </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
          </property>
@@ -3527,12 +3566,15 @@
         <widget class="QDoubleSpinBox" name="bs_nahco3Edit">
          <property name="geometry">
           <rect>
-           <x>190</x>
+           <x>170</x>
            <y>170</y>
            <width>91</width>
            <height>24</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Baking soda</string>
+         </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
          </property>
@@ -3555,12 +3597,15 @@
         <widget class="QDoubleSpinBox" name="bs_caco3Edit">
          <property name="geometry">
           <rect>
-           <x>190</x>
+           <x>170</x>
            <y>200</y>
            <width>91</width>
            <height>24</height>
           </rect>
          </property>
+         <property name="toolTip">
+          <string>Chalk undissolved</string>
+         </property>
          <property name="alignment">
           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
          </property>
@@ -3584,7 +3629,7 @@
        <widget class="QGroupBox" name="mashBox">
         <property name="geometry">
          <rect>
-          <x>360</x>
+          <x>350</x>
           <y>230</y>
           <width>421</width>
           <height>91</height>

mercurial