diff -r 27e179759bf2 -r a3653722b0d6 src/EditRecipeTab5.cpp --- a/src/EditRecipeTab5.cpp Wed Jan 25 16:17:07 2023 +0100 +++ b/src/EditRecipeTab5.cpp Sat Jan 28 10:36:59 2023 +0100 @@ -38,21 +38,22 @@ std::sort(recipe->yeasts.begin(), recipe->yeasts.end(), yeast_sort_test); const QStringList labels({tr("Yeast"), tr("Laboratory"), tr("Code"), tr("Type"), tr("Use for"), tr("Min. °C"), tr("Max. °C"), - tr("Tol. %"), tr("Attn. %"), tr("Amount"), tr("Delete"), tr("Edit") }); + tr("Tol. %"), tr("Attn. %"), tr("STA"), tr("Amount"), tr("Delete"), tr("Edit") }); - ui->yeastsTable->setColumnCount(12); + ui->yeastsTable->setColumnCount(13); ui->yeastsTable->setColumnWidth(0, 200); /* Yeast */ ui->yeastsTable->setColumnWidth(1, 125); /* Laboratory */ ui->yeastsTable->setColumnWidth(2, 80); /* Code */ ui->yeastsTable->setColumnWidth(3, 80); /* Type */ ui->yeastsTable->setColumnWidth(4, 100); /* Usage */ - ui->yeastsTable->setColumnWidth(5, 60); /* Min. */ - ui->yeastsTable->setColumnWidth(6, 60); /* Max. */ - ui->yeastsTable->setColumnWidth(7, 60); /* Tolerance */ - ui->yeastsTable->setColumnWidth(8, 60); /* Attenuation */ - ui->yeastsTable->setColumnWidth(9, 90); /* Amount */ - ui->yeastsTable->setColumnWidth(10, 80); /* Delete */ - ui->yeastsTable->setColumnWidth(11, 80); /* Edit */ + ui->yeastsTable->setColumnWidth(5, 50); /* Min. */ + ui->yeastsTable->setColumnWidth(6, 50); /* Max. */ + ui->yeastsTable->setColumnWidth(7, 50); /* Tolerance */ + ui->yeastsTable->setColumnWidth(8, 50); /* Attenuation */ + ui->yeastsTable->setColumnWidth(9, 40); /* STA1 gen */ + ui->yeastsTable->setColumnWidth(10, 90); /* Amount */ + ui->yeastsTable->setColumnWidth(11, 80); /* Delete */ + ui->yeastsTable->setColumnWidth(12, 80); /* Edit */ ui->yeastsTable->setHorizontalHeaderLabels(labels); ui->yeastsTable->verticalHeader()->hide(); ui->yeastsTable->setRowCount(recipe->yeasts.size()); @@ -87,14 +88,28 @@ item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->yeastsTable->setItem(i, 8, item); - if (recipe->yeasts.at(i).form == 0) + if (recipe->yeasts.at(i).use != YEAST_USE_BOTTLE && recipe->yeasts.at(i).sta1) { + QWidget *pWidget = new QWidget(); + QLabel *label = new QLabel; + label->setPixmap(QPixmap(":icons/silk/tick.png")); + QHBoxLayout *pLayout = new QHBoxLayout(pWidget); + pLayout->addWidget(label); + pLayout->setAlignment(Qt::AlignCenter); + pLayout->setContentsMargins(0, 0, 0, 0); + pWidget->setLayout(pLayout); + ui->yeastsTable->setCellWidget(i, 9, pWidget); + } else { + ui->yeastsTable->removeCellWidget(i, 9); + } + + if (recipe->yeasts.at(i).form == YEAST_FORMS_LIQUID) item = new QTableWidgetItem(QString("%1 pack").arg(recipe->yeasts.at(i).amount, 1, 'f', 0, '0')); - else if (recipe->yeasts.at(i).form == 1) + else if (recipe->yeasts.at(i).form == YEAST_FORMS_DRY || recipe->yeasts.at(i).form == YEAST_FORMS_DRIED) item = new QTableWidgetItem(QString("%1 gr").arg(recipe->yeasts.at(i).amount * 1000.0, 3, 'f', 2, '0')); else item = new QTableWidgetItem(QString("%1 ml").arg(recipe->yeasts.at(i).amount * 1000.0, 3, 'f', 2, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); - ui->yeastsTable->setItem(i, 9, item); + ui->yeastsTable->setItem(i, 10, item); pWidget = new QWidget(); QPushButton* btn_dele = new QPushButton(); @@ -105,7 +120,7 @@ pLayout->addWidget(btn_dele); pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); - ui->yeastsTable->setCellWidget(i, 10, pWidget); + ui->yeastsTable->setCellWidget(i, 11, pWidget); pWidget = new QWidget(); QPushButton* btn_edit = new QPushButton(); @@ -116,7 +131,7 @@ pLayout->addWidget(btn_edit); pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); - ui->yeastsTable->setCellWidget(i, 11, pWidget); + ui->yeastsTable->setCellWidget(i, 12, pWidget); } } @@ -140,8 +155,8 @@ return; // No yeast in recipe. for (int i = 0; i < recipe->yeasts.size(); i++) { - if (recipe->yeasts.at(i).use == 0) { // Primary - if (recipe->yeasts.at(i).form == 1) { + if (recipe->yeasts.at(i).use == YEAST_USE_PRIMARY) { // Primary + if (recipe->yeasts.at(i).form == YEAST_FORMS_DRY) { /* * Dry yeast, build the formule with the yeast parameters. * Based on https://www.lallemandbrewing.com/en/canada/brewers-corner/brewing-tools/pitching-rate-calculator/ @@ -210,7 +225,9 @@ { Yeasts newy; +#ifdef DEBUG_YEAST qDebug() << "Add yeast row"; +#endif for (int i = 0; i < recipe->yeasts.size(); i++) { if (recipe->yeasts.at(i).amount == 0) @@ -221,8 +238,8 @@ newy.laboratory = ""; newy.product_id = ""; newy.amount = 0; - newy.type = 0; - newy.form = 0; + newy.type = YEAST_TYPES_ALE; + newy.form = YEAST_FORMS_LIQUID; newy.min_temperature = 0; newy.max_temperature = 0; newy.flocculation = 0; @@ -230,7 +247,7 @@ newy.cells = 0; newy.tolerance = 0; newy.inventory = 0; - newy.use = 0; + newy.use = YEAST_USE_PRIMARY; newy.sta1 = false; newy.bacteria = false; newy.harvest_top = false; @@ -256,7 +273,9 @@ QPushButton *pb = qobject_cast(QObject::sender()); int row = pb->objectName().toInt(); +#ifdef DEBUG_YEAST qDebug() << "Delete yeast row" << row << recipe->yeasts.size(); +#endif int rc = QMessageBox::warning(this, tr("Delete yeast"), tr("Delete %1").arg(recipe->yeasts.at(row).name), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); @@ -286,7 +305,7 @@ item = new QTableWidgetItem(QString("%1 ml").arg(val, 3, 'f', 2, '0')); } item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); - ui->yeastsTable->setItem(recipe->yeasts_row, 9, item); + ui->yeastsTable->setItem(recipe->yeasts_row, 10, item); calcYeast(); is_changed(); @@ -303,7 +322,9 @@ if (val < 1) return; +#ifdef DEBUG_YEAST qDebug() << "yeast_select_changed()" << recipe->yeasts_row << val << instock; +#endif /* * Search the yeast pointed by the index and instock flag. @@ -320,7 +341,9 @@ for (int i = 0; i < (val - 1); i++) { query.next(); } +#ifdef DEBUG_YEAST qDebug() << "found" << query.value(0).toString() << query.value(2).toString(); +#endif /* * Replace the yeast record contents @@ -393,7 +416,20 @@ item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->yeastsTable->setItem(recipe->yeasts_row, 8, item); - calcYeast(); + if (recipe->yeasts.at(product->yeasts_row).use != YEAST_USE_BOTTLE && recipe->yeasts.at(product->yeasts_row).sta1) { + QWidget *pWidget = new QWidget(); + QLabel *label = new QLabel; + label->setPixmap(QPixmap(":icons/silk/tick.png")); + QHBoxLayout *pLayout = new QHBoxLayout(pWidget); + pLayout->addWidget(label); + pLayout->setAlignment(Qt::AlignCenter); + pLayout->setContentsMargins(0, 0, 0, 0); + pWidget->setLayout(pLayout); + ui->yeastsTable->setCellWidget(product->yeasts_row, 9, pWidget); + } else { + ui->yeastsTable->removeCellWidget(product->yeasts_row, 9); + } + is_changed(); } @@ -402,7 +438,9 @@ { QSqlQuery query; +#ifdef DEBUG_YEAST qDebug() << "yeast_instock_changed()" << recipe->yeasts_row << val; +#endif this->yselectEdit->setCurrentIndex(-1); this->yselectEdit->clear(); @@ -424,14 +462,15 @@ void EditRecipe::yeast_useat_changed(int val) { +#ifdef DEBUG_YEAST qDebug() << "yeast_useat_changed()" << recipe->yeasts_row << val; +#endif recipe->yeasts[recipe->yeasts_row].use = val; QTableWidgetItem *item = new QTableWidgetItem(QCoreApplication::translate("YeastUse", g_yeast_use[val])); item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); ui->yeastsTable->setItem(recipe->yeasts_row, 5, item); is_changed(); - emit refreshAll(); } @@ -444,7 +483,9 @@ QPushButton *pb = qobject_cast(QObject::sender()); recipe->yeasts_row = pb->objectName().toInt(); +#ifdef DEBUG_YEAST qDebug() << "Edit yeast row" << recipe->yeasts_row; +#endif Yeasts backup = recipe->yeasts.at(recipe->yeasts_row); QDialog* dialog = new QDialog(this); @@ -560,7 +601,9 @@ dialog->setModal(true); dialog->exec(); if (dialog->result() == QDialog::Rejected) { +#ifdef DEBUG_YEAST qDebug() << "reject and rollback"; +#endif recipe->yeasts[recipe->yeasts_row] = backup; } else {