diff -r aa8d421bfc24 -r 35ce719998e1 src/EditProductTab4.cpp --- a/src/EditProductTab4.cpp Tue Jun 21 16:16:43 2022 +0200 +++ b/src/EditProductTab4.cpp Thu Jun 23 16:50:23 2022 +0200 @@ -35,6 +35,14 @@ } +bool EditProduct::block_hop(int stage, int useat) +{ + if (stage > PROD_STAGE_BREW && useat < HOP_USEAT_DRY_HOP) + return true; + return false; +} + + void EditProduct::refreshHops() { QString w; @@ -111,38 +119,51 @@ item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->hopsTable->setItem(i, 8, item); - if (product->hops.at(i).inventory < 1.0) { - item = new QTableWidgetItem(QString("%1 gr").arg(product->hops.at(i).inventory * 1000.0, 2, 'f', 1, '0')); - } else { - item = new QTableWidgetItem(QString("%1 kg").arg(product->hops.at(i).inventory, 4, 'f', 3, '0')); - } - item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); - if (product->hops.at(i).inventory < product->hops.at(i).amount) - item->setForeground(QBrush(QColor(Qt::red))); + if (block_hop(product->stage, product->hops.at(i).useat)) { + item = new QTableWidgetItem(QString("")); + } else { + if (product->hops.at(i).inventory < 1.0) { + item = new QTableWidgetItem(QString("%1 gr").arg(product->hops.at(i).inventory * 1000.0, 2, 'f', 1, '0')); + } else { + item = new QTableWidgetItem(QString("%1 kg").arg(product->hops.at(i).inventory, 4, 'f', 3, '0')); + } + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + if (product->hops.at(i).inventory < product->hops.at(i).amount) + item->setForeground(QBrush(QColor(Qt::red))); + } ui->hopsTable->setItem(i, 9, item); /* Add the Delete row button */ - 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(deleteHopRow_clicked())); - pLayout = new QHBoxLayout(pWidget); - pLayout->addWidget(btn_dele); - pLayout->setContentsMargins(5, 0, 5, 0); - pWidget->setLayout(pLayout); - ui->hopsTable->setCellWidget(i, 10, pWidget); + if (block_hop(product->stage, product->hops.at(i).useat)) { + item = new QTableWidgetItem(""); + item->setToolTip(tr("Hop already used")); + ui->hopsTable->setItem(i, 10, item); + item = new QTableWidgetItem(""); + item->setToolTip(tr("Hop already used")); + ui->hopsTable->setItem(i, 11, item); + } else { + 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(deleteHopRow_clicked())); + pLayout = new QHBoxLayout(pWidget); + pLayout->addWidget(btn_dele); + pLayout->setContentsMargins(5, 0, 5, 0); + pWidget->setLayout(pLayout); + ui->hopsTable->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(editHopRow_clicked())); - pLayout = new QHBoxLayout(pWidget); - pLayout->addWidget(btn_edit); - pLayout->setContentsMargins(5, 0, 5, 0); - pWidget->setLayout(pLayout); - ui->hopsTable->setCellWidget(i, 11, 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(editHopRow_clicked())); + pLayout = new QHBoxLayout(pWidget); + pLayout->addWidget(btn_edit); + pLayout->setContentsMargins(5, 0, 5, 0); + pWidget->setLayout(pLayout); + ui->hopsTable->setCellWidget(i, 11, pWidget); + } } }