diff -r b8232133a12d -r 49ec4fdee5a6 src/EditProductTab7.cpp --- a/src/EditProductTab7.cpp Wed May 11 22:26:15 2022 +0200 +++ b/src/EditProductTab7.cpp Thu May 12 14:34:53 2022 +0200 @@ -24,17 +24,19 @@ QWidget* pWidget; QHBoxLayout* pLayout; QTableWidgetItem *item; - QIcon down_icon, up_icon; + QIcon down_icon, up_icon, del_icon, ed_icon; qDebug() << "refreshMashs" << product->mashs.size(); down_icon.addFile(QString::fromUtf8(":/icons/silk/bullet_arrow_down.png"), QSize(), QIcon::Normal, QIcon::Off); up_icon.addFile(QString::fromUtf8(":/icons/silk/bullet_arrow_up.png"), QSize(), QIcon::Normal, QIcon::Off); + del_icon.addFile(QString::fromUtf8(":/icons/silk/delete.png"), QSize(), QIcon::Normal, QIcon::Off); + ed_icon.addFile(QString::fromUtf8(":/icons/silk/pencil.png"), QSize(), QIcon::Normal, QIcon::Off); const QStringList labels({tr("Step name"), tr("Type"), tr("Start"), tr("End"), tr("Rest"), tr("Ramp"), - tr("Inf/dec"), tr("Inf/dec"), tr("Volume"), tr("W/G ratio"), "", "", tr("Delete"), tr("Edit") }); + tr("Inf/dec"), tr("Inf/dec"), tr("Volume"), tr("W/G ratio"), tr("SG"), tr("pH"), "", "", "", "" }); - ui->mashsTable->setColumnCount(14); + ui->mashsTable->setColumnCount(16); ui->mashsTable->setColumnWidth(0, 189); /* Step name */ ui->mashsTable->setColumnWidth(1, 100); /* Type */ ui->mashsTable->setColumnWidth(2, 70); /* Start temp */ @@ -45,10 +47,12 @@ ui->mashsTable->setColumnWidth(7, 70); /* Infusion tmp */ ui->mashsTable->setColumnWidth(8, 70); /* Volume */ ui->mashsTable->setColumnWidth(9, 80); /* W/G ratio */ - ui->mashsTable->setColumnWidth(10, 30); /* Up button */ - ui->mashsTable->setColumnWidth(11, 30); /* Down button */ - ui->mashsTable->setColumnWidth(12, 80); /* Delete */ - ui->mashsTable->setColumnWidth(13, 80); /* Edit */ + ui->mashsTable->setColumnWidth(10, 50); /* SG */ + ui->mashsTable->setColumnWidth(11, 50); /* pH */ + ui->mashsTable->setColumnWidth(12, 30); /* Up button */ + ui->mashsTable->setColumnWidth(13, 30); /* Down button */ + ui->mashsTable->setColumnWidth(14, 30); /* Delete */ + ui->mashsTable->setColumnWidth(15, 30); /* Edit */ ui->mashsTable->setHorizontalHeaderLabels(labels); ui->mashsTable->verticalHeader()->hide(); ui->mashsTable->setRowCount(product->mashs.size()); @@ -97,6 +101,14 @@ item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->mashsTable->setItem(i, 9, item); + item = new QTableWidgetItem(QString("%1").arg(product->mashs.at(i).step_sg, 4, 'f', 3, '0')); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->mashsTable->setItem(i, 10, item); + + item = new QTableWidgetItem(QString("%1").arg(product->mashs.at(i).step_ph, 3, 'f', 2, '0')); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->mashsTable->setItem(i, 11, item); + if (i > 0) { pWidget = new QWidget(); QPushButton* btn_up = new QPushButton(); @@ -107,9 +119,9 @@ pLayout->addWidget(btn_up); pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); - ui->mashsTable->setCellWidget(i, 10, pWidget); + ui->mashsTable->setCellWidget(i, 12, pWidget); } else { - ui->mashsTable->removeCellWidget(i, 10); + ui->mashsTable->removeCellWidget(i, 12); } if (i < (product->mashs.size() - 1)) { @@ -122,32 +134,32 @@ pLayout->addWidget(btn_down); pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); - ui->mashsTable->setCellWidget(i, 11, pWidget); + ui->mashsTable->setCellWidget(i, 13, pWidget); } else { - ui->mashsTable->removeCellWidget(i, 11); + ui->mashsTable->removeCellWidget(i, 13); } pWidget = new QWidget(); - QPushButton* btn_dele = new QPushButton(); + QToolButton* btn_dele = new QToolButton(); btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */ - btn_dele->setText(tr("Delete")); + btn_dele->setIcon(del_icon); connect(btn_dele, SIGNAL(clicked()), this, SLOT(deleteMashRow_clicked())); pLayout = new QHBoxLayout(pWidget); pLayout->addWidget(btn_dele); pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); - ui->mashsTable->setCellWidget(i, 12, pWidget); + ui->mashsTable->setCellWidget(i, 14, pWidget); pWidget = new QWidget(); - QPushButton* btn_edit = new QPushButton(); + QToolButton* btn_edit = new QToolButton(); btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */ - btn_edit->setText(tr("Edit")); + btn_edit->setIcon(ed_icon); connect(btn_edit, SIGNAL(clicked()), this, SLOT(editMashRow_clicked())); pLayout = new QHBoxLayout(pWidget); pLayout->addWidget(btn_edit); pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); - ui->mashsTable->setCellWidget(i, 13, pWidget); + ui->mashsTable->setCellWidget(i, 15, pWidget); } } @@ -284,7 +296,7 @@ if (product->locked || product->mashs.size() < 1) return; - QPushButton *pb = qobject_cast(QObject::sender()); + QToolButton *pb = qobject_cast(QObject::sender()); int row = pb->objectName().toInt(); qDebug() << "Delete mash row" << row << product->mashs.size(); @@ -432,6 +444,87 @@ } +void EditProduct::stepph_changed(double val) +{ + qDebug() << "stepph_changed" << product->mashs_row << val; + + if (product->mashs.at(product->mashs_row).step_ph == 0) { + if (product->mashs_row == 0) { + /* + * Jump start at 5.0pH + */ + product->mashs[product->mashs_row].step_ph = 5.0; + } else { + /* + * Start with pH from previous step. + */ + product->mashs[product->mashs_row].step_ph = product->mashs.at(product->mashs_row - 1).step_ph; + } + const QSignalBlocker blocker1(stepphEdit); + stepphEdit->setValue(product->mashs.at(product->mashs_row).step_ph); + } else { + product->mashs[product->mashs_row].step_ph = val; + } + + QTableWidgetItem *item = new QTableWidgetItem(QString("%1").arg(product->mashs.at(product->mashs_row).step_ph, 3, 'f', 2, '0')); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->mashsTable->setItem(product->mashs_row, 11, item); + is_changed(); +} + + +void EditProduct::stepsg_changed(double val) +{ + qDebug() << "stepsg_changed" << product->mashs_row << val; + + if (product->mashs.at(product->mashs_row).step_sg == 0) { + if (product->mashs_row > 0) { + /* Start with value from previous step. */ + product->mashs[product->mashs_row].step_sg = product->mashs.at(product->mashs_row - 1).step_sg; + } else { + /* Start at 1.001 */ + product->mashs[product->mashs_row].step_sg = 1.001; + } + const QSignalBlocker blocker1(stepsgEdit); + stepsgEdit->setValue(product->mashs.at(product->mashs_row).step_sg); + } else { + product->mashs[product->mashs_row].step_sg = val; + } + const QSignalBlocker blocker2(brixEdit); + if (product->mashs.at(product->mashs_row).step_sg >= 1.000) + brixEdit->setValue(round(Utils::sg_to_brix(product->mashs.at(product->mashs_row).step_sg) * 10.0) / 10.0); + else + brixEdit->setValue(0); + qDebug() << "brix" << brixEdit->value(); + + QTableWidgetItem *item = new QTableWidgetItem(QString("%1").arg(product->mashs.at(product->mashs_row).step_sg, 4, 'f', 3, '0')); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->mashsTable->setItem(product->mashs_row, 10, item); + is_changed(); +} + + +void EditProduct::stepbrix_changed(double val) +{ + qDebug() << "stepbrix_changed" << product->mashs_row << val << "SG" << Utils::brix_to_sg(val); + + if ((product->mashs.at(product->mashs_row).step_sg == 0) && (product->mashs_row > 0)) { + /* If not thhe first step, and SG was not set, pickip previous step. */ + val = Utils::sg_to_brix(product->mashs.at(product->mashs_row - 1).step_sg); + const QSignalBlocker blocker2(brixEdit); + brixEdit->setValue(val); + } + product->mashs[product->mashs_row].step_sg = Utils::brix_to_sg(val); + const QSignalBlocker blocker1(stepsgEdit); + stepsgEdit->setValue(product->mashs.at(product->mashs_row).step_sg); + + QTableWidgetItem *item = new QTableWidgetItem(QString("%1").arg(product->mashs.at(product->mashs_row).step_sg, 4, 'f', 3, '0')); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->mashsTable->setItem(product->mashs_row, 10, item); + is_changed(); +} + + void EditProduct::editMashRow_clicked() { QSqlQuery query; @@ -439,16 +532,16 @@ if (product->locked) return; - QPushButton *pb = qobject_cast(QObject::sender()); + QToolButton *pb = qobject_cast(QObject::sender()); product->mashs_row = pb->objectName().toInt(); qDebug() << "Edit mash row" << product->mashs_row; Mashs backup = product->mashs.at(product->mashs_row); QDialog* dialog = new QDialog(this); - dialog->resize(738, 230); + dialog->resize(738, 290); QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); buttonBox->setObjectName(QString::fromUtf8("buttonBox")); - buttonBox->setGeometry(QRect(30, 180, 671, 32)); + buttonBox->setGeometry(QRect(30, 240, 671, 32)); buttonBox->setLayoutDirection(Qt::LeftToRight); buttonBox->setOrientation(Qt::Horizontal); buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); @@ -525,18 +618,67 @@ ramptimeEdit->setDecimals(0); ramptimeEdit->setValue(product->mashs.at(product->mashs_row).ramp_time); + QLabel *phLabel = new QLabel(dialog); + phLabel->setObjectName(QString::fromUtf8("phLabel")); + phLabel->setText(tr("Measured pH:")); + phLabel->setGeometry(QRect(10, 130, 141, 20)); + phLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + stepphEdit = new QDoubleSpinBox(dialog); + stepphEdit->setObjectName(QString::fromUtf8("phEdit")); + stepphEdit->setGeometry(QRect(160, 130, 121, 24)); + stepphEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + stepphEdit->setDecimals(2); + stepphEdit->setMaximum(14.0); + stepphEdit->setAccelerated(true); + stepphEdit->setSingleStep(0.1); + stepphEdit->setValue(product->mashs.at(product->mashs_row).step_ph); + + /* + * SG or Brix, both can be used to enter the SG. + */ + QLabel *brixLabel = new QLabel(dialog); + brixLabel->setObjectName(QString::fromUtf8("brixLabel")); + brixLabel->setText(tr("Measured Brix:")); + brixLabel->setGeometry(QRect(360, 130, 141, 20)); + brixLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + brixEdit = new QDoubleSpinBox(dialog); + brixEdit->setObjectName(QString::fromUtf8("brixEdit")); + brixEdit->setGeometry(QRect(510, 130, 121, 24)); + brixEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + brixEdit->setDecimals(1); + brixEdit->setMaximum(32); + brixEdit->setAccelerated(true); + brixEdit->setSingleStep(0.1); + + QLabel *sgLabel = new QLabel(dialog); + sgLabel->setObjectName(QString::fromUtf8("sgLabel")); + sgLabel->setText(tr("Measured SG:")); + sgLabel->setGeometry(QRect(360, 160, 141, 20)); + sgLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + stepsgEdit = new QDoubleSpinBox(dialog); + stepsgEdit->setObjectName(QString::fromUtf8("sgEdit")); + stepsgEdit->setGeometry(QRect(510, 160, 121, 24)); + stepsgEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + stepsgEdit->setDecimals(3); + stepsgEdit->setMaximum(1.5); + stepsgEdit->setAccelerated(true); + stepsgEdit->setSingleStep(0.001); + /* Make it smart, if zero then start with the previous step value. */ + stepsgEdit->setValue(product->mashs.at(product->mashs_row).step_sg); + brixEdit->setValue(Utils::sg_to_brix(product->mashs.at(product->mashs_row).step_sg)); + /* * Only used for Infusion steps. */ ivolLabel = new QLabel(dialog); ivolLabel->setObjectName(QString::fromUtf8("ivolLabel")); ivolLabel->setText(tr("Infusion volume:")); - ivolLabel->setGeometry(QRect(10, 130, 141, 20)); + ivolLabel->setGeometry(QRect(10, 190, 141, 20)); ivolLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); ivolLabel->setVisible(product->mashs.at(product->mashs_row).step_type == 0); stepivolEdit = new QDoubleSpinBox(dialog); stepivolEdit->setObjectName(QString::fromUtf8("stepivolEdit")); - stepivolEdit->setGeometry(QRect(160, 130, 121, 24)); + stepivolEdit->setGeometry(QRect(160, 190, 121, 24)); stepivolEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); stepivolEdit->setVisible(product->mashs.at(product->mashs_row).step_type == 0); stepivolEdit->setDecimals(1); @@ -548,12 +690,12 @@ itmpLabel = new QLabel(dialog); itmpLabel->setObjectName(QString::fromUtf8("itmpLabel")); itmpLabel->setText(tr("Infusion Temperature:")); - itmpLabel->setGeometry(QRect(360, 130, 141, 20)); + itmpLabel->setGeometry(QRect(360, 190, 141, 20)); itmpLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); itmpLabel->setVisible(product->mashs.at(product->mashs_row).step_type == 0); stepitmpEdit = new QDoubleSpinBox(dialog); stepitmpEdit->setObjectName(QString::fromUtf8("stepitmpEdit")); - stepitmpEdit->setGeometry(QRect(510, 130, 121, 24)); + stepitmpEdit->setGeometry(QRect(510, 190, 121, 24)); stepitmpEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); stepitmpEdit->setVisible(product->mashs.at(product->mashs_row).step_type == 0); stepitmpEdit->setDecimals(1); @@ -568,6 +710,9 @@ connect(steptimeEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::step_time_changed); connect(ramptimeEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::ramp_time_changed); connect(stepivolEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::infuse_changed); + connect(stepphEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::stepph_changed); + connect(stepsgEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::stepsg_changed); + connect(brixEdit, QOverload::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::stepbrix_changed); connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); @@ -595,6 +740,9 @@ disconnect(steptimeEdit, nullptr, nullptr, nullptr); disconnect(ramptimeEdit, nullptr, nullptr, nullptr); disconnect(stepivolEdit, nullptr, nullptr, nullptr); + disconnect(stepphEdit, nullptr, nullptr, nullptr); + disconnect(stepsgEdit, nullptr, nullptr, nullptr); + disconnect(brixEdit, nullptr, nullptr, nullptr); disconnect(buttonBox, nullptr, nullptr, nullptr); emit refreshAll();