src/EditMisc.cpp

Sat, 11 Feb 2023 15:48:02 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 11 Feb 2023 15:48:02 +0100
changeset 493
520306773450
parent 385
09af9f46518f
permissions
-rw-r--r--

Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.

28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * EditMisc.cpp is part of bmsapp.
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "EditMisc.h"
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include "../ui/ui_EditMisc.h"
90
2396457a8167 Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
19 #include "MainWindow.h"
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 EditMisc::EditMisc(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditMisc)
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 QSqlQuery query;
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 qDebug() << "EditMisc record:" << id;
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 ui->setupUi(this);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 this->recno = id;
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 WindowTitle();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 ui->typeEdit->addItem(tr("Spice"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 ui->typeEdit->addItem(tr("Herb"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 ui->typeEdit->addItem(tr("Flavor"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 ui->typeEdit->addItem(tr("Fining"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 ui->typeEdit->addItem(tr("Water agent"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 ui->typeEdit->addItem(tr("Yeast nutrient"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 ui->typeEdit->addItem(tr("Other"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 ui->useEdit->addItem(tr("Starter"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 ui->useEdit->addItem(tr("Mash"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 ui->useEdit->addItem(tr("Boil"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 ui->useEdit->addItem(tr("Primary"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 ui->useEdit->addItem(tr("Secondary"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 ui->useEdit->addItem(tr("Bottling"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 if (id >= 0) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 query.prepare("SELECT * FROM inventory_miscs WHERE record = :recno");
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 query.bindValue(":recno", id);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 query.exec();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 query.next();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52
292
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
53 ui->nameEdit->setText(query.value("name").toString());
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
54 ui->typeEdit->setCurrentIndex(query.value("type").toInt());
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
55 ui->useEdit->setCurrentIndex(query.value("use_use").toInt());
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
56 ui->timeEdit->setValue(query.value("time").toInt());
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
57 ui->isweightEdit->setChecked(query.value("amount_is_weight").toInt() ? true:false);
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
58 ui->useforEdit->setPlainText(query.value("use_for").toString());
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
59 ui->notesEdit->setPlainText(query.value("notes").toString());
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
60 ui->alwaysEdit->setChecked(query.value("always_on_stock").toInt() ? true:false);
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
61 ui->inventoryEdit->setValue(query.value("inventory").toDouble() * 1000.0);
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
62 ui->costEdit->setValue(query.value("cost").toDouble());
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
63 ui->valueEdit->setValue(query.value("inventory").toDouble() * query.value("cost").toDouble());
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
64 if (query.value("production_date").toString().length() == 10) {
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
65 ui->prodEdit->setDate(query.value("production_date").toDate());
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 } else {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 ui->prodEdit->clear();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 }
292
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
69 if (query.value("tht_date").toString().length() == 10) {
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
70 ui->thtEdit->setDate(query.value("tht_date").toDate());
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 } else {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 ui->thtEdit->clear();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 } else {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 /* Set some defaults */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 ui->typeEdit->setCurrentIndex(0);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 ui->useEdit->setCurrentIndex(0);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 ui->timeEdit->setValue(0);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 ui->prodEdit->clear();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 ui->thtEdit->clear();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 }
292
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
82 UnitSet();
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 TimeSet();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditMisc::is_changed);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 connect(ui->typeEdit, &QComboBox::currentTextChanged, this, &EditMisc::is_changed);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 connect(ui->useEdit, &QComboBox::currentTextChanged, this, &EditMisc::is_changed);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 connect(ui->timeEdit, &QSpinBox::textChanged, this, &EditMisc::time_changed);
292
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
88 connect(ui->isweightEdit, &QCheckBox::stateChanged, this, &EditMisc::weight_changed);
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 connect(ui->useforEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 connect(ui->alwaysEdit, &QCheckBox::stateChanged, this, &EditMisc::is_changed);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 connect(ui->inventoryEdit, &QDoubleSpinBox::textChanged, this, &EditMisc::is_changed);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 connect(ui->costEdit, &QDoubleSpinBox::textChanged, this, &EditMisc::is_changed);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 connect(ui->prodEdit, &QDateEdit::dateChanged, this, &EditMisc::is_changed);
292
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
95 connect(ui->prodButton1, SIGNAL(clicked()), this, SLOT(prod_date_today()));
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
96 connect(ui->prodButton2, SIGNAL(clicked()), this, SLOT(prod_date_clear()));
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 connect(ui->thtEdit, &QDateEdit::dateChanged, this, &EditMisc::is_changed);
292
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
98 connect(ui->thtButton1, SIGNAL(clicked()), this, SLOT(tht_date_today()));
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
99 connect(ui->thtButton2, SIGNAL(clicked()), this, SLOT(tht_date_clear()));
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 ui->saveButton->setEnabled(false);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && id >= 0) ? true:false);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 EditMisc::~EditMisc()
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 delete ui;
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 emit entry_changed();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 /*
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 * Window header, mark any change with '**'
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 void EditMisc::WindowTitle()
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 QString txt;
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 if (this->recno < 0) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 txt = QString(tr("BMSapp - Add new misc ingredient"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 } else {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 txt = QString(tr("BMSapp - Edit misc ingredient %1").arg(this->recno));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 if (this->textIsChanged) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 txt.append((QString(" **")));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 setWindowTitle(txt);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 void EditMisc::on_saveButton_clicked()
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 QSqlQuery query;
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 /* If there are errors in the form, show a message and do "return;" */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 if (ui->nameEdit->text().length() < 2) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 QMessageBox::warning(this, tr("Edit Misc"), tr("Name empty or too short."));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 return;
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 if (this->textIsChanged) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 if (this->recno == -1) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 query.prepare("INSERT INTO inventory_miscs SET name=:name, type=:type, use_use=:use, "
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 "time=:time, amount_is_weight=:isweight, use_for=:usefor, notes=:notes, "
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 "always_on_stock=:always, inventory=:inventory, cost=:cost, production_date=:prod, "
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 "tht_date=:tht, uuid = :uuid");
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 } else {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 query.prepare("UPDATE inventory_miscs SET name=:name, type=:type, use_use=:use, "
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 "time=:time, amount_is_weight=:isweight, use_for=:usefor, notes=:notes, "
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 "always_on_stock=:always, inventory=:inventory, cost=:cost, production_date=:prod, "
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 "tht_date=:tht WHERE record = :recno");
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 query.bindValue(":name", ui->nameEdit->text());
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 query.bindValue(":type", ui->typeEdit->currentIndex());
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 query.bindValue(":use", ui->useEdit->currentIndex());
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 query.bindValue(":time", ui->timeEdit->value());
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 query.bindValue(":isweight", ui->isweightEdit->isChecked() ? 1:0);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 query.bindValue(":usefor", ui->useforEdit->toPlainText());
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 query.bindValue(":notes", ui->notesEdit->toPlainText());
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 query.bindValue(":always", ui->alwaysEdit->isChecked() ? 1:0);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 query.bindValue(":inventory", QString("%1").arg(ui->inventoryEdit->value() / 1000.0, 5, 'f', 4, '0'));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 query.bindValue(":cost", QString("%1").arg(ui->costEdit->value(), 3, 'f', 2, '0'));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 /* Uses https://www.qtcentre.org/threads/17295-How-to-put-empty-value-in-QDateEdit */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 query.bindValue(":prod", ui->prodEdit->nullDate());
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 query.bindValue(":tht", ui->thtEdit->nullDate());
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 if (this->recno == -1) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 } else {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 query.bindValue(":recno", this->recno);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 query.exec();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 if (query.lastError().isValid()) {
385
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
175 qWarning() << "EditMisc" << query.lastError();
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 QMessageBox::warning(this, tr("Database error"),
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 tr("MySQL error: %1\n%2\n%3")
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 .arg(query.lastError().nativeErrorCode())
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 .arg(query.lastError().driverText())
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 .arg(query.lastError().databaseText()));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 } else {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 qDebug() << "EditMisc Saved";
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 ui->saveButton->setEnabled(false);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 this->textIsChanged = false;
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 WindowTitle();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191
385
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
192 void EditMisc::on_cloneButton_clicked()
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
193 {
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
194 QSqlQuery query;
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
195
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
196 query.prepare("INSERT INTO inventory_miscs SET name=:name, type=:type, use_use=:use, "
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
197 "time=:time, amount_is_weight=:isweight, use_for=:usefor, notes=:notes, "
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
198 "always_on_stock=:always, inventory=:inventory, cost=:cost, production_date=:prod, "
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
199 "tht_date=:tht, uuid = :uuid");
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
200
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
201 query.bindValue(":name", ui->nameEdit->text() + " [copy]");
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
202 query.bindValue(":type", ui->typeEdit->currentIndex());
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
203 query.bindValue(":use", ui->useEdit->currentIndex());
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
204 query.bindValue(":time", ui->timeEdit->value());
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
205 query.bindValue(":isweight", ui->isweightEdit->isChecked() ? 1:0);
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
206 query.bindValue(":usefor", ui->useforEdit->toPlainText());
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
207 query.bindValue(":notes", ui->notesEdit->toPlainText());
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
208 query.bindValue(":always", ui->alwaysEdit->isChecked() ? 1:0);
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
209 query.bindValue(":inventory", QString("%1").arg(0, 5, 'f', 4, '0'));
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
210 query.bindValue(":cost", QString("%1").arg(ui->costEdit->value(), 3, 'f', 2, '0'));
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
211 query.bindValue(":prod", QDate());
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
212 query.bindValue(":tht", QDate());
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
213 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
214
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
215 query.exec();
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
216 if (query.lastError().isValid()) {
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
217 qWarning() << "EditMisc" << query.lastError();
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
218 QMessageBox::warning(this, tr("Database error"),
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
219 tr("MySQL error: %1\n%2\n%3")
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
220 .arg(query.lastError().nativeErrorCode())
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
221 .arg(query.lastError().driverText())
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
222 .arg(query.lastError().databaseText()));
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
223 } else {
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
224 qDebug() << "EditMisc Saved";
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
225 }
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
226 }
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
227
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
228
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 void EditMisc::on_deleteButton_clicked()
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 QSqlQuery query;
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232
385
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
233 int rc = QMessageBox::warning(this, tr("Delete misc"), tr("Delete %1").arg(ui->nameEdit->text()),
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
234 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
235 if (rc == QMessageBox::No)
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
236 return;
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
237
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 query.prepare("DELETE FROM inventory_miscs WHERE record = :recno");
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 query.bindValue(":recno", this->recno);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 query.exec();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 if (query.lastError().isValid()) {
385
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 292
diff changeset
242 qWarning() << "EditMisc" << query.lastError();
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 QMessageBox::warning(this, tr("Database error"),
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 tr("MySQL error: %1\n%2\n%3")
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245 .arg(query.lastError().nativeErrorCode())
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246 .arg(query.lastError().driverText())
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 .arg(query.lastError().databaseText()));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 } else {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249 qDebug() << "EditMisc Deleted" << this->recno;
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 this->close();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 this->setResult(1);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256
292
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
257 void EditMisc::UnitSet()
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
258 {
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
259 if (ui->isweightEdit->isChecked()) {
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
260 ui->inventoryEdit->setSuffix(tr(" gr"));
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
261 } else {
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
262 ui->inventoryEdit->setSuffix(tr(" ml"));
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
263 }
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
264 }
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
265
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
266
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267 void EditMisc::TimeSet()
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268 {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 int time = ui->timeEdit->value();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270 QString w = QString("");
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272 if (time == 0) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 ui->timeEdit->setSingleStep(1);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 } else if (time == 1) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 w = QString("1 minute");
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277 ui->timeEdit->setSingleStep(1);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279 } else if (time < 180) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
280 w = QString("%1 minutes").arg(time);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281 ui->timeEdit->setSingleStep(1);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 } else if (time == 180) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 w = QString("3 hours");
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285 if (lasttime == 240)
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286 ui->timeEdit->setSingleStep(1); /* Going down */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 else
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288 ui->timeEdit->setSingleStep(60);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290 } else if (time < 1440) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291 w = QString("%1 hours").arg(time / 60);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 ui->timeEdit->setSingleStep(60);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 } else if (time == 1440) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295 w = QString("1 day");
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296 if (lasttime == 2880)
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297 ui->timeEdit->setSingleStep(60); /* Going down */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 else
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299 ui->timeEdit->setSingleStep(1440);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
301 } else {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
302 w = QString("%1 days").arg(time / 1440);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
303 ui->timeEdit->setSingleStep(1440);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
304
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
305 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 ui->timeShow->setText(w);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307 lasttime = time;
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 void EditMisc::is_changed()
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312 {
292
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
313 ui->valueEdit->setValue((ui->inventoryEdit->value() / 1000.0) * ui->costEdit->value());
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314 ui->saveButton->setEnabled(true);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315 ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && this->recno >= 0) ? true:false);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
316 this->textIsChanged = true;
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 WindowTitle();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
319
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320
292
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
321 void EditMisc::weight_changed()
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
322 {
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
323 UnitSet();
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
324 is_changed();
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
325 }
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
326
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
327
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
328 void EditMisc::time_changed()
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
329 {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
330 TimeSet();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
331 is_changed();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
332 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
335 void EditMisc::on_quitButton_clicked()
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336 {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
337 if (this->textIsChanged) {
60
0d65238ebedc Updated translations and some messages.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
338 int rc = QMessageBox::warning(this, tr("Misc changed"), tr("The ingredient has been modified. Save changes?"),
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
339 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
340 switch (rc) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341 case QMessageBox::Save:
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342 on_saveButton_clicked();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
343 break; /* Saved and then Quit */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
344 case QMessageBox::Discard:
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345 break; /* Quit without Save */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346 case QMessageBox::Cancel:
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347 return; /* Return to the editor page */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
349 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
351 this->close();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
352 this->setResult(1);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353 }
292
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
354
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
355
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
356 void EditMisc::prod_date_clear()
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
357 {
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
358 ui->prodEdit->setDate(QDate());
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
359 is_changed();
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
360 }
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
361
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
362
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
363 void EditMisc::prod_date_today()
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
364 {
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
365 ui->prodEdit->setDate(QDate::currentDate());
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
366 is_changed();
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
367 }
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
368
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
369
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
370 void EditMisc::tht_date_clear()
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
371 {
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
372 ui->thtEdit->setDate(QDate());
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
373 is_changed();
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
374 }
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
375
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
376
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
377 void EditMisc::tht_date_today()
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
378 {
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
379 ui->thtEdit->setDate(QDate::currentDate());
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
380 is_changed();
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
381 }
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
382
b6ec2e275736 Fixed missing settings from the Miscs and Hops editors.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
383

mercurial