src/EditProductTab2.cpp

changeset 189
722a4eed545d
parent 184
da148d6b4c95
child 301
fe6346211b5b
--- a/src/EditProductTab2.cpp	Mon May 02 21:09:48 2022 +0200
+++ b/src/EditProductTab2.cpp	Mon May 02 22:42:19 2022 +0200
@@ -49,3 +49,96 @@
 }
 
 
+void EditProduct::initEquipment()
+{
+    QSqlQuery query;
+
+    ui->eq_selectEdit->addItem("");
+    query.prepare("SELECT name FROM inventory_equipments ORDER BY name");
+    query.exec();
+    while (query.next()) {
+        ui->eq_selectEdit->addItem(query.value(0).toString());
+    }
+    connect(ui->eq_selectEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditProduct::eq_changed);
+
+    showEquipment();
+}
+
+
+void EditProduct::eq_changed(int val)
+{
+    QSqlQuery query;
+
+    if (val == 0)
+	return;
+
+    qDebug() << "equipment changed" << val;
+    query.prepare("SELECT * FROM inventory_equipments ORDER BY name");
+    query.exec();
+    query.first();
+
+    for (int i; i < (val - 1); i++) {
+	query.next();
+    }
+    qDebug() << "got" << query.value("name").toString();
+
+    product->eq_name = query.value("name").toString();
+    product->eq_notes = query.value("notes").toString();
+    product->eq_boil_size = query.value("boil_size").toDouble();
+    product->eq_batch_size = query.value("batch_size").toDouble();
+    product->eq_tun_volume = query.value("tun_volume").toDouble();
+    product->eq_tun_weight = query.value("tun_weight").toDouble();
+    product->eq_tun_specific_heat = query.value("tun_specific_heat").toDouble();
+    product->eq_tun_material = query.value("tun_material").toInt();
+    product->eq_tun_height = query.value("tun_height").toDouble();
+    product->eq_top_up_water = query.value("top_up_water").toDouble();
+    product->eq_trub_chiller_loss = query.value("trub_chiller_loss").toDouble();
+    product->eq_evap_rate = query.value("evap_rate").toDouble();
+    product->eq_boil_time = query.value("boil_time").toDouble();
+    product->eq_calc_boil_volume = query.value("calc_boil_volume").toInt() ? true:false;
+    product->eq_top_up_kettle = query.value("top_up_kettle").toDouble();
+    product->eq_hop_utilization = query.value("hop_utilization").toDouble();
+    product->eq_lauter_volume = query.value("lauter_volume").toDouble();
+    product->eq_lauter_height = query.value("lauter_height").toDouble();
+    product->eq_lauter_deadspace = query.value("lauter_deadspace").toDouble();
+    product->eq_kettle_volume = query.value("kettle_volume").toDouble();
+    product->eq_kettle_height = query.value("kettle_height").toDouble();
+    product->eq_mash_volume = query.value("mash_volume").toDouble();
+    product->eq_mash_max = query.value("mash_max").toDouble();
+    product->eq_efficiency = query.value("efficiency").toDouble();
+    showEquipment();
+
+    /*
+     * Now change some important settings and recalculate the recipe parts.
+     */
+    double factor = product->eq_batch_size / product->batch_size;
+    double estog = product->est_og;
+
+    const QSignalBlocker blocker1(ui->batch_sizeEdit);
+    const QSignalBlocker blocker2(ui->boil_sizeEdit);
+    const QSignalBlocker blocker3(ui->boil_timeEdit);
+    const QSignalBlocker blocker4(ui->efficiencyEdit);
+
+    product->boil_size = product->eq_boil_size;
+    product->boil_time = product->eq_boil_time;
+    product->batch_size = product->eq_batch_size;
+    product->efficiency = product->eq_efficiency;
+    ui->batch_sizeEdit->setValue(product->batch_size);
+    ui->boil_sizeEdit->setValue(product->boil_size);
+    ui->boil_timeEdit->setValue(product->boil_time);
+    ui->efficiencyEdit->setValue(product->efficiency);
+
+    calcFermentablesFromOG(estog);
+    adjustWaters(factor);
+    calcFermentables();
+    adjustHops(factor);
+    adjustMiscs(factor);
+    adjustYeasts(factor);
+    calcIBUs();
+    calcWater();
+    calcMash();
+    is_changed();
+    emit refreshAll();
+}
+
+

mercurial