# HG changeset patch # User Michiel Broek # Date 1649795604 -7200 # Node ID 9ede9c75cb54da4417aba4d5d978937ce3b937d9 # Parent 0115b97e8c39b4044d1ea6f31b1fe65873c54504 Added miscs popup editor. No edit functions yet. Delete misc row added. diff -r 0115b97e8c39 -r 9ede9c75cb54 src/EditRecipe.cpp --- a/src/EditRecipe.cpp Tue Apr 12 21:03:19 2022 +0200 +++ b/src/EditRecipe.cpp Tue Apr 12 22:33:24 2022 +0200 @@ -29,7 +29,7 @@ qDebug() << "EditRecipe record:" << id; recipe = new Recipe; ui->setupUi(this); - recipe->fermentables_row = recipe->hops_row = recipe->misc_row = recipe->yeasts_row = recipe->mashs_row = -1; + recipe->fermentables_row = recipe->hops_row = recipe->miscs_row = recipe->yeasts_row = recipe->mashs_row = -1; recipe->fermentables_use100 = false; this->recno = id; diff -r 0115b97e8c39 -r 9ede9c75cb54 src/EditRecipe.h --- a/src/EditRecipe.h Tue Apr 12 21:03:19 2022 +0200 +++ b/src/EditRecipe.h Tue Apr 12 22:33:24 2022 +0200 @@ -231,7 +231,7 @@ int fermentables_row; ///< Current row, -1 is invalid. bool fermentables_use100; ///< Use percentages instead of amount int hops_row; - int misc_row; + int miscs_row; int yeasts_row; int mashs_row; double preboil_sg; @@ -280,12 +280,20 @@ void hop_select_changed(int val); void hop_instock_changed(bool val); void hop_useat_changed(int val); + void misc_amount_changed(double val); + void misc_time_changed(int val); + void misc_select_changed(int val); + void misc_instock_changed(bool val); + void misc_useat_changed(int val); void on_addFermentRow_clicked(); void on_deleteFermentRow_clicked(); void on_editFermentRow_clicked(); void on_addHopRow_clicked(); void on_deleteHopRow_clicked(); void on_editHopRow_clicked(); + void on_addMiscRow_clicked(); + void on_deleteMiscRow_clicked(); + void on_editMiscRow_clicked(); void on_perc_mash_valueChanged(int value); void on_perc_sugars_valueChanged(int value); @@ -320,12 +328,12 @@ /* * Variables for popup ingredients editing. */ - QComboBox *fselectEdit, *faddedEdit, *hselectEdit,*haddedEdit, *useatEdit; - QLineEdit *fnameEdit, *fsupplierEdit, *hnameEdit, *horiginEdit; - QDoubleSpinBox *famountEdit, *pctEdit, *fmaxEdit, *hamountEdit, *ibuEdit; - QSpinBox *htimeEdit; - QCheckBox *to100Edit, *finstockEdit, *hinstockEdit; - QLabel *htimeLabel; + QComboBox *fselectEdit, *faddedEdit, *hselectEdit,*haddedEdit, *useatEdit, *mselectEdit; + QLineEdit *fnameEdit, *fsupplierEdit, *hnameEdit, *horiginEdit, *mnameEdit; + QDoubleSpinBox *famountEdit, *pctEdit, *fmaxEdit, *hamountEdit, *ibuEdit, *mamountEdit; + QSpinBox *htimeEdit, *mtimeEdit; + QCheckBox *to100Edit, *finstockEdit, *hinstockEdit, *minstockEdit; + QLabel *htimeLabel, *mtimeLabel; void to100Fermentables(int row); static bool ferment_sort_test(const Fermentables &D1, const Fermentables &D2); diff -r 0115b97e8c39 -r 9ede9c75cb54 src/EditRecipeTab2.cpp --- a/src/EditRecipeTab2.cpp Tue Apr 12 21:03:19 2022 +0200 +++ b/src/EditRecipeTab2.cpp Tue Apr 12 22:33:24 2022 +0200 @@ -450,6 +450,7 @@ recipe->fermentables[i].f_percentage = recipe->fermentables.at(i).f_amount / total * 100; this->ignoreChanges = false; + is_changed(); emit refreshAll(); } diff -r 0115b97e8c39 -r 9ede9c75cb54 src/EditRecipeTab4.cpp --- a/src/EditRecipeTab4.cpp Tue Apr 12 21:03:19 2022 +0200 +++ b/src/EditRecipeTab4.cpp Tue Apr 12 22:33:24 2022 +0200 @@ -62,8 +62,6 @@ ui->miscsTable->verticalHeader()->hide(); ui->miscsTable->setRowCount(recipe->miscs.size()); - ui->mw_acidPick->setCurrentIndex(-1); - for (int i = 0; i < recipe->miscs.size(); i++) { ui->miscsTable->setItem(i, 0, new QTableWidgetItem(recipe->miscs.at(i).m_name)); @@ -105,7 +103,7 @@ QPushButton* btn_dele = new QPushButton(); btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */ btn_dele->setText(tr("Delete")); - connect(btn_dele, SIGNAL(clicked()), this, SLOT(on_deleteFermentRow_clicked())); + connect(btn_dele, SIGNAL(clicked()), this, SLOT(on_deleteMiscRow_clicked())); pLayout = new QHBoxLayout(pWidget); pLayout->addWidget(btn_dele); pLayout->setContentsMargins(5, 0, 5, 0); @@ -116,7 +114,7 @@ QPushButton* btn_edit = new QPushButton(); btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */ btn_edit->setText(tr("Edit")); - connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editFermentRow_clicked())); + connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editMiscRow_clicked())); pLayout = new QHBoxLayout(pWidget); pLayout->addWidget(btn_edit); pLayout->setContentsMargins(5, 0, 5, 0); @@ -169,6 +167,232 @@ } } } + this->ignoreChanges = false; +} + + +void EditRecipe::on_addMiscRow_clicked() +{ + Miscs newm; + + qDebug() << "Add misc row"; + + for (int i = 0; i < recipe->miscs.size(); i++) { + if (recipe->miscs.at(i).m_amount == 0) + return; // Add only one at a time. + } + + newm.m_name = "Select one"; + + + recipe->miscs.append(newm); + emit refreshAll(); +} + + +void EditRecipe::on_deleteMiscRow_clicked() +{ + QPushButton *pb = qobject_cast(QObject::sender()); + int row = pb->objectName().toInt(); + qDebug() << "Delete misc row" << row << recipe->miscs.size(); + + if (recipe->miscs.size() < 1) + return; + + int rc = QMessageBox::warning(this, tr("Delete misc"), tr("Delete %1").arg(recipe->miscs.at(row).m_name), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + if (rc == QMessageBox::No) + return; + + this->ignoreChanges = true; + recipe->miscs.removeAt(row); + this->ignoreChanges = false; + is_changed(); + emit refreshAll(); +} + + +void EditRecipe::misc_amount_changed(double val) +{ + +} + + +void EditRecipe::misc_time_changed(int val) +{ + +} + + +void EditRecipe::misc_select_changed(int val) +{ + QSqlQuery query; + bool instock = hinstockEdit->isChecked(); + QString w; + QTableWidgetItem *item; + + if (val < 1) + return; + + qDebug() << "misc_select_changed()" << recipe->fermentables_row << val << instock; + +} + + +void EditRecipe::misc_instock_changed(bool val) +{ + +} + + +void EditRecipe::misc_useat_changed(int val) +{ + } +void EditRecipe::on_editMiscRow_clicked() +{ + QSqlQuery query; + + QPushButton *pb = qobject_cast(QObject::sender()); + recipe->miscs_row = pb->objectName().toInt(); + qDebug() << "Edit misc row" << recipe->miscs_row; + Miscs backup = recipe->miscs.at(recipe->miscs_row); + + QDialog* dialog = new QDialog(this); + dialog->resize(738, 230); + QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); + buttonBox->setObjectName(QString::fromUtf8("buttonBox")); + buttonBox->setGeometry(QRect(30, 180, 671, 32)); + buttonBox->setLayoutDirection(Qt::LeftToRight); + buttonBox->setOrientation(Qt::Horizontal); + buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + buttonBox->setCenterButtons(true); + + QLabel *nameLabel = new QLabel(dialog); + nameLabel->setObjectName(QString::fromUtf8("nameLabel")); + nameLabel->setText(tr("Current ingredient:")); + nameLabel->setGeometry(QRect(10, 10, 141, 20)); + nameLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + + QLabel *amountLabel = new QLabel(dialog); + amountLabel->setObjectName(QString::fromUtf8("amountLabel")); + if (recipe->miscs.at(recipe->miscs_row).m_amount_is_weight) + amountLabel->setText(tr("Amount in gr:")); + else + amountLabel->setText(tr("Amount in ml:")); + amountLabel->setGeometry(QRect(10, 70, 141, 20)); + amountLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + + mtimeLabel = new QLabel(dialog); + mtimeLabel->setObjectName(QString::fromUtf8("mtimeLabel")); + if (recipe->miscs.at(recipe->miscs_row).m_use_use == 3 || recipe->miscs.at(recipe->miscs_row).m_use_use == 4) // Fermentation stages + mtimeLabel->setText(tr("Time in days:")); + else if (recipe->miscs.at(recipe->miscs_row).m_use_use == 2) // Boil + mtimeLabel->setText(tr("Time in minutes:")); + else + mtimeLabel->setText(""); + mtimeLabel->setGeometry(QRect(10, 100, 141, 20)); + mtimeLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + + QLabel *selectLabel = new QLabel(dialog); + selectLabel->setObjectName(QString::fromUtf8("selectLabel")); + selectLabel->setText(tr("Select ingredient:")); + selectLabel->setGeometry(QRect(10, 40, 141, 20)); + selectLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + QLabel *instockLabel = new QLabel(dialog); + instockLabel->setObjectName(QString::fromUtf8("instockLabel")); + instockLabel->setText(tr("In stock:")); + instockLabel->setGeometry(QRect(525, 40, 121, 20)); + instockLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + + mselectEdit = new QComboBox(dialog); + mselectEdit->setObjectName(QString::fromUtf8("selectEdit")); + mselectEdit->setGeometry(QRect(160, 40, 371, 23)); + + mnameEdit = new QLineEdit(dialog); + mnameEdit->setObjectName(QString::fromUtf8("mnameEdit")); + mnameEdit->setText(recipe->miscs.at(recipe->miscs_row).m_name); + mnameEdit->setGeometry(QRect(160, 10, 511, 23)); + mnameEdit->setReadOnly(true); + + mamountEdit = new QDoubleSpinBox(dialog); + mamountEdit->setObjectName(QString::fromUtf8("mamountEdit")); + mamountEdit->setGeometry(QRect(160, 70, 121, 24)); + mamountEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + mamountEdit->setAccelerated(true); + mamountEdit->setDecimals(1); + mamountEdit->setMaximum(1000000.0); + mamountEdit->setSingleStep(0.5); + mamountEdit->setValue(recipe->miscs.at(recipe->miscs_row).m_amount * 1000.0); + + mtimeEdit = new QSpinBox(dialog); + mtimeEdit->setObjectName(QString::fromUtf8("mtimeEdit")); + mtimeEdit->setGeometry(QRect(160, 100, 121, 24)); + mtimeEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + mtimeEdit->setAccelerated(true); + mtimeEdit->setMaximum(10000.0); + if (recipe->miscs.at(recipe->miscs_row).m_use_use == 3 || recipe->miscs.at(recipe->miscs_row).m_use_use == 4) { // Fermentation stages + mtimeEdit->setValue(recipe->miscs.at(recipe->miscs_row).m_time / 1440); + mtimeEdit->setReadOnly(false); + } else if (recipe->miscs.at(recipe->miscs_row).m_use_use == 2) { // Boil + mtimeEdit->setValue(recipe->miscs.at(recipe->miscs_row).m_time); + mtimeEdit->setReadOnly(false); + } else { + mtimeEdit->setReadOnly(true); + } + + useatEdit = new QComboBox(dialog); + useatEdit->setObjectName(QString::fromUtf8("useatEdit")); + useatEdit->setGeometry(QRect(160, 130, 161, 23)); + useatEdit->addItem(tr("Starter")); + useatEdit->addItem(tr("Mash")); + useatEdit->addItem(tr("Boil")); + useatEdit->addItem(tr("Primary")); + useatEdit->addItem(tr("Secondary")); + useatEdit->addItem(tr("Bottling")); + useatEdit->setCurrentIndex(recipe->miscs.at(recipe->miscs_row).m_use_use); + + minstockEdit = new QCheckBox(dialog); + minstockEdit->setObjectName(QString::fromUtf8("minstockEdit")); + minstockEdit->setGeometry(QRect(655, 40, 85, 21)); + minstockEdit->setChecked(true); + + misc_instock_changed(true); + + connect(mselectEdit, QOverload::of(&QComboBox::currentIndexChanged), this, &EditRecipe::misc_select_changed); + connect(mamountEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::misc_amount_changed); + connect(mtimeEdit, QOverload::of(&QSpinBox::valueChanged), this, &EditRecipe::misc_time_changed); + connect(useatEdit, QOverload::of(&QComboBox::currentIndexChanged), this, &EditRecipe::misc_useat_changed); + connect(minstockEdit, &QCheckBox::stateChanged, this, &EditRecipe::misc_instock_changed); + connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); + connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); + + dialog->setModal(true); + dialog->exec(); + if (dialog->result() == QDialog::Rejected) { + qDebug() << "reject and rollback"; + recipe->miscs[recipe->miscs_row] = backup; + } else { + /* Clear time if misc is not used for boil or fermentation. */ + if (! (recipe->miscs.at(recipe->miscs_row).m_use_use == 2 || + recipe->miscs.at(recipe->miscs_row).m_use_use == 3 || + recipe->miscs.at(recipe->miscs_row).m_use_use == 4)) { + if (recipe->miscs.at(recipe->miscs_row).m_time) { + recipe->miscs[recipe->miscs_row].m_time = 0; + is_changed(); + } + } + } + + disconnect(mselectEdit, nullptr, nullptr, nullptr); + disconnect(mamountEdit, nullptr, nullptr, nullptr); + disconnect(mtimeEdit, nullptr, nullptr, nullptr); + disconnect(useatEdit, nullptr, nullptr, nullptr); + disconnect(minstockEdit, nullptr, nullptr, nullptr); + disconnect(buttonBox, nullptr, nullptr, nullptr); + + emit refreshAll(); +} +