src/EditRecipeTab1.cpp

Thu, 18 Aug 2022 16:11:20 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 18 Aug 2022 16:11:20 +0200
changeset 397
877420a13815
parent 395
7212b980a527
child 407
c2166b972811
permissions
-rw-r--r--

Edit Product, split CO2 package pressure in bottles and kegs. BU:RE code cleanup. calcPack() sets the CO2 values on the first tab. Show final EBC on tab 1 if the stage is after brew. Show final ABV and energy on tab 1 if fermentation is done. Removed wrong bottle priming calculation from calcFermentables() because calcPack() does this.

/**
 * EditRecipe.cpp is part of bmsapp.
 *
 * Tab 1, generic 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 EditRecipe::calcStyle()
{
    /*
     * https://www.homebrewersassociation.org/forum/index.php?topic=10548.0
     *
     * Calculate the ideal BU:GU and BU:RE ranges. These values
     * will be used in the RangedSliders.
     */
    double bugu_min = recipe->st_ibu_min / ((recipe->st_og_min - 1) * 1000);
    double bugu_max = recipe->st_ibu_max / ((recipe->st_og_max - 1) * 1000);
    ui->est_buguShow->setRange(bugu_min, bugu_max);

    double fg_min = recipe->st_fg_min;
    if (fg_min < 1.002)                /* Use 1.002 fg as lowest minimal value */
       fg_min = 1.002;

    /*
     * Real Extract (RE)
     */
    double re = ((0.1808 * ((Utils::sg_to_plato(recipe->st_og_min) + Utils::sg_to_plato(recipe->st_og_max)) / 2)) +
                (0.8192 * ((Utils::sg_to_plato(fg_min) + Utils::sg_to_plato(recipe->st_fg_max)) / 2)));

    /*
     * BU:RE
     * Divide over average RE gives the best ranges.
     */
    double bure_min = recipe->st_ibu_min / re;
    double bure_max = recipe->st_ibu_max / re;
    ui->est_bufguShow->setRange(bure_min, bure_max);
}


void EditRecipe::name_changed(QString name)
{
    recipe->name = name;
    is_changed();
}


void EditRecipe::notes_changed()
{
    /* The text cannot be passed in a simple way :) */
    recipe->notes = ui->notesEdit->toPlainText();
    is_changed();
}


/*
 * New beerstyle is selected.
 */
void EditRecipe::style_changed(int val)
{
    QSqlQuery query;

    query.prepare("SELECT * FROM profile_styles ORDER BY style_guide,style_letter,name");
    query.exec();
    query.first();
    // Skip to the record index.
    for (int i = 0; i < (val - 1); i++) {
        query.next();
    }
    // Set relevant fields and update ranges.
    recipe->st_name = query.value(1).toString();
    recipe->st_category = query.value(2).toString();
    recipe->st_category_number = query.value(3).toInt();
    recipe->st_letter = query.value(4).toString();
    recipe->st_guide = query.value(5).toString();
    recipe->st_type = query.value(6).toInt();
    recipe->st_og_min = query.value(7).toDouble();
    recipe->st_og_max = query.value(8).toDouble();
    recipe->st_fg_min = query.value(9).toDouble();
    recipe->st_fg_max = query.value(10).toDouble();
    recipe->st_ibu_min = query.value(11).toDouble();
    recipe->st_ibu_max = query.value(12).toDouble();
    recipe->st_color_min = query.value(13).toDouble();
    recipe->st_color_max = query.value(14).toDouble();
    recipe->st_carb_min = query.value(15).toDouble();
    recipe->st_carb_max = query.value(16).toDouble();
    recipe->st_abv_min = query.value(17).toDouble();
    recipe->st_abv_max = query.value(18).toDouble();

    ui->st_nameEdit->setText(recipe->st_name);
    ui->st_groupEdit->setText(recipe->st_letter);
    ui->st_guideEdit->setText(recipe->st_guide);
    ui->st_catEdit->setText(recipe->st_category);
    ui->st_catnrEdit->setText(QString("%1").arg(recipe->st_category_number));
    ui->st_typeEdit->setText(QCoreApplication::translate("BeerType", g_style_types[recipe->st_type]));

    ui->est_ogShow->setRange(query.value(7).toDouble(), query.value(8).toDouble());
    ui->est_fgShow->setRange(query.value(9).toDouble(), query.value(10).toDouble());
    ui->est_ibuShow->setRange(query.value(11).toDouble(), query.value(12).toDouble());
    ui->est_colorShow->setRange(query.value(13).toDouble(), query.value(14).toDouble());
    ui->est_carbShow->setRange(query.value(15).toDouble(), query.value(16).toDouble());
    ui->est_abvShow->setRange(query.value(17).toDouble(), query.value(18).toDouble());

    calcStyle();
    is_changed();
}


void EditRecipe::colormethod_changed(int val)
{
    recipe->color_method = val;
    calcFermentables();
    is_changed();
}


void EditRecipe::ibumethod_changed(int val)
{
    recipe->ibu_method = val;
    calcIBUs();
    is_changed();
}


void EditRecipe::est_og_changed(double val)
{
    recipe->est_og = val;
    calcFermentablesFromOG(val);// Adjust fermentables amounts
    calcFermentables();		// Update the recipe details
    calcIBUs();
    calcMash();
    is_changed();
    emit refreshAll();
}


void EditRecipe::efficiency_changed(double val)
{
    double estog = recipe->est_og;
    recipe->efficiency = val;
    calcFermentablesFromOG(estog);
    calcFermentables();
    calcIBUs();
    is_changed();
    emit refreshAll();
}


void EditRecipe::boil_time_changed(int val)
{
    qDebug() << "boil_time_changed" << val;
    double new_evap = (0.1 * recipe->batch_size) * val / 60.0;
    recipe->boil_size = recipe->batch_size + new_evap;
    recipe->boil_time = val;
    ui->boil_sizeEdit->setValue(recipe->boil_size);
    calcFermentables();
    calcIBUs();
    is_changed();
}


void EditRecipe::batch_size_changed(double val)
{
    qDebug() << "batch_size_changed" << val << "old" << recipe->batch_size;

    double evap = (0.1 * val) * recipe->boil_time / 60.0;
    recipe->boil_size = val + evap;
    double factor = val / recipe->batch_size;
    ui->boil_sizeEdit->setValue(recipe->boil_size);
    recipe->sparge_volume *= factor;
    ui->sp_volEdit->setValue(recipe->sparge_volume);
    recipe->batch_size = val;
    calcFermentablesFromOG(recipe->est_og);	// Keep the OG
    adjustWaters(factor);
    calcFermentables();
    adjustHops(factor);
    adjustMiscs(factor);
    adjustYeasts(factor);
    calcIBUs();
    calcWater();
    calcMash();
    is_changed();
    emit refreshAll();
}


void EditRecipe::brew_type_changed(int val)
{
    recipe->type;
    is_changed();
}


void EditRecipe::locked_changed(bool val)
{
    qDebug() << "locked_changed" << val;

    recipe->locked = val;
    setLocked(val);
    is_changed();
}


void EditRecipe::setLocked(bool val)
{
    /* Tab 1, generic */
    ui->typeEdit->setDisabled(val);
    ui->color_methodEdit->setDisabled(val);
    ui->ibu_methodEdit->setDisabled(val);
    ui->beerstyleEdit->setDisabled(val);
    ui->nameEdit->setReadOnly(val);
    ui->notesEdit->setReadOnly(val);
    ui->batch_sizeEdit->setReadOnly(val);
    ui->batch_sizeEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->boil_sizeEdit->setReadOnly(val);
    ui->boil_sizeEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->boil_timeEdit->setReadOnly(val);
    ui->boil_timeEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->efficiencyEdit->setReadOnly(val);
    ui->efficiencyEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->est_ogEdit->setReadOnly(val);
    ui->est_ogEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);

    /* Tab 2, fermentables */
    ui->est_og2Edit->setReadOnly(val);
    ui->est_og2Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->addFermentable->setEnabled(! val);

    /* Tab 3, hops */
    ui->addHop->setEnabled(! val);

    /* Tab 4, miscs */
    ui->addMisc->setEnabled(! val);

    /* Tab 5, yeasts */
    ui->addYeast->setEnabled(! val);

    /* Tab 6, mash */
    ui->addMash->setEnabled(! val);
    ui->mash_nameEdit->setReadOnly(val);
    ui->mash_pickEdit->setDisabled(val);

    /* Tab 7, water */
    ui->wt_sourceEdit->setDisabled(val);
    ui->w1_nameEdit->setDisabled(val);
    ui->w2_nameEdit->setDisabled(val);
    ui->mw_acidPick->setDisabled(val);
    ui->sp_acidtypeEdit->setDisabled(val);
    ui->w2_volEdit->setReadOnly(val);
    ui->w2_volEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->sp_volEdit->setReadOnly(val);
    ui->sp_volEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->bs_cacl2Edit->setReadOnly(val);
    ui->bs_cacl2Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->bs_caso4Edit->setReadOnly(val);
    ui->bs_caso4Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->bs_mgso4Edit->setReadOnly(val);
    ui->bs_mgso4Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->bs_naclEdit->setReadOnly(val);
    ui->bs_naclEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->bs_mgcl2Edit->setReadOnly(val);
    ui->bs_mgcl2Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->bs_nahco3Edit->setReadOnly(val);
    ui->bs_nahco3Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->bs_caco3Edit->setReadOnly(val);
    ui->bs_caco3Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    if (val) {
    	ui->mw_phEdit->setReadOnly(true);
	ui->mw_phEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
	ui->mw_acidvolEdit->setReadOnly(true);
	ui->mw_acidvolEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
	ui->sp_phEdit->setReadOnly(true);
	ui->sp_phEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
	ui->sp_acidvolEdit->setReadOnly(true);
	ui->sp_acidvolEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
    } else {
    	ui->mw_phEdit->setReadOnly(! recipe->calc_acid);
    	ui->mw_phEdit->setButtonSymbols(recipe->calc_acid ? QAbstractSpinBox::UpDownArrows : QAbstractSpinBox::NoButtons);
    	ui->mw_acidvolEdit->setReadOnly(recipe->calc_acid);
    	ui->mw_acidvolEdit->setButtonSymbols(recipe->calc_acid ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
	ui->sp_phEdit->setReadOnly(! recipe->calc_acid);
	ui->sp_phEdit->setButtonSymbols(recipe->calc_acid ? QAbstractSpinBox::UpDownArrows : QAbstractSpinBox::NoButtons);
	ui->sp_acidvolEdit->setReadOnly(recipe->calc_acid);
	ui->sp_acidvolEdit->setButtonSymbols(recipe->calc_acid ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    }
    ui->mw_autoEdit->setDisabled(val);
    setButtons(val);
}

mercurial