src/EditRecipeTab5.cpp

changeset 478
a3653722b0d6
parent 454
2dfead81c72f
child 496
9db6080a4783
equal deleted inserted replaced
477:27e179759bf2 478:a3653722b0d6
36 QTableWidgetItem *item; 36 QTableWidgetItem *item;
37 37
38 std::sort(recipe->yeasts.begin(), recipe->yeasts.end(), yeast_sort_test); 38 std::sort(recipe->yeasts.begin(), recipe->yeasts.end(), yeast_sort_test);
39 39
40 const QStringList labels({tr("Yeast"), tr("Laboratory"), tr("Code"), tr("Type"), tr("Use for"), tr("Min. °C"), tr("Max. °C"), 40 const QStringList labels({tr("Yeast"), tr("Laboratory"), tr("Code"), tr("Type"), tr("Use for"), tr("Min. °C"), tr("Max. °C"),
41 tr("Tol. %"), tr("Attn. %"), tr("Amount"), tr("Delete"), tr("Edit") }); 41 tr("Tol. %"), tr("Attn. %"), tr("STA"), tr("Amount"), tr("Delete"), tr("Edit") });
42 42
43 ui->yeastsTable->setColumnCount(12); 43 ui->yeastsTable->setColumnCount(13);
44 ui->yeastsTable->setColumnWidth(0, 200); /* Yeast */ 44 ui->yeastsTable->setColumnWidth(0, 200); /* Yeast */
45 ui->yeastsTable->setColumnWidth(1, 125); /* Laboratory */ 45 ui->yeastsTable->setColumnWidth(1, 125); /* Laboratory */
46 ui->yeastsTable->setColumnWidth(2, 80); /* Code */ 46 ui->yeastsTable->setColumnWidth(2, 80); /* Code */
47 ui->yeastsTable->setColumnWidth(3, 80); /* Type */ 47 ui->yeastsTable->setColumnWidth(3, 80); /* Type */
48 ui->yeastsTable->setColumnWidth(4, 100); /* Usage */ 48 ui->yeastsTable->setColumnWidth(4, 100); /* Usage */
49 ui->yeastsTable->setColumnWidth(5, 60); /* Min. */ 49 ui->yeastsTable->setColumnWidth(5, 50); /* Min. */
50 ui->yeastsTable->setColumnWidth(6, 60); /* Max. */ 50 ui->yeastsTable->setColumnWidth(6, 50); /* Max. */
51 ui->yeastsTable->setColumnWidth(7, 60); /* Tolerance */ 51 ui->yeastsTable->setColumnWidth(7, 50); /* Tolerance */
52 ui->yeastsTable->setColumnWidth(8, 60); /* Attenuation */ 52 ui->yeastsTable->setColumnWidth(8, 50); /* Attenuation */
53 ui->yeastsTable->setColumnWidth(9, 90); /* Amount */ 53 ui->yeastsTable->setColumnWidth(9, 40); /* STA1 gen */
54 ui->yeastsTable->setColumnWidth(10, 80); /* Delete */ 54 ui->yeastsTable->setColumnWidth(10, 90); /* Amount */
55 ui->yeastsTable->setColumnWidth(11, 80); /* Edit */ 55 ui->yeastsTable->setColumnWidth(11, 80); /* Delete */
56 ui->yeastsTable->setColumnWidth(12, 80); /* Edit */
56 ui->yeastsTable->setHorizontalHeaderLabels(labels); 57 ui->yeastsTable->setHorizontalHeaderLabels(labels);
57 ui->yeastsTable->verticalHeader()->hide(); 58 ui->yeastsTable->verticalHeader()->hide();
58 ui->yeastsTable->setRowCount(recipe->yeasts.size()); 59 ui->yeastsTable->setRowCount(recipe->yeasts.size());
59 60
60 for (int i = 0; i < recipe->yeasts.size(); i++) { 61 for (int i = 0; i < recipe->yeasts.size(); i++) {
85 86
86 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).attenuation, 2, 'f', 1, '0')); 87 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).attenuation, 2, 'f', 1, '0'));
87 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 88 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
88 ui->yeastsTable->setItem(i, 8, item); 89 ui->yeastsTable->setItem(i, 8, item);
89 90
90 if (recipe->yeasts.at(i).form == 0) 91 if (recipe->yeasts.at(i).use != YEAST_USE_BOTTLE && recipe->yeasts.at(i).sta1) {
92 QWidget *pWidget = new QWidget();
93 QLabel *label = new QLabel;
94 label->setPixmap(QPixmap(":icons/silk/tick.png"));
95 QHBoxLayout *pLayout = new QHBoxLayout(pWidget);
96 pLayout->addWidget(label);
97 pLayout->setAlignment(Qt::AlignCenter);
98 pLayout->setContentsMargins(0, 0, 0, 0);
99 pWidget->setLayout(pLayout);
100 ui->yeastsTable->setCellWidget(i, 9, pWidget);
101 } else {
102 ui->yeastsTable->removeCellWidget(i, 9);
103 }
104
105 if (recipe->yeasts.at(i).form == YEAST_FORMS_LIQUID)
91 item = new QTableWidgetItem(QString("%1 pack").arg(recipe->yeasts.at(i).amount, 1, 'f', 0, '0')); 106 item = new QTableWidgetItem(QString("%1 pack").arg(recipe->yeasts.at(i).amount, 1, 'f', 0, '0'));
92 else if (recipe->yeasts.at(i).form == 1) 107 else if (recipe->yeasts.at(i).form == YEAST_FORMS_DRY || recipe->yeasts.at(i).form == YEAST_FORMS_DRIED)
93 item = new QTableWidgetItem(QString("%1 gr").arg(recipe->yeasts.at(i).amount * 1000.0, 3, 'f', 2, '0')); 108 item = new QTableWidgetItem(QString("%1 gr").arg(recipe->yeasts.at(i).amount * 1000.0, 3, 'f', 2, '0'));
94 else 109 else
95 item = new QTableWidgetItem(QString("%1 ml").arg(recipe->yeasts.at(i).amount * 1000.0, 3, 'f', 2, '0')); 110 item = new QTableWidgetItem(QString("%1 ml").arg(recipe->yeasts.at(i).amount * 1000.0, 3, 'f', 2, '0'));
96 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 111 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
97 ui->yeastsTable->setItem(i, 9, item); 112 ui->yeastsTable->setItem(i, 10, item);
98 113
99 pWidget = new QWidget(); 114 pWidget = new QWidget();
100 QPushButton* btn_dele = new QPushButton(); 115 QPushButton* btn_dele = new QPushButton();
101 btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */ 116 btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */
102 btn_dele->setText(tr("Delete")); 117 btn_dele->setText(tr("Delete"));
103 connect(btn_dele, SIGNAL(clicked()), this, SLOT(deleteYeastRow_clicked())); 118 connect(btn_dele, SIGNAL(clicked()), this, SLOT(deleteYeastRow_clicked()));
104 pLayout = new QHBoxLayout(pWidget); 119 pLayout = new QHBoxLayout(pWidget);
105 pLayout->addWidget(btn_dele); 120 pLayout->addWidget(btn_dele);
106 pLayout->setContentsMargins(5, 0, 5, 0); 121 pLayout->setContentsMargins(5, 0, 5, 0);
107 pWidget->setLayout(pLayout); 122 pWidget->setLayout(pLayout);
108 ui->yeastsTable->setCellWidget(i, 10, pWidget); 123 ui->yeastsTable->setCellWidget(i, 11, pWidget);
109 124
110 pWidget = new QWidget(); 125 pWidget = new QWidget();
111 QPushButton* btn_edit = new QPushButton(); 126 QPushButton* btn_edit = new QPushButton();
112 btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */ 127 btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */
113 btn_edit->setText(tr("Edit")); 128 btn_edit->setText(tr("Edit"));
114 connect(btn_edit, SIGNAL(clicked()), this, SLOT(editYeastRow_clicked())); 129 connect(btn_edit, SIGNAL(clicked()), this, SLOT(editYeastRow_clicked()));
115 pLayout = new QHBoxLayout(pWidget); 130 pLayout = new QHBoxLayout(pWidget);
116 pLayout->addWidget(btn_edit); 131 pLayout->addWidget(btn_edit);
117 pLayout->setContentsMargins(5, 0, 5, 0); 132 pLayout->setContentsMargins(5, 0, 5, 0);
118 pWidget->setLayout(pLayout); 133 pWidget->setLayout(pLayout);
119 ui->yeastsTable->setCellWidget(i, 11, pWidget); 134 ui->yeastsTable->setCellWidget(i, 12, pWidget);
120 } 135 }
121 } 136 }
122 137
123 138
124 /* 139 /*
138 153
139 if (recipe->yeasts.size() == 0) 154 if (recipe->yeasts.size() == 0)
140 return; // No yeast in recipe. 155 return; // No yeast in recipe.
141 156
142 for (int i = 0; i < recipe->yeasts.size(); i++) { 157 for (int i = 0; i < recipe->yeasts.size(); i++) {
143 if (recipe->yeasts.at(i).use == 0) { // Primary 158 if (recipe->yeasts.at(i).use == YEAST_USE_PRIMARY) { // Primary
144 if (recipe->yeasts.at(i).form == 1) { 159 if (recipe->yeasts.at(i).form == YEAST_FORMS_DRY) {
145 /* 160 /*
146 * Dry yeast, build the formule with the yeast parameters. 161 * Dry yeast, build the formule with the yeast parameters.
147 * Based on https://www.lallemandbrewing.com/en/canada/brewers-corner/brewing-tools/pitching-rate-calculator/ 162 * Based on https://www.lallemandbrewing.com/en/canada/brewers-corner/brewing-tools/pitching-rate-calculator/
148 */ 163 */
149 ui->yeastProcedure->setCurrentIndex(2); 164 ui->yeastProcedure->setCurrentIndex(2);
208 223
209 void EditRecipe::addYeastRow_clicked() 224 void EditRecipe::addYeastRow_clicked()
210 { 225 {
211 Yeasts newy; 226 Yeasts newy;
212 227
228 #ifdef DEBUG_YEAST
213 qDebug() << "Add yeast row"; 229 qDebug() << "Add yeast row";
230 #endif
214 231
215 for (int i = 0; i < recipe->yeasts.size(); i++) { 232 for (int i = 0; i < recipe->yeasts.size(); i++) {
216 if (recipe->yeasts.at(i).amount == 0) 233 if (recipe->yeasts.at(i).amount == 0)
217 return; // Add only one at a time. 234 return; // Add only one at a time.
218 } 235 }
219 236
220 newy.name = "Select one"; 237 newy.name = "Select one";
221 newy.laboratory = ""; 238 newy.laboratory = "";
222 newy.product_id = ""; 239 newy.product_id = "";
223 newy.amount = 0; 240 newy.amount = 0;
224 newy.type = 0; 241 newy.type = YEAST_TYPES_ALE;
225 newy.form = 0; 242 newy.form = YEAST_FORMS_LIQUID;
226 newy.min_temperature = 0; 243 newy.min_temperature = 0;
227 newy.max_temperature = 0; 244 newy.max_temperature = 0;
228 newy.flocculation = 0; 245 newy.flocculation = 0;
229 newy.attenuation = 0; 246 newy.attenuation = 0;
230 newy.cells = 0; 247 newy.cells = 0;
231 newy.tolerance = 0; 248 newy.tolerance = 0;
232 newy.inventory = 0; 249 newy.inventory = 0;
233 newy.use = 0; 250 newy.use = YEAST_USE_PRIMARY;
234 newy.sta1 = false; 251 newy.sta1 = false;
235 newy.bacteria = false; 252 newy.bacteria = false;
236 newy.harvest_top = false; 253 newy.harvest_top = false;
237 newy.harvest_time = 0; 254 newy.harvest_time = 0;
238 newy.pitch_temperature = 0; 255 newy.pitch_temperature = 0;
254 if (recipe->locked || recipe->yeasts.size() < 1) 271 if (recipe->locked || recipe->yeasts.size() < 1)
255 return; 272 return;
256 273
257 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); 274 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
258 int row = pb->objectName().toInt(); 275 int row = pb->objectName().toInt();
276 #ifdef DEBUG_YEAST
259 qDebug() << "Delete yeast row" << row << recipe->yeasts.size(); 277 qDebug() << "Delete yeast row" << row << recipe->yeasts.size();
278 #endif
260 279
261 int rc = QMessageBox::warning(this, tr("Delete yeast"), tr("Delete %1").arg(recipe->yeasts.at(row).name), 280 int rc = QMessageBox::warning(this, tr("Delete yeast"), tr("Delete %1").arg(recipe->yeasts.at(row).name),
262 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); 281 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
263 if (rc == QMessageBox::No) 282 if (rc == QMessageBox::No)
264 return; 283 return;
284 } else { 303 } else {
285 recipe->yeasts[recipe->yeasts_row].amount = val / 1000.0; 304 recipe->yeasts[recipe->yeasts_row].amount = val / 1000.0;
286 item = new QTableWidgetItem(QString("%1 ml").arg(val, 3, 'f', 2, '0')); 305 item = new QTableWidgetItem(QString("%1 ml").arg(val, 3, 'f', 2, '0'));
287 } 306 }
288 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 307 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
289 ui->yeastsTable->setItem(recipe->yeasts_row, 9, item); 308 ui->yeastsTable->setItem(recipe->yeasts_row, 10, item);
290 309
291 calcYeast(); 310 calcYeast();
292 is_changed(); 311 is_changed();
293 } 312 }
294 313
301 QTableWidgetItem *item; 320 QTableWidgetItem *item;
302 321
303 if (val < 1) 322 if (val < 1)
304 return; 323 return;
305 324
325 #ifdef DEBUG_YEAST
306 qDebug() << "yeast_select_changed()" << recipe->yeasts_row << val << instock; 326 qDebug() << "yeast_select_changed()" << recipe->yeasts_row << val << instock;
327 #endif
307 328
308 /* 329 /*
309 * Search the yeast pointed by the index and instock flag. 330 * Search the yeast pointed by the index and instock flag.
310 */ 331 */
311 QString sql = "SELECT name,laboratory,product_id,type,form,min_temperature,max_temperature,flocculation,attenuation," 332 QString sql = "SELECT name,laboratory,product_id,type,form,min_temperature,max_temperature,flocculation,attenuation,"
318 query.exec(); 339 query.exec();
319 query.first(); 340 query.first();
320 for (int i = 0; i < (val - 1); i++) { 341 for (int i = 0; i < (val - 1); i++) {
321 query.next(); 342 query.next();
322 } 343 }
344 #ifdef DEBUG_YEAST
323 qDebug() << "found" << query.value(0).toString() << query.value(2).toString(); 345 qDebug() << "found" << query.value(0).toString() << query.value(2).toString();
346 #endif
324 347
325 /* 348 /*
326 * Replace the yeast record contents 349 * Replace the yeast record contents
327 */ 350 */
328 recipe->yeasts[recipe->yeasts_row].name = query.value(0).toString(); 351 recipe->yeasts[recipe->yeasts_row].name = query.value(0).toString();
391 414
392 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).attenuation, 2, 'f', 1, '0')); 415 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).attenuation, 2, 'f', 1, '0'));
393 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 416 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
394 ui->yeastsTable->setItem(recipe->yeasts_row, 8, item); 417 ui->yeastsTable->setItem(recipe->yeasts_row, 8, item);
395 418
396 calcYeast(); 419 if (recipe->yeasts.at(product->yeasts_row).use != YEAST_USE_BOTTLE && recipe->yeasts.at(product->yeasts_row).sta1) {
420 QWidget *pWidget = new QWidget();
421 QLabel *label = new QLabel;
422 label->setPixmap(QPixmap(":icons/silk/tick.png"));
423 QHBoxLayout *pLayout = new QHBoxLayout(pWidget);
424 pLayout->addWidget(label);
425 pLayout->setAlignment(Qt::AlignCenter);
426 pLayout->setContentsMargins(0, 0, 0, 0);
427 pWidget->setLayout(pLayout);
428 ui->yeastsTable->setCellWidget(product->yeasts_row, 9, pWidget);
429 } else {
430 ui->yeastsTable->removeCellWidget(product->yeasts_row, 9);
431 }
432
397 is_changed(); 433 is_changed();
398 } 434 }
399 435
400 436
401 void EditRecipe::yeast_instock_changed(bool val) 437 void EditRecipe::yeast_instock_changed(bool val)
402 { 438 {
403 QSqlQuery query; 439 QSqlQuery query;
404 440
441 #ifdef DEBUG_YEAST
405 qDebug() << "yeast_instock_changed()" << recipe->yeasts_row << val; 442 qDebug() << "yeast_instock_changed()" << recipe->yeasts_row << val;
443 #endif
406 444
407 this->yselectEdit->setCurrentIndex(-1); 445 this->yselectEdit->setCurrentIndex(-1);
408 this->yselectEdit->clear(); 446 this->yselectEdit->clear();
409 QString sql = "SELECT name,laboratory,product_id,inventory FROM inventory_yeasts "; 447 QString sql = "SELECT name,laboratory,product_id,inventory FROM inventory_yeasts ";
410 if (val) 448 if (val)
422 } 460 }
423 461
424 462
425 void EditRecipe::yeast_useat_changed(int val) 463 void EditRecipe::yeast_useat_changed(int val)
426 { 464 {
465 #ifdef DEBUG_YEAST
427 qDebug() << "yeast_useat_changed()" << recipe->yeasts_row << val; 466 qDebug() << "yeast_useat_changed()" << recipe->yeasts_row << val;
467 #endif
428 468
429 recipe->yeasts[recipe->yeasts_row].use = val; 469 recipe->yeasts[recipe->yeasts_row].use = val;
430 QTableWidgetItem *item = new QTableWidgetItem(QCoreApplication::translate("YeastUse", g_yeast_use[val])); 470 QTableWidgetItem *item = new QTableWidgetItem(QCoreApplication::translate("YeastUse", g_yeast_use[val]));
431 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); 471 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
432 ui->yeastsTable->setItem(recipe->yeasts_row, 5, item); 472 ui->yeastsTable->setItem(recipe->yeasts_row, 5, item);
433 is_changed(); 473 is_changed();
434 emit refreshAll();
435 } 474 }
436 475
437 476
438 void EditRecipe::editYeastRow_clicked() 477 void EditRecipe::editYeastRow_clicked()
439 { 478 {
442 if (recipe->locked) 481 if (recipe->locked)
443 return; 482 return;
444 483
445 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); 484 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
446 recipe->yeasts_row = pb->objectName().toInt(); 485 recipe->yeasts_row = pb->objectName().toInt();
486 #ifdef DEBUG_YEAST
447 qDebug() << "Edit yeast row" << recipe->yeasts_row; 487 qDebug() << "Edit yeast row" << recipe->yeasts_row;
488 #endif
448 Yeasts backup = recipe->yeasts.at(recipe->yeasts_row); 489 Yeasts backup = recipe->yeasts.at(recipe->yeasts_row);
449 490
450 QDialog* dialog = new QDialog(this); 491 QDialog* dialog = new QDialog(this);
451 dialog->resize(738, 260); 492 dialog->resize(738, 260);
452 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); 493 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
558 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); 599 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
559 600
560 dialog->setModal(true); 601 dialog->setModal(true);
561 dialog->exec(); 602 dialog->exec();
562 if (dialog->result() == QDialog::Rejected) { 603 if (dialog->result() == QDialog::Rejected) {
604 #ifdef DEBUG_YEAST
563 qDebug() << "reject and rollback"; 605 qDebug() << "reject and rollback";
606 #endif
564 recipe->yeasts[recipe->yeasts_row] = backup; 607 recipe->yeasts[recipe->yeasts_row] = backup;
565 } else { 608 } else {
566 609
567 } 610 }
568 611

mercurial