src/EditProductTab2.cpp

Thu, 18 Aug 2022 20:34:15 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 18 Aug 2022 20:34:15 +0200
changeset 401
583148eb6e01
parent 301
fe6346211b5b
child 423
8cb46020796a
permissions
-rw-r--r--

Init est_carb field for new products.

/**
 * EditProduct.cpp is part of bmsapp.
 *
 * Tab 2, equipment settings.
 *
 * bmsapp is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * 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,
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


void EditProduct::showEquipment()
{
    ui->eq_nameEdit->setText(product->eq_name);
    ui->eq_notesEdit->setPlainText(product->eq_notes);

    /* Mashing */
    ui->tun_volumeEdit->setValue(product->eq_tun_volume);
    ui->tun_materialEdit->setText(QCoreApplication::translate("TunMaterial", g_tun_materials[product->eq_tun_material]));
    ui->mash_volumeEdit->setValue(product->eq_mash_volume);
    ui->mash_maxEdit->setValue(product->eq_mash_max);

    /* Lautering */
    ui->lauter_volumeEdit->setValue(product->eq_lauter_volume);
    ui->lauter_deadspaceEdit->setValue(product->eq_lauter_deadspace);

    /* Boiling */
    ui->kettle_volumeEdit->setValue(product->eq_kettle_volume);
    ui->eqboil_sizeEdit->setValue(product->eq_boil_size);
    ui->evap_rateEdit->setValue(product->eq_evap_rate);
    ui->eqboil_timeEdit->setValue(product->eq_boil_time);
    ui->topup_kettleEdit->setValue(product->eq_top_up_kettle);
    ui->hop_utilizationEdit->setValue(product->eq_hop_utilization);
    ui->eqbatch_sizeEdit->setValue(product->eq_batch_size);
    ui->eq_efficiencyEdit->setValue(product->eq_efficiency);

    /* Chilling */
    ui->trub_chillerlossEdit->setValue(product->eq_trub_chiller_loss);
    ui->topup_waterEdit->setValue(product->eq_top_up_water);
}


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