# HG changeset patch # User Michiel Broek # Date 1650554521 -7200 # Node ID b5b2483f3a3f65764998774cb6da9eca7eceb47c # Parent fd568cc1dd0e8f19ff3577aba7ecae68123a2d86 New recipe, calculate the boil_size. Lot's of ignoreChanges removeals and where needed QSignalBlocker is used. Bottle priming calculation added. In fermentables editor block and release to100 settings only in mash to fermentation steps, bottle and kegging are ignored. Update the IBU slider after hop changes. Set the mash name when another mash profile is selected. Don't backup initial infuse amount if there was no mash table. A small cosmetic layout change on the mash tab. diff -r fd568cc1dd0e -r b5b2483f3a3f src/EditRecipe.cpp --- a/src/EditRecipe.cpp Wed Apr 20 22:48:20 2022 +0200 +++ b/src/EditRecipe.cpp Thu Apr 21 17:22:01 2022 +0200 @@ -422,8 +422,8 @@ recipe->notes = ""; recipe->efficiency = 75; recipe->batch_size = 20; - recipe->boil_size = 24; recipe->boil_time = 60; + recipe->boil_size = recipe->batch_size + (round(recipe->batch_size * recipe->boil_time / 60.0) / 10.0); recipe->type = 2; recipe->est_og = recipe->est_fg = recipe->est_color = recipe->est_ibu = recipe->est_abv = 0; recipe->sparge_temp = 80; diff -r fd568cc1dd0e -r b5b2483f3a3f src/EditRecipeTab2.cpp --- a/src/EditRecipeTab2.cpp Wed Apr 20 22:48:20 2022 +0200 +++ b/src/EditRecipeTab2.cpp Thu Apr 21 17:22:01 2022 +0200 @@ -21,7 +21,11 @@ bool EditRecipe::ferment_sort_test(const Fermentables &D1, const Fermentables &D2) { - return (D1.f_added <= D2.f_added) && (D1.f_amount >= D2.f_amount) && (D1.f_color < D2.f_color); + if (D1.f_added > D2.f_added) + return false; + if (D1.f_added < D2.f_added) + return true; + return (D1.f_amount >= D2.f_amount) && (D1.f_color < D2.f_color); } @@ -53,12 +57,6 @@ qDebug() << "refreshFermentables" << recipe->fermentables.size(); std::sort(recipe->fermentables.begin(), recipe->fermentables.end(), ferment_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("Supplier"), tr("Fermentable"), tr("EBC"), tr("Type"), tr("Graintype"), tr("When"), tr("Yield"), tr("Amount"), tr("Procent"), tr("100%"), tr("Delete"), tr("Edit") }); ui->fermentablesTable->setColumnCount(12); @@ -141,7 +139,6 @@ pWidget->setLayout(pLayout); ui->fermentablesTable->setCellWidget(i, 11, pWidget); } - this->ignoreChanges = false; } @@ -186,6 +183,9 @@ qDebug() << " no mash schedule"; } + const QSignalBlocker blocker1(ui->est_ogEdit); + const QSignalBlocker blocker2(ui->est_og2Edit); + if (recipe->fermentables.size() < 1) { qDebug() << " no fermentables, return."; recipe->est_og = 0.980; @@ -346,6 +346,25 @@ double alc = 1881.22 * fg * (og - fg) / (1.775 - og); double sug = 3550 * fg * (0.1808 * og + 0.8192 * fg - 1.0004); ui->calEdit->setValue(round((alc + sug) / (12 * 0.0295735296))); + + // Bottle priming + double priming_total = 0; + for (i = 0; i < recipe->fermentables.size(); i++) { + if (recipe->fermentables.at(i).f_added == 4) { + priming_total += ((recipe->fermentables.at(i).f_yield / 100) * (1 - recipe->fermentables.at(i).f_moisture / 100)) * + recipe->fermentables.at(i).f_amount; + qDebug() << " priming" << recipe->fermentables.at(i).f_amount << "total" << priming_total; + } + } + double grl = priming_total * 1000.0 * (1 / recipe->batch_size); + double volco2 = grl * 0.510; + qDebug() << " priming gr/l" << grl << "volco2" << volco2; + + if (volco2 > 0) { + recipe->est_carb = volco2; + ui->est_carbEdit->setValue(recipe->est_carb); + ui->est_carbShow->setValue(recipe->est_carb); + } } @@ -475,7 +494,7 @@ if (rc == QMessageBox::No) return; - this->ignoreChanges = true; +// this->ignoreChanges = true; recipe->fermentables.removeAt(row); /* @@ -489,7 +508,7 @@ if (recipe->fermentables.at(i).f_added < 4) recipe->fermentables[i].f_percentage = recipe->fermentables.at(i).f_amount / total * 100; - this->ignoreChanges = false; +// this->ignoreChanges = false; is_changed(); emit refreshAll(); } @@ -500,11 +519,11 @@ QTableWidgetItem *item; double total = 0, perc; - if (recipe->fermentables_use100) + if (recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).f_added < 4) return; qDebug() << "ferment_amount_changed()" << recipe->fermentables_row << val; - this->ignoreChanges = true; +// this->ignoreChanges = true; recipe->fermentables[recipe->fermentables_row].f_amount = val; item = new QTableWidgetItem(QString("%1 Kg").arg(val, 4, 'f', 3, '0')); @@ -528,7 +547,7 @@ this->pctEdit->setValue(perc); } } - this->ignoreChanges = false; +// this->ignoreChanges = false; is_changed(); } @@ -557,7 +576,7 @@ double diffw = (diffp / 100) * total; qDebug() << "row100" << row100 << "total" << total << "diff kg" << diffw << "diff %" << diffp; - this->ignoreChanges = true; +// this->ignoreChanges = true; recipe->fermentables[recipe->fermentables_row].f_percentage += diffp; recipe->fermentables[recipe->fermentables_row].f_amount += diffw; recipe->fermentables[row100].f_percentage -= diffp; @@ -580,7 +599,7 @@ item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->fermentablesTable->setItem(row100, 8, item); - this->ignoreChanges = false; +// this->ignoreChanges = false; is_changed(); } @@ -589,6 +608,13 @@ { qDebug() << "ferment_to100_changed()" << recipe->fermentables_row << val << recipe->fermentables_use100; + if (recipe->fermentables.at(recipe->fermentables_row).f_added >= 4) { + const QSignalBlocker blocker1(to100Edit); + recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 = false; + to100Edit->setChecked(false); + return; + } + /* * Three scenario's. * 1. There is no fermentable selected yet, just mark it. @@ -618,14 +644,15 @@ return; } - this->ignoreChanges = true; +// this->ignoreChanges = true; for (int i = 0; i < recipe->fermentables.size(); i++) { to100Fermentables(i); } - this->ignoreChanges = false; +// this->ignoreChanges = false; is_changed(); } + void EditRecipe::ferment_select_changed(int val) { QSqlQuery query; @@ -657,7 +684,6 @@ /* * Replace the fermentable record contents */ - this->ignoreChanges = true; recipe->fermentables[recipe->fermentables_row].f_name = query.value(0).toString(); recipe->fermentables[recipe->fermentables_row].f_origin = query.value(1).toString(); recipe->fermentables[recipe->fermentables_row].f_supplier = query.value(2).toString(); @@ -704,7 +730,6 @@ item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->fermentablesTable->setItem(recipe->fermentables_row, 6, item); - this->ignoreChanges = false; calcFermentables(); is_changed(); } @@ -738,12 +763,15 @@ { qDebug() << "ferment_added_changed()" << recipe->fermentables_row << val; - this->ignoreChanges = true; +// this->ignoreChanges = true; recipe->fermentables[recipe->fermentables_row].f_added = val; QTableWidgetItem *item = new QTableWidgetItem(f_added[val]); item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); ui->fermentablesTable->setItem(recipe->fermentables_row, 5, item); + famountEdit->setReadOnly(recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).f_added < 4); + pctEdit->setReadOnly(! (recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).f_added < 4)); + double total = 0; for (int i = 0; i < recipe->fermentables.size(); i++) if (recipe->fermentables.at(i).f_added < 4) // Only before bottle/kegging @@ -752,7 +780,7 @@ if (recipe->fermentables.at(i).f_added < 4) recipe->fermentables[i].f_percentage = recipe->fermentables.at(i).f_amount / total * 100; - this->ignoreChanges = false; +// this->ignoreChanges = false; is_changed(); emit refreshAll(); } @@ -842,7 +870,7 @@ famountEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); famountEdit->setAccelerated(true); famountEdit->setDecimals(3); - famountEdit->setReadOnly(recipe->fermentables_use100); + famountEdit->setReadOnly(recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).f_added < 4); famountEdit->setMaximum(100000.0); famountEdit->setSingleStep(0.0010); famountEdit->setValue(recipe->fermentables.at(recipe->fermentables_row).f_amount); @@ -853,7 +881,7 @@ pctEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); pctEdit->setAccelerated(true); pctEdit->setDecimals(1); - if (recipe->fermentables_use100) { + if (recipe->fermentables_use100 && recipe->fermentables.at(recipe->fermentables_row).f_added < 4) { if (recipe->fermentables.at(recipe->fermentables_row).f_adjust_to_total_100) pctEdit->setReadOnly(true); else diff -r fd568cc1dd0e -r b5b2483f3a3f src/EditRecipeTab3.cpp --- a/src/EditRecipeTab3.cpp Wed Apr 20 22:48:20 2022 +0200 +++ b/src/EditRecipeTab3.cpp Thu Apr 21 17:22:01 2022 +0200 @@ -45,12 +45,6 @@ qDebug() << "refreshHops" << recipe->hops.size(); std::sort(recipe->hops.begin(), recipe->hops.end(), hop_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("Origin"), tr("Hop"), tr("Type"), tr("Form"), tr("Alpha"), tr("Use at"), tr("Time"), tr("IBU"), tr("Amount"), tr("Delete"), tr("Edit") }); @@ -138,7 +132,6 @@ pWidget->setLayout(pLayout); ui->hopsTable->setCellWidget(i, 10, pWidget); } - this->ignoreChanges = false; } @@ -207,6 +200,7 @@ recipe->est_ibu = ibus; ui->est_ibuEdit->setValue(recipe->est_ibu); ui->est_ibu2Edit->setValue(recipe->est_ibu); + ui->est_ibuShow->setValue(recipe->est_ibu); ui->hop_tasteShow->setValue(hop_flavour); ui->hop_aromaShow->setValue(hop_aroma); } @@ -259,9 +253,7 @@ if (rc == QMessageBox::No) return; - this->ignoreChanges = true; recipe->hops.removeAt(row); - this->ignoreChanges = false; is_changed(); emit refreshAll(); } @@ -272,7 +264,6 @@ QTableWidgetItem *item; qDebug() << "hop_amount_changed()" << recipe->hops_row << val; - this->ignoreChanges = true; recipe->hops[recipe->hops_row].h_amount = val / 1000.0; item = new QTableWidgetItem(QString("%1 gr").arg(val, 2, 'f', 1, '0')); @@ -288,7 +279,6 @@ item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->hopsTable->setItem(recipe->hops_row, 7, item); - this->ignoreChanges = false; calcIBUs(); is_changed(); } @@ -300,9 +290,7 @@ qDebug() << "hop_time_changed()" << recipe->hops_row << val; - this->ignoreChanges = true; recipe->hops[recipe->hops_row].h_time = val; - if (recipe->hops.at(recipe->hops_row).h_useat == 2 || recipe->hops.at(recipe->hops_row).h_useat == 4) { // Boil or whirlpool item = new QTableWidgetItem(QString("%1 min.").arg(val, 1, 'f', 0, '0')); } else if (recipe->hops.at(recipe->hops_row).h_useat == 5) { // Dry-hop @@ -322,7 +310,6 @@ item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->hopsTable->setItem(recipe->hops_row, 7, item); - this->ignoreChanges = false; calcIBUs(); is_changed(); } diff -r fd568cc1dd0e -r b5b2483f3a3f src/EditRecipeTab6.cpp --- a/src/EditRecipeTab6.cpp Wed Apr 20 22:48:20 2022 +0200 +++ b/src/EditRecipeTab6.cpp Thu Apr 21 17:22:01 2022 +0200 @@ -31,12 +31,6 @@ down_icon.addFile(QString::fromUtf8(":/icons/silk/bullet_arrow_down.png"), QSize(), QIcon::Normal, QIcon::Off); up_icon.addFile(QString::fromUtf8(":/icons/silk/bullet_arrow_up.png"), QSize(), QIcon::Normal, QIcon::Off); - /* - * 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("Step name"), tr("Type"), tr("Start"), tr("End"), tr("Rest"), tr("Ramp"), tr("Inf/dec"), tr("Inf/dec"), tr("Volume"), tr("W/G ratio"), "", "", tr("Delete"), tr("Edit") }); @@ -235,7 +229,7 @@ recipe->mashs[i].step_infuse_temp = 99; } recipe->mashs[i].step_volume = infused; - qDebug() << i << " type:" << recipe->mashs.at(i).step_type << "volume:" << recipe->mashs.at(i).step_infuse_amount << "temp:" << recipe->mashs.at(i).step_infuse_temp; + //qDebug() << i << " type:" << recipe->mashs.at(i).step_type << "volume:" << recipe->mashs.at(i).step_infuse_amount << "temp:" << recipe->mashs.at(i).step_infuse_temp; lasttemp = recipe->mashs.at(i).step_temp; recipe->mashs_time += recipe->mashs.at(i).step_time; if (i > 0) @@ -293,9 +287,7 @@ if (rc == QMessageBox::No) return; - this->ignoreChanges = true; recipe->mashs.removeAt(row); - this->ignoreChanges = false; is_changed(); emit refreshAll(); } @@ -310,12 +302,10 @@ if (recipe->mashs.size() < 1) return; - this->ignoreChanges = true; Mashs temp; temp = recipe->mashs[row - 1]; recipe->mashs[row - 1] = recipe->mashs[row]; recipe->mashs[row] = temp; - this->ignoreChanges = false; is_changed(); emit refreshAll(); } @@ -330,12 +320,10 @@ if (recipe->mashs.size() < 1) return; - this->ignoreChanges = true; Mashs temp; temp = recipe->mashs[row + 1]; recipe->mashs[row + 1] = recipe->mashs[row]; recipe->mashs[row] = temp; - this->ignoreChanges = false; is_changed(); emit refreshAll(); } @@ -343,10 +331,8 @@ void EditRecipe::step_name_changed(QString val) { - this->ignoreChanges = true; recipe->mashs[recipe->mashs_row].step_name = val; ui->mashsTable->setItem(recipe->mashs_row, 0, new QTableWidgetItem(val)); - this->ignoreChanges = false; is_changed(); } @@ -355,9 +341,7 @@ { qDebug() << "step_type_changed" << recipe->mashs_row << val; - this->ignoreChanges = true; recipe->mashs[recipe->mashs_row].step_type = val; - this->ignoreChanges = false; ivolLabel->setVisible(recipe->mashs.at(recipe->mashs_row).step_type == 0); stepivolEdit->setVisible(recipe->mashs.at(recipe->mashs_row).step_type == 0); itmpLabel->setVisible(recipe->mashs.at(recipe->mashs_row).step_type == 0); @@ -370,12 +354,10 @@ void EditRecipe::step_temp_changed(double val) { qDebug() << "step_temp_changed" << recipe->mashs_row << val; - this->ignoreChanges = true; recipe->mashs[recipe->mashs_row].step_temp = val; QTableWidgetItem *item = new QTableWidgetItem(QString("%1 °C").arg(val, 2, 'f', 1, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->mashsTable->setItem(recipe->mashs_row, 2, item); - this->ignoreChanges = false; is_changed(); emit refreshAll(); } @@ -384,12 +366,10 @@ void EditRecipe::end_temp_changed(double val) { qDebug() << "end_temp_changed" << recipe->mashs_row << val; - this->ignoreChanges = true; recipe->mashs[recipe->mashs_row].end_temp = val; QTableWidgetItem *item = new QTableWidgetItem(QString("%1 °C").arg(val, 2, 'f', 1, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->mashsTable->setItem(recipe->mashs_row, 3, item); - this->ignoreChanges = false; is_changed(); emit refreshAll(); } @@ -398,12 +378,10 @@ void EditRecipe::step_time_changed(double val) { qDebug() << "step_time_changed" << recipe->mashs_row << val; - this->ignoreChanges = true; recipe->mashs[recipe->mashs_row].step_time = val; QTableWidgetItem *item = new QTableWidgetItem(QString("%1 min").arg(val, 1, 'f', 0, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->mashsTable->setItem(recipe->mashs_row, 4, item); - this->ignoreChanges = false; is_changed(); emit refreshAll(); } @@ -412,12 +390,10 @@ void EditRecipe::ramp_time_changed(double val) { qDebug() << "ramp_time_changed" << recipe->mashs_row << val; - this->ignoreChanges = true; recipe->mashs[recipe->mashs_row].ramp_time = val; QTableWidgetItem *item = new QTableWidgetItem(QString("%1 min").arg(val, 1, 'f', 0, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->mashsTable->setItem(recipe->mashs_row, 5, item); - this->ignoreChanges = false; is_changed(); emit refreshAll(); } @@ -426,7 +402,6 @@ void EditRecipe::infuse_changed(double val) { qDebug() << "infuse_changed" << recipe->mashs_row << val; - this->ignoreChanges = true; recipe->mashs[recipe->mashs_row].step_infuse_amount = val; QTableWidgetItem *item = new QTableWidgetItem(QString("%1 L").arg(val, 1, 'f', 0, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); @@ -446,7 +421,6 @@ recipe->wg_amount = volume; ui->w1_volEdit->setValue(recipe->w1_amount); - this->ignoreChanges = false; is_changed(); emit refreshAll(); } @@ -630,6 +604,9 @@ query.next(); } + recipe->mash_name = query.value(0).toString(); + ui->mash_nameEdit->setText(recipe->mash_name); + QJsonParseError parseError; const auto& json = query.value(1).toString(); if (!json.trimmed().isEmpty()) { @@ -642,9 +619,12 @@ /* * Got the json data in the steps array, replace the recipe steps. */ - double infuse = recipe->mashs.at(0).step_infuse_amount; - recipe->mashs.clear(); - ui->mashsTable->clear(); + double infuse = 0; + if (recipe->mashs.size()) { + infuse = recipe->mashs.at(0).step_infuse_amount; + recipe->mashs.clear(); + ui->mashsTable->clear(); + } if (newsteps.isArray()) { for (i = 0; i < newsteps.array().size(); i++) { QJsonObject obj = newsteps.array().at(i).toObject(); @@ -678,7 +658,7 @@ } } if (recipe->mashs.at(0).step_type == 0) - recipe->mashs[0].step_infuse_amount = infuse; // Restore save initial infusion + recipe->mashs[0].step_infuse_amount = infuse; // Restore saved initial infusion } } is_changed(); diff -r fd568cc1dd0e -r b5b2483f3a3f ui/EditRecipe.ui --- a/ui/EditRecipe.ui Wed Apr 20 22:48:20 2022 +0200 +++ b/ui/EditRecipe.ui Thu Apr 21 17:22:01 2022 +0200 @@ -2312,9 +2312,9 @@ 10 - 70 + 110 1101 - 391 + 351