src/EditProductTab1.cpp

Tue, 03 May 2022 20:05:04 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 03 May 2022 20:05:04 +0200
changeset 190
bb6c06910f0f
parent 189
722a4eed545d
child 204
decbf82ae9a5
permissions
-rw-r--r--

Added calcSupplies() which shows if ingredients are in stock to brew the recipe. In tab 3, changed the fermentables numbers into more readable enum constants. Disable delete and edit buttons in fermentables rows for bottle and kegs sugars. Better mash time calculation in calcFermentables. Added check supplies. Added recalculate volumes. Update inventory when a fermentable is replaced. Added tooltips in brewing salts fields in the miscs table.

/**
 * EditProduct.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 EditProduct::name_changed(QString name)
{
    product->name = name;
    is_changed();
}


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


/*
 * New beerstyle is selected.
 */
void EditProduct::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.
    product->st_name = query.value(1).toString();
    product->st_category = query.value(2).toString();
    product->st_category_number = query.value(3).toInt();
    product->st_letter = query.value(4).toString();
    product->st_guide = query.value(5).toString();
    product->st_type = query.value(6).toInt();
    product->st_og_min = query.value(7).toDouble();
    product->st_og_max = query.value(8).toDouble();
    product->st_fg_min = query.value(9).toDouble();
    product->st_fg_max = query.value(10).toDouble();
    product->st_ibu_min = query.value(11).toDouble();
    product->st_ibu_max = query.value(12).toDouble();
    product->st_color_min = query.value(13).toDouble();
    product->st_color_max = query.value(14).toDouble();
    product->st_carb_min = query.value(15).toDouble();
    product->st_carb_max = query.value(16).toDouble();
    product->st_abv_min = query.value(17).toDouble();
    product->st_abv_max = query.value(18).toDouble();

    ui->st_nameEdit->setText(product->st_name);
    ui->st_groupEdit->setText(product->st_letter);
    ui->st_guideEdit->setText(product->st_guide);
    ui->st_catEdit->setText(product->st_category);
    ui->st_catnrEdit->setText(QString("%1").arg(product->st_category_number));
    ui->st_typeEdit->setText(style_types[product->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 EditProduct::colormethod_changed(int val)
{
    product->color_method = val;
    calcFermentables();
    is_changed();
}


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


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


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


void EditProduct::boil_time_changed(int val)
{
    qDebug() << "boil_time_changed" << val;
    double new_evap = (0.1 * product->batch_size) * val / 60.0;
    product->boil_size = product->batch_size + new_evap;
    product->boil_time = val;
    ui->brew_boilBox->setTitle(tr("Boiling %1 minutes").arg(product->boil_time));
    ui->boil_sizeEdit->setValue(product->boil_size);
    ui->brew_preboilvolShow->setValue(product->boil_size * 1.04);
    calcFermentables();
    calcIBUs();
    is_changed();
}


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

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


void EditProduct::brew_type_changed(int val)
{
    product->type;
    is_changed();
}


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

    if (product->stage < PROD_STAGE_READY)
	return;

    product->locked = val;
    product->stage = val ? PROD_STAGE_CLOSED : PROD_STAGE_READY;
    setStage();
    is_changed();
}


void EditProduct::setStage()
{
    int	 stage = product->stage;
    bool locked = product->locked;

    /*
     * See if we need to set a new stage.
     */
    if ((stage == PROD_STAGE_PLAN) && (product->est_og > 1.005) && (product->est_color > 3) && (product->est_ibu > 3))
	stage = 1;

    if (product->stage != stage) {
	qDebug() << "setStage() change state:" << prod_stages[product->stage] << "to:" << prod_stages[stage];
    	product->stage = stage;
	is_changed();
    } else {
	qDebug() << "setStage() stage:" << prod_stages[stage];
    }

    ui->stageEdit->setText(prod_stages[stage]);

    /* Tab 1, generic */
    ui->typeEdit->setDisabled(stage > PROD_STAGE_WAIT);
    ui->color_methodEdit->setDisabled(locked);
    ui->ibu_methodEdit->setDisabled(locked);
    ui->beerstyleEdit->setDisabled(stage > PROD_STAGE_WAIT);
    ui->nameEdit->setReadOnly(stage > PROD_STAGE_WAIT);
    ui->codeEdit->setReadOnly(stage > PROD_STAGE_WAIT);
    ui->notesEdit->setReadOnly(locked);
    ui->batch_sizeEdit->setReadOnly(stage > PROD_STAGE_WAIT);
    ui->batch_sizeEdit->setButtonSymbols((stage > PROD_STAGE_WAIT) ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->boil_sizeEdit->setReadOnly(stage > PROD_STAGE_WAIT);
    ui->boil_sizeEdit->setButtonSymbols((stage > PROD_STAGE_WAIT) ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->boil_timeEdit->setReadOnly(stage > PROD_STAGE_WAIT);
    ui->boil_timeEdit->setButtonSymbols((stage > PROD_STAGE_WAIT) ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->efficiencyEdit->setReadOnly(stage > PROD_STAGE_WAIT);
    ui->efficiencyEdit->setButtonSymbols((stage > PROD_STAGE_WAIT) ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->est_ogEdit->setReadOnly(stage > PROD_STAGE_WAIT);
    ui->est_ogEdit->setButtonSymbols((stage > PROD_STAGE_WAIT) ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    // Block locked if stage <= PROD_STAGE_TASTE

    /* Tab 2, equipment */
    ui->tabWidget->setTabEnabled(1, stage < PROD_STAGE_BREW);

    /* Tab 3, fermentables */
    ui->est_og2Edit->setReadOnly(stage > PROD_STAGE_WAIT);
    ui->est_og2Edit->setButtonSymbols((stage > PROD_STAGE_WAIT) ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
    ui->addFermentable->setEnabled(stage <= PROD_STAGE_PACKAGE);

    /* Tab 4, hops */
    ui->addHop->setEnabled(stage <= PROD_STAGE_PACKAGE);

    /* Tab 5, miscs */
    ui->addMisc->setEnabled(stage <= PROD_STAGE_PACKAGE);

    /* Tab 6, yeasts */
    ui->addYeast->setEnabled(stage <= PROD_STAGE_PACKAGE);

    /* Tab 7, mash */
    ui->addMash->setEnabled(stage <= PROD_STAGE_BREW);
    ui->mash_nameEdit->setReadOnly(stage > PROD_STAGE_BREW);
    ui->mash_pickEdit->setDisabled(stage > PROD_STAGE_BREW);

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

    /* Tab 9, brewday */
    ui->tabWidget->setTabEnabled(8, stage > PROD_STAGE_PLAN);

    /* Tab 10, fermentation */
    ui->tabWidget->setTabEnabled(9, stage > PROD_STAGE_WAIT);


    /* Tab 11, packaging */
    ui->tabWidget->setTabEnabled(10, stage > PROD_STAGE_PLAN);


    /* Tab 12, tasting */
    ui->tabWidget->setTabEnabled(11, stage > PROD_STAGE_PACKAGE);

}

mercurial