|
1 /** |
|
2 * EditProduct.cpp is part of bmsapp. |
|
3 * |
|
4 * tab 5, miscs. |
|
5 * |
|
6 * bmsapp is free software: you can redistribute it and/or modify |
|
7 * it under the terms of the GNU General Public License as published by |
|
8 * the Free Software Foundation, either version 3 of the License, or |
|
9 * (at your option) any later version. |
|
10 * |
|
11 * bmsapp is distributed in the hope that it will be useful, |
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 * GNU General Public License for more details. |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License |
|
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
18 */ |
|
19 |
|
20 |
|
21 bool EditProduct::misc_sort_test(const Miscs &D1, const Miscs &D2) |
|
22 { |
|
23 if (D1.m_use_use > D2.m_use_use) |
|
24 return false; |
|
25 if (D1.m_use_use < D2.m_use_use) |
|
26 return true; |
|
27 if (D1.m_type > D2.m_type) |
|
28 return false; |
|
29 if (D1.m_type < D2.m_type) |
|
30 return true; |
|
31 return (D1.m_amount > D2.m_amount); |
|
32 } |
|
33 |
|
34 |
|
35 void EditProduct::refreshMiscs() |
|
36 { |
|
37 QString w; |
|
38 QWidget* pWidget; |
|
39 QHBoxLayout* pLayout; |
|
40 QTableWidgetItem *item; |
|
41 |
|
42 qDebug() << "refreshMiscs" << product->miscs.size(); |
|
43 std::sort(product->miscs.begin(), product->miscs.end(), misc_sort_test); |
|
44 |
|
45 const QSignalBlocker blocker1(ui->bs_cacl2Edit); |
|
46 const QSignalBlocker blocker2(ui->bs_caso4Edit); |
|
47 const QSignalBlocker blocker3(ui->bs_mgso4Edit); |
|
48 const QSignalBlocker blocker4(ui->bs_naclEdit); |
|
49 const QSignalBlocker blocker5(ui->bs_mgcl2Edit); |
|
50 const QSignalBlocker blocker6(ui->bs_nahco3Edit); |
|
51 const QSignalBlocker blocker7(ui->bs_caco3Edit); |
|
52 const QSignalBlocker blocker8(ui->mw_acidPick); |
|
53 const QSignalBlocker blocker9(ui->mw_acidvolEdit); |
|
54 |
|
55 const QStringList labels({tr("Ingredient"), tr("Type"), tr("Use at"), tr("Time"), tr("Amount"), tr("Delete"), tr("Edit") }); |
|
56 |
|
57 ui->miscsTable->setColumnCount(7); |
|
58 ui->miscsTable->setColumnWidth(0, 300); /* Ingredient */ |
|
59 ui->miscsTable->setColumnWidth(1, 100); /* Type */ |
|
60 ui->miscsTable->setColumnWidth(2, 100); /* Added */ |
|
61 ui->miscsTable->setColumnWidth(3, 75); /* Time */ |
|
62 ui->miscsTable->setColumnWidth(4, 90); /* Amount */ |
|
63 ui->miscsTable->setColumnWidth(5, 80); /* Delete */ |
|
64 ui->miscsTable->setColumnWidth(6, 80); /* Edit */ |
|
65 ui->miscsTable->setHorizontalHeaderLabels(labels); |
|
66 ui->miscsTable->verticalHeader()->hide(); |
|
67 ui->miscsTable->setRowCount(product->miscs.size()); |
|
68 |
|
69 for (int i = 0; i < product->miscs.size(); i++) { |
|
70 |
|
71 ui->miscsTable->setItem(i, 0, new QTableWidgetItem(product->miscs.at(i).m_name)); |
|
72 |
|
73 item = new QTableWidgetItem(misc_types[product->miscs.at(i).m_type]); |
|
74 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
|
75 ui->miscsTable->setItem(i, 1, item); |
|
76 |
|
77 item = new QTableWidgetItem(misc_uses[product->miscs.at(i).m_use_use]); |
|
78 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
|
79 ui->miscsTable->setItem(i, 2, item); |
|
80 |
|
81 if (product->miscs.at(i).m_use_use == 2) { // Boil |
|
82 item = new QTableWidgetItem(QString("%1 min.").arg(product->miscs.at(i).m_time, 1, 'f', 0, '0')); |
|
83 } else if (product->miscs.at(i).m_use_use == 3 || product->miscs.at(i).m_use_use == 4) { // Primary or secondary |
|
84 item = new QTableWidgetItem(QString("%1 days.").arg(product->miscs.at(i).m_time / 1440, 1, 'f', 0, '0')); |
|
85 } else { |
|
86 item = new QTableWidgetItem(QString("")); |
|
87 } |
|
88 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
89 ui->miscsTable->setItem(i, 3, item); |
|
90 |
|
91 if (product->miscs.at(i).m_amount_is_weight) |
|
92 item = new QTableWidgetItem(QString("%1 gr").arg(product->miscs.at(i).m_amount * 1000.0, 3, 'f', 2, '0')); |
|
93 else |
|
94 item = new QTableWidgetItem(QString("%1 ml").arg(product->miscs.at(i).m_amount * 1000.0, 3, 'f', 2, '0')); |
|
95 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
96 ui->miscsTable->setItem(i, 4, item); |
|
97 |
|
98 /* |
|
99 * Add the Delete and Edit row buttons. |
|
100 * Not for water agents, these are set on the water tab. |
|
101 */ |
|
102 if (product->miscs.at(i).m_type == 4) { |
|
103 ui->miscsTable->removeCellWidget(i, 5); |
|
104 ui->miscsTable->removeCellWidget(i, 6); |
|
105 } else { |
|
106 pWidget = new QWidget(); |
|
107 QPushButton* btn_dele = new QPushButton(); |
|
108 btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */ |
|
109 btn_dele->setText(tr("Delete")); |
|
110 connect(btn_dele, SIGNAL(clicked()), this, SLOT(deleteMiscRow_clicked())); |
|
111 pLayout = new QHBoxLayout(pWidget); |
|
112 pLayout->addWidget(btn_dele); |
|
113 pLayout->setContentsMargins(5, 0, 5, 0); |
|
114 pWidget->setLayout(pLayout); |
|
115 ui->miscsTable->setCellWidget(i, 5, pWidget); |
|
116 |
|
117 pWidget = new QWidget(); |
|
118 QPushButton* btn_edit = new QPushButton(); |
|
119 btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */ |
|
120 btn_edit->setText(tr("Edit")); |
|
121 connect(btn_edit, SIGNAL(clicked()), this, SLOT(editMiscRow_clicked())); |
|
122 pLayout = new QHBoxLayout(pWidget); |
|
123 pLayout->addWidget(btn_edit); |
|
124 pLayout->setContentsMargins(5, 0, 5, 0); |
|
125 pWidget->setLayout(pLayout); |
|
126 ui->miscsTable->setCellWidget(i, 6, pWidget); |
|
127 } |
|
128 |
|
129 /* |
|
130 * Update the water agents. |
|
131 */ |
|
132 if (product->miscs.at(i).m_type == 4) { |
|
133 if (product->miscs.at(i).m_name == "CaCl2") { |
|
134 ui->bs_cacl2Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
135 } else if (product->miscs.at(i).m_name == "CaSO4") { |
|
136 ui->bs_caso4Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
137 } else if (product->miscs.at(i).m_name == "MgSO4") { |
|
138 ui->bs_mgso4Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
139 } else if (product->miscs.at(i).m_name == "NaCl") { |
|
140 ui->bs_naclEdit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
141 } else if (product->miscs.at(i).m_name == "MgCl2") { |
|
142 ui->bs_mgcl2Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
143 } else if (product->miscs.at(i).m_name == "NaHCO3") { |
|
144 ui->bs_nahco3Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
145 } else if (product->miscs.at(i).m_name == "CaCO3") { |
|
146 ui->bs_caco3Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
147 } else if (product->miscs.at(i).m_name == "Melkzuur" || product->miscs.at(i).m_name == "Lactic") { |
|
148 product->wa_acid_name = 0; |
|
149 product->wa_acid_perc = my_acids.at(0).AcidPrc; |
|
150 ui->mw_acidPick->setCurrentIndex(0); |
|
151 ui->mw_acidpercEdit->setValue(my_acids.at(0).AcidPrc); |
|
152 ui->mw_acidvolEdit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
153 } else if (product->miscs.at(i).m_name == "Zoutzuur" || product->miscs.at(i).m_name == "Hydrochloric") { |
|
154 product->wa_acid_name = 1; |
|
155 product->wa_acid_perc = my_acids.at(1).AcidPrc; |
|
156 ui->mw_acidPick->setCurrentIndex(1); |
|
157 ui->mw_acidpercEdit->setValue(my_acids.at(1).AcidPrc); |
|
158 ui->mw_acidvolEdit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
159 } else if (product->miscs.at(i).m_name == "Fosforzuur" || product->miscs.at(i).m_name == "Phosphoric") { |
|
160 product->wa_acid_name = 2; |
|
161 product->wa_acid_perc = my_acids.at(2).AcidPrc; |
|
162 ui->mw_acidPick->setCurrentIndex(2); |
|
163 ui->mw_acidpercEdit->setValue(my_acids.at(2).AcidPrc); |
|
164 ui->mw_acidvolEdit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
165 } else if (product->miscs.at(i).m_name == "Zwavelzuur" || product->miscs.at(i).m_name == "Sulfuric") { |
|
166 product->wa_acid_name = 3; |
|
167 product->wa_acid_perc = my_acids.at(3).AcidPrc; |
|
168 ui->mw_acidPick->setCurrentIndex(3); |
|
169 ui->mw_acidpercEdit->setValue(my_acids.at(3).AcidPrc); |
|
170 ui->mw_acidvolEdit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
171 } |
|
172 } |
|
173 } |
|
174 } |
|
175 |
|
176 |
|
177 /* |
|
178 * Manipulate the memory array and update the miscs table. |
|
179 */ |
|
180 void EditProduct::brewing_salt_sub(QString salt, double val) |
|
181 { |
|
182 QTableWidgetItem *item; |
|
183 |
|
184 val = round(val * 100.0) / 100.0; |
|
185 if (val == 0) { |
|
186 /* |
|
187 * Remove this salt if it is in the table. |
|
188 */ |
|
189 for (int i = 0; i < product->miscs.size(); i++) { |
|
190 if (salt.contains(product->miscs.at(i).m_name)) { |
|
191 qDebug() << " brewing_salt_sub delete" << salt; |
|
192 product->miscs.removeAt(i); |
|
193 refreshMiscs(); |
|
194 return; |
|
195 } |
|
196 } |
|
197 qDebug() << " brewing_salt_sub delete error"; |
|
198 return; |
|
199 } |
|
200 |
|
201 /* |
|
202 * First see if this salt is in the table. |
|
203 * If it is, update the amount. |
|
204 */ |
|
205 for (int i = 0; i < product->miscs.size(); i++) { |
|
206 if (salt.contains(product->miscs.at(i).m_name)) { |
|
207 product->miscs[i].m_amount = val / 1000.0; |
|
208 if (product->miscs.at(i).m_amount_is_weight) |
|
209 item = new QTableWidgetItem(QString("%1 gr").arg(val, 3, 'f', 2, '0')); |
|
210 else |
|
211 item = new QTableWidgetItem(QString("%1 ml").arg(val, 3, 'f', 2, '0')); |
|
212 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
213 ui->miscsTable->setItem(i, 4, item); |
|
214 return; |
|
215 } |
|
216 } |
|
217 |
|
218 /* |
|
219 * We need a new entry. Search in the database is tricky because |
|
220 * we are here with possible more names for the same salt. The |
|
221 * name can be like 'Lactic Melkzuur'. So we select only the |
|
222 * brewing salts and manually check their names. |
|
223 */ |
|
224 QSqlQuery query("SELECT * FROM inventory_miscs WHERE type = 4"); |
|
225 while (query.next()) { |
|
226 if (salt.contains(query.value(1).toString())) { |
|
227 qDebug() << " found it, append"; |
|
228 Miscs m; |
|
229 m.m_name = query.value(1).toString(); |
|
230 m.m_amount = val / 1000.0; |
|
231 m.m_type = query.value(2).toInt(); |
|
232 m.m_use_use = query.value(3).toInt(); |
|
233 m.m_time = query.value(4).toDouble(); |
|
234 m.m_amount_is_weight = query.value(5).toInt() ? true:false; |
|
235 m.m_cost = query.value(10).toDouble(); |
|
236 product->miscs.append(m); |
|
237 refreshMiscs(); |
|
238 return; |
|
239 } |
|
240 } |
|
241 |
|
242 qDebug() << "brewing_salt_sub, nothing done." << salt << val; |
|
243 } |
|
244 |
|
245 |
|
246 /* |
|
247 * Edit brewing salt and recalculate. |
|
248 */ |
|
249 void EditProduct::set_brewing_salt(QString salt, double val) |
|
250 { |
|
251 val = round(val * 100.0) / 100.0; |
|
252 qDebug() << "set_brewing_salt" << salt << val; |
|
253 brewing_salt_sub(salt, val); |
|
254 calcWater(); |
|
255 is_changed(); |
|
256 } |
|
257 |
|
258 |
|
259 void EditProduct::addMiscRow_clicked() |
|
260 { |
|
261 Miscs newm; |
|
262 |
|
263 for (int i = 0; i < product->miscs.size(); i++) { |
|
264 if (product->miscs.at(i).m_amount == 0) |
|
265 return; // Add only one at a time. |
|
266 } |
|
267 |
|
268 newm.m_name = "Select one"; |
|
269 newm.m_amount = 0; |
|
270 newm.m_type = 0; |
|
271 newm.m_use_use = 0; |
|
272 newm.m_time = 0; |
|
273 newm.m_amount_is_weight = true; |
|
274 newm.m_cost = 0; |
|
275 product->miscs.append(newm); |
|
276 is_changed(); |
|
277 emit refreshAll(); |
|
278 } |
|
279 |
|
280 |
|
281 void EditProduct::deleteMiscRow_clicked() |
|
282 { |
|
283 if (product->locked || product->miscs.size() < 1) |
|
284 return; |
|
285 |
|
286 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
|
287 int row = pb->objectName().toInt(); |
|
288 qDebug() << "Delete misc row" << row << product->miscs.size(); |
|
289 |
|
290 int rc = QMessageBox::warning(this, tr("Delete misc"), tr("Delete %1").arg(product->miscs.at(row).m_name), |
|
291 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
|
292 if (rc == QMessageBox::No) |
|
293 return; |
|
294 |
|
295 product->miscs.removeAt(row); |
|
296 is_changed(); |
|
297 emit refreshAll(); |
|
298 } |
|
299 |
|
300 |
|
301 void EditProduct::misc_amount_changed(double val) |
|
302 { |
|
303 QTableWidgetItem *item; |
|
304 |
|
305 qDebug() << "misc_amount_changed()" << product->miscs_row << val; |
|
306 |
|
307 product->miscs[product->miscs_row].m_amount = val / 1000.0; |
|
308 if (product->miscs.at(product->miscs_row).m_amount_is_weight) { |
|
309 item = new QTableWidgetItem(QString("%1 gr").arg(product->miscs.at(product->miscs_row).m_amount * 1000.0, 3, 'f', 2, '0')); |
|
310 } else { |
|
311 item = new QTableWidgetItem(QString("%1 ml").arg(product->miscs.at(product->miscs_row).m_amount * 1000.0, 3, 'f', 2, '0')); |
|
312 } |
|
313 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
314 ui->miscsTable->setItem(product->miscs_row, 4, item); |
|
315 |
|
316 is_changed(); |
|
317 } |
|
318 |
|
319 |
|
320 void EditProduct::misc_time_changed(int val) |
|
321 { |
|
322 QTableWidgetItem *item; |
|
323 |
|
324 qDebug() << "misc_time_changed()" << product->miscs_row << val; |
|
325 |
|
326 if (product->miscs.at(product->miscs_row).m_use_use == 2) { // Boil |
|
327 product->miscs[product->miscs_row].m_time = val; |
|
328 item = new QTableWidgetItem(QString("%1 min.").arg(val, 1, 'f', 0, '0')); |
|
329 } else if (product->miscs.at(product->miscs_row).m_use_use == 3 || product->miscs.at(product->miscs_row).m_use_use == 4) { // Primary or secondary |
|
330 product->miscs[product->miscs_row].m_time = val * 1440; |
|
331 item = new QTableWidgetItem(QString("%1 days.").arg(val, 1, 'f', 0, '0')); |
|
332 } else { |
|
333 item = new QTableWidgetItem(QString("")); |
|
334 } |
|
335 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
336 ui->miscsTable->setItem(product->miscs_row, 3, item); |
|
337 |
|
338 is_changed(); |
|
339 } |
|
340 |
|
341 |
|
342 void EditProduct::misc_select_changed(int val) |
|
343 { |
|
344 QSqlQuery query; |
|
345 bool instock = minstockEdit->isChecked(); |
|
346 QString w; |
|
347 QTableWidgetItem *item; |
|
348 |
|
349 if (val < 1) |
|
350 return; |
|
351 |
|
352 qDebug() << "misc_select_changed()" << product->miscs_row << val << instock; |
|
353 |
|
354 /* |
|
355 * Search the misc ingredient pointed by the index and instock flag. |
|
356 */ |
|
357 QString sql = "SELECT name,type,use_use,time,amount_is_weight,cost FROM inventory_miscs WHERE "; |
|
358 if (instock) |
|
359 sql.append("inventory > 0 AND "); |
|
360 sql.append("type != 4 ORDER BY name"); |
|
361 qDebug() << sql; |
|
362 query.prepare(sql); |
|
363 query.exec(); |
|
364 query.first(); |
|
365 for (int i = 0; i < (val - 1); i++) { |
|
366 query.next(); |
|
367 } |
|
368 qDebug() << "found" << query.value(0).toString(); |
|
369 |
|
370 /* |
|
371 * Replace the misc record contents |
|
372 */ |
|
373 product->miscs[product->miscs_row].m_name = query.value(0).toString(); |
|
374 product->miscs[product->miscs_row].m_type = query.value(1).toInt(); |
|
375 product->miscs[product->miscs_row].m_use_use = query.value(2).toInt(); |
|
376 product->miscs[product->miscs_row].m_time = query.value(3).toDouble(); |
|
377 product->miscs[product->miscs_row].m_amount_is_weight = query.value(4).toInt() ? true:false; |
|
378 product->miscs[product->miscs_row].m_cost = query.value(5).toDouble(); |
|
379 |
|
380 /* |
|
381 * Update the visible fields |
|
382 */ |
|
383 mnameEdit->setText(product->miscs.at(product->miscs_row).m_name); |
|
384 ui->miscsTable->setItem(product->miscs_row, 0, new QTableWidgetItem(product->miscs.at(product->miscs_row).m_name)); |
|
385 |
|
386 item = new QTableWidgetItem(misc_types[product->miscs.at(product->miscs_row).m_type]); |
|
387 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
|
388 ui->miscsTable->setItem(product->miscs_row, 1, item); |
|
389 |
|
390 item = new QTableWidgetItem(misc_uses[product->miscs.at(product->miscs_row).m_use_use]); |
|
391 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
|
392 ui->miscsTable->setItem(product->miscs_row, 2, item); |
|
393 useatEdit->setCurrentIndex(product->miscs.at(product->miscs_row).m_use_use); |
|
394 |
|
395 if (product->miscs.at(product->miscs_row).m_use_use == 3 || product->miscs.at(product->miscs_row).m_use_use == 4) { // Fermentation stages |
|
396 mtimeEdit->setValue(product->miscs.at(product->miscs_row).m_time / 1440); |
|
397 mtimeEdit->setReadOnly(false); |
|
398 mtimeLabel->setText(tr("Time in days:")); |
|
399 item = new QTableWidgetItem(QString("%1 days.").arg(product->miscs.at(product->miscs_row).m_time / 1440, 1, 'f', 0, '0')); |
|
400 } else if (product->miscs.at(product->miscs_row).m_use_use == 2) { // Boil |
|
401 mtimeEdit->setValue(product->miscs.at(product->miscs_row).m_time); |
|
402 mtimeEdit->setReadOnly(false); |
|
403 mtimeLabel->setText(tr("Time in minutes:")); |
|
404 item = new QTableWidgetItem(QString("%1 min.").arg(product->miscs.at(product->miscs_row).m_time, 1, 'f', 0, '0')); |
|
405 } else { |
|
406 mtimeEdit->setReadOnly(true); |
|
407 mtimeLabel->setText(""); |
|
408 item = new QTableWidgetItem(QString("")); |
|
409 } |
|
410 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
411 ui->miscsTable->setItem(product->miscs_row, 3, item); |
|
412 |
|
413 if (product->miscs.at(product->miscs_row).m_amount_is_weight) { |
|
414 mamountLabel->setText(tr("Amount in gr:")); |
|
415 item = new QTableWidgetItem(QString("%1 gr").arg(product->miscs.at(product->miscs_row).m_amount * 1000.0, 3, 'f', 2, '0')); |
|
416 } else { |
|
417 mamountLabel->setText(tr("Amount in ml:")); |
|
418 item = new QTableWidgetItem(QString("%1 ml").arg(product->miscs.at(product->miscs_row).m_amount * 1000.0, 3, 'f', 2, '0')); |
|
419 } |
|
420 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
421 ui->miscsTable->setItem(product->miscs_row, 4, item); |
|
422 |
|
423 is_changed(); |
|
424 emit refreshAll(); |
|
425 } |
|
426 |
|
427 |
|
428 void EditProduct::misc_instock_changed(bool val) |
|
429 { |
|
430 QSqlQuery query; |
|
431 |
|
432 qDebug() << "misc_instock_changed()" << product->miscs_row << val; |
|
433 |
|
434 this->mselectEdit->setCurrentIndex(-1); |
|
435 this->mselectEdit->clear(); |
|
436 QString sql = "SELECT name,type,amount_is_weight,inventory FROM inventory_miscs WHERE "; |
|
437 if (val) |
|
438 sql.append("inventory > 0 AND "); |
|
439 sql.append("type != 4 ORDER BY name"); |
|
440 query.prepare(sql); |
|
441 query.exec(); |
|
442 query.first(); |
|
443 this->mselectEdit->addItem(""); // Start with empty value |
|
444 for (int i = 0; i < query.size(); i++) { |
|
445 this->mselectEdit->addItem(query.value(0).toString()+ " (" + misc_types[query.value(1).toInt()] + ") " + |
|
446 QString("%1 %2").arg(query.value(3).toDouble() * 1000.0, 3, 'f', 2, '0').arg(query.value(2).toInt()?"gr":"ml")); |
|
447 query.next(); |
|
448 } |
|
449 } |
|
450 |
|
451 |
|
452 void EditProduct::misc_useat_changed(int val) |
|
453 { |
|
454 QTableWidgetItem *item; |
|
455 |
|
456 qDebug() << "misc_useat_changed" << val; |
|
457 product->miscs[product->miscs_row].m_use_use = val; |
|
458 item = new QTableWidgetItem(misc_uses[val]); |
|
459 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
|
460 ui->miscsTable->setItem(product->miscs_row, 2, item); |
|
461 |
|
462 if (val == 3 || val == 4) { // Fermentation stages |
|
463 product->miscs[product->miscs_row].m_time = mtimeEdit->value() * 1440; |
|
464 mtimeEdit->setReadOnly(false); |
|
465 mtimeLabel->setText(tr("Time in days:")); |
|
466 item = new QTableWidgetItem(QString("%1 days.").arg(product->miscs.at(product->miscs_row).m_time / 1440, 1, 'f', 0, '0')); |
|
467 } else if (val == 2) { // Boil |
|
468 product->miscs[product->miscs_row].m_time = mtimeEdit->value(); |
|
469 mtimeEdit->setReadOnly(false); |
|
470 mtimeLabel->setText(tr("Time in minutes:")); |
|
471 item = new QTableWidgetItem(QString("%1 min.").arg(product->miscs.at(product->miscs_row).m_time, 1, 'f', 0, '0')); |
|
472 } else { |
|
473 product->miscs[product->miscs_row].m_time = 0; |
|
474 mtimeEdit->setValue(0); |
|
475 mtimeEdit->setReadOnly(true); |
|
476 mtimeLabel->setText(""); |
|
477 item = new QTableWidgetItem(QString("")); |
|
478 } |
|
479 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
480 ui->miscsTable->setItem(product->miscs_row, 3, item); |
|
481 |
|
482 is_changed(); |
|
483 } |
|
484 |
|
485 |
|
486 void EditProduct::editMiscRow_clicked() |
|
487 { |
|
488 QSqlQuery query; |
|
489 |
|
490 if (product->locked) |
|
491 return; |
|
492 |
|
493 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
|
494 product->miscs_row = pb->objectName().toInt(); |
|
495 qDebug() << "Edit misc row" << product->miscs_row; |
|
496 Miscs backup = product->miscs.at(product->miscs_row); |
|
497 |
|
498 QDialog* dialog = new QDialog(this); |
|
499 dialog->resize(738, 230); |
|
500 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); |
|
501 buttonBox->setObjectName(QString::fromUtf8("buttonBox")); |
|
502 buttonBox->setGeometry(QRect(30, 180, 671, 32)); |
|
503 buttonBox->setLayoutDirection(Qt::LeftToRight); |
|
504 buttonBox->setOrientation(Qt::Horizontal); |
|
505 buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); |
|
506 buttonBox->setCenterButtons(true); |
|
507 |
|
508 QLabel *nameLabel = new QLabel(dialog); |
|
509 nameLabel->setObjectName(QString::fromUtf8("nameLabel")); |
|
510 nameLabel->setText(tr("Current ingredient:")); |
|
511 nameLabel->setGeometry(QRect(10, 10, 141, 20)); |
|
512 nameLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
513 |
|
514 mamountLabel = new QLabel(dialog); |
|
515 mamountLabel->setObjectName(QString::fromUtf8("mamountLabel")); |
|
516 if (product->miscs.at(product->miscs_row).m_amount_is_weight) |
|
517 mamountLabel->setText(tr("Amount in gr:")); |
|
518 else |
|
519 mamountLabel->setText(tr("Amount in ml:")); |
|
520 mamountLabel->setGeometry(QRect(10, 70, 141, 20)); |
|
521 mamountLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
522 |
|
523 mtimeLabel = new QLabel(dialog); |
|
524 mtimeLabel->setObjectName(QString::fromUtf8("mtimeLabel")); |
|
525 if (product->miscs.at(product->miscs_row).m_use_use == 3 || product->miscs.at(product->miscs_row).m_use_use == 4) // Fermentation stages |
|
526 mtimeLabel->setText(tr("Time in days:")); |
|
527 else if (product->miscs.at(product->miscs_row).m_use_use == 2) // Boil |
|
528 mtimeLabel->setText(tr("Time in minutes:")); |
|
529 else |
|
530 mtimeLabel->setText(""); |
|
531 mtimeLabel->setGeometry(QRect(10, 100, 141, 20)); |
|
532 mtimeLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
533 |
|
534 QLabel *selectLabel = new QLabel(dialog); |
|
535 selectLabel->setObjectName(QString::fromUtf8("selectLabel")); |
|
536 selectLabel->setText(tr("Select ingredient:")); |
|
537 selectLabel->setGeometry(QRect(10, 40, 141, 20)); |
|
538 selectLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
539 QLabel *instockLabel = new QLabel(dialog); |
|
540 instockLabel->setObjectName(QString::fromUtf8("instockLabel")); |
|
541 instockLabel->setText(tr("In stock:")); |
|
542 instockLabel->setGeometry(QRect(525, 40, 121, 20)); |
|
543 instockLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
544 |
|
545 mselectEdit = new QComboBox(dialog); |
|
546 mselectEdit->setObjectName(QString::fromUtf8("selectEdit")); |
|
547 mselectEdit->setGeometry(QRect(160, 40, 371, 23)); |
|
548 |
|
549 mnameEdit = new QLineEdit(dialog); |
|
550 mnameEdit->setObjectName(QString::fromUtf8("mnameEdit")); |
|
551 mnameEdit->setText(product->miscs.at(product->miscs_row).m_name); |
|
552 mnameEdit->setGeometry(QRect(160, 10, 511, 23)); |
|
553 mnameEdit->setReadOnly(true); |
|
554 |
|
555 mamountEdit = new QDoubleSpinBox(dialog); |
|
556 mamountEdit->setObjectName(QString::fromUtf8("mamountEdit")); |
|
557 mamountEdit->setGeometry(QRect(160, 70, 121, 24)); |
|
558 mamountEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
559 mamountEdit->setAccelerated(true); |
|
560 mamountEdit->setDecimals(2); |
|
561 mamountEdit->setMaximum(1000000.0); |
|
562 mamountEdit->setSingleStep(0.1); |
|
563 mamountEdit->setValue(product->miscs.at(product->miscs_row).m_amount * 1000.0); |
|
564 |
|
565 mtimeEdit = new QSpinBox(dialog); |
|
566 mtimeEdit->setObjectName(QString::fromUtf8("mtimeEdit")); |
|
567 mtimeEdit->setGeometry(QRect(160, 100, 121, 24)); |
|
568 mtimeEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
569 mtimeEdit->setAccelerated(true); |
|
570 mtimeEdit->setMaximum(10000.0); |
|
571 if (product->miscs.at(product->miscs_row).m_use_use == 3 || product->miscs.at(product->miscs_row).m_use_use == 4) { // Fermentation stages |
|
572 mtimeEdit->setValue(product->miscs.at(product->miscs_row).m_time / 1440); |
|
573 mtimeEdit->setReadOnly(false); |
|
574 } else if (product->miscs.at(product->miscs_row).m_use_use == 2) { // Boil |
|
575 mtimeEdit->setValue(product->miscs.at(product->miscs_row).m_time); |
|
576 mtimeEdit->setReadOnly(false); |
|
577 } else { |
|
578 mtimeEdit->setReadOnly(true); |
|
579 } |
|
580 |
|
581 useatEdit = new QComboBox(dialog); |
|
582 useatEdit->setObjectName(QString::fromUtf8("useatEdit")); |
|
583 useatEdit->setGeometry(QRect(160, 130, 161, 23)); |
|
584 useatEdit->addItem(tr("Starter")); |
|
585 useatEdit->addItem(tr("Mash")); |
|
586 useatEdit->addItem(tr("Boil")); |
|
587 useatEdit->addItem(tr("Primary")); |
|
588 useatEdit->addItem(tr("Secondary")); |
|
589 useatEdit->addItem(tr("Bottling")); |
|
590 useatEdit->setCurrentIndex(product->miscs.at(product->miscs_row).m_use_use); |
|
591 |
|
592 minstockEdit = new QCheckBox(dialog); |
|
593 minstockEdit->setObjectName(QString::fromUtf8("minstockEdit")); |
|
594 minstockEdit->setGeometry(QRect(655, 40, 85, 21)); |
|
595 minstockEdit->setChecked(true); |
|
596 |
|
597 misc_instock_changed(true); |
|
598 |
|
599 connect(mselectEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditProduct::misc_select_changed); |
|
600 connect(mamountEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::misc_amount_changed); |
|
601 connect(mtimeEdit, QOverload<int>::of(&QSpinBox::valueChanged), this, &EditProduct::misc_time_changed); |
|
602 connect(useatEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditProduct::misc_useat_changed); |
|
603 connect(minstockEdit, &QCheckBox::stateChanged, this, &EditProduct::misc_instock_changed); |
|
604 connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); |
|
605 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); |
|
606 |
|
607 dialog->setModal(true); |
|
608 dialog->exec(); |
|
609 if (dialog->result() == QDialog::Rejected) { |
|
610 qDebug() << "reject and rollback"; |
|
611 product->miscs[product->miscs_row] = backup; |
|
612 } else { |
|
613 /* Clear time if misc is not used for boil or fermentation. */ |
|
614 if (! (product->miscs.at(product->miscs_row).m_use_use == 2 || |
|
615 product->miscs.at(product->miscs_row).m_use_use == 3 || |
|
616 product->miscs.at(product->miscs_row).m_use_use == 4)) { |
|
617 if (product->miscs.at(product->miscs_row).m_time) { |
|
618 product->miscs[product->miscs_row].m_time = 0; |
|
619 is_changed(); |
|
620 } |
|
621 } |
|
622 } |
|
623 |
|
624 disconnect(mselectEdit, nullptr, nullptr, nullptr); |
|
625 disconnect(mamountEdit, nullptr, nullptr, nullptr); |
|
626 disconnect(mtimeEdit, nullptr, nullptr, nullptr); |
|
627 disconnect(useatEdit, nullptr, nullptr, nullptr); |
|
628 disconnect(minstockEdit, nullptr, nullptr, nullptr); |
|
629 disconnect(buttonBox, nullptr, nullptr, nullptr); |
|
630 |
|
631 emit refreshAll(); |
|
632 } |
|
633 |
|
634 |
|
635 void EditProduct::adjustMiscs(double factor) |
|
636 { |
|
637 double amount; |
|
638 |
|
639 if (product->miscs.size() == 0) |
|
640 return; |
|
641 |
|
642 const QSignalBlocker blocker1(ui->bs_cacl2Edit); |
|
643 const QSignalBlocker blocker2(ui->bs_caso4Edit); |
|
644 const QSignalBlocker blocker3(ui->bs_mgso4Edit); |
|
645 const QSignalBlocker blocker4(ui->bs_naclEdit); |
|
646 const QSignalBlocker blocker5(ui->bs_mgcl2Edit); |
|
647 const QSignalBlocker blocker6(ui->bs_nahco3Edit); |
|
648 const QSignalBlocker blocker7(ui->bs_caco3Edit); |
|
649 const QSignalBlocker blocker9(ui->mw_acidvolEdit); |
|
650 |
|
651 for (int i = 0; i < product->miscs.size(); i++) { |
|
652 amount = product->miscs.at(i).m_amount * factor; |
|
653 product->miscs[i].m_amount = amount; |
|
654 |
|
655 /* |
|
656 * Update the water agents. |
|
657 */ |
|
658 if (product->miscs.at(i).m_type == 4) { |
|
659 if (product->miscs.at(i).m_name == "CaCl2") { |
|
660 ui->bs_cacl2Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
661 } else if (product->miscs.at(i).m_name == "CaSO4") { |
|
662 ui->bs_caso4Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
663 } else if (product->miscs.at(i).m_name == "MgSO4") { |
|
664 ui->bs_mgso4Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
665 } else if (product->miscs.at(i).m_name == "NaCl") { |
|
666 ui->bs_naclEdit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
667 } else if (product->miscs.at(i).m_name == "MgCl2") { |
|
668 ui->bs_mgcl2Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
669 } else if (product->miscs.at(i).m_name == "NaHCO3") { |
|
670 ui->bs_nahco3Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
671 } else if (product->miscs.at(i).m_name == "CaCO3") { |
|
672 ui->bs_caco3Edit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
673 } else if (product->miscs.at(i).m_name == "Melkzuur" || product->miscs.at(i).m_name == "Lactic") { |
|
674 ui->mw_acidvolEdit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
675 } else if (product->miscs.at(i).m_name == "Zoutzuur" || product->miscs.at(i).m_name == "Hydrochloric") { |
|
676 ui->mw_acidvolEdit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
677 } else if (product->miscs.at(i).m_name == "Fosforzuur" || product->miscs.at(i).m_name == "Phosphoric") { |
|
678 ui->mw_acidvolEdit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
679 } else if (product->miscs.at(i).m_name == "Zwavelzuur" || product->miscs.at(i).m_name == "Sulfuric") { |
|
680 ui->mw_acidvolEdit->setValue(product->miscs.at(i).m_amount * 1000.0); |
|
681 } |
|
682 } |
|
683 } |
|
684 } |
|
685 |
|
686 |