src/EditProductTab11.cpp

changeset 283
242a68fa7186
parent 238
047e99c90848
child 297
c8f0ecc8a1cc
equal deleted inserted replaced
282:d1d208a857b0 283:242a68fa7186
113 * Sometimes bugs have good things. 113 * Sometimes bugs have good things.
114 */ 114 */
115 found1 = false; 115 found1 = false;
116 if (product->bottle_amount) { 116 if (product->bottle_amount) {
117 for (i = 0; i < product->fermentables.size(); i++) { 117 for (i = 0; i < product->fermentables.size(); i++) {
118 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_BOTTLE) { 118 if (product->fermentables.at(i).added == FERMENTABLE_ADDED_BOTTLE) {
119 found1 = true; 119 found1 = true;
120 break; 120 break;
121 } 121 }
122 } 122 }
123 if (found1) { 123 if (found1) {
124 SFactor = 1 / ((product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100)); 124 SFactor = 1 / ((product->fermentables.at(i).yield / 100) * (1 - product->fermentables.at(i).moisture / 100));
125 qDebug() << " bottle sugar" << product->fermentables.at(i).f_name << SFactor << TSec; 125 qDebug() << " bottle sugar" << product->fermentables.at(i).name << SFactor << TSec;
126 126
127 query.prepare("SELECT name,supplier FROM inventory_fermentables WHERE type = '1' OR type = '3' ORDER BY name"); // Sugars or dry extract 127 query.prepare("SELECT name,supplier FROM inventory_fermentables WHERE type = '1' OR type = '3' ORDER BY name"); // Sugars or dry extract
128 query.exec(); 128 query.exec();
129 j = 0; 129 j = 0;
130 found2 = false; 130 found2 = false;
131 while (query.next()) { 131 while (query.next()) {
132 j++; 132 j++;
133 if (query.value(0).toString() == product->fermentables.at(i).f_name && query.value(1).toString() == product->fermentables.at(i).f_supplier) { 133 if (query.value(0).toString() == product->fermentables.at(i).name && query.value(1).toString() == product->fermentables.at(i).supplier) {
134 ui->bottle_sugarEdit->setCurrentIndex(j); 134 ui->bottle_sugarEdit->setCurrentIndex(j);
135 product->bottle_priming_sugar = j; 135 product->bottle_priming_sugar = j;
136 found2 = true; 136 found2 = true;
137 break; 137 break;
138 } 138 }
143 refreshFermentables(); 143 refreshFermentables();
144 } else { 144 } else {
145 product->bottle_priming_amount = CarbCO2toS(product->bottle_carbonation, TSec, SFactor); 145 product->bottle_priming_amount = CarbCO2toS(product->bottle_carbonation, TSec, SFactor);
146 ui->bottle_sug_amountShow->setValue(product->bottle_priming_amount); 146 ui->bottle_sug_amountShow->setValue(product->bottle_priming_amount);
147 double total = round(product->bottle_priming_amount * product->bottle_amount * 100.0) / 100000.0; 147 double total = round(product->bottle_priming_amount * product->bottle_amount * 100.0) / 100000.0;
148 qDebug() << " total" << total << product->fermentables.at(i).f_amount; 148 qDebug() << " total" << total << product->fermentables.at(i).amount;
149 if (total != product->fermentables.at(i).f_amount) { 149 if (total != product->fermentables.at(i).amount) {
150 qDebug() << " update priming sugar" << total; 150 qDebug() << " update priming sugar" << total;
151 product->fermentables[i].f_amount = total; 151 product->fermentables[i].amount = total;
152 refreshFermentables(); 152 refreshFermentables();
153 is_changed(); 153 is_changed();
154 } 154 }
155 ui->bottle_sug_weightShow->setValue(total * 1000); 155 ui->bottle_sug_weightShow->setValue(total * 1000);
156 156
194 product->keg_pressure = Pressure; 194 product->keg_pressure = Pressure;
195 ui->keg_barShow->setValue(Pressure); 195 ui->keg_barShow->setValue(Pressure);
196 196
197 if (! product->keg_forced_carb) { 197 if (! product->keg_forced_carb) {
198 for (i = 0; i < product->fermentables.size(); i++) { 198 for (i = 0; i < product->fermentables.size(); i++) {
199 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_KEGS) { 199 if (product->fermentables.at(i).added == FERMENTABLE_ADDED_KEGS) {
200 found1 = true; 200 found1 = true;
201 break; 201 break;
202 } 202 }
203 } 203 }
204 if (found1) { 204 if (found1) {
205 SFactor = 1 / ((product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100)); 205 SFactor = 1 / ((product->fermentables.at(i).yield / 100) * (1 - product->fermentables.at(i).moisture / 100));
206 qDebug() << " kegs sugar" << product->fermentables.at(i).f_name << SFactor << TSec; 206 qDebug() << " kegs sugar" << product->fermentables.at(i).name << SFactor << TSec;
207 207
208 query.prepare("SELECT name,supplier FROM inventory_fermentables WHERE type = '1' OR type = '3' ORDER BY name"); // Sugars or dry extract 208 query.prepare("SELECT name,supplier FROM inventory_fermentables WHERE type = '1' OR type = '3' ORDER BY name"); // Sugars or dry extract
209 query.exec(); 209 query.exec();
210 j = 0; 210 j = 0;
211 found2 = false; 211 found2 = false;
212 while (query.next()) { 212 while (query.next()) {
213 j++; 213 j++;
214 if (query.value(0).toString() == product->fermentables.at(i).f_name && query.value(1).toString() == product->fermentables.at(i).f_supplier) { 214 if (query.value(0).toString() == product->fermentables.at(i).name && query.value(1).toString() == product->fermentables.at(i).supplier) {
215 ui->keg_sugarEdit->setCurrentIndex(j); 215 ui->keg_sugarEdit->setCurrentIndex(j);
216 product->keg_priming_sugar = j; 216 product->keg_priming_sugar = j;
217 found2 = true; 217 found2 = true;
218 break; 218 break;
219 } 219 }
224 refreshFermentables(); 224 refreshFermentables();
225 } else { 225 } else {
226 product->keg_priming_amount = CarbCO2toS(product->keg_carbonation, TSec, SFactor); 226 product->keg_priming_amount = CarbCO2toS(product->keg_carbonation, TSec, SFactor);
227 ui->keg_sug_amountShow->setValue(product->keg_priming_amount); 227 ui->keg_sug_amountShow->setValue(product->keg_priming_amount);
228 double total = round(product->keg_priming_amount * product->keg_amount * 100.0) / 100000.0; 228 double total = round(product->keg_priming_amount * product->keg_amount * 100.0) / 100000.0;
229 qDebug() << " total" << total << product->fermentables.at(i).f_amount; 229 qDebug() << " total" << total << product->fermentables.at(i).amount;
230 if (total != product->fermentables.at(i).f_amount) { 230 if (total != product->fermentables.at(i).amount) {
231 qDebug() << " update priming sugar" << total; 231 qDebug() << " update priming sugar" << total;
232 product->fermentables[i].f_amount = total; 232 product->fermentables[i].amount = total;
233 refreshFermentables(); 233 refreshFermentables();
234 is_changed(); 234 is_changed();
235 } 235 }
236 ui->keg_sug_weightShow->setValue(total * 1000); 236 ui->keg_sug_weightShow->setValue(total * 1000);
237 237
383 Fermentables newf; 383 Fermentables newf;
384 QSqlQuery query; 384 QSqlQuery query;
385 385
386 qDebug() << "bottle_sugar_changed" << product->bottle_priming_sugar << val; 386 qDebug() << "bottle_sugar_changed" << product->bottle_priming_sugar << val;
387 for (int i = 0; i < product->fermentables.size(); i++) { 387 for (int i = 0; i < product->fermentables.size(); i++) {
388 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_BOTTLE) { 388 if (product->fermentables.at(i).added == FERMENTABLE_ADDED_BOTTLE) {
389 product->fermentables.removeAt(i); 389 product->fermentables.removeAt(i);
390 refreshFermentables(); 390 refreshFermentables();
391 break; 391 break;
392 } 392 }
393 } 393 }
403 query.first(); 403 query.first();
404 for (int i = 0; i < (val - 1); i++) { 404 for (int i = 0; i < (val - 1); i++) {
405 query.next(); 405 query.next();
406 } 406 }
407 407
408 newf.f_name = query.value(0).toString(); 408 newf.name = query.value(0).toString();
409 newf.f_origin = query.value(1).toString(); 409 newf.origin = query.value(1).toString();
410 newf.f_supplier = query.value(2).toString(); 410 newf.supplier = query.value(2).toString();
411 newf.f_cost = query.value(3).toDouble(); 411 newf.cost = query.value(3).toDouble();
412 newf.f_type = query.value(4).toInt(); 412 newf.type = query.value(4).toInt();
413 newf.f_yield = query.value(5).toDouble(); 413 newf.yield = query.value(5).toDouble();
414 newf.f_color = query.value(6).toDouble(); 414 newf.color = query.value(6).toDouble();
415 newf.f_coarse_fine_diff = query.value(7).toDouble(); 415 newf.coarse_fine_diff = query.value(7).toDouble();
416 newf.f_moisture = query.value(8).toDouble(); 416 newf.moisture = query.value(8).toDouble();
417 newf.f_diastatic_power = query.value(9).toDouble(); 417 newf.diastatic_power = query.value(9).toDouble();
418 newf.f_protein = query.value(10).toDouble(); 418 newf.protein = query.value(10).toDouble();
419 newf.f_dissolved_protein = query.value(11).toDouble(); 419 newf.dissolved_protein = query.value(11).toDouble();
420 newf.f_max_in_batch = query.value(12).toDouble(); 420 newf.max_in_batch = query.value(12).toDouble();
421 newf.f_graintype = query.value(13).toInt(); 421 newf.graintype = query.value(13).toInt();
422 newf.f_recommend_mash = query.value(14).toInt() ? true:false; 422 newf.recommend_mash = query.value(14).toInt() ? true:false;
423 newf.f_add_after_boil = true; 423 newf.add_after_boil = true;
424 newf.f_di_ph = query.value(16).toDouble(); 424 newf.di_ph = query.value(16).toDouble();
425 newf.f_acid_to_ph_57 = query.value(17).toDouble(); 425 newf.acid_to_ph_57 = query.value(17).toDouble();
426 newf.f_inventory = query.value(18).toDouble(); 426 newf.inventory = query.value(18).toDouble();
427 newf.f_amount = 0; 427 newf.amount = 0;
428 newf.f_added = FERMENTABLE_ADDED_BOTTLE; 428 newf.added = FERMENTABLE_ADDED_BOTTLE;
429 429
430 product->fermentables.append(newf); 430 product->fermentables.append(newf);
431 refreshFermentables(); 431 refreshFermentables();
432 const QSignalBlocker blocker1(ui->bottle_sugarEdit); 432 const QSignalBlocker blocker1(ui->bottle_sugarEdit);
433 calcPack(); 433 calcPack();
481 Fermentables newf; 481 Fermentables newf;
482 QSqlQuery query; 482 QSqlQuery query;
483 483
484 qDebug() << "kegs_sugar_changed" << product->keg_priming_sugar << val; 484 qDebug() << "kegs_sugar_changed" << product->keg_priming_sugar << val;
485 for (int i = 0; i < product->fermentables.size(); i++) { 485 for (int i = 0; i < product->fermentables.size(); i++) {
486 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_KEGS) { 486 if (product->fermentables.at(i).added == FERMENTABLE_ADDED_KEGS) {
487 product->fermentables.removeAt(i); 487 product->fermentables.removeAt(i);
488 refreshFermentables(); 488 refreshFermentables();
489 break; 489 break;
490 } 490 }
491 } 491 }
501 query.first(); 501 query.first();
502 for (int i = 0; i < (val - 1); i++) { 502 for (int i = 0; i < (val - 1); i++) {
503 query.next(); 503 query.next();
504 } 504 }
505 505
506 newf.f_name = query.value(0).toString(); 506 newf.name = query.value(0).toString();
507 newf.f_origin = query.value(1).toString(); 507 newf.origin = query.value(1).toString();
508 newf.f_supplier = query.value(2).toString(); 508 newf.supplier = query.value(2).toString();
509 newf.f_cost = query.value(3).toDouble(); 509 newf.cost = query.value(3).toDouble();
510 newf.f_type = query.value(4).toInt(); 510 newf.type = query.value(4).toInt();
511 newf.f_yield = query.value(5).toDouble(); 511 newf.yield = query.value(5).toDouble();
512 newf.f_color = query.value(6).toDouble(); 512 newf.color = query.value(6).toDouble();
513 newf.f_coarse_fine_diff = query.value(7).toDouble(); 513 newf.coarse_fine_diff = query.value(7).toDouble();
514 newf.f_moisture = query.value(8).toDouble(); 514 newf.moisture = query.value(8).toDouble();
515 newf.f_diastatic_power = query.value(9).toDouble(); 515 newf.diastatic_power = query.value(9).toDouble();
516 newf.f_protein = query.value(10).toDouble(); 516 newf.protein = query.value(10).toDouble();
517 newf.f_dissolved_protein = query.value(11).toDouble(); 517 newf.dissolved_protein = query.value(11).toDouble();
518 newf.f_max_in_batch = query.value(12).toDouble(); 518 newf.max_in_batch = query.value(12).toDouble();
519 newf.f_graintype = query.value(13).toInt(); 519 newf.graintype = query.value(13).toInt();
520 newf.f_recommend_mash = query.value(14).toInt() ? true:false; 520 newf.recommend_mash = query.value(14).toInt() ? true:false;
521 newf.f_add_after_boil = true; 521 newf.add_after_boil = true;
522 newf.f_di_ph = query.value(16).toDouble(); 522 newf.di_ph = query.value(16).toDouble();
523 newf.f_acid_to_ph_57 = query.value(17).toDouble(); 523 newf.acid_to_ph_57 = query.value(17).toDouble();
524 newf.f_inventory = query.value(18).toDouble(); 524 newf.inventory = query.value(18).toDouble();
525 newf.f_amount = 0; 525 newf.amount = 0;
526 newf.f_added = FERMENTABLE_ADDED_KEGS; 526 newf.added = FERMENTABLE_ADDED_KEGS;
527 527
528 product->fermentables.append(newf); 528 product->fermentables.append(newf);
529 refreshFermentables(); 529 refreshFermentables();
530 const QSignalBlocker blocker1(ui->keg_sugarEdit); 530 const QSignalBlocker blocker1(ui->keg_sugarEdit);
531 calcPack(); 531 calcPack();
549 if (val) { 549 if (val) {
550 /* 550 /*
551 * Make sure to remove priming sugars. 551 * Make sure to remove priming sugars.
552 */ 552 */
553 for (int i = 0; i < product->fermentables.size(); i++) { 553 for (int i = 0; i < product->fermentables.size(); i++) {
554 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_KEGS) { 554 if (product->fermentables.at(i).added == FERMENTABLE_ADDED_KEGS) {
555 product->fermentables.removeAt(i); 555 product->fermentables.removeAt(i);
556 refreshFermentables(); 556 refreshFermentables();
557 break; 557 break;
558 } 558 }
559 } 559 }

mercurial