# HG changeset patch # User Michiel Broek # Date 1650272133 -7200 # Node ID eea8a9e7e1f6809c57663021f825e62408c06bc6 # Parent 6638609328c2c01ee1f29b2897e0da439c8cf119 Upgrade yeasts fields if needed during recipe startup. Added yeast table. diff -r 6638609328c2 -r eea8a9e7e1f6 src/EditRecipe.cpp --- a/src/EditRecipe.cpp Sun Apr 17 10:50:48 2022 +0200 +++ b/src/EditRecipe.cpp Mon Apr 18 10:55:33 2022 +0200 @@ -266,7 +266,7 @@ } else if (miscs.isArray()) { for (int i = 0; i < miscs.array().size(); i++) { QJsonObject obj = miscs.array().at(i).toObject(); - qDebug() << i << obj; + //qDebug() << i << obj; Miscs m; m.m_name = obj["m_name"].toString(); m.m_amount = obj["m_amount"].toDouble(); @@ -283,7 +283,6 @@ qDebug() << "empty miscs"; } -qDebug() << query.value(87).toString(); const auto& y_json = query.value(87).toString(); if (!y_json.trimmed().isEmpty()) { const auto& formattedJson = QString("%1").arg(y_json); @@ -330,9 +329,35 @@ y.y_sg_hi = obj["y_sg_hi"].toDouble(); y.y_cost = obj["y_cost"].toDouble(); - // Upgrade fields from current database: - // y_tolerance y_sta1 y_bacteria y_harvest_top y_harvest_time y_pitch_temperature - // y_pofpos y_zymocide y_gr_hl_lo y_sg_lo y_gr_hl_hi y_sg_hi + if (y.y_tolerance == 0) { // More and better tests? + /* + * Possible data upgrade needed. + */ + query.prepare("SELECT tolerance,cells,sta1,bacteria,harvest_top,harvest_time,pitch_temperature," + "pofpos,zymocide,gr_hl_lo,sg_lo,gr_hl_hi,sg_hi " + "FROM inventory_yeasts WHERE name=:name AND laboratory=:laboratory AND product_id=:product_id"); + query.bindValue(":name", y.y_name); + query.bindValue(":laboratory", y.y_laboratory); + query.bindValue(":product_id", y.y_product_id); + query.exec(); + if (query.first()) { + y.y_tolerance = query.value(0).toDouble(); + y.y_cells = query.value(1).toDouble(); + y.y_sta1 = query.value(2).toInt() ? true:false; + y.y_bacteria = query.value(3).toInt() ? true:false; + y.y_harvest_top = query.value(4).toInt() ? true:false; + y.y_harvest_time = query.value(5).toInt(); + y.y_pitch_temperature = query.value(6).toDouble(); + y.y_pofpos = query.value(7).toInt() ? true:false; + y.y_zymocide = query.value(8).toInt(); + y.y_gr_hl_lo = query.value(9).toInt(); + y.y_sg_lo = query.value(10).toDouble(); + y.y_gr_hl_hi = query.value(11).toInt(); + y.y_sg_hi = query.value(12).toDouble(); + } else { + qDebug() << y.y_name << y.y_product_id << "not found for upgrade"; + } + } recipe->yeasts.append(y); } qDebug() << "yeasts" << recipe->yeasts.size(); @@ -341,6 +366,7 @@ qDebug() << "empty yeasts"; } +qDebug() << query.value(88).toString(); const auto& ma_json = query.value(88).toString(); if (!ma_json.trimmed().isEmpty()) { const auto& formattedJson = QString("%1").arg(ma_json); @@ -643,6 +669,8 @@ connect(ui->addMisc, SIGNAL(clicked()), this, SLOT(addMiscRow_clicked())); // All signals from tab "Yeasts" + ui->yeastsTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + connect(ui->addYeast, SIGNAL(clicked()), this, SLOT(addYeastRow_clicked())); // All signals from tab "Mash" diff -r 6638609328c2 -r eea8a9e7e1f6 src/EditRecipe.h --- a/src/EditRecipe.h Sun Apr 17 10:50:48 2022 +0200 +++ b/src/EditRecipe.h Mon Apr 18 10:55:33 2022 +0200 @@ -294,6 +294,9 @@ void addMiscRow_clicked(); void deleteMiscRow_clicked(); void editMiscRow_clicked(); + void addYeastRow_clicked(); + void deleteYeastRow_clicked(); + void editYeastRow_clicked(); void w2_volume_changed(double val); void wb_cacl2_changed(double val); @@ -328,6 +331,8 @@ QStringList h_useat = { tr("Mash"), tr("First wort"), tr("Boil"), tr("Aroma"), tr("Whirlpool"), tr("Dry hop") }; QStringList m_types = { tr("Spice"), tr("Herb"), tr("Flavor"), tr("Fining"), tr("Water agent"), tr("Yeast nutrient"), tr("Other") }; QStringList m_uses = { tr("Starter"), tr("Mash"), tr("Boil"), tr("Primary"), tr("Secondary"), tr("Bottling") }; + QStringList y_types = { tr("Liquid"), tr("Dry"), tr("Slant"), tr("Culture"), tr("Frozen"), tr("Bottle"), tr("Dried") }; + QStringList y_use = { tr("Primary"), tr("Secondary"), tr("Tertiary"), tr("Bottle") }; QString bar_red = "QProgressBar::chunk {background: #FF0000;}"; QString bar_orange = "QProgressBar::chunk {background: #EB7331;}"; QString bar_green = "QProgressBar::chunk {background: #008C00;}"; @@ -354,6 +359,7 @@ static bool ferment_sort_test(const Fermentables &D1, const Fermentables &D2); static bool hop_sort_test(const Hops &D1, const Hops &D2); static bool misc_sort_test(const Miscs &D1, const Miscs &D2); + static bool yeast_sort_test(const Yeasts &D1, const Yeasts &D2); void WindowTitle(); void brewing_salt_sub(QString salt, double val); void set_brewing_salt(QString salt, double val); diff -r 6638609328c2 -r eea8a9e7e1f6 src/EditRecipeTab5.cpp --- a/src/EditRecipeTab5.cpp Sun Apr 17 10:50:48 2022 +0200 +++ b/src/EditRecipeTab5.cpp Mon Apr 18 10:55:33 2022 +0200 @@ -18,8 +18,174 @@ */ -void EditRecipe::refreshYeasts() +bool EditRecipe::yeast_sort_test(const Yeasts &D1, const Yeasts &D2) { + if (D1.y_use > D2.y_use) + return false; + if (D1.y_use < D2.y_use) + return true; + return (D1.y_amount > D2.y_amount); } +void EditRecipe::refreshYeasts() +{ + QString w; + QWidget* pWidget; + QHBoxLayout* pLayout; + QTableWidgetItem *item; + + qDebug() << "refreshYeasts" << recipe->yeasts.size(); + std::sort(recipe->yeasts.begin(), recipe->yeasts.end(), yeast_sort_test); + + /* + * During filling the table turn off the cellChanged signal because every cell that is filled + * triggers the cellChanged signal. The QTableWidget has no better signal to use. + */ + this->ignoreChanges = true; + + 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") }); + + ui->yeastsTable->setColumnCount(12); + 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->setHorizontalHeaderLabels(labels); + ui->yeastsTable->verticalHeader()->hide(); + ui->yeastsTable->setRowCount(recipe->yeasts.size()); + + for (int i = 0; i < recipe->yeasts.size(); i++) { + + ui->yeastsTable->setItem(i, 0, new QTableWidgetItem(recipe->yeasts.at(i).y_name)); + ui->yeastsTable->setItem(i, 1, new QTableWidgetItem(recipe->yeasts.at(i).y_laboratory)); + ui->yeastsTable->setItem(i, 2, new QTableWidgetItem(recipe->yeasts.at(i).y_product_id)); + + item = new QTableWidgetItem(y_types[recipe->yeasts.at(i).y_type]); + item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); + ui->yeastsTable->setItem(i, 3, item); + + item = new QTableWidgetItem(y_use[recipe->yeasts.at(i).y_use]); + item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); + ui->yeastsTable->setItem(i, 4, item); + + item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).y_min_temperature, 2, 'f', 1, '0')); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->yeastsTable->setItem(i, 5, item); + + item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).y_max_temperature, 2, 'f', 1, '0')); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->yeastsTable->setItem(i, 6, item); + + item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).y_tolerance, 2, 'f', 1, '0')); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->yeastsTable->setItem(i, 7, item); + + item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(i).y_attenuation, 2, 'f', 1, '0')); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->yeastsTable->setItem(i, 8, item); + + if (recipe->yeasts.at(i).y_type == 0) + item = new QTableWidgetItem(QString("%1 pack").arg(recipe->yeasts.at(i).y_amount * 1000.0, 3, 'f', 2, '0')); + else if (recipe->yeasts.at(i).y_type == 1) + item = new QTableWidgetItem(QString("%1 gr").arg(recipe->yeasts.at(i).y_amount * 1000.0, 3, 'f', 2, '0')); + else + item = new QTableWidgetItem(QString("%1 ml").arg(recipe->yeasts.at(i).y_amount * 1000.0, 3, 'f', 2, '0')); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->yeastsTable->setItem(i, 9, item); + + pWidget = new QWidget(); + QPushButton* btn_dele = new QPushButton(); + btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */ + btn_dele->setText(tr("Delete")); + connect(btn_dele, SIGNAL(clicked()), this, SLOT(deleteYeastRow_clicked())); + pLayout = new QHBoxLayout(pWidget); + pLayout->addWidget(btn_dele); + pLayout->setContentsMargins(5, 0, 5, 0); + pWidget->setLayout(pLayout); + ui->yeastsTable->setCellWidget(i, 10, pWidget); + + pWidget = new QWidget(); + QPushButton* btn_edit = new QPushButton(); + btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */ + btn_edit->setText(tr("Edit")); + connect(btn_edit, SIGNAL(clicked()), this, SLOT(editYeastRow_clicked())); + pLayout = new QHBoxLayout(pWidget); + pLayout->addWidget(btn_edit); + pLayout->setContentsMargins(5, 0, 5, 0); + pWidget->setLayout(pLayout); + ui->yeastsTable->setCellWidget(i, 11, pWidget); + } + + this->ignoreChanges = false; +} + + +void EditRecipe::addYeastRow_clicked() +{ + +} + + +void EditRecipe::deleteYeastRow_clicked() +{ + QPushButton *pb = qobject_cast(QObject::sender()); + int row = pb->objectName().toInt(); + qDebug() << "Delete yeast row" << row << recipe->yeasts.size(); + + if (recipe->yeasts.size() < 1) + return; + + int rc = QMessageBox::warning(this, tr("Delete yeast"), tr("Delete %1").arg(recipe->yeasts.at(row).y_name), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + if (rc == QMessageBox::No) + return; + + this->ignoreChanges = true; + recipe->yeasts.removeAt(row); + this->ignoreChanges = false; + is_changed(); + emit refreshAll(); +} + + +void EditRecipe::editYeastRow_clicked() +{ + QSqlQuery query; + + QPushButton *pb = qobject_cast(QObject::sender()); + recipe->yeasts_row = pb->objectName().toInt(); + qDebug() << "Edit yeast row" << recipe->yeasts_row; + Yeasts backup = recipe->yeasts.at(recipe->yeasts_row); + + QDialog* dialog = new QDialog(this); + dialog->resize(738, 230); + QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); + buttonBox->setObjectName(QString::fromUtf8("buttonBox")); + buttonBox->setGeometry(QRect(30, 180, 671, 32)); + buttonBox->setLayoutDirection(Qt::LeftToRight); + buttonBox->setOrientation(Qt::Horizontal); + buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + buttonBox->setCenterButtons(true); + + + + connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); + connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); + + + + disconnect(buttonBox, nullptr, nullptr, nullptr); + + emit refreshAll(); +} +