55 query.prepare("SELECT * FROM inventory_fermentables WHERE record = :recno"); |
55 query.prepare("SELECT * FROM inventory_fermentables WHERE record = :recno"); |
56 query.bindValue(":recno", id); |
56 query.bindValue(":recno", id); |
57 query.exec(); |
57 query.exec(); |
58 query.next(); |
58 query.next(); |
59 |
59 |
60 ui->nameEdit->setText(query.value(1).toString()); |
60 QSqlRecord rec = query.record(); |
61 ui->notesEdit->setPlainText(query.value(8).toString()); |
61 for (int i = 0; i < rec.count(); i++) |
62 ui->originEdit->setText(query.value(6).toString()); |
62 qDebug() << i << rec.fieldName(i) << query.value(i); |
63 ui->supplierEdit->setText(query.value(7).toString()); |
63 |
64 ui->typeEdit->setCurrentIndex(query.value(2).toInt()); |
64 ui->nameEdit->setText(query.value("name").toString()); |
65 ui->graintypeEdit->setCurrentIndex(query.value(20).toInt()); |
65 ui->notesEdit->setPlainText(query.value("notes").toString()); |
66 ui->maxinbatchEdit->setValue(query.value(14).toDouble()); |
66 ui->originEdit->setText(query.value("origin").toString()); |
67 ui->mashEdit->setChecked(query.value(15).toInt() ? true:false); |
67 ui->supplierEdit->setText(query.value("supplier").toString()); |
68 ui->addafterEdit->setChecked(query.value(5).toInt() ? true:false); |
68 ui->typeEdit->setCurrentIndex(query.value("type").toInt()); |
69 ui->addedEdit->setCurrentIndex(query.value(17).toInt()); |
69 ui->graintypeEdit->setCurrentIndex(query.value("graintype").toInt()); |
70 ui->alwaysEdit->setChecked(query.value(5).toInt() ? true:false); |
70 ui->maxinbatchEdit->setValue(query.value("max_in_batch").toDouble()); |
71 ui->inventoryEdit->setValue(query.value(21).toDouble()); |
71 ui->mashEdit->setChecked(query.value("recommend_mash").toInt() ? true:false); |
72 ui->costEdit->setValue(query.value(22).toDouble()); |
72 ui->addafterEdit->setChecked(query.value("add_after_boil").toInt() ? true:false); |
73 ui->valueEdit->setValue(query.value(21).toDouble() * query.value(22).toDouble()); |
73 ui->addedEdit->setCurrentIndex(query.value("added").toInt()); |
74 ui->yieldEdit->setValue(query.value(3).toDouble()); |
74 ui->alwaysEdit->setChecked(query.value("always_on_stock").toInt() ? true:false); |
75 ui->colorEdit->setValue(query.value(4).toDouble()); |
75 ui->inventoryEdit->setValue(query.value("inventory").toDouble()); |
76 ui->moistureEdit->setValue(query.value(10).toDouble()); |
76 ui->costEdit->setValue(query.value("cost").toDouble()); |
77 ui->coarseEdit->setValue(query.value(9).toDouble()); |
77 ui->valueEdit->setValue(query.value("inventory").toDouble() * query.value("cost").toDouble()); |
78 ui->proteinEdit->setValue(query.value(12).toDouble()); |
78 ui->yieldEdit->setValue(query.value("yield").toDouble()); |
79 ui->dissolvedEdit->setValue(query.value(13).toDouble()); |
79 ui->colorEdit->setValue(query.value("color").toDouble()); |
80 ui->diastaticEdit->setValue(Utils::lintner_to_kolbach(query.value(11).toDouble())); |
80 ui->moistureEdit->setValue(query.value("moisture").toDouble()); |
81 ui->diphEdit->setValue(query.value(18).toDouble()); |
81 ui->coarseEdit->setValue(query.value("coarse_fine_diff").toDouble()); |
82 ui->acidphEdit->setValue(query.value(19).toDouble()); |
82 ui->proteinEdit->setValue(query.value("protein").toDouble()); |
83 if (query.value(23).toString().length() == 10) { |
83 ui->dissolvedEdit->setValue(query.value("dissolved_protein").toDouble()); |
84 ui->prodEdit->setDate(query.value(23).toDate()); |
84 ui->lintnerEdit->setValue(query.value("diastatic_power").toDouble()); |
|
85 ui->wkEdit->setValue(Utils::lintner_to_kolbach(query.value("diastatic_power").toDouble())); |
|
86 ui->diphEdit->setValue(query.value("di_ph").toDouble()); |
|
87 ui->acidphEdit->setValue(query.value("acid_to_ph_57").toDouble()); |
|
88 if (query.value("production_date").toString().length() == 10) { |
|
89 ui->prodEdit->setDate(query.value("production_date").toDate()); |
85 } else { |
90 } else { |
86 ui->prodEdit->clear(); |
91 ui->prodEdit->clear(); |
87 } |
92 } |
88 if (query.value(24).toString().length() == 10) { |
93 if (query.value("tht_date").toString().length() == 10) { |
89 ui->thtEdit->setDate(query.value(24).toDate()); |
94 ui->thtEdit->setDate(query.value("tht_date").toDate()); |
90 } else { |
95 } else { |
91 ui->thtEdit->clear(); |
96 ui->thtEdit->clear(); |
92 } |
97 } |
93 } else { |
98 } else { |
94 /* Set some defaults */ |
99 /* Set some defaults */ |
121 connect(ui->colorEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
126 connect(ui->colorEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
122 connect(ui->moistureEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
127 connect(ui->moistureEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
123 connect(ui->coarseEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
128 connect(ui->coarseEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
124 connect(ui->proteinEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
129 connect(ui->proteinEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
125 connect(ui->dissolvedEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
130 connect(ui->dissolvedEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
126 connect(ui->diastaticEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
131 connect(ui->wkEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditFermentable::wk_changed); |
|
132 connect(ui->lintnerEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditFermentable::lintner_changed); |
127 connect(ui->diphEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
133 connect(ui->diphEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
128 connect(ui->acidphEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
134 connect(ui->acidphEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed); |
129 connect(ui->prodEdit, &QDateEdit::dateChanged, this, &EditFermentable::is_changed); |
135 connect(ui->prodEdit, &QDateEdit::dateChanged, this, &EditFermentable::is_changed); |
130 connect(ui->thtEdit, &QDateEdit::dateChanged, this, &EditFermentable::is_changed); |
136 connect(ui->thtEdit, &QDateEdit::dateChanged, this, &EditFermentable::is_changed); |
131 |
137 |
204 query.bindValue(":origin", ui->originEdit->text()); |
210 query.bindValue(":origin", ui->originEdit->text()); |
205 query.bindValue(":supplier", ui->supplierEdit->text()); |
211 query.bindValue(":supplier", ui->supplierEdit->text()); |
206 query.bindValue(":notes", ui->notesEdit->toPlainText()); |
212 query.bindValue(":notes", ui->notesEdit->toPlainText()); |
207 query.bindValue(":coarse", QString("%1").arg(ui->coarseEdit->value(), 2, 'f', 1, '0')); |
213 query.bindValue(":coarse", QString("%1").arg(ui->coarseEdit->value(), 2, 'f', 1, '0')); |
208 query.bindValue(":moisture", QString("%1").arg(ui->moistureEdit->value(), 2, 'f', 1, '0')); |
214 query.bindValue(":moisture", QString("%1").arg(ui->moistureEdit->value(), 2, 'f', 1, '0')); |
209 query.bindValue(":diastatic", Utils::kolbach_to_lintner(ui->diastaticEdit->value())); |
215 query.bindValue(":diastatic", Utils::kolbach_to_lintner(ui->wkEdit->value())); |
210 query.bindValue(":protein", QString("%1").arg(ui->proteinEdit->value(), 2, 'f', 1, '0')); |
216 query.bindValue(":protein", QString("%1").arg(ui->proteinEdit->value(), 2, 'f', 1, '0')); |
211 query.bindValue(":dissolved", QString("%1").arg(ui->dissolvedEdit->value(), 2, 'f', 1, '0')); |
217 query.bindValue(":dissolved", QString("%1").arg(ui->dissolvedEdit->value(), 2, 'f', 1, '0')); |
212 query.bindValue(":maxinbatch", QString("%1").arg(ui->maxinbatchEdit->value(), 2, 'f', 1, '0')); |
218 query.bindValue(":maxinbatch", QString("%1").arg(ui->maxinbatchEdit->value(), 2, 'f', 1, '0')); |
213 query.bindValue(":mash", ui->mashEdit->isChecked() ? 1:0); |
219 query.bindValue(":mash", ui->mashEdit->isChecked() ? 1:0); |
214 query.bindValue(":added", ui->addedEdit->currentIndex()); |
220 query.bindValue(":added", ui->addedEdit->currentIndex()); |
276 this->textIsChanged = true; |
282 this->textIsChanged = true; |
277 WindowTitle(); |
283 WindowTitle(); |
278 } |
284 } |
279 |
285 |
280 |
286 |
|
287 void EditFermentable::wk_changed(double val) |
|
288 { |
|
289 const QSignalBlocker blocker1(ui->lintnerEdit); |
|
290 if (val == 0) |
|
291 ui->lintnerEdit->setValue(0); |
|
292 else |
|
293 ui->lintnerEdit->setValue(Utils::kolbach_to_lintner(val)); |
|
294 is_changed(); |
|
295 } |
|
296 |
|
297 |
|
298 void EditFermentable::lintner_changed(double val) |
|
299 { |
|
300 const QSignalBlocker blocker1(ui->wkEdit); |
|
301 ui->wkEdit->setValue(Utils::lintner_to_kolbach(val)); |
|
302 is_changed(); |
|
303 } |
|
304 |
|
305 |
281 void EditFermentable::on_quitButton_clicked() |
306 void EditFermentable::on_quitButton_clicked() |
282 { |
307 { |
283 if (this->textIsChanged) { |
308 if (this->textIsChanged) { |
284 int rc = QMessageBox::warning(this, tr("Fermentable changed"), tr("This fermentable has been modified. Save changes?"), |
309 int rc = QMessageBox::warning(this, tr("Fermentable changed"), tr("This fermentable has been modified. Save changes?"), |
285 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); |
310 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); |