src/EditProductTab9.cpp

changeset 461
add4dbef0c81
parent 454
2dfead81c72f
--- a/src/EditProductTab9.cpp	Sat Jan 14 15:38:28 2023 +0100
+++ b/src/EditProductTab9.cpp	Sun Jan 15 12:35:04 2023 +0100
@@ -153,20 +153,87 @@
 }
 
 
-void EditProduct::brew_volume_calc(double volume, double kettle_volume, double kettle_height, double est_volume, bool aboil)
+void EditProduct::brew_brix_changed(double val)
+{
+    sg_return = Utils::brix_to_sg(val);
+}
+
+
+double EditProduct::brew_brix_edit(double sg, double sg_default)
+{
+    double brix = 0.0;
+
+    QDialog* dialog = new QDialog(this);
+    dialog->resize(360, 110);
+    QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
+    buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
+    buttonBox->setGeometry(QRect(30, 60, 300, 32));
+    buttonBox->setLayoutDirection(Qt::LeftToRight);
+    buttonBox->setOrientation(Qt::Horizontal);
+    buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
+    buttonBox->setCenterButtons(true);
+
+    QLabel *brixLabel = new QLabel(dialog);
+    brixLabel->setObjectName(QString::fromUtf8("brixLabel"));
+    brixLabel->setText(tr("Refractometer Brix:"));
+    brixLabel->setGeometry(QRect(10, 20, 161, 24));
+    brixLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
+
+    QDoubleSpinBox *brixEdit = new QDoubleSpinBox(dialog);
+    brixEdit->setObjectName(QString::fromUtf8("brixEdit"));
+    brixEdit->setGeometry(QRect(180, 20, 101, 24));
+    brixEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
+    brixEdit->setAccelerated(true);
+    brixEdit->setDecimals(1);
+    brixEdit->setMaximum(32.0);
+    brixEdit->setSingleStep(0.1);
+
+    if (sg > 1.001)
+	brix = Utils::sg_to_brix(sg);
+    else
+	brix = Utils::sg_to_brix(sg_default);
+    brixEdit->setValue(brix);
+
+    connect(brixEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::brew_brix_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) {
+        sg_return = sg;
+    }
+
+    disconnect(brixEdit, nullptr, nullptr, nullptr);
+    disconnect(buttonBox, nullptr, nullptr, nullptr);
+
+    qDebug() << "brew_brix_edit(" << sg << sg_default << ") return" << sg_return;
+    return sg_return;
+}
+
+
+void EditProduct::brew_volume_calc(double volume, double kettle_volume, double kettle_height, double est_volume, bool aboil, bool chiller)
 {
     double k_cm;
 
-    if (volume > 0)
+    if ((chiller && volume > product->eq_chiller_volume) || (! chiller && volume > 0))
         k_cm = Utils::kettle_cm(volume, kettle_volume, kettle_height);
     else
         k_cm = Utils::kettle_cm(est_volume, kettle_volume, kettle_height);
 
+    qDebug() << "brew_volume_calc(" << volume << kettle_volume << kettle_height << est_volume << aboil << chiller << ") cm:" << k_cm;
+
     QDialog* dialog = new QDialog(this);
-    dialog->resize(320, 110);
+    if (chiller)
+	dialog->resize(320, 140);
+    else
+    	dialog->resize(320, 110);
     QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
     buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
-    buttonBox->setGeometry(QRect(40, 65, 240, 32));
+    if (chiller)
+	buttonBox->setGeometry(QRect(40, 95, 240, 32));
+    else
+    	buttonBox->setGeometry(QRect(40, 65, 240, 32));
     buttonBox->setLayoutDirection(Qt::LeftToRight);
     buttonBox->setOrientation(Qt::Horizontal);
     buttonBox->setStandardButtons(QDialogButtonBox::Ok);
@@ -189,6 +256,14 @@
     cmEdit->setSingleStep(0.1);
     cmEdit->setValue(k_cm);
 
+    if (chiller) {
+	QLabel *opmLabel = new QLabel(dialog);
+	opmLabel->setObjectName(QString::fromUtf8("opmLabel"));
+	opmLabel->setText(tr("Measure with placed immersion chiller."));
+	opmLabel->setGeometry(QRect(10, 60, 300, 24));
+	opmLabel->setAlignment(Qt::AlignCenter);
+    }
+
     if (aboil)
 	connect(cmEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::brew_aboil_cm_changed);
     else
@@ -278,9 +353,16 @@
 }
 
 
+void EditProduct::brew_preboil_brix_button()
+{
+    product->brew_preboil_sg = brew_brix_edit(product->brew_preboil_sg, product->preboil_sg);
+    ui->brew_preboilsgEdit->setValue(product->brew_preboil_sg);
+}
+
+
 void EditProduct::brew_preboil_button()
 {
-    brew_volume_calc(product->brew_preboil_volume, product->eq_kettle_volume, product->eq_kettle_height, product->boil_size * 1.04, false);
+    brew_volume_calc(product->brew_preboil_volume, product->eq_kettle_volume, product->eq_kettle_height, product->boil_size * 1.04, false, false);
 }
 
 
@@ -342,9 +424,9 @@
     if (product->brew_aboil_volume == 0) {
         product->brew_aboil_volume = product->batch_size * 1.04;
         const QSignalBlocker blocker1(ui->brew_aboilvolEdit);
-        ui->brew_aboilvolEdit->setValue(product->batch_size * 1.04);
+        ui->brew_aboilvolEdit->setValue(product->brew_aboil_volume + product->eq_chiller_volume);
     } else {
-        product->brew_aboil_volume = val;
+        product->brew_aboil_volume = val - product->eq_chiller_volume;
     }
     is_changed();
     calcEfficiencyAfterBoil();
@@ -354,7 +436,7 @@
 void EditProduct::brew_aboil_cm_changed(double val)
 {
     double vol = Utils::kettle_vol(val, product->eq_kettle_volume, product->eq_kettle_height);
-    product->brew_aboil_volume = vol;
+    product->brew_aboil_volume = vol - product->eq_chiller_volume;
     const QSignalBlocker blocker1(ui->brew_aboilvolEdit);
     ui->brew_aboilvolEdit->setValue(vol);
     is_changed();
@@ -362,9 +444,19 @@
 }
 
 
+void EditProduct::brew_aboil_brix_button()
+{
+    product->brew_aboil_sg = brew_brix_edit(product->brew_aboil_sg, product->est_og3);
+    ui->brew_aboilsgEdit->setValue(product->brew_aboil_sg);
+}
+
+
 void EditProduct::brew_aboil_button()
 {
-    brew_volume_calc(product->brew_aboil_volume, product->eq_kettle_volume, product->eq_kettle_height, product->batch_size * 1.04, true);
+    brew_volume_calc(product->brew_aboil_volume + product->eq_chiller_volume,
+		     product->eq_kettle_volume, product->eq_kettle_height,
+		     (product->batch_size * 1.04) + product->eq_chiller_volume,
+		     true, (product->eq_chiller_volume > 0));
 }
 
 

mercurial