Fri, 20 May 2022 22:06:06 +0200
Version 0.2.1. Updated translations.
157 | 1 | /** |
2 | * EditRecipe.cpp is part of bmsapp. | |
3 | * | |
4 | * Export recipe. | |
5 | * | |
6 | * bmsapp is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * bmsapp is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | ||
21 | void EditRecipe::on_exportButton_clicked() | |
22 | { | |
23 | qDebug() << "export"; | |
24 | ||
25 | const QStringList styletype({ "Lager", "Ale", "Mead", "Wheat", "Mixed", "Cider" }); | |
26 | const QStringList recipetypes({ "Extract", "Partial Mash", "All Grain" }); | |
27 | const QStringList color_method({ "Morey", "Mosher", "Daniels", "Halberstadt", "Naudts" }); | |
28 | const QStringList ibu_method({ "Tinseth", "Rager", "Daniels", "Garetz", "Mosher", "Noonan" }); | |
29 | const QStringList hop_types({ "Bittering", "Aroma", "Both" }); | |
30 | const QStringList hop_forms({ "Pellet", "Plug", "Leaf", "Leaf", "Pellet" }); | |
31 | /* "Leaf Wet", "Cryo" */ | |
32 | /* We use more hop forms then beerxml knows about, so we send known names */ | |
33 | /* instead of what we internally use. */ | |
34 | const QStringList hop_use({ "Mash", "First wort", "Boil", "Aroma", "Whirlpool", "Dry hop" }); | |
35 | const QStringList fermentable_type({ "Grain", "Sugar", "Extract", "Dry extract", "Adjunct" }); | |
36 | const QStringList fermentable_graintype({ "Base", "Roast", "Crystal", "Kilned", "Sour malt", "Special", "No malt" }); | |
37 | const QStringList yeast_type({ "Lager", "Ale", "Wheat", "Wine", "Champagne", "Other", "Other", "Other", "Other", "Other" }); | |
38 | const QStringList yeast_form({ "Liquid", "Dry", "Slant", "Culture", "Frozen", "Bottle", "Dry" }); | |
39 | const QStringList yeast_use({ "Primary", "Secondary", "Tertiary", "Bottle" }); | |
40 | const QStringList misc_type({ "Spice", "Herb", "Flavor", "Fining", "Water agent", "Yeast nutrient", "Other" }); | |
41 | const QStringList misc_use({ "Starter", "Mash", "Boil", "Primary", "Secondary", "Bottling" }); | |
42 | const QStringList step_type({ "Infusion", "Temperature", "Decoction" }); | |
43 | ||
44 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QDir::homePath() + "/" + recipe->name + ".xml", tr("Files (*.xml)")); | |
45 | if (fileName == 0) { | |
46 | QMessageBox::warning(this, tr("Save File"), tr("No XML file selected.")); | |
47 | return; | |
48 | } | |
49 | ||
50 | QFile file(fileName); | |
51 | file.open(QIODevice::WriteOnly); | |
52 | ||
53 | QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(&file); | |
54 | xmlWriter->writeStartDocument(); | |
55 | xmlWriter->setAutoFormatting(true); | |
56 | xmlWriter->setAutoFormattingIndent(1); | |
57 | ||
58 | xmlWriter->writeStartElement("RECIPES"); | |
59 | xmlWriter->writeStartElement("RECIPE"); | |
60 | /* | |
61 | * Recipe basics | |
62 | */ | |
63 | xmlWriter->writeTextElement("VERSION", "1"); | |
64 | xmlWriter->writeTextElement("NAME", recipe->name); | |
65 | if (recipe->notes != "") | |
66 | xmlWriter->writeTextElement("NOTES", recipe->notes); | |
67 | xmlWriter->writeTextElement("TYPE", recipetypes[recipe->type]); | |
68 | xmlWriter->writeTextElement("BREWER", "Anonymous"); | |
69 | xmlWriter->writeTextElement("BATCH_SIZE", QString::number(recipe->batch_size, 'f', 4)); | |
70 | xmlWriter->writeTextElement("BOIL_SIZE", QString::number(recipe->boil_size, 'f', 4)); | |
71 | xmlWriter->writeTextElement("BOIL_TIME", QString::number(recipe->boil_time, 'f', 3)); | |
72 | xmlWriter->writeTextElement("EFFICIENCY", QString::number(recipe->efficiency, 'f', 4)); | |
73 | xmlWriter->writeTextElement("EST_OG", QString::number(recipe->est_og, 'f', 3)); | |
74 | xmlWriter->writeTextElement("EST_FG", QString::number(recipe->est_fg, 'f', 3)); | |
75 | if (recipe->est_abv > 0) | |
76 | xmlWriter->writeTextElement("EST_ABV", QString::number(recipe->est_abv, 'f', 1)); | |
77 | if (recipe->est_color > 0) { | |
78 | xmlWriter->writeTextElement("EST_COLOR", QString::number(Utils::ebc_to_srm(recipe->est_color), 'f', 6)); | |
79 | xmlWriter->writeTextElement("COLOR_METHOD", color_method[recipe->color_method]); | |
80 | } | |
81 | if (recipe->est_ibu > 0) { | |
82 | xmlWriter->writeTextElement("EST_IBU", QString::number(recipe->est_ibu, 'f', 1)); | |
83 | xmlWriter->writeTextElement("IBU_METHOD", ibu_method[recipe->ibu_method]); | |
84 | } | |
85 | ||
86 | xmlWriter->writeStartElement("STYLE"); | |
87 | xmlWriter->writeTextElement("VERSION", "1"); | |
88 | xmlWriter->writeTextElement("NAME", recipe->st_name); | |
89 | xmlWriter->writeTextElement("CATEGORY", recipe->st_category); | |
90 | xmlWriter->writeTextElement("CATEGORY_NUMBER", QString::number(recipe->st_category_number, 'f', 0)); | |
91 | xmlWriter->writeTextElement("STYLE_LETTER", recipe->st_letter); | |
92 | xmlWriter->writeTextElement("STYLE_GUIDE", recipe->st_guide); | |
93 | xmlWriter->writeTextElement("TYPE", styletype[recipe->st_type]); | |
94 | xmlWriter->writeTextElement("OG_MIN", QString::number(recipe->st_og_min, 'f', 3)); | |
95 | xmlWriter->writeTextElement("OG_MAX", QString::number(recipe->st_og_max, 'f', 3)); | |
96 | xmlWriter->writeTextElement("FG_MIN", QString::number(recipe->st_fg_min, 'f', 3)); | |
97 | xmlWriter->writeTextElement("FG_MAX", QString::number(recipe->st_fg_max, 'f', 3)); | |
98 | xmlWriter->writeTextElement("IBU_MIN", QString::number(recipe->st_ibu_min, 'f', 0)); | |
99 | xmlWriter->writeTextElement("IBU_MAX", QString::number(recipe->st_ibu_max, 'f', 0)); | |
100 | xmlWriter->writeTextElement("COLOR_MIN", QString::number(Utils::ebc_to_srm(recipe->st_color_min), 'f', 2)); | |
101 | xmlWriter->writeTextElement("COLOR_MAX", QString::number(Utils::ebc_to_srm(recipe->st_color_max), 'f', 2)); | |
102 | xmlWriter->writeTextElement("CARB_MIN", QString::number(recipe->st_carb_min, 'f', 1)); | |
103 | xmlWriter->writeTextElement("CARB_MAX", QString::number(recipe->st_carb_max, 'f', 1)); | |
104 | xmlWriter->writeTextElement("ABV_MIN", QString::number(recipe->st_abv_min, 'f', 1)); | |
105 | xmlWriter->writeTextElement("ABV_MAX", QString::number(recipe->st_abv_max, 'f', 1)); | |
106 | xmlWriter->writeEndElement(); // STYLE | |
107 | ||
108 | xmlWriter->writeStartElement("EQUIPMENT"); | |
109 | xmlWriter->writeTextElement("VERSION", "1"); | |
110 | xmlWriter->writeTextElement("NAME", "Dummy Brewery"); | |
111 | xmlWriter->writeTextElement("BATCH_SIZE", QString::number(recipe->batch_size, 'f', 2)); | |
112 | xmlWriter->writeTextElement("BOIL_SIZE", QString::number(recipe->boil_size, 'f', 2)); | |
113 | xmlWriter->writeTextElement("BOIL_TIME", QString::number(recipe->boil_time, 'f', 0)); | |
114 | xmlWriter->writeEndElement(); // EQUIPMENT | |
115 | ||
116 | xmlWriter->writeStartElement("HOPS"); | |
117 | for (int i = 0; i < recipe->hops.size(); i++) { | |
118 | xmlWriter->writeStartElement("HOP"); | |
119 | xmlWriter->writeTextElement("VERSION", "1"); | |
120 | xmlWriter->writeTextElement("NAME", recipe->hops.at(i).h_name); | |
121 | xmlWriter->writeTextElement("ALPHA", QString::number(recipe->hops.at(i).h_alpha, 'f', 1)); | |
122 | xmlWriter->writeTextElement("AMOUNT", QString::number(recipe->hops.at(i).h_amount, 'f', 4)); | |
123 | xmlWriter->writeTextElement("USE", hop_use[recipe->hops.at(i).h_useat]); | |
124 | xmlWriter->writeTextElement("TIME", QString::number(recipe->hops.at(i).h_time, 'f', 0)); | |
125 | xmlWriter->writeTextElement("TYPE", hop_types[recipe->hops.at(i).h_type]); | |
126 | xmlWriter->writeTextElement("FORM", hop_forms[recipe->hops.at(i).h_form]); | |
127 | xmlWriter->writeTextElement("BETA", QString::number(recipe->hops.at(i).h_beta, 'f', 1)); | |
128 | xmlWriter->writeTextElement("HSI", QString::number(recipe->hops.at(i).h_hsi, 'f', 1)); | |
129 | xmlWriter->writeTextElement("ORIGIN", recipe->hops.at(i).h_origin); | |
130 | xmlWriter->writeEndElement(); | |
131 | } | |
132 | xmlWriter->writeEndElement(); // HOPS | |
133 | ||
134 | xmlWriter->writeStartElement("FERMENTABLES"); | |
135 | for (int i = 0; i < recipe->fermentables.size(); i++) { | |
136 | xmlWriter->writeStartElement("FERMENTABLE"); | |
137 | xmlWriter->writeTextElement("VERSION", "1"); | |
138 | xmlWriter->writeTextElement("NAME", recipe->fermentables.at(i).f_name); | |
139 | xmlWriter->writeTextElement("TYPE", fermentable_type[recipe->fermentables.at(i).f_type]); | |
140 | xmlWriter->writeTextElement("AMOUNT", QString::number(recipe->fermentables.at(i).f_amount, 'f', 4)); | |
141 | xmlWriter->writeTextElement("YIELD", QString::number(recipe->fermentables.at(i).f_yield, 'f', 1)); | |
142 | xmlWriter->writeTextElement("COLOR", QString::number(Utils::ebc_to_srm(recipe->fermentables.at(i).f_color), 'f', 1)); | |
143 | xmlWriter->writeTextElement("ADD_AFTER_BOIL", recipe->fermentables.at(i).f_add_after_boil ? "TRUE":"FALSE"); | |
144 | xmlWriter->writeTextElement("ORIGIN", recipe->fermentables.at(i).f_origin); | |
145 | xmlWriter->writeTextElement("SUPPLIER", recipe->fermentables.at(i).f_supplier); | |
146 | if (recipe->fermentables.at(i).f_coarse_fine_diff) | |
147 | xmlWriter->writeTextElement("COARSE_FINE_DIFF", QString::number(recipe->fermentables.at(i).f_coarse_fine_diff, 'f', 4)); | |
148 | if (recipe->fermentables.at(i).f_moisture) | |
149 | xmlWriter->writeTextElement("MOISTURE", QString::number(recipe->fermentables.at(i).f_moisture, 'f', 4)); | |
150 | if (recipe->fermentables.at(i).f_diastatic_power) | |
151 | xmlWriter->writeTextElement("DIASTATIC_POWER", QString::number(recipe->fermentables.at(i).f_diastatic_power, 'f', 4)); | |
152 | if (recipe->fermentables.at(i).f_protein) | |
153 | xmlWriter->writeTextElement("PROTEIN", QString::number(recipe->fermentables.at(i).f_protein, 'f', 4)); | |
154 | if (recipe->fermentables.at(i).f_max_in_batch) | |
155 | xmlWriter->writeTextElement("MAX_IN_BATCH", QString::number(recipe->fermentables.at(i).f_max_in_batch, 'f', 1)); | |
156 | xmlWriter->writeTextElement("RECOMMEND_MASH", recipe->fermentables.at(i).f_recommend_mash ? "TRUE":"FALSE"); | |
157 | xmlWriter->writeTextElement("GRAINTYPE", fermentable_graintype[recipe->fermentables.at(i).f_graintype]); | |
158 | xmlWriter->writeEndElement(); | |
159 | } | |
160 | xmlWriter->writeEndElement(); // FERMENTABLES | |
161 | ||
162 | xmlWriter->writeStartElement("MISCS"); | |
163 | for (int i = 0; i < recipe->miscs.size(); i++) { | |
164 | xmlWriter->writeStartElement("MISC"); | |
165 | xmlWriter->writeTextElement("VERSION", "1"); | |
166 | xmlWriter->writeTextElement("NAME", recipe->miscs.at(i).m_name); | |
167 | xmlWriter->writeTextElement("TYPE", misc_type[recipe->miscs.at(i).m_type]); | |
168 | xmlWriter->writeTextElement("AMOUNT", QString::number(recipe->miscs.at(i).m_amount, 'f', 5)); | |
169 | xmlWriter->writeTextElement("AMOUNT_IS_WEIGHT", recipe->miscs.at(i).m_amount_is_weight ? "TRUE":"FALSE"); | |
170 | xmlWriter->writeTextElement("USE", misc_use[recipe->miscs.at(i).m_use_use]); | |
171 | xmlWriter->writeTextElement("TIME", QString::number(recipe->miscs.at(i).m_time, 'f', 0)); | |
172 | xmlWriter->writeEndElement(); | |
173 | } | |
174 | xmlWriter->writeEndElement(); // MISCS | |
175 | ||
176 | xmlWriter->writeStartElement("YEASTS"); | |
177 | for (int i = 0; i < recipe->yeasts.size(); i++) { | |
178 | xmlWriter->writeStartElement("YEAST"); | |
179 | xmlWriter->writeTextElement("VERSION", "1"); | |
180 | xmlWriter->writeTextElement("NAME", recipe->yeasts.at(i).y_name); | |
181 | xmlWriter->writeTextElement("TYPE", yeast_type[recipe->yeasts.at(i).y_type]); | |
182 | xmlWriter->writeTextElement("FORM", yeast_form[recipe->yeasts.at(i).y_form]); | |
183 | xmlWriter->writeTextElement("AMOUNT", QString::number(recipe->yeasts.at(i).y_amount, 'f', 5)); | |
184 | xmlWriter->writeTextElement("AMOUNT_IS_WEIGHT", (recipe->yeasts.at(i).y_form == 1) ? "TRUE":"FALSE"); | |
185 | xmlWriter->writeTextElement("LABORATORY", recipe->yeasts.at(i).y_laboratory); | |
186 | xmlWriter->writeTextElement("PRODUCT_ID", recipe->yeasts.at(i).y_product_id); | |
187 | xmlWriter->writeTextElement("MIN_TEMPERATURE", QString::number(recipe->yeasts.at(i).y_min_temperature, 'f', 1)); | |
188 | xmlWriter->writeTextElement("MAX_TEMPERATURE", QString::number(recipe->yeasts.at(i).y_max_temperature, 'f', 1)); | |
189 | xmlWriter->writeTextElement("ATTENUATION", QString::number(recipe->yeasts.at(i).y_attenuation, 'f', 1)); | |
190 | xmlWriter->writeTextElement("ADD_TO_SECONDARY", (recipe->yeasts.at(i).y_use == 0) ? "FALSE":"TRUE"); | |
191 | xmlWriter->writeEndElement(); | |
192 | } | |
193 | xmlWriter->writeEndElement(); // YEASTS | |
194 | ||
195 | xmlWriter->writeStartElement("WATERS"); | |
196 | if (recipe->w1_amount > 0) { | |
197 | xmlWriter->writeStartElement("WATER"); | |
198 | xmlWriter->writeTextElement("VERSION", "1"); | |
199 | xmlWriter->writeTextElement("NAME", recipe->w1_name); | |
200 | xmlWriter->writeTextElement("AMOUNT", QString::number(recipe->w1_amount, 'f', 2)); | |
201 | xmlWriter->writeTextElement("CALCIUM", QString::number(recipe->w1_calcium, 'f', 2)); | |
202 | xmlWriter->writeTextElement("MAGNESIUM", QString::number(recipe->w1_magnesium, 'f', 2)); | |
203 | xmlWriter->writeTextElement("BICARBONATE", QString::number(recipe->w1_total_alkalinity * 1.22, 'f', 2)); | |
204 | xmlWriter->writeTextElement("SULFATE", QString::number(recipe->w1_sulfate, 'f', 2)); | |
205 | xmlWriter->writeTextElement("CHLORIDE", QString::number(recipe->w1_chloride, 'f', 2)); | |
206 | xmlWriter->writeTextElement("SODIUM", QString::number(recipe->w1_sodium, 'f', 2)); | |
207 | xmlWriter->writeTextElement("PH", QString::number(recipe->w1_ph, 'f', 2)); | |
208 | xmlWriter->writeTextElement("TOTAL_ALKALINITY", QString::number(recipe->w1_total_alkalinity, 'f', 2)); | |
209 | xmlWriter->writeEndElement(); | |
210 | if (recipe->w2_amount > 0) { | |
211 | xmlWriter->writeStartElement("WATER"); | |
212 | xmlWriter->writeTextElement("VERSION", "1"); | |
213 | xmlWriter->writeTextElement("NAME", recipe->w2_name); | |
214 | xmlWriter->writeTextElement("AMOUNT", QString::number(recipe->w2_amount, 'f', 2)); | |
215 | xmlWriter->writeTextElement("CALCIUM", QString::number(recipe->w2_calcium, 'f', 2)); | |
216 | xmlWriter->writeTextElement("MAGNESIUM", QString::number(recipe->w2_magnesium, 'f', 2)); | |
217 | xmlWriter->writeTextElement("BICARBONATE", QString::number(recipe->w2_total_alkalinity * 1.22, 'f', 2)); | |
218 | xmlWriter->writeTextElement("SULFATE", QString::number(recipe->w2_sulfate, 'f', 2)); | |
219 | xmlWriter->writeTextElement("CHLORIDE", QString::number(recipe->w2_chloride, 'f', 2)); | |
220 | xmlWriter->writeTextElement("SODIUM", QString::number(recipe->w2_sodium, 'f', 2)); | |
221 | xmlWriter->writeTextElement("PH", QString::number(recipe->w2_ph, 'f', 2)); | |
222 | xmlWriter->writeTextElement("TOTAL_ALKALINITY", QString::number(recipe->w2_total_alkalinity, 'f', 2)); | |
223 | xmlWriter->writeEndElement(); | |
224 | } | |
225 | } | |
226 | xmlWriter->writeEndElement(); // WATERS | |
227 | ||
228 | xmlWriter->writeStartElement("MASH"); | |
229 | xmlWriter->writeTextElement("VERSION", "1"); | |
230 | xmlWriter->writeTextElement("NAME", recipe->mash_name); | |
231 | xmlWriter->writeTextElement("GRAIN_TEMP", "10.0"); | |
232 | xmlWriter->writeTextElement("PH", QString::number(recipe->sparge_ph, 'f', 2)); | |
233 | xmlWriter->writeTextElement("SPARGE_TEMP", QString::number(recipe->sparge_temp, 'f', 2)); | |
234 | xmlWriter->writeStartElement("MASH_STEPS"); | |
235 | for (int i = 0; i < recipe->mashs.size(); i++) { | |
236 | xmlWriter->writeStartElement("MASH_STEP"); | |
237 | xmlWriter->writeTextElement("VERSION", "1"); | |
238 | xmlWriter->writeTextElement("NAME", recipe->mashs.at(i).step_name); | |
239 | xmlWriter->writeTextElement("TYPE", step_type[recipe->mashs.at(i).step_type]); | |
240 | if (recipe->mashs.at(i).step_type == 0) { | |
241 | xmlWriter->writeTextElement("INFUSE_AMOUNT", QString::number(recipe->mashs.at(i).step_infuse_amount, 'f', 3)); | |
242 | xmlWriter->writeTextElement("INFUSE_TEMP", QString::number(recipe->mashs.at(i).step_infuse_temp, 'f', 3)); | |
243 | } | |
244 | if (recipe->mashs.at(i).step_type == 2) { | |
245 | xmlWriter->writeTextElement("DECOCTION_AMT", QString::number(recipe->mashs.at(i).step_infuse_amount, 'f', 3)); | |
246 | } | |
247 | xmlWriter->writeTextElement("STEP_TEMP", QString::number(recipe->mashs.at(i).step_temp, 'f', 1)); | |
248 | xmlWriter->writeTextElement("STEP_TIME", QString::number(recipe->mashs.at(i).step_time, 'f', 1)); | |
249 | xmlWriter->writeTextElement("RAMP_TIME", QString::number(recipe->mashs.at(i).ramp_time, 'f', 1)); | |
250 | xmlWriter->writeTextElement("END_TEMP", QString::number(recipe->mashs.at(i).end_temp, 'f', 1)); | |
251 | xmlWriter->writeTextElement("PH", QString::number(recipe->mash_ph, 'f', 1)); | |
252 | xmlWriter->writeEndElement(); | |
253 | } | |
254 | xmlWriter->writeEndElement(); // MASH_STEPS | |
255 | xmlWriter->writeEndElement(); // MASH | |
256 | xmlWriter->writeEndElement(); // RECIPE | |
257 | xmlWriter->writeEndElement(); // RECIPES | |
258 | xmlWriter->writeEndDocument(); | |
259 | QMessageBox::information(this, tr("Save File"), tr("XML export ready")); | |
260 | ||
261 | file.close(); | |
262 | } | |
263 | ||
264 | ||
265 | void EditRecipe::on_printButton_clicked() | |
266 | { | |
158
24bc2de721d9
Activated print recipe button. The recipe record structure is now global. Added global product record structure.
Michiel Broek <mbroek@mbse.eu>
parents:
157
diff
changeset
|
267 | PrinterDialog(PR_RECIPE, -1, this); |
157 | 268 | } |
269 | ||
270 |