# HG changeset patch # User Michiel Broek # Date 1654266738 -7200 # Node ID d130385c1b0d6b2cbf30ce4df2061eba8278eb15 # Parent 73b734edd03484cdd077ae0f45919915ba57ce20 Copy recipe to duplicated recipe added. Copy recipe to product added. Added popup with export choices. diff -r 73b734edd034 -r d130385c1b0d src/EditRecipe.cpp --- a/src/EditRecipe.cpp Thu Jun 02 22:41:18 2022 +0200 +++ b/src/EditRecipe.cpp Fri Jun 03 16:32:18 2022 +0200 @@ -21,6 +21,7 @@ #include "Utils.h" #include "global.h" #include "database/db_recipe.h" +#include "database/db_product.h" EditRecipe::EditRecipe(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditRecipe) diff -r 73b734edd034 -r d130385c1b0d src/EditRecipe.h --- a/src/EditRecipe.h Thu Jun 02 22:41:18 2022 +0200 +++ b/src/EditRecipe.h Fri Jun 03 16:32:18 2022 +0200 @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -177,6 +178,10 @@ double decoctionVol(double step_volume, double step_temp, double prev_temp); void calcMash(); void adjustWaters(double factor); + void exportBeerXML(); + void copyRecipe(); + void copyProduct(); + void toforumRecipe(); }; #endif diff -r 73b734edd034 -r d130385c1b0d src/EditRecipeExport.cpp --- a/src/EditRecipeExport.cpp Thu Jun 02 22:41:18 2022 +0200 +++ b/src/EditRecipeExport.cpp Fri Jun 03 16:32:18 2022 +0200 @@ -18,10 +18,8 @@ */ -void EditRecipe::on_exportButton_clicked() +void EditRecipe::exportBeerXML() { - qDebug() << "export"; - const QStringList styletype({ "Lager", "Ale", "Mead", "Wheat", "Mixed", "Cider" }); const QStringList recipetypes({ "Extract", "Partial Mash", "All Grain" }); const QStringList color_method({ "Morey", "Mosher", "Daniels", "Halberstadt", "Naudts" }); @@ -262,6 +260,235 @@ } +void EditRecipe::copyRecipe() +{ + Recipe *dup = new Recipe; + + dup = recipe; + dup->record = -1; + dup->uuid = ""; + qDebug() << dup->record << dup->name; + if (DB_recipe::save(dup, this)) { + QMessageBox::information(this, tr("Copy Recipe"), tr("Copy Recipe export ready.")); + } else { + QMessageBox::warning(this, tr("Copy Recipe"), tr("Copy Recipe error.")); + } + delete dup; +} + + +void EditRecipe::copyProduct() +{ + Product *p = new Product; + + p->record = -1; + p->name = recipe->name + QString(" [duplicate]"); + p->code = ""; + p->birth = QDate::currentDate(); + p->stage = p->inventory_reduced = PROD_STAGE_PLAN; + p->notes = recipe->notes; + p->log_brew = p->log_fermentation = p->log_ispindel = p->log_co2pressure = p->locked = false; + + p->st_name = recipe->st_name; + p->st_letter = recipe->st_letter; + p->st_guide = recipe->st_guide; + p->st_category = recipe->st_category; + p->st_category_number = recipe->st_category_number; + p->st_type = recipe->st_type; + p->st_og_min = recipe->st_og_min; + p->st_og_max = recipe->st_og_max; + p->st_fg_min = recipe->st_fg_min; + p->st_fg_max = recipe->st_fg_max; + p->st_ibu_min = recipe->st_ibu_min; + p->st_ibu_max = recipe->st_ibu_max; + p->st_color_min = recipe->st_color_min; + p->st_color_max = recipe->st_color_max; + p->st_carb_min = recipe->st_carb_min; + p->st_carb_max = recipe->st_carb_max; + p->st_abv_min = recipe->st_abv_min; + p->st_abv_max = recipe->st_abv_max; + + p->eq_name = QString("Not yet set"); + p->eq_notes = QString(""); + p->eq_tun_specific_heat = 0.11; + p->eq_tun_material = 0; + p->eq_tun_volume = p->eq_tun_height = 20; + p->eq_tun_weight = 2; + p->eq_top_up_water = 0; + p->eq_trub_chiller_loss = 0.5; + p->eq_evap_rate = 1.8; + p->eq_calc_boil_volume = true; + p->eq_top_up_kettle = 0; + p->eq_hop_utilization = 100; + p->eq_lauter_volume = p->eq_lauter_height = p->eq_kettle_volume = p->eq_kettle_height = p->eq_mash_volume = 20; + p->eq_lauter_deadspace = 0.5; + p->eq_mash_max = 6; + p->eq_efficiency = p->efficiency = recipe->efficiency; + p->eq_batch_size = p->batch_size = recipe->batch_size; + p->eq_boil_time = p->boil_time = recipe->boil_time; + p->eq_boil_size = p->boil_size = p->batch_size + (round(p->batch_size * p->boil_time / 60.0) / 10.0); + p->type = 2; + p->color_method = recipe->color_method; + p->ibu_method = recipe->ibu_method; + p->est_og = recipe->est_og; + p->est_fg = recipe->est_fg; + p->est_color = recipe->est_color; + p->est_ibu = recipe->est_ibu; + p->est_abv = recipe->est_abv; + + p->brew_date_start = p->brew_date_end = QDateTime(); + p->brew_mash_ph = p->brew_mash_sg = p->brew_mash_efficiency = 0; + p->brew_sparge_temperature = p->brew_sparge_volume = p->brew_sparge_est = p->brew_sparge_ph = 0; + p->brew_preboil_volume = p->brew_preboil_sg = p->brew_preboil_ph = p->brew_preboil_efficiency = 0; + p->brew_aboil_volume = p->brew_aboil_sg = p->brew_aboil_ph = p->brew_aboil_efficiency = 0; + p->brew_cooling_method = p->brew_cooling_time = 0; + p->brew_cooling_to = 20; + p->brew_whirlpool9 = p->brew_whirlpool7 = p->brew_whirlpool6 = p->brew_whirlpool2 = 0; + p->brew_fermenter_volume = p->brew_fermenter_extrawater = p->brew_fermenter_tcloss = 0; + p->brew_aeration_time = p->brew_aeration_speed = p->brew_aeration_type = 0; + p->brew_fermenter_sg = p->brew_fermenter_ibu = p->brew_fermenter_color = 0; + + p->og = p->fg = 0; + p->primary_start_temp = p->primary_max_temp = p->primary_end_temp = p->primary_end_sg = 0; + p->primary_end_date = p->secondary_end_date = QDate(); + p->secondary_temp = p->secondary_end_sg = p->tertiary_temp = 0; + p->package_date = QDate(); + p->package_volume = p->package_infuse_amount = p->package_infuse_abv = p->package_abv = p->package_ph = 0; + p->package_infuse_notes = ""; + p->bottle_amount = p->bottle_carbonation = p->bottle_priming_amount = p->bottle_carbonation_temp = 0; + p->keg_amount = p->keg_carbonation = p->keg_priming_amount = p->keg_carbonation_temp = 0; + p->keg_pressure = 0; + p->bottle_priming_water = p->keg_priming_water = 0; + p->bottle_priming_sugar = p->keg_priming_sugar = 0; + p->taste_rate = 0; + p->taste_date = QDate(); + p->taste_notes = p->taste_color = p->taste_transparency = p->taste_head = ""; + p->taste_aroma = p->taste_taste = p->taste_mouthfeel = p->taste_aftertaste = ""; + + p->sparge_temp = 80; + p->sparge_ph = 5.4; + p->sparge_volume = 8; + p->sparge_source = 0; + p->sparge_acid_type = 0; + p->sparge_acid_perc = 80; + p->sparge_acid_amount = 0; + p->mash_ph = 5.4; + p->mash_name = ""; + + p->calc_acid = true; + p->w1_name = recipe->w1_name; + p->w1_amount = recipe->w1_amount; + p->w1_calcium = recipe->w1_calcium; + p->w1_sulfate = recipe->w1_sulfate; + p->w1_chloride = recipe->w1_chloride; + p->w1_sodium = recipe->w1_sodium; + p->w1_magnesium = recipe->w1_magnesium; + p->w1_total_alkalinity = recipe->w1_total_alkalinity; + p->w1_ph = recipe->w1_ph; + p->w2_name = recipe->w2_name; + p->w2_amount = recipe->w2_amount; + p->w2_calcium = recipe->w2_calcium; + p->w2_sulfate = recipe->w2_sulfate; + p->w2_chloride = recipe->w2_chloride; + p->w2_sodium = recipe->w2_sodium; + p->w2_magnesium = recipe->w2_magnesium; + p->w2_total_alkalinity = recipe->w2_total_alkalinity; + p->w2_ph = recipe->w2_ph; + p->wg_amount = recipe->wg_amount; + p->wg_calcium = recipe->wg_calcium; + p->wg_sulfate = recipe->wg_sulfate; + p->wg_chloride = recipe->wg_chloride; + p->wg_sodium = recipe->wg_sodium; + p->wg_magnesium = recipe->wg_magnesium; + p->wg_total_alkalinity = recipe->wg_total_alkalinity; + p->wg_ph = recipe->wg_ph; + p->wb_calcium = recipe->wb_calcium; + p->wb_sulfate = recipe->wb_sulfate; + p->wb_chloride = recipe->wb_chloride; + p->wb_sodium = recipe->wb_sodium; + p->wb_magnesium = recipe->wb_magnesium; + p->wb_total_alkalinity = recipe->wb_total_alkalinity; + p->wb_ph = recipe->wb_ph; + p->wa_acid_name = recipe->wa_acid_name; + p->wa_acid_perc = recipe->wa_acid_perc; + p->wa_base_name = recipe->wa_base_name; + + p->starter_enable = false; + p->starter_type = p->prop_type[0] = p->prop_type[1] = p->prop_type[2] = p->prop_type[3] = 0; + p->starter_viability = 100; + p->starter_sg = 1.037; + p->yeast_prod_date = QDate(); + p->yeast_pitchrate = p->prop_volume[0] = p->prop_volume[1] = p->prop_volume[2] = p->prop_volume[3] = 0; + p->divide_type = p->divide_parts = p->divide_part = 0; + p->divide_size = p->divide_factor = 0; + + p->fermentables = recipe->fermentables; + p->hops = recipe->hops; + p->miscs = recipe->miscs; + p->yeasts = recipe->yeasts; + p->mashs = recipe->mashs; + + if (DB_product::save(p, this)) { + QMessageBox::information(this, tr("Copy Recipe"), tr("Copy Recipe to Product ready.")); + } else { + QMessageBox::warning(this, tr("Copy Recipe"), tr("Copy Recipe to Product error.")); + } + delete p; +} + + +void EditRecipe::toforumRecipe() { } + +void EditRecipe::on_exportButton_clicked() +{ + QDialog* dialog = new QDialog(this); + dialog->setWindowTitle(tr("Export choices")); + dialog->setObjectName(QString::fromUtf8("Dialog")); + dialog->resize(400, 149); + QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); + buttonBox->setObjectName(QString::fromUtf8("buttonBox")); + buttonBox->setGeometry(QRect(280, 20, 81, 61)); + buttonBox->setOrientation(Qt::Vertical); + buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + + QRadioButton *beerxmlButton = new QRadioButton(dialog); + beerxmlButton->setObjectName(QString::fromUtf8("beerxmlButton")); + beerxmlButton->setGeometry(QRect(50, 20, 171, 21)); + beerxmlButton->setText(tr("Export to beerXML")); + + QRadioButton *copy_recipeButton = new QRadioButton(dialog); + copy_recipeButton->setObjectName(QString::fromUtf8("copy_recipeButton")); + copy_recipeButton->setGeometry(QRect(50, 50, 171, 21)); + copy_recipeButton->setText(tr("Copy to recipe")); + + QRadioButton *copy_productButton = new QRadioButton(dialog); + copy_productButton->setObjectName(QString::fromUtf8("copy_productButton")); + copy_productButton->setGeometry(QRect(50, 80, 171, 21)); + copy_productButton->setText(tr("Copy to product")); + + QRadioButton *toforumButton = new QRadioButton(dialog); + toforumButton->setObjectName(QString::fromUtf8("toforumButton")); + toforumButton->setGeometry(QRect(50, 110, 171, 21)); + toforumButton->setText(tr("Export to forum")); + + QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); + QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); + + dialog->setModal(true); + dialog->exec(); + if (dialog->result() == QDialog::Accepted) { + if (beerxmlButton->isChecked()) + exportBeerXML(); + if (copy_recipeButton->isChecked()) + copyRecipe(); + if (copy_productButton->isChecked()) + copyProduct(); + } + + disconnect(buttonBox, nullptr, nullptr, nullptr); +} + + void EditRecipe::on_printButton_clicked() { PrinterDialog(PR_RECIPE, -1, this);