diff -r 9ede9c75cb54 -r 08635b028dcf src/EditRecipe.cpp --- 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::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_cacl2_changed); + connect(ui->bs_caso4Edit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_caso4_changed); + connect(ui->bs_mgso4Edit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_mgso4_changed); + connect(ui->bs_naclEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_nacl_changed); + connect(ui->bs_mgcl2Edit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_mgcl2_changed); + connect(ui->bs_nahco3Edit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_nahco3_changed); + connect(ui->bs_caco3Edit, QOverload::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(); }