src/EditProductTab9.cpp

changeset 209
19c50b1f58d3
parent 207
3b164a0aea90
child 210
b45bd6da5220
equal deleted inserted replaced
208:615afedbcd25 209:19c50b1f58d3
131 } 131 }
132 is_changed(); 132 is_changed();
133 } 133 }
134 134
135 135
136 void EditProduct::calcEfficiencyBeforeBoil()
137 {
138 double m = 0;
139 double tot;
140 double result = 0;
141
142 if (product->fermentables.size() == 0)
143 return; // no fermentables loaded yet
144 for (int i = 0; i < product->fermentables.size(); i++) {
145 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_MASH) {
146 m += product->fermentables.at(i).f_amount * (product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100);
147 }
148 }
149 tot = Utils::sg_to_plato(product->brew_preboil_sg) * (product->brew_preboil_volume / 1.04) * product->brew_preboil_sg * 10 / 1000;
150
151 if (m > 0)
152 result = round((tot / m * 100) * 10.0) / 10.0;
153
154 if (result < 0)
155 result = 0;
156 ui->brew_preboileffShow->setValue(result);
157 }
158
159
160 void EditProduct::brew_preboilsg_changed(double val)
161 {
162 if (product->brew_preboil_sg == 0) {
163 product->brew_preboil_sg = product->preboil_sg;
164 const QSignalBlocker blocker1(ui->brew_preboilsgEdit);
165 ui->brew_preboilsgEdit->setValue(product->preboil_sg);
166 } else {
167 product->brew_preboil_sg = val;
168 }
169 is_changed();
170 calcEfficiencyBeforeBoil();
171 }
172
173
174 void EditProduct::brew_preboilvol_changed(double val)
175 {
176 if (product->brew_preboil_volume == 0) {
177 product->brew_preboil_volume = product->boil_size * 1.04;
178 const QSignalBlocker blocker1(ui->brew_preboilvolEdit);
179 ui->brew_preboilvolEdit->setValue(product->boil_size * 1.04);
180 } else {
181 product->brew_preboil_volume = val;
182 }
183 is_changed();
184 calcEfficiencyBeforeBoil();
185 }
186
187
136 void EditProduct::brew_aboilph_changed(double val) 188 void EditProduct::brew_aboilph_changed(double val)
137 { 189 {
138 if (product->brew_aboil_ph == 0) { 190 if (product->brew_aboil_ph == 0) {
139 product->brew_aboil_ph = 4.8; 191 product->brew_aboil_ph = 4.8;
140 const QSignalBlocker blocker1(ui->brew_aboilphEdit); 192 const QSignalBlocker blocker1(ui->brew_aboilphEdit);
144 } 196 }
145 is_changed(); 197 is_changed();
146 } 198 }
147 199
148 200
201 void EditProduct::calcEfficiencyAfterBoil()
202 {
203 double m = 0; // Sugars added at mash
204 double b = 0; // Sugars added at boil
205 double result = 0;
206
207 if (product->fermentables.size() == 0)
208 return; // no fermentables loaded yet
209 for (int i = 0; i < product->fermentables.size(); i++) {
210 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_MASH) {
211 m += product->fermentables.at(i).f_amount * (product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100);
212 } else if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_BOIL) {
213 b += product->fermentables.at(i).f_amount * (product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100);
214 }
215 }
216 double tot = Utils::sg_to_plato(product->brew_aboil_sg) * (product->brew_aboil_volume / 1.04) * product->brew_aboil_sg * 10 / 1000;
217 tot -= b; // total sugars in wort minus added sugars.
218
219 if (m > 0)
220 result = round((tot / m * 100) * 10.0) / 10.0;
221 product->brew_aboil_efficiency = result;
222 ui->brew_aboileffShow->setValue(result);
223 calcFermentables(); // This will also recalculate all volumes.
224 }
225
226
227 void EditProduct::brew_aboilsg_changed(double val)
228 {
229 if (product->brew_aboil_sg == 0) {
230 product->brew_aboil_sg = product->est_og3;
231 const QSignalBlocker blocker1(ui->brew_aboilsgEdit);
232 ui->brew_aboilsgEdit->setValue(product->est_og3);
233 } else {
234 product->brew_aboil_sg = val;
235 }
236 is_changed();
237 calcEfficiencyAfterBoil();
238 }
239
240
241 void EditProduct::brew_aboilvol_changed(double val)
242 {
243 if (product->brew_aboil_volume == 0) {
244 product->brew_aboil_volume = product->batch_size * 1.04;
245 const QSignalBlocker blocker1(ui->brew_aboilvolEdit);
246 ui->brew_aboilvolEdit->setValue(product->batch_size * 1.04);
247 } else {
248 product->brew_aboil_volume = val;
249 }
250 is_changed();
251 calcEfficiencyAfterBoil();
252 }
253
254

mercurial