576 QMessageBox::information(this, tr("Export to forum"), tr("The recipe and all data are copied to the clipboard.\n" |
576 QMessageBox::information(this, tr("Export to forum"), tr("The recipe and all data are copied to the clipboard.\n" |
577 "You can \"paste\" this data in the forum screen in your web browser.")); |
577 "You can \"paste\" this data in the forum screen in your web browser.")); |
578 } |
578 } |
579 |
579 |
580 |
580 |
|
581 void EditProduct::split_show() |
|
582 { |
|
583 double left = vol_availEdit->value(); |
|
584 |
|
585 qDebug() << "split_show" << product->splits.size(); |
|
586 const QSignalBlocker blocker1(splitTable); |
|
587 split_delButton->setEnabled(product->splits.size() > 0); |
|
588 |
|
589 for (int i = 0; i < product->splits.size(); i++) { |
|
590 |
|
591 qDebug() << i << product->splits.at(i).code << product->splits.at(i).name << QString::number(product->splits.at(i).size); |
|
592 splitTable->setItem(i, 0, new QTableWidgetItem(product->splits.at(i).code)); |
|
593 splitTable->setItem(i, 1, new QTableWidgetItem(product->splits.at(i).name)); |
|
594 splitTable->setItem(i, 2, new QTableWidgetItem(QString::number(product->splits.at(i).size, 'f', 1))); |
|
595 left -= product->splits.at(i).size; |
|
596 } |
|
597 |
|
598 if (left < 0) |
|
599 left = 0; |
|
600 vol_leftEdit->setValue(left); |
|
601 } |
|
602 |
|
603 |
|
604 void EditProduct::split_add_clicked() |
|
605 { |
|
606 Splits news; |
|
607 int entry = product->splits.size(); |
|
608 |
|
609 qDebug() << "split_add_clicked" << entry; |
|
610 |
|
611 news.name = product->name + QString(" %1").arg(entry + 1); |
|
612 news.code = product->code + QString("-%1").arg(entry + 1); |
|
613 news.size = 0; |
|
614 product->splits.append(news); |
|
615 splitTable->setRowCount(entry + 1); |
|
616 split_show(); |
|
617 } |
|
618 |
|
619 |
|
620 void EditProduct::split_del_clicked() |
|
621 { |
|
622 int last = product->splits.size() - 1; |
|
623 |
|
624 qDebug() << "split_del_clicked" << last; |
|
625 |
|
626 product->splits.removeAt(last); |
|
627 splitTable->setRowCount(last); |
|
628 split_show(); |
|
629 } |
|
630 |
|
631 |
|
632 void EditProduct::split_splitat_changed(int val) |
|
633 { |
|
634 qDebug() << "split_splitat_changed" << val; |
|
635 |
|
636 switch (val) { |
|
637 case 0: vol_availEdit->setValue(0); |
|
638 break; |
|
639 case 1: vol_availEdit->setValue(product->boil_size); |
|
640 break; |
|
641 case 2: vol_availEdit->setValue(product->batch_size); |
|
642 break; |
|
643 case 3: vol_availEdit->setValue(product->brew_fermenter_volume); |
|
644 break; |
|
645 case 4: |
|
646 case 5: vol_availEdit->setValue(round(product->brew_fermenter_volume * 9.2) / 10.0); // Estimate without trub |
|
647 break; |
|
648 case 6: vol_availEdit->setValue(product->package_volume); |
|
649 break; |
|
650 } |
|
651 product->divide_type = val; |
|
652 split_addButton->setEnabled(product->divide_type != 0); |
|
653 split_show(); |
|
654 } |
|
655 |
|
656 |
|
657 void EditProduct::split_table_changed(int nRow, int nCol) |
|
658 { |
|
659 qDebug() << "split_table_changed" << nRow << nCol; |
|
660 |
|
661 split_show(); |
|
662 } |
|
663 |
|
664 |
581 void EditProduct::splitProduct() |
665 void EditProduct::splitProduct() |
582 { |
666 { |
|
667 bool doit = false; |
|
668 |
|
669 if (this->textIsChanged) { |
|
670 DB_product::save(product, this); |
|
671 this->textIsChanged = false; |
|
672 } |
|
673 |
|
674 QDialog* dialog = new QDialog(this); |
|
675 dialog->setWindowTitle(tr("Split product")); |
|
676 |
|
677 dialog->setObjectName(QString::fromUtf8("SplitDialog")); |
|
678 dialog->resize(1024, 560); |
|
679 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); |
|
680 buttonBox->setObjectName(QString::fromUtf8("buttonBox")); |
|
681 buttonBox->setGeometry(QRect(30, 510, 961, 32)); |
|
682 buttonBox->setOrientation(Qt::Horizontal); |
|
683 buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); |
|
684 buttonBox->setCenterButtons(true); |
|
685 QLabel *topLabel = new QLabel(dialog); |
|
686 topLabel->setObjectName(QString::fromUtf8("topLabel")); |
|
687 topLabel->setGeometry(QRect(30, 20, 961, 31)); |
|
688 topLabel->setText(tr("Split product")); |
|
689 QFont font; |
|
690 font.setPointSize(12); |
|
691 font.setBold(true); |
|
692 font.setWeight(75); |
|
693 topLabel->setFont(font); |
|
694 topLabel->setAlignment(Qt::AlignCenter); |
|
695 |
|
696 QLabel *nameLabel = new QLabel(dialog); |
|
697 nameLabel->setObjectName(QString::fromUtf8("nameLabel")); |
|
698 nameLabel->setGeometry(QRect(20, 80, 141, 20)); |
|
699 nameLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
700 nameLabel->setText(tr("Product name:")); |
|
701 QLineEdit *nameEdit = new QLineEdit(dialog); |
|
702 nameEdit->setObjectName(QString::fromUtf8("nameEdit")); |
|
703 nameEdit->setGeometry(QRect(170, 80, 481, 23)); |
|
704 nameEdit->setReadOnly(true); |
|
705 nameEdit->setText(product->name); |
|
706 |
|
707 QLabel *codeLabel = new QLabel(dialog); |
|
708 codeLabel->setObjectName(QString::fromUtf8("codeLabel")); |
|
709 codeLabel->setGeometry(QRect(20, 110, 141, 20)); |
|
710 codeLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
711 codeLabel->setText(tr("Product code:")); |
|
712 QLineEdit *codeEdit = new QLineEdit(dialog); |
|
713 codeEdit->setObjectName(QString::fromUtf8("codeEdit")); |
|
714 codeEdit->setGeometry(QRect(170, 110, 113, 23)); |
|
715 codeEdit->setReadOnly(true); |
|
716 codeEdit->setText(product->code); |
|
717 |
|
718 QLabel *vol_availLabel = new QLabel(dialog); |
|
719 vol_availLabel->setObjectName(QString::fromUtf8("vol_availLabel")); |
|
720 vol_availLabel->setGeometry(QRect(20, 140, 141, 20)); |
|
721 vol_availLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
722 vol_availLabel->setText(tr("Available volume:")); |
|
723 |
|
724 QLabel *stageLabel = new QLabel(dialog); |
|
725 stageLabel->setObjectName(QString::fromUtf8("stageLabel")); |
|
726 stageLabel->setGeometry(QRect(660, 80, 141, 20)); |
|
727 stageLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
728 stageLabel->setText(tr("Current brew stage:")); |
|
729 QLineEdit *stageEdit = new QLineEdit(dialog); |
|
730 stageEdit->setObjectName(QString::fromUtf8("stageEdit")); |
|
731 stageEdit->setGeometry(QRect(810, 80, 113, 23)); |
|
732 stageEdit->setReadOnly(true); |
|
733 stageEdit->setText(prod_stages[product->stage]); |
|
734 |
|
735 QLabel *splitatLabel = new QLabel(dialog); |
|
736 splitatLabel->setObjectName(QString::fromUtf8("splitatLabel")); |
|
737 splitatLabel->setGeometry(QRect(660, 110, 141, 20)); |
|
738 splitatLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
739 splitatLabel->setText(tr("Split at moment:")); |
|
740 QLabel *vol_leftLabel = new QLabel(dialog); |
|
741 vol_leftLabel->setObjectName(QString::fromUtf8("vol_leftLabel")); |
|
742 vol_leftLabel->setGeometry(QRect(660, 140, 141, 20)); |
|
743 vol_leftLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
744 vol_leftLabel->setText(tr("Volume remaining:")); |
|
745 |
|
746 splitatEdit = new QComboBox(dialog); |
|
747 splitatEdit->setObjectName(QString::fromUtf8("splitatEdit")); |
|
748 splitatEdit->setGeometry(QRect(810, 110, 181, 23)); |
|
749 splitatEdit->addItem(tr("Not divided")); |
|
750 splitatEdit->addItem(tr("After mash")); |
|
751 splitatEdit->addItem(tr("After boil")); |
|
752 splitatEdit->addItem(tr("After cooling")); |
|
753 splitatEdit->addItem(tr("After primary")); |
|
754 splitatEdit->addItem(tr("After secondary")); |
|
755 splitatEdit->addItem(tr("After tertiary")); |
|
756 /* Disable items that have been done. */ |
|
757 if (product->stage > PROD_STAGE_BREW) { |
|
758 splitatEdit->setItemData(1, false, Qt::UserRole -1); |
|
759 splitatEdit->setItemData(2, false, Qt::UserRole -1); |
|
760 splitatEdit->setItemData(3, false, Qt::UserRole -1); |
|
761 } |
|
762 if (product->stage > PROD_STAGE_PRIMARY) { |
|
763 splitatEdit->setItemData(4, false, Qt::UserRole -1); |
|
764 } |
|
765 if (product->stage > PROD_STAGE_SECONDARY) { |
|
766 splitatEdit->setItemData(5, false, Qt::UserRole -1); |
|
767 } |
|
768 if (product->stage > PROD_STAGE_TERTIARY) { |
|
769 splitatEdit->setItemData(6, false, Qt::UserRole -1); |
|
770 } |
|
771 |
|
772 vol_leftEdit = new QDoubleSpinBox(dialog); |
|
773 vol_leftEdit->setObjectName(QString::fromUtf8("vol_leftEdit")); |
|
774 vol_leftEdit->setGeometry(QRect(810, 140, 111, 24)); |
|
775 vol_leftEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
776 vol_leftEdit->setReadOnly(true); |
|
777 vol_leftEdit->setButtonSymbols(QAbstractSpinBox::NoButtons); |
|
778 vol_leftEdit->setMaximum(1000000.000000000000000); |
|
779 vol_leftEdit->setSuffix(tr(" L")); |
|
780 vol_availEdit = new QDoubleSpinBox(dialog); |
|
781 vol_availEdit->setObjectName(QString::fromUtf8("vol_availEdit")); |
|
782 vol_availEdit->setGeometry(QRect(170, 140, 111, 24)); |
|
783 vol_availEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
784 vol_availEdit->setReadOnly(true); |
|
785 vol_availEdit->setButtonSymbols(QAbstractSpinBox::NoButtons); |
|
786 vol_availEdit->setMaximum(1000000.000000000000000); |
|
787 vol_availEdit->setSuffix(tr(" L")); |
|
788 |
|
789 const QStringList labels({tr("Split code"), tr("Split name"), tr("Split volume") }); |
|
790 splitTable = new QTableWidget(dialog); |
|
791 splitTable->setObjectName(QString::fromUtf8("splitTable")); |
|
792 splitTable->setGeometry(QRect(30, 220, 961, 281)); |
|
793 splitTable->setColumnCount(3); |
|
794 splitTable->setColumnWidth(0, 140); /* Split code */ |
|
795 splitTable->setColumnWidth(1, 680); /* Split name */ |
|
796 splitTable->setColumnWidth(2, 116); /* Split volume */ |
|
797 splitTable->setHorizontalHeaderLabels(labels); |
|
798 splitTable->verticalHeader()->hide(); |
|
799 splitTable->setRowCount(0); |
|
800 |
|
801 split_addButton = new QPushButton(dialog); |
|
802 split_addButton->setObjectName(QString::fromUtf8("addButton")); |
|
803 split_addButton->setGeometry(QRect(170, 180, 100, 23)); |
|
804 QIcon icon; |
|
805 icon.addFile(QString::fromUtf8("../resources/icons/silk/add.png"), QSize(), QIcon::Normal, QIcon::Off); |
|
806 split_addButton->setIcon(icon); |
|
807 split_addButton->setText(tr("Add")); |
|
808 split_addButton->setEnabled(product->divide_type != 0); |
|
809 |
|
810 split_delButton = new QPushButton(dialog); |
|
811 split_delButton->setObjectName(QString::fromUtf8("delButton")); |
|
812 split_delButton->setGeometry(QRect(660, 180, 100, 23)); |
|
813 QIcon icon2; |
|
814 icon2.addFile(QString::fromUtf8("../resources/icons/silk/delete.png"), QSize(), QIcon::Normal, QIcon::Off); |
|
815 split_delButton->setIcon(icon2); |
|
816 split_delButton->setText(tr("Delete")); |
|
817 split_delButton->setEnabled(false); |
|
818 |
|
819 QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); |
|
820 QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); |
|
821 connect(split_addButton, SIGNAL(clicked()), this, SLOT(split_add_clicked())); |
|
822 connect(split_delButton, SIGNAL(clicked()), this, SLOT(split_del_clicked())); |
|
823 connect(splitatEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditProduct::split_splitat_changed); |
|
824 connect(splitTable, SIGNAL(cellChanged(int, int)), this, SLOT(split_table_changed(int, int))); |
|
825 |
|
826 dialog->setModal(true); |
|
827 dialog->exec(); |
|
828 if (dialog->result() == QDialog::Accepted) { |
|
829 doit = true; |
|
830 } |
|
831 |
|
832 disconnect(buttonBox, nullptr, nullptr, nullptr); |
|
833 disconnect(splitatEdit, nullptr, nullptr, nullptr); |
|
834 disconnect(splitTable, nullptr, nullptr, nullptr); |
|
835 |
|
836 if (! doit) |
|
837 return; |
|
838 qInfo() << "split starts now"; |
|
839 |
|
840 /* Make sure the product editor is closed after splitting */ |
|
841 qInfo() << "split ready, destroy windows"; |
|
842 this->close(); |
|
843 this->setResult(1); |
583 } |
844 } |
584 |
845 |
585 |
846 |
586 void EditProduct::on_exportButton_clicked() |
847 void EditProduct::on_exportButton_clicked() |
587 { |
848 { |
601 beerxmlButton->setText(tr("Export to beerXML")); |
862 beerxmlButton->setText(tr("Export to beerXML")); |
602 QRadioButton *copy_productButton = new QRadioButton(dialog); |
863 QRadioButton *copy_productButton = new QRadioButton(dialog); |
603 copy_productButton->setObjectName(QString::fromUtf8("copy_productButton")); |
864 copy_productButton->setObjectName(QString::fromUtf8("copy_productButton")); |
604 copy_productButton->setGeometry(QRect(50, 50, 171, 21)); |
865 copy_productButton->setGeometry(QRect(50, 50, 171, 21)); |
605 copy_productButton->setText(tr("Copy to product")); |
866 copy_productButton->setText(tr("Copy to product")); |
606 /* QRadioButton *splitButton = new QRadioButton(dialog); |
|
607 splitButton->setObjectName(QString::fromUtf8("splitButton")); |
|
608 splitButton->setGeometry(QRect(50, 110, 171, 21)); |
|
609 splitButton->setText(tr("Split this batch")); */ |
|
610 QRadioButton *copy_recipeButton = new QRadioButton(dialog); |
867 QRadioButton *copy_recipeButton = new QRadioButton(dialog); |
611 copy_recipeButton->setObjectName(QString::fromUtf8("copy_recipeButton")); |
868 copy_recipeButton->setObjectName(QString::fromUtf8("copy_recipeButton")); |
612 copy_recipeButton->setGeometry(QRect(50, 80, 171, 21)); |
869 copy_recipeButton->setGeometry(QRect(50, 80, 171, 21)); |
613 copy_recipeButton->setText(tr("Copy to recipe")); |
870 copy_recipeButton->setText(tr("Copy to recipe")); |
614 QRadioButton *toforumButton = new QRadioButton(dialog); |
871 QRadioButton *toforumButton = new QRadioButton(dialog); |
615 toforumButton->setObjectName(QString::fromUtf8("toforumButton")); |
872 toforumButton->setObjectName(QString::fromUtf8("toforumButton")); |
616 toforumButton->setGeometry(QRect(50, 110, 171, 21)); |
873 toforumButton->setGeometry(QRect(50, 110, 171, 21)); |
617 toforumButton->setText(tr("Export to forum")); |
874 toforumButton->setText(tr("Export to forum")); |
|
875 QRadioButton *splitButton = new QRadioButton(dialog); |
|
876 splitButton->setObjectName(QString::fromUtf8("splitButton")); |
|
877 splitButton->setGeometry(QRect(50, 140, 171, 21)); |
|
878 splitButton->setText(tr("Split this batch")); |
618 |
879 |
619 QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); |
880 QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); |
620 QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); |
881 QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); |
621 |
882 |
622 dialog->setModal(true); |
883 dialog->setModal(true); |