Tue, 19 Apr 2022 11:17:16 +0200
First setup of the mash tab with the table.
/** * EditRecipe.cpp is part of bmsapp. * * tab 6, mash. * * bmsapp is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * bmsapp is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ void EditRecipe::refreshMashs() { QString w; QWidget* pWidget; QHBoxLayout* pLayout; QTableWidgetItem *item; qDebug() << "refreshYeasts" << recipe->yeasts.size(); std::sort(recipe->yeasts.begin(), recipe->yeasts.end(), yeast_sort_test); /* * During filling the table turn off the cellChanged signal because every cell that is filled * triggers the cellChanged signal. The QTableWidget has no better signal to use. */ this->ignoreChanges = true; 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") }); ui->mashsTable->setColumnCount(14); ui->mashsTable->setColumnWidth(0, 189); /* Step name */ ui->mashsTable->setColumnWidth(1, 100); /* Type */ ui->mashsTable->setColumnWidth(2, 70); /* Start temp */ ui->mashsTable->setColumnWidth(3, 70); /* End temp */ ui->mashsTable->setColumnWidth(4, 70); /* Rest time */ ui->mashsTable->setColumnWidth(5, 70); /* Ramp time */ ui->mashsTable->setColumnWidth(6, 70); /* Infusion vol */ 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->setHorizontalHeaderLabels(labels); ui->mashsTable->verticalHeader()->hide(); ui->mashsTable->setRowCount(recipe->mashs.size()); for (int i = 0; i < recipe->mashs.size(); i++) { ui->mashsTable->setItem(i, 0, new QTableWidgetItem(recipe->mashs.at(i).step_name)); item = new QTableWidgetItem(step_types[recipe->mashs.at(i).step_type]); item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); ui->mashsTable->setItem(i, 1, item); item = new QTableWidgetItem(QString("%1 °C").arg(recipe->mashs.at(i).step_temp, 2, 'f', 1, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->mashsTable->setItem(i, 2, item); item = new QTableWidgetItem(QString("%1 °C").arg(recipe->mashs.at(i).end_temp, 2, 'f', 1, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->mashsTable->setItem(i, 3, item); item = new QTableWidgetItem(QString("%1 min").arg(recipe->mashs.at(i).step_time, 1, 'f', 0, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->mashsTable->setItem(i, 4, item); item = new QTableWidgetItem(QString("%1 min").arg(recipe->mashs.at(i).ramp_time, 1, 'f', 0, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->mashsTable->setItem(i, 5, item); if (recipe->mashs.at(i).step_infuse_amount) { item = new QTableWidgetItem(QString("%1 L").arg(recipe->mashs.at(i).step_infuse_amount, 2, 'f', 1, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->mashsTable->setItem(i, 6, item); item = new QTableWidgetItem(QString("%1 °C").arg(recipe->mashs.at(i).step_infuse_temp, 3, 'f', 2, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->mashsTable->setItem(i, 7, item); } else { ui->mashsTable->removeCellWidget(i, 6); ui->mashsTable->removeCellWidget(i, 7); } item = new QTableWidgetItem(QString("%1 L").arg(recipe->mashs.at(i).step_volume, 2, 'f', 1, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->mashsTable->setItem(i, 8, item); item = new QTableWidgetItem(QString("%1 L/kg").arg(recipe->mashs.at(i).step_wg_ratio, 3, 'f', 2, '0')); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->mashsTable->setItem(i, 9, item); pWidget = new QWidget(); QPushButton* btn_up = new QPushButton(); btn_up->setObjectName(QString("%1").arg(i)); /* Send row with the button */ btn_up->setText(tr("U")); connect(btn_up, SIGNAL(clicked()), this, SLOT(upMashRow_clicked())); pLayout = new QHBoxLayout(pWidget); pLayout->addWidget(btn_up); pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); ui->mashsTable->setCellWidget(i, 10, pWidget); pWidget = new QWidget(); QPushButton* btn_down = new QPushButton(); btn_down->setObjectName(QString("%1").arg(i)); /* Send row with the button */ btn_down->setText(tr("D")); connect(btn_down, SIGNAL(clicked()), this, SLOT(downMashRow_clicked())); pLayout = new QHBoxLayout(pWidget); pLayout->addWidget(btn_down); pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); ui->mashsTable->setCellWidget(i, 11, pWidget); pWidget = new QWidget(); 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(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); pWidget = new QWidget(); 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(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); } } void EditRecipe::addMashRow_clicked() { } void EditRecipe::deleteMashRow_clicked() { } void EditRecipe::upMashRow_clicked() { } void EditRecipe::downMashRow_clicked() { } void EditRecipe::editMashRow_clicked() { }