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