# HG changeset patch # User Michiel Broek # Date 1651664977 -7200 # Node ID ea8cce5e7eb93baef9119a8697e6d05ec72d035f # Parent f5a1973236efaa6868e586906888e02f56718362 Added calcMiscs(). In miscs check supplies. Update inventory check when setting a new brewing salt. Use enum constants to make code more readable. diff -r f5a1973236ef -r ea8cce5e7eb9 src/EditProduct.cpp --- a/src/EditProduct.cpp Wed May 04 09:14:00 2022 +0200 +++ b/src/EditProduct.cpp Wed May 04 13:49:37 2022 +0200 @@ -1100,8 +1100,8 @@ return; } - qDebug() << "calcSupplies() f:" << product->fermentables_ok << "h:" << product->hops_ok /*<< "m:" << product->miscs_ok << "y:" << product->yeasts_ok << "w:" << product->waters_ok*/; - if (product->fermentables_ok && product->hops_ok /*&& product->miscs_ok && product->yeasts_ok && product->waters_ok */) { + qDebug() << "calcSupplies() f:" << product->fermentables_ok << "h:" << product->hops_ok << "m:" << product->miscs_ok /*<< "y:" << product->yeasts_ok << "w:" << product->waters_ok*/; + if (product->fermentables_ok && product->hops_ok && product->miscs_ok /*&& product->yeasts_ok && product->waters_ok */) { ui->ok_pmptIcon->setPixmap(QPixmap(QString::fromUtf8(":/icons/silk/tick.png"))); } else { ui->ok_pmptIcon->setPixmap(QPixmap(QString::fromUtf8(":/icons/silk/cancel.png"))); @@ -1116,6 +1116,7 @@ refreshHops(); calcIBUs(); refreshMiscs(); + calcMiscs(); refreshYeasts(); calcYeast(); calcMash(); diff -r f5a1973236ef -r ea8cce5e7eb9 src/EditProduct.h --- a/src/EditProduct.h Wed May 04 09:14:00 2022 +0200 +++ b/src/EditProduct.h Wed May 04 13:49:37 2022 +0200 @@ -165,6 +165,7 @@ void setStage(); void brewing_salt_sub(QString salt, double val); void set_brewing_salt(QString salt, double val); + void calcMiscs(); void calcFermentables(); void calcFermentablesFromOG(double og); void calcIBUs(); diff -r f5a1973236ef -r ea8cce5e7eb9 src/EditProductTab5.cpp --- a/src/EditProductTab5.cpp Wed May 04 09:14:00 2022 +0200 +++ b/src/EditProductTab5.cpp Wed May 04 13:49:37 2022 +0200 @@ -79,9 +79,9 @@ item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); ui->miscsTable->setItem(i, 2, item); - if (product->miscs.at(i).m_use_use == 2) { // Boil + if (product->miscs.at(i).m_use_use == MISC_USES_BOIL) { item = new QTableWidgetItem(QString("%1 min.").arg(product->miscs.at(i).m_time, 1, 'f', 0, '0')); - } else if (product->miscs.at(i).m_use_use == 3 || product->miscs.at(i).m_use_use == 4) { // Primary or secondary + } else if (product->miscs.at(i).m_use_use == MISC_USES_PRIMARY || product->miscs.at(i).m_use_use == MISC_USES_SECONDARY) { item = new QTableWidgetItem(QString("%1 days.").arg(product->miscs.at(i).m_time / 1440, 1, 'f', 0, '0')); } else { item = new QTableWidgetItem(QString("")); @@ -101,13 +101,15 @@ else item = new QTableWidgetItem(QString("%1 ml").arg(product->miscs.at(i).m_inventory * 1000.0, 3, 'f', 2, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + if (product->miscs.at(i).m_inventory < product->miscs.at(i).m_amount) + item->setForeground(QBrush(QColor(Qt::red))); ui->miscsTable->setItem(i, 5, item); /* * Add the Delete and Edit row buttons. * Not for water agents, these are set on the water tab. */ - if (product->miscs.at(i).m_type == 4) { + if (product->miscs.at(i).m_type == MISC_TYPES_WATER_AGENT) { item = new QTableWidgetItem(""); item->setToolTip(tr("Edit this from the water tab")); ui->miscsTable->setItem(i, 6, item); @@ -141,7 +143,7 @@ /* * Update the water agents. */ - if (product->miscs.at(i).m_type == 4) { + if (product->miscs.at(i).m_type == MISC_TYPES_WATER_AGENT) { if (product->miscs.at(i).m_name == "CaCl2") { ui->bs_cacl2Edit->setValue(product->miscs.at(i).m_amount * 1000.0); } else if (product->miscs.at(i).m_name == "CaSO4") { @@ -186,6 +188,21 @@ } +void EditProduct::calcMiscs() +{ + product->miscs_ok = true; + for (int i = 0; i < product->miscs.size(); i++) { + if ((((product->inventory_reduced <= PROD_STAGE_BREW) && (product->miscs.at(i).m_use_use <= MISC_USES_BOIL)) || // Starter, Mash, Boil + ((product->inventory_reduced <= PROD_STAGE_PRIMARY) && (product->miscs.at(i).m_use_use == MISC_USES_PRIMARY)) || + ((product->inventory_reduced <= PROD_STAGE_TERTIARY) && (product->miscs.at(i).m_use_use == MISC_USES_SECONDARY)) || + ((product->inventory_reduced <= PROD_STAGE_PACKAGE) && (product->miscs.at(i).m_use_use == MISC_USES_BOTTLING))) && + (product->miscs.at(i).m_inventory < product->miscs.at(i).m_amount)) { + product->miscs_ok = false; + } + } +} + + /* * Manipulate the memory array and update the miscs table. */ @@ -245,6 +262,7 @@ m.m_time = query.value(4).toDouble(); m.m_amount_is_weight = query.value(5).toInt() ? true:false; m.m_cost = query.value(10).toDouble(); + m.m_inventory = query.value(9).toDouble(); product->miscs.append(m); refreshMiscs(); return; @@ -279,8 +297,8 @@ newm.m_name = "Select one"; newm.m_amount = 0; - newm.m_type = 0; - newm.m_use_use = 0; + newm.m_type = MISC_TYPES_SPICE; + newm.m_use_use = MISC_USES_STARTER; newm.m_time = 0; newm.m_amount_is_weight = true; newm.m_cost = 0; @@ -335,10 +353,11 @@ qDebug() << "misc_time_changed()" << product->miscs_row << val; - if (product->miscs.at(product->miscs_row).m_use_use == 2) { // Boil + if (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_BOIL) { product->miscs[product->miscs_row].m_time = val; item = new QTableWidgetItem(QString("%1 min.").arg(val, 1, 'f', 0, '0')); - } 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 + } else if (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_PRIMARY || + product->miscs.at(product->miscs_row).m_use_use == MISC_USES_SECONDARY) { product->miscs[product->miscs_row].m_time = val * 1440; item = new QTableWidgetItem(QString("%1 days.").arg(val, 1, 'f', 0, '0')); } else { @@ -366,7 +385,7 @@ /* * Search the misc ingredient pointed by the index and instock flag. */ - QString sql = "SELECT name,type,use_use,time,amount_is_weight,cost FROM inventory_miscs WHERE "; + QString sql = "SELECT name,type,use_use,time,amount_is_weight,cost,inventory FROM inventory_miscs WHERE "; if (instock) sql.append("inventory > 0 AND "); sql.append("type != 4 ORDER BY name"); @@ -388,6 +407,7 @@ product->miscs[product->miscs_row].m_time = query.value(3).toDouble(); product->miscs[product->miscs_row].m_amount_is_weight = query.value(4).toInt() ? true:false; product->miscs[product->miscs_row].m_cost = query.value(5).toDouble(); + product->miscs[product->miscs_row].m_inventory = query.value(6).toDouble(); /* * Update the visible fields @@ -432,6 +452,15 @@ item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->miscsTable->setItem(product->miscs_row, 4, item); + if (product->miscs.at(product->miscs_row).m_amount_is_weight) + item = new QTableWidgetItem(QString("%1 gr").arg(product->miscs.at(product->miscs_row).m_inventory * 1000.0, 3, 'f', 2, '0')); + else + item = new QTableWidgetItem(QString("%1 ml").arg(product->miscs.at(product->miscs_row).m_inventory * 1000.0, 3, 'f', 2, '0')); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + if (product->miscs.at(product->miscs_row).m_inventory < product->miscs.at(product->miscs_row).m_amount) + item->setForeground(QBrush(QColor(Qt::red))); + ui->miscsTable->setItem(product->miscs_row, 5, item); + is_changed(); emit refreshAll(); } @@ -471,12 +500,12 @@ item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); ui->miscsTable->setItem(product->miscs_row, 2, item); - if (val == 3 || val == 4) { // Fermentation stages + if (val == MISC_USES_PRIMARY || val == MISC_USES_SECONDARY) { product->miscs[product->miscs_row].m_time = mtimeEdit->value() * 1440; mtimeEdit->setReadOnly(false); mtimeLabel->setText(tr("Time in days:")); item = new QTableWidgetItem(QString("%1 days.").arg(product->miscs.at(product->miscs_row).m_time / 1440, 1, 'f', 0, '0')); - } else if (val == 2) { // Boil + } else if (val == MISC_USES_BOIL) { product->miscs[product->miscs_row].m_time = mtimeEdit->value(); mtimeEdit->setReadOnly(false); mtimeLabel->setText(tr("Time in minutes:")); @@ -534,9 +563,9 @@ mtimeLabel = new QLabel(dialog); mtimeLabel->setObjectName(QString::fromUtf8("mtimeLabel")); - if (product->miscs.at(product->miscs_row).m_use_use == 3 || product->miscs.at(product->miscs_row).m_use_use == 4) // Fermentation stages + if (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_PRIMARY || product->miscs.at(product->miscs_row).m_use_use == MISC_USES_SECONDARY) mtimeLabel->setText(tr("Time in days:")); - else if (product->miscs.at(product->miscs_row).m_use_use == 2) // Boil + else if (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_BOIL) mtimeLabel->setText(tr("Time in minutes:")); else mtimeLabel->setText(""); @@ -580,10 +609,10 @@ mtimeEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); mtimeEdit->setAccelerated(true); mtimeEdit->setMaximum(10000.0); - if (product->miscs.at(product->miscs_row).m_use_use == 3 || product->miscs.at(product->miscs_row).m_use_use == 4) { // Fermentation stages + if (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_PRIMARY || product->miscs.at(product->miscs_row).m_use_use == MISC_USES_SECONDARY) { mtimeEdit->setValue(product->miscs.at(product->miscs_row).m_time / 1440); mtimeEdit->setReadOnly(false); - } else if (product->miscs.at(product->miscs_row).m_use_use == 2) { // Boil + } else if (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_BOIL) { mtimeEdit->setValue(product->miscs.at(product->miscs_row).m_time); mtimeEdit->setReadOnly(false); } else { @@ -623,9 +652,9 @@ product->miscs[product->miscs_row] = backup; } else { /* Clear time if misc is not used for boil or fermentation. */ - if (! (product->miscs.at(product->miscs_row).m_use_use == 2 || - product->miscs.at(product->miscs_row).m_use_use == 3 || - product->miscs.at(product->miscs_row).m_use_use == 4)) { + if (! (product->miscs.at(product->miscs_row).m_use_use == MISC_USES_BOIL || + product->miscs.at(product->miscs_row).m_use_use == MISC_USES_PRIMARY || + product->miscs.at(product->miscs_row).m_use_use == MISC_USES_SECONDARY)) { if (product->miscs.at(product->miscs_row).m_time) { product->miscs[product->miscs_row].m_time = 0; is_changed(); @@ -667,7 +696,7 @@ /* * Update the water agents. */ - if (product->miscs.at(i).m_type == 4) { + if (product->miscs.at(i).m_type == MISC_TYPES_WATER_AGENT) { if (product->miscs.at(i).m_name == "CaCl2") { ui->bs_cacl2Edit->setValue(product->miscs.at(i).m_amount * 1000.0); } else if (product->miscs.at(i).m_name == "CaSO4") { diff -r f5a1973236ef -r ea8cce5e7eb9 src/global.h --- a/src/global.h Wed May 04 09:14:00 2022 +0200 +++ b/src/global.h Wed May 04 13:49:37 2022 +0200 @@ -639,7 +639,28 @@ }; extern const QStringList hop_useat; + +enum MiscTypes { + MISC_TYPES_SPICE, + MISC_TYPES_HERB, + MISC_TYPES_FLAVOR, + MISC_TYPES_FINING, + MISC_TYPES_WATER_AGENT, + MISC_TYPES_YEAST_NUTRIENT, + MISC_TYPES_OTHER +}; + extern const QStringList misc_types; + +enum MiscUses { + MISC_USES_STARTER, + MISC_USES_MASH, + MISC_USES_BOIL, + MISC_USES_PRIMARY, + MISC_USES_SECONDARY, + MISC_USES_BOTTLING +}; + extern const QStringList misc_uses; extern const QStringList yeast_types; extern const QStringList yeast_forms;