src/EditFermentable.cpp

Sat, 19 Mar 2022 19:22:58 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 19 Mar 2022 19:22:58 +0100
changeset 64
b0d30697af67
parent 60
0d65238ebedc
child 90
2396457a8167
permissions
-rw-r--r--

First step in loading the Inventory Suppliers database on the mainscreen. But, it is loaded at program start en not removed when done. Weird programming to get this working.

20
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * EditFermentable.cpp is part of bmsapp.
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "EditFermentable.h"
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include "../ui/ui_EditFermentable.h"
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 #include "bmsapp.h"
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 EditFermentable::EditFermentable(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditFermentable)
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 QSqlQuery query;
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 qDebug() << "EditFermentable record:" << id;
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 ui->setupUi(this);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 this->recno = id;
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 WindowTitle();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 ui->typeEdit->addItem(tr("Grain"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 ui->typeEdit->addItem(tr("Sugar"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 ui->typeEdit->addItem(tr("Extract"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 ui->typeEdit->addItem(tr("Dry extract"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 ui->typeEdit->addItem(tr("Adjunct"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 ui->graintypeEdit->addItem(tr("Base"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 ui->graintypeEdit->addItem(tr("Roast"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 ui->graintypeEdit->addItem(tr("Crystal"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 ui->graintypeEdit->addItem(tr("Kilned"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 ui->graintypeEdit->addItem(tr("Sour Malt"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 ui->graintypeEdit->addItem(tr("Special"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 ui->graintypeEdit->addItem(tr("No malt"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 ui->addedEdit->addItem(tr("Mash"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 ui->addedEdit->addItem(tr("Boil"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 ui->addedEdit->addItem(tr("Fermentation"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 ui->addedEdit->addItem(tr("Lagering"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 ui->addedEdit->addItem(tr("Bottle"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 ui->addedEdit->addItem(tr("Kegs"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 if (id >= 0) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 query.prepare("SELECT * FROM inventory_fermentables WHERE record = :recno");
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 query.bindValue(":recno", id);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 query.exec();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 query.next();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 ui->nameEdit->setText(query.value(1).toString());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 ui->notesEdit->setPlainText(query.value(8).toString());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 ui->originEdit->setText(query.value(6).toString());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 ui->supplierEdit->setText(query.value(7).toString());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 ui->typeEdit->setCurrentIndex(query.value(2).toInt());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 ui->graintypeEdit->setCurrentIndex(query.value(20).toInt());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 ui->maxinbatchEdit->setValue(query.value(14).toDouble());
42
88e827ea7172 Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
66 ui->mashEdit->setChecked(query.value(15).toInt() ? true:false);
20
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 ui->addafterEdit->setChecked(query.value(5).toInt() ? true:false);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 ui->addedEdit->setCurrentIndex(query.value(17).toInt());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 ui->alwaysEdit->setChecked(query.value(5).toInt() ? true:false);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 ui->inventoryEdit->setValue(query.value(21).toDouble());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 ui->costEdit->setValue(query.value(22).toDouble());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 ui->valueEdit->setValue(query.value(21).toDouble() * query.value(22).toDouble());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 ui->yieldEdit->setValue(query.value(3).toDouble());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 ui->colorEdit->setValue(query.value(4).toDouble());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 ui->moistureEdit->setValue(query.value(10).toDouble());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 ui->coarseEdit->setValue(query.value(9).toDouble());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 ui->proteinEdit->setValue(query.value(12).toDouble());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 ui->dissolvedEdit->setValue(query.value(13).toDouble());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 ui->diastaticEdit->setValue(Utils::lintner_to_kolbach(query.value(11).toDouble()));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 ui->diphEdit->setValue(query.value(18).toDouble());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 ui->acidphEdit->setValue(query.value(19).toDouble());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 if (query.value(23).toString().length() == 10) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 ui->prodEdit->setDate(query.value(23).toDate());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 } else {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 ui->prodEdit->clear();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 if (query.value(24).toString().length() == 10) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 ui->thtEdit->setDate(query.value(24).toDate());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 } else {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 ui->thtEdit->clear();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 } else {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 /* Set some defaults */
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 ui->typeEdit->setCurrentIndex(0);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 ui->graintypeEdit->setCurrentIndex(0);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 ui->maxinbatchEdit->setValue(100);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 ui->mashEdit->setChecked(true);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 ui->addedEdit->setCurrentIndex(0);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 ui->yieldEdit->setValue(80);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 ui->colorEdit->setValue(3);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 ui->coarseEdit->setValue(3);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 ui->moistureEdit->setValue(4);
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
103 ui->prodEdit->clear();
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
104 ui->thtEdit->clear();
20
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 connect(ui->originEdit, &QLineEdit::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 connect(ui->supplierEdit, &QLineEdit::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 connect(ui->typeEdit, &QComboBox::currentTextChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 connect(ui->graintypeEdit, &QComboBox::currentTextChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 connect(ui->maxinbatchEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 connect(ui->mashEdit, &QCheckBox::stateChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 connect(ui->addafterEdit, &QCheckBox::stateChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 connect(ui->addedEdit, &QComboBox::currentTextChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 connect(ui->alwaysEdit, &QCheckBox::stateChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 connect(ui->inventoryEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 connect(ui->costEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 connect(ui->yieldEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 connect(ui->colorEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 connect(ui->moistureEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 connect(ui->coarseEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 connect(ui->proteinEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 connect(ui->dissolvedEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 connect(ui->diastaticEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 connect(ui->diphEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 connect(ui->acidphEdit, &QDoubleSpinBox::textChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 connect(ui->prodEdit, &QDateEdit::dateChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 connect(ui->thtEdit, &QDateEdit::dateChanged, this, &EditFermentable::is_changed);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 ui->saveButton->setEnabled(false);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && id >= 0) ? true:false);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 EditFermentable::~EditFermentable()
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 qDebug() << "EditFermentable done";
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 delete ui;
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 emit entry_changed();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 /*
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 * Window header, mark any change with '**'
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 */
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 void EditFermentable::WindowTitle()
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 QString txt;
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 if (this->recno < 0) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 txt = QString(tr("BMSapp - Add new fermentable"));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 } else {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 txt = QString(tr("BMSapp - Edit fermentable %1").arg(this->recno));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 if (this->textIsChanged) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 txt.append((QString(" **")));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 setWindowTitle(txt);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 void EditFermentable::on_saveButton_clicked()
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 QSqlQuery query;
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 /* If there are errors in the form, show a message and do "return;" */
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 if (ui->nameEdit->text().length() < 2) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 QMessageBox::warning(this, tr("Edit Fermentable"), tr("Name empty or too short."));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 return;
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 if (ui->originEdit->text().length() < 2) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 QMessageBox::warning(this, tr("Edit Fermentable"), tr("Origin empty or too short."));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 return;
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 if (ui->supplierEdit->text().length() < 2) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 QMessageBox::warning(this, tr("Edit Fermentable"), tr("Supplier empty or too short."));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 return;
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 if (this->textIsChanged) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 if (this->recno == -1) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 query.prepare("INSERT INTO inventory_fermentables SET name=:name, type=:type, yield=:yield, color=:color, "
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 "add_after_boil=:addafter, origin=:origin, supplier=:supplier, notes=:notes, coarse_fine_diff=:coarse, "
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 "moisture=:moisture, diastatic_power=:diastatic, protein=:protein, dissolved_protein=:dissolved, "
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 "max_in_batch=:maxinbatch, recommend_mash=:mash, added=:added, always_on_stock=:always, di_ph=:diph, "
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 "acid_to_ph_57=:acidph, graintype=:graintype, inventory=:inventory, cost=:cost, production_date=:prod, "
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 "tht_date=:tht, uuid = :uuid");
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 } else {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 query.prepare("UPDATE inventory_fermentables SET name=:name, type=:type, yield=:yield, color=:color, "
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 "add_after_boil=:addafter, origin=:origin, supplier=:supplier, notes=:notes, coarse_fine_diff=:coarse, "
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 "moisture=:moisture, diastatic_power=:diastatic, protein=:protein, dissolved_protein=:dissolved, "
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 "max_in_batch=:maxinbatch, recommend_mash=:mash, added=:added, always_on_stock=:always, di_ph=:diph, "
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 "acid_to_ph_57=:acidph, graintype=:graintype, inventory=:inventory, cost=:cost, production_date=:prod, "
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 "tht_date=:tht WHERE record = :recno");
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 query.bindValue(":name", ui->nameEdit->text());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 query.bindValue(":type", ui->typeEdit->currentIndex());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 query.bindValue(":yield", QString("%1").arg(ui->yieldEdit->value(), 2, 'f', 1, '0'));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 query.bindValue(":color", QString("%1").arg(ui->colorEdit->value(), 1, 'f', 0, '0'));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 query.bindValue(":addafter", ui->addafterEdit->isChecked() ? 1:0);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203 query.bindValue(":origin", ui->originEdit->text());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 query.bindValue(":supplier", ui->supplierEdit->text());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 query.bindValue(":notes", ui->notesEdit->toPlainText());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 query.bindValue(":coarse", QString("%1").arg(ui->coarseEdit->value(), 2, 'f', 1, '0'));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207 query.bindValue(":moisture", QString("%1").arg(ui->moistureEdit->value(), 2, 'f', 1, '0'));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208 query.bindValue(":diastatic", Utils::kolbach_to_lintner(ui->diastaticEdit->value()));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209 query.bindValue(":protein", QString("%1").arg(ui->proteinEdit->value(), 2, 'f', 1, '0'));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210 query.bindValue(":dissolved", QString("%1").arg(ui->dissolvedEdit->value(), 2, 'f', 1, '0'));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 query.bindValue(":maxinbatch", QString("%1").arg(ui->maxinbatchEdit->value(), 2, 'f', 1, '0'));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 query.bindValue(":mash", ui->mashEdit->isChecked() ? 1:0);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 query.bindValue(":added", ui->addedEdit->currentIndex());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 query.bindValue(":always", ui->alwaysEdit->isChecked() ? 1:0);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 query.bindValue(":diph", QString("%1").arg(ui->diphEdit->value(), 3, 'f', 2, '0'));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 query.bindValue(":acidph", QString("%1").arg(ui->acidphEdit->value(), 6, 'f', 5, '0'));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217 query.bindValue(":graintype", ui->graintypeEdit->currentIndex());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218 query.bindValue(":inventory", QString("%1").arg(ui->inventoryEdit->value(), 4, 'f', 3, '0'));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 query.bindValue(":cost", QString("%1").arg(ui->costEdit->value(), 3, 'f', 2, '0'));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 /* Uses https://www.qtcentre.org/threads/17295-How-to-put-empty-value-in-QDateEdit */
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221 query.bindValue(":prod", ui->prodEdit->nullDate());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 query.bindValue(":tht", ui->thtEdit->nullDate());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 if (this->recno == -1) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 } else {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 query.bindValue(":recno", this->recno);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 query.exec();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 if (query.lastError().isValid()) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 qDebug() << "EditFermentable" << query.lastError();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 QMessageBox::warning(this, tr("Database error"),
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 tr("MySQL error: %1\n%2\n%3")
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 .arg(query.lastError().nativeErrorCode())
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 .arg(query.lastError().driverText())
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 .arg(query.lastError().databaseText()));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 } else {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 qDebug() << "EditFermentable Saved";
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 ui->saveButton->setEnabled(false);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 this->textIsChanged = false;
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 WindowTitle();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 void EditFermentable::on_deleteButton_clicked()
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249 QSqlQuery query;
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251 query.prepare("DELETE FROM inventory_fermentables WHERE record = :recno");
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 query.bindValue(":recno", this->recno);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 query.exec();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 if (query.lastError().isValid()) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 qDebug() << "EditFermentable" << query.lastError();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 QMessageBox::warning(this, tr("Database error"),
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257 tr("MySQL error: %1\n%2\n%3")
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258 .arg(query.lastError().nativeErrorCode())
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259 .arg(query.lastError().driverText())
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 .arg(query.lastError().databaseText()));
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 } else {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
262 qDebug() << "EditFermentable Deleted" << this->recno;
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
264
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 this->close();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 this->setResult(1);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270 void EditFermentable::is_changed()
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271 {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272 ui->valueEdit->setValue(ui->inventoryEdit->value() * ui->costEdit->value());
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 ui->saveButton->setEnabled(true);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274 ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && this->recno >= 0) ? true:false);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 this->textIsChanged = true;
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 WindowTitle();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
280 void EditFermentable::on_quitButton_clicked()
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281 {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282 if (this->textIsChanged) {
60
0d65238ebedc Updated translations and some messages.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
283 int rc = QMessageBox::warning(this, tr("Fermentable changed"), tr("This fermentable has been modified. Save changes?"),
20
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285 switch (rc) {
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286 case QMessageBox::Save:
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 on_saveButton_clicked();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288 break; /* Saved and then Quit */
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 case QMessageBox::Discard:
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290 break; /* Quit without Save */
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291 case QMessageBox::Cancel:
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 return; /* Return to the editor page */
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 }
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296 this->close();
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297 this->setResult(1);
fcbbddcc22c1 Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 }

mercurial