--- 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