src/EditRecipe.cpp

changeset 125
2e79e0975e58
parent 124
ba26b19572ab
child 126
3c013ef88a00
equal deleted inserted replaced
124:ba26b19572ab 125:2e79e0975e58
486 connect(ui->perc_caraShow, &QProgressBar::valueChanged, this, &EditRecipe::on_perc_cara_valueChanged); 486 connect(ui->perc_caraShow, &QProgressBar::valueChanged, this, &EditRecipe::on_perc_cara_valueChanged);
487 connect(ui->lintnerShow, &QProgressBar::valueChanged, this, &EditRecipe::on_lintner_valueChanged); 487 connect(ui->lintnerShow, &QProgressBar::valueChanged, this, &EditRecipe::on_lintner_valueChanged);
488 connect(ui->addFermentable, SIGNAL(clicked()), this, SLOT(on_addFermentRow_clicked())); 488 connect(ui->addFermentable, SIGNAL(clicked()), this, SLOT(on_addFermentRow_clicked()));
489 489
490 // All signals from tab "Hops" 490 // All signals from tab "Hops"
491 connect(ui->hop_tasteShow, &QProgressBar::valueChanged, this, &EditRecipe::on_Flavour_valueChanged);
492 connect(ui->hop_aromaShow, &QProgressBar::valueChanged, this, &EditRecipe::on_Aroma_valueChanged);
491 // connect(ui->hopsTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int))); 493 // connect(ui->hopsTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int)));
492 494
493 // All signals from tab "Miscs" 495 // All signals from tab "Miscs"
494 // connect(ui->hopsTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int))); 496 // connect(ui->hopsTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int)));
495 497
641 } 643 }
642 this->ignoreChanges = false; 644 this->ignoreChanges = false;
643 } 645 }
644 646
645 647
648 bool EditRecipe::hop_sort_test(const Hops &D1, const Hops &D2)
649 {
650 return (D1.h_useat <= D2.h_useat ) && (D1.h_time >= D2.h_time) && (D1.h_amount >= D2.h_amount);
651 }
652
653
646 void EditRecipe::refreshHops() 654 void EditRecipe::refreshHops()
647 { 655 {
656 QString w;
657 QWidget* pWidget;
658 QHBoxLayout* pLayout;
659 QTableWidgetItem *item;
660
661 qDebug() << "refreshHops" << recipe->hops.size();
662 // std::sort(recipe->hops.begin(), recipe->hops.end(), hop_sort_test);
663
664 /*
665 * During filling the table turn off the cellChanged signal because every cell that is filled
666 * triggers the cellChanged signal. The QTableWidget has no better signal to use.
667 */
668 this->ignoreChanges = true;
669
670 const QStringList labels({tr("Origin"), tr("Hop"), tr("Type"), tr("Form"), tr("Alpha"), tr("Use at"), tr("Time"),
671 tr("IBU"), tr("Amount"), tr("Delete"), tr("Edit") });
672
673 ui->hopsTable->setColumnCount(11);
674 ui->hopsTable->setColumnWidth(0, 150); /* Origin */
675 ui->hopsTable->setColumnWidth(1, 225); /* Hop */
676 ui->hopsTable->setColumnWidth(2, 75); /* Type */
677 ui->hopsTable->setColumnWidth(3, 75); /* Form */
678 ui->hopsTable->setColumnWidth(4, 75); /* Alpha% */
679 ui->hopsTable->setColumnWidth(5, 75); /* Added */
680 ui->hopsTable->setColumnWidth(6, 75); /* Time */
681 ui->hopsTable->setColumnWidth(7, 60); /* IBU */
682 ui->hopsTable->setColumnWidth(8, 75); /* Amount */
683 ui->hopsTable->setColumnWidth(9, 80); /* Delete */
684 ui->hopsTable->setColumnWidth(10, 80); /* Edit */
685 ui->hopsTable->setHorizontalHeaderLabels(labels);
686 ui->hopsTable->verticalHeader()->hide();
687 ui->hopsTable->setRowCount(recipe->hops.size());
688
689 for (int i = 0; i < recipe->hops.size(); i++) {
690
691 ui->hopsTable->setItem(i, 0, new QTableWidgetItem(recipe->hops.at(i).h_origin));
692 ui->hopsTable->setItem(i, 1, new QTableWidgetItem(recipe->hops.at(i).h_name));
693
694 item = new QTableWidgetItem(h_types[recipe->hops.at(i).h_type]);
695 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
696 ui->hopsTable->setItem(i, 2, item);
697
698 item = new QTableWidgetItem(h_forms[recipe->hops.at(i).h_form]);
699 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
700 ui->hopsTable->setItem(i, 3, item);
701
702 item = new QTableWidgetItem(QString("%1%").arg(recipe->hops.at(i).h_alpha, 2, 'f', 1, '0'));
703 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
704 ui->hopsTable->setItem(i, 4, item);
705
706 item = new QTableWidgetItem(h_useat[recipe->hops.at(i).h_useat]);
707 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
708 ui->hopsTable->setItem(i, 5, item);
709
710 if (recipe->hops.at(i).h_useat == 2 || recipe->hops.at(i).h_useat == 4) { // Boil or whirlpool
711 item = new QTableWidgetItem(QString("%1 min.").arg(recipe->hops.at(i).h_time, 1, 'f', 0, '0'));
712 } else if (recipe->hops.at(i).h_useat == 5) { // Dry-hop
713 item = new QTableWidgetItem(QString("%1 days.").arg(recipe->hops.at(i).h_time / 1440, 1, 'f', 0, '0'));
714 } else {
715 item = new QTableWidgetItem(QString(""));
716 }
717 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
718 ui->hopsTable->setItem(i, 6, item);
719
720 double ibu = Utils::toIBU(recipe->hops.at(i).h_useat, recipe->hops.at(i).h_form, recipe->preboil_sg, recipe->batch_size, recipe->hops.at(i).h_amount,
721 recipe->hops.at(i).h_time, recipe->hops.at(i).h_alpha, recipe->ibu_method, 0, recipe->hops.at(i).h_time, 0);
722 item = new QTableWidgetItem(QString("%1").arg(ibu, 2, 'f', 1, '0'));
723 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
724 ui->hopsTable->setItem(i, 7, item);
725
726 if (recipe->hops.at(i).h_amount < 1.0) {
727 item = new QTableWidgetItem(QString("%1 gr").arg(recipe->hops.at(i).h_amount * 1000.0, 2, 'f', 1, '0'));
728 } else {
729 item = new QTableWidgetItem(QString("%1 kg").arg(recipe->hops.at(i).h_amount, 4, 'f', 3, '0'));
730 }
731 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
732 ui->hopsTable->setItem(i, 8, item);
733
734 /* Add the Delete row button */
735 pWidget = new QWidget();
736 QPushButton* btn_dele = new QPushButton();
737 btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */
738 btn_dele->setText(tr("Delete"));
739 connect(btn_dele, SIGNAL(clicked()), this, SLOT(on_deleteHopRow_clicked()));
740 pLayout = new QHBoxLayout(pWidget);
741 pLayout->addWidget(btn_dele);
742 pLayout->setContentsMargins(5, 0, 5, 0);
743 pWidget->setLayout(pLayout);
744 ui->hopsTable->setCellWidget(i, 9, pWidget);
745
746 pWidget = new QWidget();
747 QPushButton* btn_edit = new QPushButton();
748 btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */
749 btn_edit->setText(tr("Edit"));
750 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editHopRow_clicked()));
751 pLayout = new QHBoxLayout(pWidget);
752 pLayout->addWidget(btn_edit);
753 pLayout->setContentsMargins(5, 0, 5, 0);
754 pWidget->setLayout(pLayout);
755 ui->hopsTable->setCellWidget(i, 10, pWidget);
756 }
757 this->ignoreChanges = false;
758 }
759
760
761 void EditRecipe::on_Flavour_valueChanged(int value)
762 {
763 if (value < 20) {
764 ui->hop_tasteShow->setStyleSheet(bar_20);
765 ui->hop_tasteShow->setFormat(tr("Very low"));
766 } else if (value < 40) {
767 ui->hop_tasteShow->setStyleSheet(bar_40);
768 ui->hop_tasteShow->setFormat(tr("Low"));
769 } else if (value < 60) {
770 ui->hop_tasteShow->setStyleSheet(bar_60);
771 ui->hop_tasteShow->setFormat(tr("Moderate"));
772 } else if (value < 80) {
773 ui->hop_tasteShow->setStyleSheet(bar_80);
774 ui->hop_tasteShow->setFormat(tr("High"));
775 } else {
776 ui->hop_tasteShow->setStyleSheet(bar_100);
777 ui->hop_tasteShow->setFormat(tr("Very high"));
778 }
779 }
780
781
782 void EditRecipe::on_Aroma_valueChanged(int value)
783 {
784 if (value < 20) {
785 ui->hop_aromaShow->setStyleSheet(bar_20);
786 ui->hop_aromaShow->setFormat(tr("Very low"));
787 } else if (value < 40) {
788 ui->hop_aromaShow->setStyleSheet(bar_40);
789 ui->hop_aromaShow->setFormat(tr("Low"));
790 } else if (value < 60) {
791 ui->hop_aromaShow->setStyleSheet(bar_60);
792 ui->hop_aromaShow->setFormat(tr("Moderate"));
793 } else if (value < 80) {
794 ui->hop_aromaShow->setStyleSheet(bar_80);
795 ui->hop_aromaShow->setFormat(tr("High"));
796 } else {
797 ui->hop_aromaShow->setStyleSheet(bar_100);
798 ui->hop_aromaShow->setFormat(tr("Very high"));
799 }
800 }
801
802
803 void EditRecipe::calcIBUs()
804 {
805 double hop_flavour = 0, hop_aroma = 0, ibus = 0;
806
807 for (int i = 0; i < recipe->hops.size(); i++) {
808
809 ibus += Utils::toIBU(recipe->hops.at(i).h_useat, recipe->hops.at(i).h_form, recipe->preboil_sg, recipe->batch_size, recipe->hops.at(i).h_amount,
810 recipe->hops.at(i).h_time, recipe->hops.at(i).h_alpha, recipe->ibu_method, 0, recipe->hops.at(i).h_time, 0);
811 hop_flavour += Utils::hopFlavourContribution(recipe->hops.at(i).h_time, recipe->batch_size, recipe->hops.at(i).h_useat, recipe->hops.at(i).h_amount);
812 hop_aroma += Utils::hopAromaContribution(recipe->hops.at(i).h_time, recipe->batch_size, recipe->hops.at(i).h_useat, recipe->hops.at(i).h_amount);
813 }
814
815 hop_flavour = round(hop_flavour * 1000.0 / 5.0) / 10;
816 hop_aroma = round(hop_aroma * 1000.0 / 6.0) / 10;
817 if (hop_flavour > 100)
818 hop_flavour = 100;
819 if (hop_aroma > 100)
820 hop_aroma = 100;
821 qDebug() << "ibu" << recipe->est_ibu << ibus << "flavour" << hop_flavour << "aroma" << hop_aroma;
822
823 recipe->est_ibu = ibus;
824 ui->est_ibuEdit->setValue(recipe->est_ibu);
825 ui->est_ibu2Edit->setValue(recipe->est_ibu);
826 ui->hop_tasteShow->setValue(hop_flavour);
827 ui->hop_aromaShow->setValue(hop_aroma);
648 } 828 }
649 829
650 830
651 void EditRecipe::refreshMiscs() 831 void EditRecipe::refreshMiscs()
652 { 832 {
664 844
665 845
666 void EditRecipe::refreshAll() 846 void EditRecipe::refreshAll()
667 { 847 {
668 refreshFermentables(); 848 refreshFermentables();
669 849 calcFermentables(); /* Must be before Hops */
670 calcFermentables(); 850 refreshHops();
851 calcIBUs();
852 refreshMiscs();
853 refreshYeasts();
854 refreshMashs();
671 } 855 }
672 856
673 857
674 void EditRecipe::calcFermentables() 858 void EditRecipe::calcFermentables()
675 { 859 {
787 ui->est_ogEdit->setValue(og); 971 ui->est_ogEdit->setValue(og);
788 ui->est_og2Edit->setValue(og); 972 ui->est_og2Edit->setValue(og);
789 ui->est_og3Edit->setValue(og); 973 ui->est_og3Edit->setValue(og);
790 ui->est_ogShow->setValue(og); 974 ui->est_ogShow->setValue(og);
791 975
792 double preboil_sg = Utils::estimate_sg(sugarsm, ui->boil_sizeEdit->value()); 976 recipe->preboil_sg = Utils::estimate_sg(sugarsm, ui->boil_sizeEdit->value());
793 qDebug() << " preboil SG" << preboil_sg; 977 qDebug() << " preboil SG" << recipe->preboil_sg;
794 978
795 /* 979 /*
796 * Color of the wort 980 * Color of the wort
797 */ 981 */
798 if (ui->color_methodEdit->currentIndex() == 4) { // Naudts 982 if (ui->color_methodEdit->currentIndex() == 4) { // Naudts

mercurial