36 QTableWidgetItem *item; |
36 QTableWidgetItem *item; |
37 |
37 |
38 qDebug() << "refreshYeasts" << recipe->yeasts.size(); |
38 qDebug() << "refreshYeasts" << recipe->yeasts.size(); |
39 std::sort(recipe->yeasts.begin(), recipe->yeasts.end(), yeast_sort_test); |
39 std::sort(recipe->yeasts.begin(), recipe->yeasts.end(), yeast_sort_test); |
40 |
40 |
41 /* |
|
42 * During filling the table turn off the cellChanged signal because every cell that is filled |
|
43 * triggers the cellChanged signal. The QTableWidget has no better signal to use. |
|
44 */ |
|
45 this->ignoreChanges = true; |
|
46 |
|
47 const QStringList labels({tr("Yeast"), tr("Laboratory"), tr("Code"), tr("Type"), tr("Use for"), tr("Min. °C"), tr("Max. °C"), |
41 const QStringList labels({tr("Yeast"), tr("Laboratory"), tr("Code"), tr("Type"), tr("Use for"), tr("Min. °C"), tr("Max. °C"), |
48 tr("Tol. %"), tr("Attn. %"), tr("Amount"), tr("Delete"), tr("Edit") }); |
42 tr("Tol. %"), tr("Attn. %"), tr("Amount"), tr("Delete"), tr("Edit") }); |
49 |
43 |
50 ui->yeastsTable->setColumnCount(12); |
44 ui->yeastsTable->setColumnCount(12); |
51 ui->yeastsTable->setColumnWidth(0, 200); /* Yeast */ |
45 ui->yeastsTable->setColumnWidth(0, 200); /* Yeast */ |
123 pLayout->addWidget(btn_edit); |
117 pLayout->addWidget(btn_edit); |
124 pLayout->setContentsMargins(5, 0, 5, 0); |
118 pLayout->setContentsMargins(5, 0, 5, 0); |
125 pWidget->setLayout(pLayout); |
119 pWidget->setLayout(pLayout); |
126 ui->yeastsTable->setCellWidget(i, 11, pWidget); |
120 ui->yeastsTable->setCellWidget(i, 11, pWidget); |
127 } |
121 } |
128 |
|
129 this->ignoreChanges = false; |
|
130 } |
122 } |
131 |
123 |
132 |
124 |
133 /* |
125 /* |
134 * The results are not stored line in EditProduct. This is just a hint. |
126 * The results are not stored line in EditProduct. This is just a hint. |
269 int rc = QMessageBox::warning(this, tr("Delete yeast"), tr("Delete %1").arg(recipe->yeasts.at(row).y_name), |
261 int rc = QMessageBox::warning(this, tr("Delete yeast"), tr("Delete %1").arg(recipe->yeasts.at(row).y_name), |
270 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
262 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
271 if (rc == QMessageBox::No) |
263 if (rc == QMessageBox::No) |
272 return; |
264 return; |
273 |
265 |
274 this->ignoreChanges = true; |
|
275 recipe->yeasts.removeAt(row); |
266 recipe->yeasts.removeAt(row); |
276 this->ignoreChanges = false; |
|
277 is_changed(); |
267 is_changed(); |
278 emit refreshAll(); |
268 emit refreshAll(); |
279 } |
269 } |
280 |
270 |
281 |
271 |
282 void EditRecipe::yeast_amount_changed(double val) |
272 void EditRecipe::yeast_amount_changed(double val) |
283 { |
273 { |
284 QTableWidgetItem *item; |
274 QTableWidgetItem *item; |
285 |
275 |
286 qDebug() << "yeast_amount_changed()" << recipe->yeasts_row << val; |
276 qDebug() << "yeast_amount_changed()" << recipe->yeasts_row << val; |
287 this->ignoreChanges = true; |
277 |
288 |
278 if (recipe->yeasts.at(recipe->yeasts_row).y_form == 0) { |
289 recipe->yeasts[recipe->yeasts_row].y_amount = val / 1000.0; |
279 recipe->yeasts[recipe->yeasts_row].y_amount = val; |
290 item = new QTableWidgetItem(QString("%1 gr").arg(val, 2, 'f', 1, '0')); |
280 item = new QTableWidgetItem(QString("%1 pack").arg(val, 1, 'f', 0, '0')); |
|
281 } else if (recipe->yeasts.at(recipe->yeasts_row).y_form == 1) { |
|
282 recipe->yeasts[recipe->yeasts_row].y_amount = val / 1000.0; |
|
283 item = new QTableWidgetItem(QString("%1 gr").arg(val, 3, 'f', 2, '0')); |
|
284 } else { |
|
285 recipe->yeasts[recipe->yeasts_row].y_amount = val / 1000.0; |
|
286 item = new QTableWidgetItem(QString("%1 ml").arg(val, 3, 'f', 2, '0')); |
|
287 } |
291 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
288 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
292 ui->yeastsTable->setItem(recipe->yeasts_row, 8, item); |
289 ui->yeastsTable->setItem(recipe->yeasts_row, 9, item); |
293 |
290 |
294 this->ignoreChanges = false; |
|
295 calcYeast(); |
291 calcYeast(); |
296 is_changed(); |
292 is_changed(); |
297 } |
293 } |
298 |
294 |
299 |
295 |
327 qDebug() << "found" << query.value(0).toString() << query.value(2).toString(); |
323 qDebug() << "found" << query.value(0).toString() << query.value(2).toString(); |
328 |
324 |
329 /* |
325 /* |
330 * Replace the yeast record contents |
326 * Replace the yeast record contents |
331 */ |
327 */ |
332 this->ignoreChanges = true; |
|
333 recipe->yeasts[recipe->yeasts_row].y_name = query.value(0).toString(); |
328 recipe->yeasts[recipe->yeasts_row].y_name = query.value(0).toString(); |
334 recipe->yeasts[recipe->yeasts_row].y_laboratory = query.value(1).toString(); |
329 recipe->yeasts[recipe->yeasts_row].y_laboratory = query.value(1).toString(); |
335 recipe->yeasts[recipe->yeasts_row].y_product_id = query.value(2).toString(); |
330 recipe->yeasts[recipe->yeasts_row].y_product_id = query.value(2).toString(); |
336 recipe->yeasts[recipe->yeasts_row].y_type = query.value(3).toInt(); |
331 recipe->yeasts[recipe->yeasts_row].y_type = query.value(3).toInt(); |
337 recipe->yeasts[recipe->yeasts_row].y_form = query.value(4).toInt(); |
332 recipe->yeasts[recipe->yeasts_row].y_form = query.value(4).toInt(); |
358 * Update the visible fields |
353 * Update the visible fields |
359 */ |
354 */ |
360 ynameEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_name); |
355 ynameEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_name); |
361 ylaboratoryEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_laboratory); |
356 ylaboratoryEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_laboratory); |
362 yproduct_idEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_product_id); |
357 yproduct_idEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_product_id); |
|
358 if (recipe->yeasts.at(recipe->yeasts_row).y_form == 0) { |
|
359 yamountEdit->setDecimals(0); |
|
360 yamountEdit->setSingleStep(1.0); |
|
361 yamountLabel->setText(tr("Total packs:")); |
|
362 } else if (recipe->yeasts.at(recipe->yeasts_row).y_form == 1) { |
|
363 yamountEdit->setDecimals(1); |
|
364 yamountEdit->setSingleStep(0.5); |
|
365 yamountLabel->setText(tr("Amount in gr:")); |
|
366 } else { |
|
367 yamountEdit->setDecimals(1); |
|
368 yamountEdit->setSingleStep(0.5); |
|
369 yamountLabel->setText(tr("Amount in ml:")); |
|
370 } |
363 |
371 |
364 ui->yeastsTable->setItem(recipe->yeasts_row, 0, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).y_name)); |
372 ui->yeastsTable->setItem(recipe->yeasts_row, 0, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).y_name)); |
365 ui->yeastsTable->setItem(recipe->yeasts_row, 1, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).y_laboratory)); |
373 ui->yeastsTable->setItem(recipe->yeasts_row, 1, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).y_laboratory)); |
366 ui->yeastsTable->setItem(recipe->yeasts_row, 2, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).y_product_id)); |
374 ui->yeastsTable->setItem(recipe->yeasts_row, 2, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).y_product_id)); |
367 |
375 |
383 |
391 |
384 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).y_attenuation, 2, 'f', 1, '0')); |
392 item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).y_attenuation, 2, 'f', 1, '0')); |
385 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
393 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
386 ui->yeastsTable->setItem(recipe->yeasts_row, 8, item); |
394 ui->yeastsTable->setItem(recipe->yeasts_row, 8, item); |
387 |
395 |
388 this->ignoreChanges = false; |
|
389 calcYeast(); |
396 calcYeast(); |
390 is_changed(); |
397 is_changed(); |
391 } |
398 } |
392 |
399 |
393 |
400 |
417 |
424 |
418 void EditRecipe::yeast_useat_changed(int val) |
425 void EditRecipe::yeast_useat_changed(int val) |
419 { |
426 { |
420 qDebug() << "yeast_useat_changed()" << recipe->yeasts_row << val; |
427 qDebug() << "yeast_useat_changed()" << recipe->yeasts_row << val; |
421 |
428 |
422 this->ignoreChanges = true; |
|
423 recipe->yeasts[recipe->yeasts_row].y_use = val; |
429 recipe->yeasts[recipe->yeasts_row].y_use = val; |
424 QTableWidgetItem *item = new QTableWidgetItem(y_use[val]); |
430 QTableWidgetItem *item = new QTableWidgetItem(y_use[val]); |
425 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
431 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
426 ui->yeastsTable->setItem(recipe->yeasts_row, 5, item); |
432 ui->yeastsTable->setItem(recipe->yeasts_row, 5, item); |
427 this->ignoreChanges = false; |
|
428 is_changed(); |
433 is_changed(); |
429 emit refreshAll(); |
434 emit refreshAll(); |
430 } |
435 } |
431 |
436 |
432 |
437 |
472 QLabel *instockLabel = new QLabel(dialog); |
477 QLabel *instockLabel = new QLabel(dialog); |
473 instockLabel->setObjectName(QString::fromUtf8("instockLabel")); |
478 instockLabel->setObjectName(QString::fromUtf8("instockLabel")); |
474 instockLabel->setText(tr("In stock:")); |
479 instockLabel->setText(tr("In stock:")); |
475 instockLabel->setGeometry(QRect(525,100, 121, 20)); |
480 instockLabel->setGeometry(QRect(525,100, 121, 20)); |
476 instockLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
481 instockLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
477 QLabel *amountLabel = new QLabel(dialog); |
482 yamountLabel = new QLabel(dialog); |
478 amountLabel->setObjectName(QString::fromUtf8("amountLabel")); |
483 yamountLabel->setObjectName(QString::fromUtf8("amountLabel")); |
479 amountLabel->setText(tr("Amount in gr:")); |
484 if (recipe->yeasts.at(recipe->yeasts_row).y_form == 0) |
480 amountLabel->setGeometry(QRect(10, 130, 141, 20)); |
485 yamountLabel->setText(tr("Total packs:")); |
481 amountLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
486 else if (recipe->yeasts.at(recipe->yeasts_row).y_form == 1) |
|
487 yamountLabel->setText(tr("Amount in gr:")); |
|
488 else |
|
489 yamountLabel->setText(tr("Amount in ml:")); |
|
490 yamountLabel->setGeometry(QRect(10, 130, 141, 20)); |
|
491 yamountLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
482 QLabel *useatLabel = new QLabel(dialog); |
492 QLabel *useatLabel = new QLabel(dialog); |
483 useatLabel->setObjectName(QString::fromUtf8("useatLabel")); |
493 useatLabel->setObjectName(QString::fromUtf8("useatLabel")); |
484 useatLabel->setText(tr("Use at:")); |
494 useatLabel->setText(tr("Use at:")); |
485 useatLabel->setGeometry(QRect(10, 160, 141, 20)); |
495 useatLabel->setGeometry(QRect(10, 160, 141, 20)); |
486 useatLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
496 useatLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
510 yamountEdit = new QDoubleSpinBox(dialog); |
520 yamountEdit = new QDoubleSpinBox(dialog); |
511 yamountEdit->setObjectName(QString::fromUtf8("yamountEdit")); |
521 yamountEdit->setObjectName(QString::fromUtf8("yamountEdit")); |
512 yamountEdit->setGeometry(QRect(160, 130, 121, 24)); |
522 yamountEdit->setGeometry(QRect(160, 130, 121, 24)); |
513 yamountEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
523 yamountEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
514 yamountEdit->setAccelerated(true); |
524 yamountEdit->setAccelerated(true); |
515 yamountEdit->setDecimals(1); |
525 if (recipe->yeasts.at(recipe->yeasts_row).y_form == 0) { |
516 yamountEdit->setMaximum(1000000.0); |
526 yamountEdit->setDecimals(0); |
517 yamountEdit->setSingleStep(0.5); |
527 yamountEdit->setSingleStep(1.0); |
518 yamountEdit->setValue(recipe->yeasts.at(recipe->yeasts_row).y_amount * 1000.0); |
528 yamountEdit->setValue(recipe->yeasts.at(recipe->yeasts_row).y_amount); |
|
529 } else if (recipe->yeasts.at(recipe->yeasts_row).y_form == 1) { |
|
530 yamountEdit->setDecimals(1); |
|
531 yamountEdit->setSingleStep(0.5); |
|
532 yamountEdit->setValue(recipe->yeasts.at(recipe->yeasts_row).y_amount * 1000.0); |
|
533 } else { |
|
534 yamountEdit->setDecimals(1); |
|
535 yamountEdit->setSingleStep(0.5); |
|
536 yamountEdit->setValue(recipe->yeasts.at(recipe->yeasts_row).y_amount * 1000.0); |
|
537 } |
|
538 yamountEdit->setMaximum(1000000000.0); |
519 useatEdit = new QComboBox(dialog); |
539 useatEdit = new QComboBox(dialog); |
520 useatEdit->setObjectName(QString::fromUtf8("useatEdit")); |
540 useatEdit->setObjectName(QString::fromUtf8("useatEdit")); |
521 useatEdit->setGeometry(QRect(160, 160, 161, 23)); |
541 useatEdit->setGeometry(QRect(160, 160, 161, 23)); |
522 useatEdit->addItem(tr("Primary")); |
542 useatEdit->addItem(tr("Primary")); |
523 useatEdit->addItem(tr("Secondary")); |
543 useatEdit->addItem(tr("Secondary")); |