src/EditRecipeTab3.cpp

changeset 258
70bb9c3ee60f
parent 230
b68c0c61d261
child 263
14d79ec33db4
--- a/src/EditRecipeTab3.cpp	Mon Jun 06 13:04:27 2022 +0200
+++ b/src/EditRecipeTab3.cpp	Mon Jun 06 14:12:35 2022 +0200
@@ -303,8 +303,6 @@
 {
     QTableWidgetItem *item;
 
-    qDebug() << "hop_amount_changed()" << recipe->hops_row << val;
-
     recipe->hops[recipe->hops_row].h_amount = val / 1000.0;
     item = new QTableWidgetItem(QString("%1 gr").arg(val, 2, 'f', 1, '0'));
     item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
@@ -325,12 +323,34 @@
 }
 
 
+void EditRecipe::hop_alpha_changed(double val)
+{
+    QTableWidgetItem *item;
+
+    recipe->hops[recipe->hops_row].h_alpha = val;
+    item = new QTableWidgetItem(QString("%1%").arg(val, 2, 'f', 1, '0'));
+    item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+    ui->hopsTable->setItem(recipe->hops_row, 4, item);
+
+    double ibu = Utils::toIBU(recipe->hops.at(recipe->hops_row).h_useat, recipe->hops.at(recipe->hops_row).h_form, recipe->preboil_sg,
+                              recipe->batch_size, recipe->hops.at(recipe->hops_row).h_amount, recipe->hops.at(recipe->hops_row).h_time,
+                              recipe->hops.at(recipe->hops_row).h_alpha, recipe->ibu_method, 0, recipe->hops.at(recipe->hops_row).h_time,
+                              0, recipe->boil_time);
+
+    ibuEdit->setValue(ibu);
+    item = new QTableWidgetItem(QString("%1").arg(ibu, 2, 'f', 1, '0'));
+    item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+    ui->hopsTable->setItem(recipe->hops_row, 7, item);
+
+    calcIBUs();
+    is_changed();
+}
+
+
 void EditRecipe::hop_time_changed(int val)
 {
     QTableWidgetItem *item;
 
-    qDebug() << "hop_time_changed()" << recipe->hops_row << val;
-
     if (recipe->hops.at(recipe->hops_row).h_useat == 2 || recipe->hops.at(recipe->hops_row).h_useat == 4) {       // Boil or whirlpool
         item = new QTableWidgetItem(QString("%1 min.").arg(val, 1, 'f', 0, '0'));
 	recipe->hops[recipe->hops_row].h_time = val;
@@ -369,8 +389,6 @@
     if (val < 1)
         return;
 
-    qDebug() << "hop_select_changed()" << recipe->fermentables_row << val << instock;
-
     /*
      * Search the hop pointed by the index and instock flag.
      */
@@ -384,7 +402,6 @@
     for (int i = 0; i < (val - 1); i++) {
         query.next();
     }
-    qDebug() << "found" << query.value(1).toString() << query.value(0).toString();
 
     /*
      * Replace the hop record contents
@@ -443,8 +460,6 @@
 {
     QSqlQuery query;
 
-    qDebug() << "hop_instock_changed()" << recipe->hops_row << val;
-
     this->hselectEdit->setCurrentIndex(-1);
     this->hselectEdit->clear();
     QString sql = "SELECT origin,name,alpha,inventory FROM inventory_hops ";
@@ -465,8 +480,6 @@
 
 void EditRecipe::hop_useat_changed(int val)
 {
-    qDebug() << "hop_useat_changed()" << recipe->hops_row << val;
-
     recipe->hops[recipe->hops_row].h_useat = val;
     QTableWidgetItem *item = new QTableWidgetItem(hop_useat[val]);
     item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
@@ -491,6 +504,28 @@
 }
 
 
+void EditRecipe::hop_form_changed(int val)
+{
+    recipe->hops[recipe->hops_row].h_form = val;
+    QTableWidgetItem *item = new QTableWidgetItem(hop_forms[val]);
+    item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
+    ui->hopsTable->setItem(recipe->hops_row, 3, item);
+
+    double ibu = Utils::toIBU(recipe->hops.at(recipe->hops_row).h_useat, recipe->hops.at(recipe->hops_row).h_form, recipe->preboil_sg,
+                              recipe->batch_size, recipe->hops.at(recipe->hops_row).h_amount, recipe->hops.at(recipe->hops_row).h_time,
+                              recipe->hops.at(recipe->hops_row).h_alpha, recipe->ibu_method, 0, recipe->hops.at(recipe->hops_row).h_time,
+                              0, recipe->boil_time);
+
+    ibuEdit->setValue(ibu);
+    item = new QTableWidgetItem(QString("%1").arg(ibu, 2, 'f', 1, '0'));
+    item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+    ui->hopsTable->setItem(recipe->hops_row, 7, item);
+
+    is_changed();
+    emit refreshAll();
+}
+
+
 void EditRecipe::editHopRow_clicked()
 {
     QSqlQuery query;
@@ -527,6 +562,11 @@
     amountLabel->setText(tr("Amount in gr:"));
     amountLabel->setGeometry(QRect(10, 100, 141, 20));
     amountLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
+    QLabel *alphaLabel = new QLabel(dialog);
+    alphaLabel->setObjectName(QString::fromUtf8("alphaLabel"));
+    alphaLabel->setText(tr("Alpha percentage:"));
+    alphaLabel->setGeometry(QRect(420, 100, 121, 20));
+    alphaLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
     htimeLabel = new QLabel(dialog);
     htimeLabel->setObjectName(QString::fromUtf8("htimeLabel"));
     if (recipe->hops.at(recipe->hops_row).h_useat == 5)		// Dry-hop
@@ -543,6 +583,11 @@
     useatLabel->setText(tr("Use at:"));
     useatLabel->setGeometry(QRect(10, 160, 141, 20));
     useatLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
+    QLabel *formLabel = new QLabel(dialog);
+    formLabel->setObjectName(QString::fromUtf8("formLabel"));
+    formLabel->setText(tr("Hop form:"));
+    formLabel->setGeometry(QRect(380, 160, 121, 20));
+    formLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
     QLabel *selectLabel = new QLabel(dialog);
     selectLabel->setObjectName(QString::fromUtf8("selectLabel"));
     selectLabel->setText(tr("Select hop:"));
@@ -582,6 +627,15 @@
     hamountEdit->setMaximum(1000000.0);
     hamountEdit->setSingleStep(0.5);
     hamountEdit->setValue(recipe->hops.at(recipe->hops_row).h_amount * 1000.0);
+    halphaEdit = new QDoubleSpinBox(dialog);
+    halphaEdit->setObjectName(QString::fromUtf8("halphaEdit"));
+    halphaEdit->setGeometry(QRect(550, 100, 121, 24));
+    halphaEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
+    halphaEdit->setAccelerated(true);
+    halphaEdit->setDecimals(1);
+    halphaEdit->setMaximum(100.0);
+    halphaEdit->setSingleStep(0.1);
+    halphaEdit->setValue(recipe->hops.at(recipe->hops_row).h_alpha);
     htimeEdit = new QSpinBox(dialog);
     htimeEdit->setObjectName(QString::fromUtf8("htimeEdit"));
     htimeEdit->setGeometry(QRect(160, 130, 121, 24));
@@ -608,6 +662,16 @@
     useatEdit->addItem(tr("Dry hop"));
     useatEdit->setCurrentIndex(recipe->hops.at(recipe->hops_row).h_useat);
 
+    hformEdit = new QComboBox(dialog);
+    hformEdit->setObjectName(QString::fromUtf8("formEdit"));
+    hformEdit->setGeometry(QRect(510, 160, 161, 23));
+    hformEdit->addItem(tr("Pellet"));
+    hformEdit->addItem(tr("Plug"));
+    hformEdit->addItem(tr("Leaf"));
+    hformEdit->addItem(tr("Wet leaf"));
+    hformEdit->addItem(tr("Cryo"));
+    hformEdit->setCurrentIndex(recipe->hops.at(recipe->hops_row).h_form);
+
     hinstockEdit = new QCheckBox(dialog);
     hinstockEdit->setObjectName(QString::fromUtf8("hinstockEdit"));
     hinstockEdit->setGeometry(QRect(655, 70, 85, 21));
@@ -630,8 +694,10 @@
 
     connect(hselectEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::hop_select_changed);
     connect(hamountEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::hop_amount_changed);
+    connect(halphaEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::hop_alpha_changed);
     connect(htimeEdit, QOverload<int>::of(&QSpinBox::valueChanged), this, &EditRecipe::hop_time_changed);
     connect(useatEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::hop_useat_changed);
+    connect(hformEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::hop_form_changed);
     connect(hinstockEdit, &QCheckBox::stateChanged, this, &EditRecipe::hop_instock_changed);
     connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
     connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
@@ -655,8 +721,10 @@
 
     disconnect(hselectEdit, nullptr, nullptr, nullptr);
     disconnect(hamountEdit, nullptr, nullptr, nullptr);
+    disconnect(halphaEdit, nullptr, nullptr, nullptr);
     disconnect(htimeEdit, nullptr, nullptr, nullptr);
     disconnect(useatEdit, nullptr, nullptr, nullptr);
+    disconnect(hformEdit, nullptr, nullptr, nullptr);
     disconnect(hinstockEdit, nullptr, nullptr, nullptr);
     disconnect(buttonBox, nullptr, nullptr, nullptr);
 

mercurial