src/EditRecipeTab1.cpp

Sat, 23 Apr 2022 13:18:47 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 23 Apr 2022 13:18:47 +0200
changeset 154
1af9f7b7f317
parent 150
fd568cc1dd0e
child 171
6cd2d808d863
permissions
-rw-r--r--

Moved QStringList arrays to global.

/**
 * 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::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(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());

    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();
    //calcSparge();
    calcMash();
    is_changed();
    emit refreshAll();
}


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

mercurial