# HG changeset patch # User Michiel Broek # Date 1654180293 -7200 # Node ID baab61fb8bcdb517c804bd9eb43a09d41ff2243a # Parent 3c28dc8dd51d9f02c7967893d8213aea7a9a1389 Edit fermentables load record using namefields. Splitted diastaticEdit edit field in wkEdit and lintnerEdit. These fields are linked using the kolbach/lintner convert formula. The date input fields start on 1-1-2000 instead of ages ago. diff -r 3c28dc8dd51d -r baab61fb8bcd src/EditFermentable.cpp --- a/src/EditFermentable.cpp Wed Jun 01 21:46:26 2022 +0200 +++ b/src/EditFermentable.cpp Thu Jun 02 16:31:33 2022 +0200 @@ -57,36 +57,41 @@ query.exec(); query.next(); - ui->nameEdit->setText(query.value(1).toString()); - ui->notesEdit->setPlainText(query.value(8).toString()); - ui->originEdit->setText(query.value(6).toString()); - ui->supplierEdit->setText(query.value(7).toString()); - ui->typeEdit->setCurrentIndex(query.value(2).toInt()); - ui->graintypeEdit->setCurrentIndex(query.value(20).toInt()); - ui->maxinbatchEdit->setValue(query.value(14).toDouble()); - ui->mashEdit->setChecked(query.value(15).toInt() ? true:false); - ui->addafterEdit->setChecked(query.value(5).toInt() ? true:false); - ui->addedEdit->setCurrentIndex(query.value(17).toInt()); - ui->alwaysEdit->setChecked(query.value(5).toInt() ? true:false); - ui->inventoryEdit->setValue(query.value(21).toDouble()); - ui->costEdit->setValue(query.value(22).toDouble()); - ui->valueEdit->setValue(query.value(21).toDouble() * query.value(22).toDouble()); - ui->yieldEdit->setValue(query.value(3).toDouble()); - ui->colorEdit->setValue(query.value(4).toDouble()); - ui->moistureEdit->setValue(query.value(10).toDouble()); - ui->coarseEdit->setValue(query.value(9).toDouble()); - ui->proteinEdit->setValue(query.value(12).toDouble()); - ui->dissolvedEdit->setValue(query.value(13).toDouble()); - ui->diastaticEdit->setValue(Utils::lintner_to_kolbach(query.value(11).toDouble())); - ui->diphEdit->setValue(query.value(18).toDouble()); - ui->acidphEdit->setValue(query.value(19).toDouble()); - if (query.value(23).toString().length() == 10) { - ui->prodEdit->setDate(query.value(23).toDate()); + QSqlRecord rec = query.record(); + for (int i = 0; i < rec.count(); i++) + qDebug() << i << rec.fieldName(i) << query.value(i); + + ui->nameEdit->setText(query.value("name").toString()); + ui->notesEdit->setPlainText(query.value("notes").toString()); + ui->originEdit->setText(query.value("origin").toString()); + ui->supplierEdit->setText(query.value("supplier").toString()); + ui->typeEdit->setCurrentIndex(query.value("type").toInt()); + ui->graintypeEdit->setCurrentIndex(query.value("graintype").toInt()); + ui->maxinbatchEdit->setValue(query.value("max_in_batch").toDouble()); + ui->mashEdit->setChecked(query.value("recommend_mash").toInt() ? true:false); + ui->addafterEdit->setChecked(query.value("add_after_boil").toInt() ? true:false); + ui->addedEdit->setCurrentIndex(query.value("added").toInt()); + ui->alwaysEdit->setChecked(query.value("always_on_stock").toInt() ? true:false); + ui->inventoryEdit->setValue(query.value("inventory").toDouble()); + ui->costEdit->setValue(query.value("cost").toDouble()); + ui->valueEdit->setValue(query.value("inventory").toDouble() * query.value("cost").toDouble()); + ui->yieldEdit->setValue(query.value("yield").toDouble()); + ui->colorEdit->setValue(query.value("color").toDouble()); + ui->moistureEdit->setValue(query.value("moisture").toDouble()); + ui->coarseEdit->setValue(query.value("coarse_fine_diff").toDouble()); + ui->proteinEdit->setValue(query.value("protein").toDouble()); + ui->dissolvedEdit->setValue(query.value("dissolved_protein").toDouble()); + ui->lintnerEdit->setValue(query.value("diastatic_power").toDouble()); + ui->wkEdit->setValue(Utils::lintner_to_kolbach(query.value("diastatic_power").toDouble())); + ui->diphEdit->setValue(query.value("di_ph").toDouble()); + ui->acidphEdit->setValue(query.value("acid_to_ph_57").toDouble()); + if (query.value("production_date").toString().length() == 10) { + ui->prodEdit->setDate(query.value("production_date").toDate()); } else { ui->prodEdit->clear(); } - if (query.value(24).toString().length() == 10) { - ui->thtEdit->setDate(query.value(24).toDate()); + if (query.value("tht_date").toString().length() == 10) { + ui->thtEdit->setDate(query.value("tht_date").toDate()); } else { ui->thtEdit->clear(); } @@ -123,7 +128,8 @@ connect(ui->coarseEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); connect(ui->proteinEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); connect(ui->dissolvedEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); - connect(ui->diastaticEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); + connect(ui->wkEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditFermentable::wk_changed); + connect(ui->lintnerEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditFermentable::lintner_changed); connect(ui->diphEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); connect(ui->acidphEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); connect(ui->prodEdit, &QDateEdit::dateChanged, this, &EditFermentable::is_changed); @@ -206,7 +212,7 @@ query.bindValue(":notes", ui->notesEdit->toPlainText()); query.bindValue(":coarse", QString("%1").arg(ui->coarseEdit->value(), 2, 'f', 1, '0')); query.bindValue(":moisture", QString("%1").arg(ui->moistureEdit->value(), 2, 'f', 1, '0')); - query.bindValue(":diastatic", Utils::kolbach_to_lintner(ui->diastaticEdit->value())); + query.bindValue(":diastatic", Utils::kolbach_to_lintner(ui->wkEdit->value())); query.bindValue(":protein", QString("%1").arg(ui->proteinEdit->value(), 2, 'f', 1, '0')); query.bindValue(":dissolved", QString("%1").arg(ui->dissolvedEdit->value(), 2, 'f', 1, '0')); query.bindValue(":maxinbatch", QString("%1").arg(ui->maxinbatchEdit->value(), 2, 'f', 1, '0')); @@ -278,6 +284,25 @@ } +void EditFermentable::wk_changed(double val) +{ + const QSignalBlocker blocker1(ui->lintnerEdit); + if (val == 0) + ui->lintnerEdit->setValue(0); + else + ui->lintnerEdit->setValue(Utils::kolbach_to_lintner(val)); + is_changed(); +} + + +void EditFermentable::lintner_changed(double val) +{ + const QSignalBlocker blocker1(ui->wkEdit); + ui->wkEdit->setValue(Utils::lintner_to_kolbach(val)); + is_changed(); +} + + void EditFermentable::on_quitButton_clicked() { if (this->textIsChanged) { diff -r 3c28dc8dd51d -r baab61fb8bcd src/EditFermentable.h --- a/src/EditFermentable.h Wed Jun 01 21:46:26 2022 +0200 +++ b/src/EditFermentable.h Thu Jun 02 16:31:33 2022 +0200 @@ -24,6 +24,8 @@ void on_quitButton_clicked(); void on_deleteButton_clicked(); void is_changed(); + void wk_changed(double val); + void lintner_changed(double val); private: Ui::EditFermentable *ui; diff -r 3c28dc8dd51d -r baab61fb8bcd ui/EditFermentable.ui --- a/ui/EditFermentable.ui Wed Jun 01 21:46:26 2022 +0200 +++ b/ui/EditFermentable.ui Thu Jun 02 16:31:33 2022 +0200 @@ -196,13 +196,13 @@ 5 - 410 + 440 131 20 - Inventory: + Inventory Kg: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -212,7 +212,7 @@ 5 - 440 + 470 131 20 @@ -227,14 +227,14 @@ - 5 + 270 470 - 131 + 71 20 - Total value: + Total: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -320,7 +320,7 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + 660 @@ -330,7 +330,7 @@ - Diastatic power: + Windisch-Kolbach: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -356,7 +356,7 @@ 660 - 340 + 370 141 20 @@ -372,7 +372,7 @@ 660 - 370 + 400 141 20 @@ -388,7 +388,7 @@ 660 - 410 + 440 141 20 @@ -404,7 +404,7 @@ 660 - 440 + 470 141 20 @@ -538,7 +538,7 @@ 140 - 410 + 440 121 24 @@ -572,7 +572,7 @@ 140 - 440 + 470 121 24 @@ -608,6 +608,9 @@ true + + % + 1 @@ -649,6 +652,9 @@ true + + % + 1 @@ -687,6 +693,9 @@ true + + % + 1 @@ -706,11 +715,14 @@ true + + % + 1 - + 810 @@ -725,6 +737,9 @@ true + + WK + 0 @@ -736,7 +751,7 @@ 810 - 340 + 370 121 24 @@ -752,7 +767,7 @@ 810 - 370 + 400 121 24 @@ -832,7 +847,7 @@ 810 - 410 + 440 121 24 @@ -843,6 +858,16 @@ 0 0 2000 + 9 + 14 + + + + + 0 + 0 + 0 + 2000 1 1 @@ -858,11 +883,21 @@ 810 - 440 + 470 121 24 + + + 0 + 0 + 0 + 2000 + 1 + 1 + + yyyy-MM-dd @@ -936,7 +971,7 @@ - 140 + 350 470 107 24 @@ -952,6 +987,47 @@ QAbstractSpinBox::NoButtons + + + + 660 + 340 + 141 + 20 + + + + Lintner: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 810 + 340 + 121 + 24 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + 3 + + + 10000.000000000000000 + + + 0.500000000000000 + + @@ -983,7 +1059,7 @@ coarseEdit proteinEdit dissolvedEdit - diastaticEdit + wkEdit diphEdit acidphEdit prodEdit