Wed, 06 Apr 2022 20:26:47 +0200
Fermentables are loaded in the main recipe record in a QList. The refresh table function does the sorting, on added moment (mash first), amount and finally color of the malt. Removed the old hidden table columns. Do all manipulation on the recipe record with QList arrays. The ferment_amount_changed() slot is complete. The whole recipe editor is going in the right direction.
#ifndef _EDITRECIPE_H #define _EDITRECIPE_H #include <QDialog> #include <QStringList> #include <QJsonDocument> #include <QJsonObject> #include <QDoubleSpinBox> #include <QCheckBox> #include <QComboBox> #include <QLineEdit> #include <QDialogButtonBox> #include <QList> /* * Fermentables, Hops, Miscs, Yeasts and Mashs are stored in the * database in json arrays. These are the QList structures. */ struct Fermentables { QString f_name; QString f_origin; QString f_supplier; double f_amount; double f_cost; int f_type; double f_yield; double f_color; double f_coarse_fine_diff; double f_moisture; double f_diastatic_power; double f_protein; double f_dissolved_protein; double f_max_in_batch; int f_graintype; int f_added; bool f_recommend_mash; bool f_add_after_boil; bool f_adjust_to_total_100; double f_percentage; double f_di_ph; double f_acid_to_ph_57; }; struct Hops { QString h_name; QString h_origin; double h_amount; double h_cost; int h_type; int h_form; int h_useat; double h_time; double h_alpha; double h_beta; double h_hsi; double h_humulene; double h_caryophyllene; double h_cohumulone; double h_myrcene; double h_total_oil; }; struct Miscs { QString m_name; double m_amount; int m_type; int m_use_use; int m_time; bool m_amount_is_weight; double m_cost; }; struct Yeasts { QString y_name; QString y_laboratory; QString y_product_id; double y_amount; int y_type; int y_form; double y_min_temperature; double y_max_temperature; int y_flocculation; double y_attenuation; double y_cells; double y_tolerance; double y_inventory; int y_use; bool y_sta1; bool y_bacteria; bool y_harvest_top; double y_harvest_time; double y_pitch_temperature; bool y_pofpos; int y_zymocide; double y_gr_hl_lo; double y_sg_lo; double y_gr_hl_hi; double y_sg_hi; double y_cost; }; struct Mashs { QString step_name; int step_type; double step_volume; // May not be present double step_infuse_amount; // May not be present double step_infuse_temp; // May not be present double step_temp; double step_time; double ramp_time; double end_temp; double step_wg_ratio; // May not be present }; /* * The main recipe record stored in the database. */ struct Recipe { int record; QString uuid; bool locked; QString st_name; QString st_letter; QString st_guide; QString st_category; int st_category_number; int st_type; double st_og_min; double st_og_max; double st_fg_min; double st_fg_max; double st_ibu_min; double st_ibu_max; double st_color_min; double st_color_max; double st_carb_min; double st_carb_max; double st_abv_min; double st_abv_max; QString name; QString notes; int type; double batch_size; double boil_size; double boil_time; double efficiency; double est_og; double est_fg; double est_abv; double est_color; int color_method; double est_ibu; int ibu_method; double est_carb; double sparge_temp; double sparge_ph; double sparge_volume; int sparge_source; int sparge_acid_type; double sparge_acid_perc; double sparge_acid_amount; double mash_ph; QString mash_name; bool calc_acid; QString w1_name; ///< Water source 1 double w1_amount; double w1_calcium; double w1_sulfate; double w1_chloride; double w1_sodium; double w1_magnesium; double w1_total_alkalinity; double w1_ph; double w1_cost; QString w2_name; ///< Water source 2 double w2_amount; double w2_calcium; double w2_sulfate; double w2_chloride; double w2_sodium; double w2_magnesium; double w2_total_alkalinity; double w2_ph; double w2_cost; double wg_amount; ///< Mixed water double wg_calcium; double wg_sulfate; double wg_chloride; double wg_sodium; double wg_magnesium; double wg_total_alkalinity; double wg_ph; double wb_calcium; ///< Treated water double wb_sulfate; double wb_chloride; double wb_sodium; double wb_magnesium; double wb_total_alkalinity; double wb_ph; double wa_acid_name; double wa_acid_perc; double wa_base_name; QList<Fermentables> fermentables; QList<Hops> hops; QList<Miscs> miscs; QList<Yeasts> yeasts; QList<Mashs> mashs; /* * These are not in the MySL database, but are global variables * that belong with the loaded recipe data and are present to * make things easier. */ int fermentables_current; ///< Current record, -1 is invalid. bool fermentables_use100; ///< Use percentages instead of amount int hops_current; int misc_current; int yeasts_current; int mashs_current; }; namespace Ui { class EditRecipe; } class EditRecipe : public QDialog { Q_OBJECT signals: void entry_changed(); public: explicit EditRecipe(int id, QWidget *parent = 0); ~EditRecipe(); private slots: void on_saveButton_clicked(); void on_quitButton_clicked(); void on_deleteButton_clicked(); void is_changed(); void style_changed(); void colormethod_changed(); void refreshFermentables(); void refreshHops(); void refreshMiscs(); void refreshYeasts(); void refreshMashs(); void refreshAll(); void ferment_amount_changed(double val); void ferment_pct_changed(double val); void on_deleteFermentRow_clicked(); void on_editFermentRow_clicked(); void on_perc_mash_valueChanged(int value); void on_perc_sugars_valueChanged(int value); void on_perc_cara_valueChanged(int value); void on_lintner_valueChanged(int value); private: Ui::EditRecipe *ui; QStringList s_types = { tr("Lager"), tr("Ale"), tr("Mead"), tr("Wheat"), tr("Mixed"), tr("Cider") }; QStringList f_types = { tr("Grain"), tr("Sugar"), tr("Extract"), tr("Dry extract"), tr("Adjunct") }; QStringList f_graintypes = { tr("Base"), tr("Roast"), tr("Crystal"), tr("Kilned"), tr("Sour Malt"), tr("Special"), tr("No malt")}; QStringList f_added = { tr("Mash"), tr("Boil"), tr("Fermentation"), tr("Lagering"), tr("Bottle"), tr("Kegs") }; QString bar_red = "QProgressBar::chunk {background: #FF0000;}"; QString bar_orange = "QProgressBar::chunk {background: #EB7331;}"; QString bar_green = "QProgressBar::chunk {background: #008C00;}"; int recno, editrow; bool textIsChanged = false; bool ignoreChanges = false; Recipe *recipe; /* * Variables for popup ingredients editing. */ QJsonDocument hops, miscs, yeasts; QComboBox *selectEdit, *addedEdit; QLineEdit *nameEdit, *supplierEdit; QDoubleSpinBox *amountEdit, *pctEdit, *maxEdit; QCheckBox *to100Edit, *instockEdit; static bool ferment_sort_test(const Fermentables &D1, const Fermentables &D2); void WindowTitle(); void fermentable_Json(); void calcFermentables(); }; #endif