src/EditRecipe.cpp

changeset 133
08635b028dcf
parent 132
9ede9c75cb54
child 135
e68b27ad8a40
equal deleted inserted replaced
132:9ede9c75cb54 133:08635b028dcf
22 22
23 23
24 24
25 EditRecipe::EditRecipe(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditRecipe) 25 EditRecipe::EditRecipe(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditRecipe)
26 { 26 {
27 QSqlQuery query; 27 QSqlQuery query, wquery;
28 28
29 qDebug() << "EditRecipe record:" << id; 29 qDebug() << "EditRecipe record:" << id;
30 recipe = new Recipe; 30 recipe = new Recipe;
31 ui->setupUi(this); 31 ui->setupUi(this);
32 recipe->fermentables_row = recipe->hops_row = recipe->miscs_row = recipe->yeasts_row = recipe->mashs_row = -1; 32 recipe->fermentables_row = recipe->hops_row = recipe->miscs_row = recipe->yeasts_row = recipe->mashs_row = -1;
56 } 56 }
57 57
58 ui->sp_sourceEdit->addItem(tr("Source 1")); 58 ui->sp_sourceEdit->addItem(tr("Source 1"));
59 ui->sp_sourceEdit->addItem(tr("Source 2")); 59 ui->sp_sourceEdit->addItem(tr("Source 2"));
60 ui->sp_sourceEdit->addItem(tr("Mixed")); 60 ui->sp_sourceEdit->addItem(tr("Mixed"));
61
62 query.prepare("SELECT name FROM inventory_waters ORDER BY record");
63 query.exec();
64 query.first();
65 ui->w1_nameEdit->addItem("");
66 ui->w2_nameEdit->addItem("");
67 for (int i = 0; i < query.size(); i++) {
68 ui->w1_nameEdit->addItem(query.value(0).toString());
69 ui->w2_nameEdit->addItem(query.value(0).toString());
70 query.next();
71 }
61 72
62 ui->beerstyleEdit->addItem(""); // First add a dummy 73 ui->beerstyleEdit->addItem(""); // First add a dummy
63 query.prepare("SELECT style_guide,style_letter,name FROM profile_styles ORDER BY style_guide,style_letter,name"); 74 query.prepare("SELECT style_guide,style_letter,name FROM profile_styles ORDER BY style_guide,style_letter,name");
64 query.exec(); 75 query.exec();
65 query.first(); 76 query.first();
425 recipe->wa_acid_name = 0; 436 recipe->wa_acid_name = 0;
426 recipe->wa_acid_perc = 80; 437 recipe->wa_acid_perc = 80;
427 recipe->wa_base_name = 0; 438 recipe->wa_base_name = 0;
428 } 439 }
429 440
441 // Tab generic.
430 ui->lockedEdit->setChecked(recipe->locked); 442 ui->lockedEdit->setChecked(recipe->locked);
431 ui->st_nameEdit->setText(recipe->st_name); 443 ui->st_nameEdit->setText(recipe->st_name);
432 ui->st_groupEdit->setText(recipe->st_letter); 444 ui->st_groupEdit->setText(recipe->st_letter);
433 ui->st_guideEdit->setText(recipe->st_guide); 445 ui->st_guideEdit->setText(recipe->st_guide);
434 ui->st_catEdit->setText(recipe->st_category); 446 ui->st_catEdit->setText(recipe->st_category);
435 ui->st_catnrEdit->setText(QString("%1").arg(recipe->st_category_number)); 447 ui->st_catnrEdit->setText(QString("%1").arg(recipe->st_category_number));
436 ui->st_typeEdit->setText(s_types[recipe->st_type]); 448 ui->st_typeEdit->setText(s_types[recipe->st_type]);
437
438 ui->nameEdit->setText(recipe->name); 449 ui->nameEdit->setText(recipe->name);
439 ui->notesEdit->setPlainText(recipe->notes); 450 ui->notesEdit->setPlainText(recipe->notes);
440 ui->typeEdit->setCurrentIndex(recipe->type); 451 ui->typeEdit->setCurrentIndex(recipe->type);
441 ui->batch_sizeEdit->setValue(recipe->batch_size); 452 ui->batch_sizeEdit->setValue(recipe->batch_size);
442 ui->boil_sizeEdit->setValue(recipe->boil_size); 453 ui->boil_sizeEdit->setValue(recipe->boil_size);
443 ui->boil_timeEdit->setValue(recipe->boil_time); 454 ui->boil_timeEdit->setValue(recipe->boil_time);
444 ui->efficiencyEdit->setValue(recipe->efficiency); 455 ui->efficiencyEdit->setValue(recipe->efficiency);
445
446 ui->est_ogEdit->setValue(recipe->est_og); 456 ui->est_ogEdit->setValue(recipe->est_og);
447 ui->est_og2Edit->setValue(recipe->est_og);
448 ui->est_og3Edit->setValue(recipe->est_og);
449 ui->est_ogShow->setRange(recipe->st_og_min, recipe->st_og_max); 457 ui->est_ogShow->setRange(recipe->st_og_min, recipe->st_og_max);
450 ui->est_ogShow->setPrecision(3); 458 ui->est_ogShow->setPrecision(3);
451 ui->est_ogShow->setMarkerTextIsValue(true); 459 ui->est_ogShow->setMarkerTextIsValue(true);
452 ui->est_ogShow->setValue(recipe->est_og); 460 ui->est_ogShow->setValue(recipe->est_og);
453
454 ui->est_fgEdit->setValue(recipe->est_fg); 461 ui->est_fgEdit->setValue(recipe->est_fg);
455 ui->est_fg3Edit->setValue(recipe->est_fg);
456 ui->est_fgShow->setRange(recipe->st_fg_min, recipe->st_fg_max); 462 ui->est_fgShow->setRange(recipe->st_fg_min, recipe->st_fg_max);
457 ui->est_fgShow->setPrecision(3); 463 ui->est_fgShow->setPrecision(3);
458 ui->est_fgShow->setMarkerTextIsValue(true); 464 ui->est_fgShow->setMarkerTextIsValue(true);
459 ui->est_fgShow->setValue(recipe->est_fg); 465 ui->est_fgShow->setValue(recipe->est_fg);
460
461 ui->est_abvEdit->setValue(recipe->est_abv); 466 ui->est_abvEdit->setValue(recipe->est_abv);
462 ui->est_abv2Edit->setValue(recipe->est_abv);
463 ui->est_abvShow->setRange(recipe->st_abv_min, recipe->st_abv_max); 467 ui->est_abvShow->setRange(recipe->st_abv_min, recipe->st_abv_max);
464 ui->est_abvShow->setPrecision(1); 468 ui->est_abvShow->setPrecision(1);
465 ui->est_abvShow->setMarkerTextIsValue(true); 469 ui->est_abvShow->setMarkerTextIsValue(true);
466 ui->est_abvShow->setValue(recipe->est_abv); 470 ui->est_abvShow->setValue(recipe->est_abv);
467
468 ui->est_colorEdit->setValue(recipe->est_color); 471 ui->est_colorEdit->setValue(recipe->est_color);
469 ui->est_colorEdit->setStyleSheet(Utils::ebc_to_style(recipe->est_color)); 472 ui->est_colorEdit->setStyleSheet(Utils::ebc_to_style(recipe->est_color));
470 ui->est_color2Edit->setValue(recipe->est_color);
471 ui->est_color2Edit->setStyleSheet(Utils::ebc_to_style(recipe->est_color));
472 ui->est_colorShow->setPrecision(0); 473 ui->est_colorShow->setPrecision(0);
473 ui->est_colorShow->setMarkerTextIsValue(true); 474 ui->est_colorShow->setMarkerTextIsValue(true);
474 ui->est_colorShow->setRange(recipe->st_color_min, recipe->st_color_max); 475 ui->est_colorShow->setRange(recipe->st_color_min, recipe->st_color_max);
475 ui->est_colorShow->setValue(recipe->est_color); 476 ui->est_colorShow->setValue(recipe->est_color);
476
477 ui->color_methodEdit->setCurrentIndex(recipe->color_method); 477 ui->color_methodEdit->setCurrentIndex(recipe->color_method);
478
479 ui->est_ibuEdit->setValue(recipe->est_ibu); 478 ui->est_ibuEdit->setValue(recipe->est_ibu);
480 ui->est_ibu2Edit->setValue(recipe->est_ibu);
481 ui->est_ibuShow->setPrecision(0); 479 ui->est_ibuShow->setPrecision(0);
482 ui->est_ibuShow->setMarkerTextIsValue(true); 480 ui->est_ibuShow->setMarkerTextIsValue(true);
483 ui->est_ibuShow->setRange(recipe->st_ibu_min, recipe->st_ibu_max); 481 ui->est_ibuShow->setRange(recipe->st_ibu_min, recipe->st_ibu_max);
484 ui->est_ibuShow->setValue(recipe->est_ibu); 482 ui->est_ibuShow->setValue(recipe->est_ibu);
485
486 ui->ibu_methodEdit->setCurrentIndex(recipe->ibu_method); 483 ui->ibu_methodEdit->setCurrentIndex(recipe->ibu_method);
487
488 ui->est_carbEdit->setValue(recipe->est_carb); 484 ui->est_carbEdit->setValue(recipe->est_carb);
489 ui->est_carbShow->setPrecision(1); 485 ui->est_carbShow->setPrecision(1);
490 ui->est_carbShow->setMarkerTextIsValue(true); 486 ui->est_carbShow->setMarkerTextIsValue(true);
491 ui->est_carbShow->setRange(recipe->st_carb_min, recipe->st_carb_max); 487 ui->est_carbShow->setRange(recipe->st_carb_min, recipe->st_carb_max);
492 ui->est_carbShow->setValue(recipe->est_carb); 488 ui->est_carbShow->setValue(recipe->est_carb);
489
490 // Tab fermentables.
491 ui->est_og2Edit->setValue(recipe->est_og);
492 ui->est_color2Edit->setValue(recipe->est_color);
493 ui->est_color2Edit->setStyleSheet(Utils::ebc_to_style(recipe->est_color));
494
495 // Tab hops.
496 ui->est_ibu2Edit->setValue(recipe->est_ibu);
497
498 // Tab yeasts.
499 ui->est_og3Edit->setValue(recipe->est_og);
500 ui->est_fg3Edit->setValue(recipe->est_fg);
501 ui->est_abv2Edit->setValue(recipe->est_abv);
502
503 // Tab waters.
504 qDebug() << "water 1" << recipe->w1_name << "default" << my_default_water;
505 if (recipe->w1_ph > 4.0) {
506 /*
507 * Water data seems present, use that and set the name between []
508 */
509 ui->w1_nameEdit->setPlaceholderText(QString("["+recipe->w1_name+"]"));
510 } else {
511 bool found = false;
512 if (recipe->w1_name != "") {
513 /*
514 * We have a name, but do we know it?
515 */
516 query.prepare("SELECT * FROM inventory_waters WHERE name=:water");
517 query.bindValue(":water", recipe->w1_name);
518 query.exec();
519 found = query.first();
520 qDebug() << "found name" << recipe->w1_name << found;
521 }
522 if (!found) {
523 /*
524 * Try to load default water
525 */
526 query.prepare("SELECT * FROM inventory_waters WHERE record=:record");
527 query.bindValue(":record", my_default_water);
528 query.exec();
529 found = query.first();
530 qDebug() << "found record" << my_default_water << found;
531 }
532 if (found) {
533 qDebug() << "found record" << query.value(0).toInt();
534 recipe->w1_calcium = query.value(3).toDouble();
535 recipe->w1_magnesium = query.value(8).toDouble();
536 recipe->w1_total_alkalinity = query.value(11).toDouble();
537 recipe->w1_sodium = query.value(7).toDouble();
538 recipe->w1_chloride = query.value(6).toDouble();
539 recipe->w1_sulfate = query.value(5).toDouble();
540 recipe->w1_ph = query.value(9).toDouble();
541 ui->w1_nameEdit->setCurrentIndex(query.value(0).toInt());
542 } else {
543 recipe->w1_calcium = 0;
544 recipe->w1_magnesium = 0;
545 recipe->w1_total_alkalinity = 0;
546 recipe->w1_sodium = 0;
547 recipe->w1_chloride = 0;
548 recipe->w1_sulfate = 0;
549 recipe->w1_ph = 0;
550 }
551 }
552 ui->w1_volEdit->setValue(recipe->w1_amount);
553 ui->w1_caEdit->setValue(recipe->w1_calcium);
554 ui->w1_mgEdit->setValue(recipe->w1_magnesium);
555 ui->w1_hco3Edit->setValue(recipe->w1_total_alkalinity * 1.22);
556 ui->w1_caco3Edit->setValue(recipe->w1_total_alkalinity);
557 ui->w1_naEdit->setValue(recipe->w1_sodium);
558 ui->w1_clEdit->setValue(recipe->w1_chloride);
559 ui->w1_so4Edit->setValue(recipe->w1_sulfate);
560 ui->w1_phEdit->setValue(recipe->w1_ph);
561
562 qDebug() << "water 2" << recipe->w2_name;
563 if (recipe->w2_ph > 4.0) {
564 ui->w2_nameEdit->setPlaceholderText(QString("["+recipe->w2_name+"]"));
565 } else if (recipe->w2_name != "") {
566 query.prepare("SELECT * FROM inventory_waters WHERE name=:water");
567 query.bindValue(":water", recipe->w2_name);
568 query.exec();
569 if (query.first()) {
570 qDebug() << "found record" << query.value(0).toInt();
571 recipe->w2_calcium = query.value(3).toDouble();
572 recipe->w2_magnesium = query.value(8).toDouble();
573 recipe->w2_total_alkalinity = query.value(11).toDouble();
574 recipe->w2_sodium = query.value(7).toDouble();
575 recipe->w2_chloride = query.value(6).toDouble();
576 recipe->w2_sulfate = query.value(5).toDouble();
577 recipe->w2_ph = query.value(9).toDouble();
578 ui->w2_nameEdit->setCurrentIndex(query.value(0).toInt());
579 } else {
580 recipe->w2_calcium = 0;
581 recipe->w2_magnesium = 0;
582 recipe->w2_total_alkalinity = 0;
583 recipe->w2_sodium = 0;
584 recipe->w2_chloride = 0;
585 recipe->w2_sulfate = 0;
586 recipe->w2_ph = 0;
587 }
588 }
589 ui->w2_volEdit->setValue(recipe->w2_amount);
590 ui->w2_caEdit->setValue(recipe->w2_calcium);
591 ui->w2_mgEdit->setValue(recipe->w2_magnesium);
592 ui->w2_hco3Edit->setValue(recipe->w2_total_alkalinity * 1.22);
593 ui->w2_caco3Edit->setValue(recipe->w2_total_alkalinity);
594 ui->w2_naEdit->setValue(recipe->w2_sodium);
595 ui->w2_clEdit->setValue(recipe->w2_chloride);
596 ui->w2_so4Edit->setValue(recipe->w2_sulfate);
597 ui->w2_phEdit->setValue(recipe->w2_ph);
598
599 ui->sp_volEdit->setValue(recipe->sparge_volume);
600 ui->sp_tempEdit->setValue(recipe->sparge_temp);
601 ui->sp_phEdit->setValue(recipe->sparge_ph);
602 ui->sp_sourceEdit->setCurrentIndex(recipe->sparge_source);
603 ui->sp_acidtypeEdit->setCurrentIndex(recipe->sparge_acid_type);
604 ui->sp_acidpercEdit->setValue(recipe->sparge_acid_perc);
605 ui->sp_acidvolEdit->setValue(recipe->sparge_acid_amount);
493 606
494 // All signals from tab "Generic" 607 // All signals from tab "Generic"
495 connect(ui->lockedEdit, &QCheckBox::stateChanged, this, &EditRecipe::is_changed); 608 connect(ui->lockedEdit, &QCheckBox::stateChanged, this, &EditRecipe::is_changed);
496 connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditRecipe::name_changed); 609 connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditRecipe::name_changed);
497 connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(notes_changed())); 610 connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(notes_changed()));
525 // All signals from tab "Yeasts" 638 // All signals from tab "Yeasts"
526 639
527 // All signals from tab "Mash" 640 // All signals from tab "Mash"
528 641
529 // All signals from tab "Water" 642 // All signals from tab "Water"
643 connect(ui->bs_cacl2Edit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_cacl2_changed);
644 connect(ui->bs_caso4Edit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_caso4_changed);
645 connect(ui->bs_mgso4Edit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_mgso4_changed);
646 connect(ui->bs_naclEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_nacl_changed);
647 connect(ui->bs_mgcl2Edit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_mgcl2_changed);
648 connect(ui->bs_nahco3Edit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_nahco3_changed);
649 connect(ui->bs_caco3Edit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::on_caco3_changed);
530 650
531 ui->saveButton->setEnabled(false); 651 ui->saveButton->setEnabled(false);
532 ui->deleteButton->setEnabled((id >= 0) ? true:false); 652 ui->deleteButton->setEnabled((id >= 0) ? true:false);
533 653
534 emit refreshAll(); 654 emit refreshAll();
552 calcIBUs(); 672 calcIBUs();
553 refreshMiscs(); 673 refreshMiscs();
554 refreshYeasts(); 674 refreshYeasts();
555 refreshMashs(); 675 refreshMashs();
556 refreshWaters(); 676 refreshWaters();
677 calcWater();
557 } 678 }
558 679
559 680
560 /* 681 /*
561 * Window header, mark any change with '**' 682 * Window header, mark any change with '**'

mercurial