Added all yeast edit functions and the popup editor window.

Mon, 18 Apr 2022 21:56:11 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 18 Apr 2022 21:56:11 +0200
changeset 143
8414844c9f8b
parent 142
1caa15a0eefc
child 144
c4b107bf153a

Added all yeast edit functions and the popup editor window.

src/EditRecipe.h file | annotate | diff | comparison | revisions
src/EditRecipeTab5.cpp file | annotate | diff | comparison | revisions
--- a/src/EditRecipe.h	Mon Apr 18 20:00:49 2022 +0200
+++ b/src/EditRecipe.h	Mon Apr 18 21:56:11 2022 +0200
@@ -285,6 +285,10 @@
     void misc_select_changed(int val);
     void misc_instock_changed(bool val);
     void misc_useat_changed(int val);
+    void yeast_amount_changed(double val);
+    void yeast_select_changed(int val);
+    void yeast_instock_changed(bool val);
+    void yeast_useat_changed(int val);
     void addFermentRow_clicked();
     void deleteFermentRow_clicked();
     void editFermentRow_clicked();
@@ -350,11 +354,11 @@
     /*
      * Variables for popup ingredients editing.
      */
-    QComboBox *fselectEdit, *faddedEdit, *hselectEdit,*haddedEdit, *useatEdit, *mselectEdit;
-    QLineEdit *fnameEdit, *fsupplierEdit, *hnameEdit, *horiginEdit, *mnameEdit;
-    QDoubleSpinBox *famountEdit, *pctEdit, *fmaxEdit, *hamountEdit, *ibuEdit, *mamountEdit;
+    QComboBox *fselectEdit, *faddedEdit, *hselectEdit,*haddedEdit, *useatEdit, *mselectEdit, *yselectEdit;
+    QLineEdit *fnameEdit, *fsupplierEdit, *hnameEdit, *horiginEdit, *mnameEdit, *ynameEdit, *ylaboratoryEdit, *yproduct_idEdit;
+    QDoubleSpinBox *famountEdit, *pctEdit, *fmaxEdit, *hamountEdit, *ibuEdit, *mamountEdit, *yamountEdit;
     QSpinBox *htimeEdit, *mtimeEdit;
-    QCheckBox *to100Edit, *finstockEdit, *hinstockEdit, *minstockEdit;
+    QCheckBox *to100Edit, *finstockEdit, *hinstockEdit, *minstockEdit, *yinstockEdit;
     QLabel *htimeLabel, *mtimeLabel, *mamountLabel;
 
     void to100Fermentables(int row);
--- a/src/EditRecipeTab5.cpp	Mon Apr 18 20:00:49 2022 +0200
+++ b/src/EditRecipeTab5.cpp	Mon Apr 18 21:56:11 2022 +0200
@@ -8,7 +8,7 @@
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
- * bmsapp is distributed in the hope that it will be useful,
+ * bmsapp is distributed in the yeaste that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
@@ -216,7 +216,44 @@
 
 void EditRecipe::addYeastRow_clicked()
 {
+    Yeasts newy;
 
+    qDebug() << "Add yeast row";
+
+    for (int i = 0; i < recipe->yeasts.size(); i++) {
+        if (recipe->yeasts.at(i).y_amount == 0)
+            return;     // Add only one at a time.
+    }
+
+    newy.y_name = "Select one";
+    newy.y_laboratory = "";
+    newy.y_product_id = "";
+    newy.y_amount = 0;
+    newy.y_type = 0;
+    newy.y_form = 0;
+    newy.y_min_temperature = 0;
+    newy.y_max_temperature = 0;
+    newy.y_flocculation = 0;
+    newy.y_attenuation = 0;
+    newy.y_cells = 0;
+    newy.y_tolerance = 0;
+    newy.y_inventory = 0;
+    newy.y_use = 0;
+    newy.y_sta1 = false;
+    newy.y_bacteria = false;
+    newy.y_harvest_top = false;
+    newy.y_harvest_time = 0;
+    newy.y_pitch_temperature = 0;
+    newy.y_pofpos = false;
+    newy.y_zymocide = 0;
+    newy.y_gr_hl_lo = 0;
+    newy.y_sg_lo = 0;
+    newy.y_gr_hl_hi = 0;
+    newy.y_sg_hi = 0;
+    newy.y_cost = 0;
+
+    recipe->yeasts.append(newy);
+    emit refreshAll();
 }
 
 
@@ -242,6 +279,157 @@
 }
 
 
+void EditRecipe::yeast_amount_changed(double val)
+{
+    QTableWidgetItem *item;
+
+    qDebug() << "yeast_amount_changed()" << recipe->yeasts_row << val;
+    this->ignoreChanges = true;
+
+    recipe->yeasts[recipe->yeasts_row].y_amount = val / 1000.0;
+    item = new QTableWidgetItem(QString("%1 gr").arg(val, 2, 'f', 1, '0'));
+    item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+    ui->yeastsTable->setItem(recipe->yeasts_row, 8, item);
+
+    this->ignoreChanges = false;
+    calcYeast();
+    is_changed();
+}
+
+
+void EditRecipe::yeast_select_changed(int val)
+{
+    QSqlQuery query;
+    bool instock = yinstockEdit->isChecked();
+    QString w;
+    QTableWidgetItem *item;
+
+    if (val < 1)
+        return;
+
+    qDebug() << "yeast_select_changed()" << recipe->yeasts_row << val << instock;
+
+    /*
+     * Search the yeast pointed by the index and instock flag.
+     */
+    QString sql = "SELECT name,laboratory,product_id,type,form,min_temperature,max_temperature,flocculation,attenuation,"
+	          "cells,tolerance,sta1,bacteria,harvest_top,harvest_time,pitch_temperature,pofpos,zymocide,"
+		  "gr_hl_lo,sg_lo,gr_hl_hi,sg_hi,cost FROM inventory_yeasts ";
+    if (instock)
+        sql.append("WHERE inventory > 0 ");
+    sql.append("ORDER BY laboratory,product_id,name");
+    query.prepare(sql);
+    query.exec();
+    query.first();
+    for (int i = 0; i < (val - 1); i++) {
+        query.next();
+    }
+    qDebug() << "found" << query.value(0).toString() << query.value(2).toString();
+
+    /*
+     * Replace the yeast record contents
+     */
+    this->ignoreChanges = true;
+    recipe->yeasts[recipe->yeasts_row].y_name = query.value(0).toString();
+    recipe->yeasts[recipe->yeasts_row].y_laboratory = query.value(1).toString();
+    recipe->yeasts[recipe->yeasts_row].y_product_id = query.value(2).toString();
+    recipe->yeasts[recipe->yeasts_row].y_type = query.value(3).toInt();
+    recipe->yeasts[recipe->yeasts_row].y_form = query.value(4).toInt();
+    recipe->yeasts[recipe->yeasts_row].y_min_temperature = query.value(5).toDouble();
+    recipe->yeasts[recipe->yeasts_row].y_max_temperature = query.value(6).toDouble();
+    recipe->yeasts[recipe->yeasts_row].y_flocculation = query.value(7).toInt();
+    recipe->yeasts[recipe->yeasts_row].y_attenuation = query.value(8).toDouble();
+    recipe->yeasts[recipe->yeasts_row].y_cells = query.value(9).toDouble();
+    recipe->yeasts[recipe->yeasts_row].y_tolerance = query.value(10).toDouble();
+    recipe->yeasts[recipe->yeasts_row].y_sta1 = query.value(11).toInt() ? true:false;
+    recipe->yeasts[recipe->yeasts_row].y_bacteria = query.value(12).toInt() ? true:false;
+    recipe->yeasts[recipe->yeasts_row].y_harvest_top = query.value(13).toInt() ? true:false;
+    recipe->yeasts[recipe->yeasts_row].y_harvest_time = query.value(14).toInt();
+    recipe->yeasts[recipe->yeasts_row].y_pitch_temperature = query.value(15).toDouble();
+    recipe->yeasts[recipe->yeasts_row].y_pofpos = query.value(16).toInt() ? true:false;
+    recipe->yeasts[recipe->yeasts_row].y_zymocide = query.value(17).toInt();
+    recipe->yeasts[recipe->yeasts_row].y_gr_hl_lo = query.value(18).toInt();
+    recipe->yeasts[recipe->yeasts_row].y_sg_lo = query.value(19).toDouble();
+    recipe->yeasts[recipe->yeasts_row].y_gr_hl_hi = query.value(20).toInt();
+    recipe->yeasts[recipe->yeasts_row].y_sg_hi = query.value(21).toDouble();
+    recipe->yeasts[recipe->yeasts_row].y_cost = query.value(22).toDouble();
+
+    /*
+     * Update the visible fields
+     */
+    ynameEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_name);
+    ylaboratoryEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_laboratory);
+    yproduct_idEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_product_id);
+
+    ui->yeastsTable->setItem(recipe->yeasts_row, 0, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).y_name));
+    ui->yeastsTable->setItem(recipe->yeasts_row, 1, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).y_laboratory));
+    ui->yeastsTable->setItem(recipe->yeasts_row, 2, new QTableWidgetItem(recipe->yeasts.at(recipe->yeasts_row).y_product_id));
+
+    item = new QTableWidgetItem(y_forms[recipe->yeasts.at(recipe->yeasts_row).y_form]);
+    item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
+    ui->yeastsTable->setItem(recipe->yeasts_row, 3, item);
+
+    item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).y_min_temperature, 2, 'f', 1, '0'));
+    item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+    ui->yeastsTable->setItem(recipe->yeasts_row, 5, item);
+
+    item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).y_max_temperature, 2, 'f', 1, '0'));
+    item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+    ui->yeastsTable->setItem(recipe->yeasts_row, 6, item);
+
+    item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).y_tolerance, 2, 'f', 1, '0'));
+    item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+    ui->yeastsTable->setItem(recipe->yeasts_row, 7, item);
+
+    item = new QTableWidgetItem(QString("%1").arg(recipe->yeasts.at(recipe->yeasts_row).y_attenuation, 2, 'f', 1, '0'));
+    item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+    ui->yeastsTable->setItem(recipe->yeasts_row, 8, item);
+
+    this->ignoreChanges = false;
+    calcYeast();
+    is_changed();
+}
+
+
+void EditRecipe::yeast_instock_changed(bool val)
+{
+    QSqlQuery query;
+
+    qDebug() << "yeast_instock_changed()" << recipe->yeasts_row << val;
+
+    this->yselectEdit->setCurrentIndex(-1);
+    this->yselectEdit->clear();
+    QString sql = "SELECT name,laboratory,product_id,inventory FROM inventory_yeasts ";
+    if (val)
+        sql.append("WHERE inventory > 0 ");
+    sql.append("ORDER BY laboratory,product_id,name");
+    query.prepare(sql);
+    query.exec();
+    query.first();
+    this->yselectEdit->addItem("");      // Start with empty value
+    for (int i = 0; i < query.size(); i++) {
+        this->yselectEdit->addItem(query.value(1).toString()+" - "+query.value(2).toString()+" "+query.value(0).toString() + 
+                        QString(" (%1 gr)").arg(query.value(3).toDouble() * 1000.0, 2, 'f', 1, '0'));
+        query.next();
+    }
+}
+
+
+void EditRecipe::yeast_useat_changed(int val)
+{
+    qDebug() << "yeast_useat_changed()" << recipe->yeasts_row << val;
+
+    this->ignoreChanges = true;
+    recipe->yeasts[recipe->yeasts_row].y_use = val;
+    QTableWidgetItem *item = new QTableWidgetItem(y_use[val]);
+    item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
+    ui->yeastsTable->setItem(recipe->yeasts_row, 5, item);
+    this->ignoreChanges = false;
+    is_changed();
+    emit refreshAll();
+}
+
+
 void EditRecipe::editYeastRow_clicked()
 {
     QSqlQuery query;
@@ -252,22 +440,113 @@
     Yeasts backup = recipe->yeasts.at(recipe->yeasts_row);
 
     QDialog* dialog = new QDialog(this);
-    dialog->resize(738, 230);
+    dialog->resize(738, 260);
     QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
     buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
-    buttonBox->setGeometry(QRect(30, 180, 671, 32));
+    buttonBox->setGeometry(QRect(30, 210, 671, 32));
     buttonBox->setLayoutDirection(Qt::LeftToRight);
     buttonBox->setOrientation(Qt::Horizontal);
     buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
     buttonBox->setCenterButtons(true);
 
+    QLabel *nameLabel = new QLabel(dialog);
+    nameLabel->setObjectName(QString::fromUtf8("nameLabel"));
+    nameLabel->setText(tr("Yeast name:"));
+    nameLabel->setGeometry(QRect(10, 10, 141, 20));
+    nameLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
+    QLabel *laboratoryLabel = new QLabel(dialog);
+    laboratoryLabel->setObjectName(QString::fromUtf8("laboratoryLabel"));
+    laboratoryLabel->setText(tr("Laboratory:"));
+    laboratoryLabel->setGeometry(QRect(10, 40, 141, 20));
+    laboratoryLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
+    QLabel *product_idLabel = new QLabel(dialog);
+    product_idLabel->setObjectName(QString::fromUtf8("product_idLabel"));
+    product_idLabel->setText(tr("Laboratory:"));
+    product_idLabel->setGeometry(QRect(10, 70, 141, 20));
+    product_idLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
+    QLabel *selectLabel = new QLabel(dialog);
+    selectLabel->setObjectName(QString::fromUtf8("selectLabel"));
+    selectLabel->setText(tr("Select yeast:"));
+    selectLabel->setGeometry(QRect(10,100, 141, 20));
+    selectLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
+    QLabel *instockLabel = new QLabel(dialog);
+    instockLabel->setObjectName(QString::fromUtf8("instockLabel"));
+    instockLabel->setText(tr("In stock:"));
+    instockLabel->setGeometry(QRect(525,100, 121, 20));
+    instockLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
+    QLabel *amountLabel = new QLabel(dialog);
+    amountLabel->setObjectName(QString::fromUtf8("amountLabel"));
+    amountLabel->setText(tr("Amount in gr:"));
+    amountLabel->setGeometry(QRect(10, 130, 141, 20));
+    amountLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
+    QLabel *useatLabel = new QLabel(dialog);
+    useatLabel->setObjectName(QString::fromUtf8("useatLabel"));
+    useatLabel->setText(tr("Use at:"));
+    useatLabel->setGeometry(QRect(10, 160, 141, 20));
+    useatLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
 
+    ynameEdit = new QLineEdit(dialog);
+    ynameEdit->setObjectName(QString::fromUtf8("ynameEdit"));
+    ynameEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_name);
+    ynameEdit->setGeometry(QRect(160, 10, 511, 23));
+    ynameEdit->setReadOnly(true);
+    ylaboratoryEdit = new QLineEdit(dialog);
+    ylaboratoryEdit->setObjectName(QString::fromUtf8("ylaboratoryEdit"));
+    ylaboratoryEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_laboratory);
+    ylaboratoryEdit->setGeometry(QRect(160, 40, 511, 23));
+    ylaboratoryEdit->setReadOnly(true);
+    yproduct_idEdit = new QLineEdit(dialog);
+    yproduct_idEdit->setObjectName(QString::fromUtf8("yproduct_idEdit"));
+    yproduct_idEdit->setText(recipe->yeasts.at(recipe->yeasts_row).y_product_id);
+    yproduct_idEdit->setGeometry(QRect(160, 70, 511, 23));
+    yproduct_idEdit->setReadOnly(true);
+    yselectEdit = new QComboBox(dialog);
+    yselectEdit->setObjectName(QString::fromUtf8("selectEdit"));
+    yselectEdit->setGeometry(QRect(160,100, 371, 23));
+    yinstockEdit = new QCheckBox(dialog);
+    yinstockEdit->setObjectName(QString::fromUtf8("yinstockEdit"));
+    yinstockEdit->setGeometry(QRect(655,100, 85, 21));
+    yinstockEdit->setChecked(true);
+    yamountEdit = new QDoubleSpinBox(dialog);
+    yamountEdit->setObjectName(QString::fromUtf8("yamountEdit"));
+    yamountEdit->setGeometry(QRect(160, 130, 121, 24));
+    yamountEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
+    yamountEdit->setAccelerated(true);
+    yamountEdit->setDecimals(1);
+    yamountEdit->setMaximum(1000000.0);
+    yamountEdit->setSingleStep(0.5);
+    yamountEdit->setValue(recipe->yeasts.at(recipe->yeasts_row).y_amount * 1000.0);
+    useatEdit = new QComboBox(dialog);
+    useatEdit->setObjectName(QString::fromUtf8("useatEdit"));
+    useatEdit->setGeometry(QRect(160, 160, 161, 23));
+    useatEdit->addItem(tr("Primary"));
+    useatEdit->addItem(tr("Secondary"));
+    useatEdit->addItem(tr("Tertiary"));
+    useatEdit->addItem(tr("Bottle"));
+    useatEdit->setCurrentIndex(recipe->yeasts.at(recipe->yeasts_row).y_use);
 
+    yeast_instock_changed(true);
+
+    connect(yselectEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::yeast_select_changed);
+    connect(yamountEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::yeast_amount_changed);
+    connect(useatEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::yeast_useat_changed);
+    connect(yinstockEdit, &QCheckBox::stateChanged, this, &EditRecipe::yeast_instock_changed);
     connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
     connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
 
+    dialog->setModal(true);
+    dialog->exec();
+    if (dialog->result() == QDialog::Rejected) {
+        qDebug() << "reject and rollback";
+        recipe->yeasts[recipe->yeasts_row] = backup;
+    } else {
 
+    }
 
+    disconnect(yselectEdit, nullptr, nullptr, nullptr);
+    disconnect(yamountEdit, nullptr, nullptr, nullptr);
+    disconnect(useatEdit, nullptr, nullptr, nullptr);
+    disconnect(yinstockEdit, nullptr, nullptr, nullptr);
     disconnect(buttonBox, nullptr, nullptr, nullptr);
 
     emit refreshAll();

mercurial